コード例 #1
0
def _triangulate_bundle(bnd_node, mkr_cam_node_frm_list):
    """
    Triangulate a 3D bundle position.

    :param bnd_node: Bundle node to be triangulated.
    :type bnd_node: str

    :param mkr_cam_node_frm_list: Marker and Camera transform to be considered for triangulation.
    :type mkr_cam_node_frm_list: [(str, stc, (int, int)), ..]
    """
    LOG.debug('triangulate_bundle: %r %r', bnd_node, mkr_cam_node_frm_list)
    prev_frame = maya.cmds.currentTime(query=True)
    try:
        for mkr_node, cam_tfm, frm_list in mkr_cam_node_frm_list:
            if len(frm_list) == 0:
                continue

            first_frm = frm_list[0]
            last_frm = frm_list[-1]
            first_pnt, first_dir = tri_utils.get_point_and_direction(
                cam_tfm, mkr_node, first_frm)
            last_pnt, last_dir = tri_utils.get_point_and_direction(
                cam_tfm, mkr_node, last_frm)
            a_pnt, b_pnt = tri_utils.calculate_approx_intersection_point_between_two_3d_lines(
                first_pnt, first_dir, last_pnt, last_dir)
            pnt = OpenMaya.MPoint((a_pnt.x + b_pnt.x) * 0.5,
                                  (a_pnt.y + b_pnt.y) * 0.5,
                                  (a_pnt.z + b_pnt.z) * 0.5)

            maya.cmds.xform(bnd_node,
                            translation=(pnt.x, pnt.y, pnt.z),
                            worldSpace=True)
    finally:
        maya.cmds.currentTime(prev_frame, update=False)
    return
コード例 #2
0
def triangulate_bundle(bnd, relock=None):
    """
    Triangulate a 3D bundle position.

    :param bnd: Bundle to be triangulated.
    :type bnd: Bundle

    :param relock: If True any bundle translate attributes will be
                   unlocked, changed then relocked.
    :type relock: bool
    """
    if relock is None:
        relock = False
    assert isinstance(relock, bool) is True

    prev_frame = maya.cmds.currentTime(query=True)
    try:
        mkr_list = bnd.get_marker_list()
        for mkr in mkr_list:
            mkr_node = mkr.get_node()
            frm_list = get_marker_frame_list(mkr_node)
            if len(frm_list) == 0:
                continue

            bnd_node = bnd.get_node()
            cam = mkr.get_camera()
            cam_tfm = cam.get_transform_node()

            first_frm = frm_list[0]
            last_frm = frm_list[-1]
            first_pnt, first_dir = tri_utils.get_point_and_direction(
                cam_tfm, mkr_node, first_frm)
            last_pnt, last_dir = tri_utils.get_point_and_direction(
                cam_tfm, mkr_node, last_frm)

            a_pnt, b_pnt = tri_utils.calculate_approx_intersection_point_between_two_3d_lines(
                first_pnt, first_dir, last_pnt, last_dir)
            pnt = OpenMaya.MPoint((a_pnt.x + b_pnt.x) * 0.5,
                                  (a_pnt.y + b_pnt.y) * 0.5,
                                  (a_pnt.z + b_pnt.z) * 0.5)

            plugs = [
                '%s.translateX' % bnd_node,
                '%s.translateY' % bnd_node,
                '%s.translateZ' % bnd_node
            ]
            lock_state = {}
            for plug in plugs:
                value = maya.cmds.getAttr(plug, lock=True)
                lock_state[plug] = value
                maya.cmds.setAttr(plug, lock=False)

            maya.cmds.xform(bnd_node,
                            translation=(pnt.x, pnt.y, pnt.z),
                            worldSpace=True)

            if relock is True:
                for plug in plugs:
                    value = lock_state.get(plug)
                    maya.cmds.setAttr(plug, lock=value)
    finally:
        maya.cmds.currentTime(prev_frame, update=False)
    return