示例#1
0
def convert_nodes_to_marker_data_list(cam_tfm, cam_shp, nodes, start_frame,
                                      end_frame):
    # Create nodes and objects for loop.
    node_pairs = []
    reproj_nodes = []
    mkr_data_list = []
    for node in nodes:
        reproj = reproject_utils.create_reprojection_on_camera(
            cam_tfm, cam_shp)
        reproject_utils.connect_transform_to_reprojection(node, reproj)
        reproj_nodes.append(reproj)

        mkr_data = loadmkr_interface.MarkerData()
        mkr_data.set_name(node)
        mkr_data_list.append(mkr_data)

        node_pairs.append((node, reproj, mkr_data))

    # Query Screen-space coordinates across time for all nodes
    cur_time = maya.cmds.currentTime(query=True)
    for f in xrange(start_frame, end_frame + 1):
        maya.cmds.currentTime(f, edit=True, update=True)
        for node, reproj, mkr_data in node_pairs:
            node_attr = reproj + '.outNormCoord'
            mkr_u = maya.cmds.getAttr(node_attr + 'X')
            mkr_v = maya.cmds.getAttr(node_attr + 'Y')
            mkr_enable = True
            mkr_weight = 1.0

            mkr_data.weight.set_value(f, mkr_weight)
            mkr_data.enable.set_value(f, mkr_enable)
            mkr_data.x.set_value(f, mkr_u)
            mkr_data.y.set_value(f, mkr_v)

    if len(reproj_nodes) > 0:
        maya.cmds.delete(reproj_nodes)

    maya.cmds.currentTime(cur_time, edit=True, update=True)
    return mkr_data_list
示例#2
0
def main():
    """
    Center the selected transform onto the camera view.

    .. todo::

        - Allow 2D Center on selected vertices.

        - Support Stereo-camera setups (center both cameras, and ensure
          both have the same zoom).

        - Allow centering on multiple objects at once. We will center
          on the middle of all transforms.

    """
    model_editor = viewport_utils.get_active_model_editor()
    if model_editor is None:
        msg = 'Please select an active 3D viewport.'
        LOG.warning(msg)
        return

    cam_tfm, cam_shp = viewport_utils.get_viewport_camera(model_editor)
    if cam_shp is None:
        msg = 'Please select an active 3D viewport to get a camera.'
        LOG.warning(msg)
        return

    try:
        mmapi.set_solver_running(True)

        save_sel = maya.cmds.ls(selection=True, long=True) or []

        # Get selection
        nodes = maya.cmds.ls(
            selection=True,
            long=True,
            type='transform',
        ) or []

        # Filter out selected imagePlanes.
        nodes_tmp = list(nodes)
        nodes = []
        for node in nodes_tmp:
            shps = maya.cmds.listRelatives(
                node, shapes=True, fullPath=True, type='imagePlane') or []
            if len(shps) == 0:
                nodes.append(node)

        # Create centering node network.
        if len(nodes) == 0:
            msg = 'No objects selected, removing 2D centering.'
            LOG.warning(msg)
            mmapi.load_plugin()
            reproject_utils.remove_reprojection_from_camera(cam_tfm, cam_shp)
            reproject_utils.reset_pan_zoom(cam_tfm, cam_shp)
        elif len(nodes) == 1:
            msg = 'Applying 2D centering to %r'
            LOG.warning(msg, nodes)
            mmapi.load_plugin()
            reproj_nodes = reproject_utils.find_reprojection_nodes(
                cam_tfm, cam_shp)
            if len(reproj_nodes) > 0:
                maya.cmds.delete(reproj_nodes)

            reproj_node = reproject_utils.create_reprojection_on_camera(
                cam_tfm, cam_shp)
            reproject_utils.connect_transform_to_reprojection(
                nodes[0], reproj_node)
        elif len(nodes) > 1:
            msg = 'Please select only 1 node to center on.'
            LOG.error(msg)

        if len(save_sel) > 0:
            maya.cmds.select(save_sel, replace=True)
    finally:
        mmapi.set_solver_running(False)
    return