def main(): """ Convert all selected transforms into 2D markers under a camera. """ # Get camera model_editor = utils_viewport.get_active_model_editor() if model_editor is None: msg = 'Please select an active 3D viewport.' LOG.warning(msg) return cam_tfm, cam_shp = utils_viewport.get_viewport_camera(model_editor) if cam_shp is None: LOG.error('Please select an active viewport to get a camera.') return if utils_camera.is_startup_cam(cam_shp) is True: LOG.error("Cannot create Markers in 'persp' camera.") return # Get transforms nodes = maya.cmds.ls( selection=True, long=True, type='transform', ) or [] if len(nodes) == 0: LOG.warning('Please select one or more transform nodes.') return mmapi.load_plugin() try: # Turn off Maya UI maya.mel.eval('paneLayout -e -manage false $gMainPane') # Compute the Marker Data. start_frame, end_frame = utils_time.get_maya_timeline_range_outer() mkr_data_list = __convert_nodes_to_marker_data_list( cam_tfm, cam_shp, nodes, start_frame, end_frame, ) cam = mmapi.Camera(shape=cam_shp) mkr_list = mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=None, with_bundles=True, ) mkr_nodes = [mkr.get_node() for mkr in mkr_list] except: raise finally: # Turn on Maya UI maya.mel.eval('paneLayout -e -manage true $gMainPane') if len(mkr_nodes) > 0: maya.cmds.select(mkr_nodes, replace=True) return
def _get_active_viewport_camera(): """Get the active viewport camera.""" cam = None model_editor = utils_viewport.get_active_model_editor() if model_editor is None: msg = 'Please select an active 3D viewport.' LOG.warning(msg) return cam cam_tfm, cam_shp = utils_viewport.get_viewport_camera(model_editor) node = cam_shp if node is None: msg = 'Please select an active viewport to get a camera.' LOG.error(msg) return cam if camera_utils.is_startup_cam(node) is True: msg = "Cannot create Markers in 'persp' camera." LOG.error(msg) return cam if maya.cmds.nodeType(node) == 'transform': cam = mmapi.Camera(transform=node) elif maya.cmds.nodeType(node) == 'camera': cam = mmapi.Camera(shape=node) else: LOG.error('Camera node is invalid; %r', node) return cam return cam
def get_active_viewport_camera(): """ Get the Camera that is attached to the active viewport. :return: The Camera object, or None. :rtype: Camera or None """ cam = None # Get the camera from the active viewport. model_editor = viewport_utils.get_active_model_editor() if model_editor is None: return cam cam_tfm, cam_shp = viewport_utils.get_viewport_camera(model_editor) if cam_shp is None: return cam if camera_utils.is_startup_cam(cam_shp) is True: return cam cam = mmapi.Camera(shape=cam_shp) return cam
def test_startup_camera(self): cam_tfm, cam_shp = self.create_camera('myCamera') cam_tfm_value = camera_utils.is_startup_cam(cam_tfm) cam_shp_value = camera_utils.is_startup_cam(cam_shp) cam_tfm_not_value = camera_utils.is_not_startup_cam(cam_tfm) cam_shp_not_value = camera_utils.is_not_startup_cam(cam_shp) self.assertEqual(cam_tfm_value, False) self.assertEqual(cam_shp_value, False) self.assertNotEqual(cam_tfm_value, cam_tfm_not_value) self.assertNotEqual(cam_shp_value, cam_shp_not_value) # Custom transform node type. GitHub issue #123. custom_node_type = 'mmMarkerGroupTransform' cam_tfm, cam_shp = self.create_camera( 'myCameraWithCustomNodeType', tfm_node_type=custom_node_type) cam_tfm_value = camera_utils.is_startup_cam(cam_tfm) cam_shp_value = camera_utils.is_startup_cam(cam_shp) cam_tfm_not_value = camera_utils.is_not_startup_cam(cam_tfm) cam_shp_not_value = camera_utils.is_not_startup_cam(cam_shp) self.assertEqual(cam_tfm_value, False) self.assertEqual(cam_shp_value, False) self.assertNotEqual(cam_tfm_value, cam_tfm_not_value) self.assertNotEqual(cam_shp_value, cam_shp_not_value) # Maya default start up cameras. names = ['persp', 'top', 'side', 'front'] for name in names: tfm_name = '|{name}'.format(name=name) shp_name = '|{name}|{name}Shape'.format(name=name) cam_tfm_value = camera_utils.is_startup_cam(tfm_name) cam_shp_value = camera_utils.is_startup_cam(shp_name) self.assertEqual(cam_tfm_value, True) self.assertEqual(cam_shp_value, True) return
def main(): """ Convert all selected transforms into 2D markers under a camera. """ # Get camera model_editor = utils_viewport.get_active_model_editor() if model_editor is None: msg = 'Please select an active 3D viewport.' LOG.warning(msg) return cam_tfm, cam_shp = utils_viewport.get_viewport_camera(model_editor) if cam_shp is None: LOG.error('Please select an active viewport to get a camera.') return if utils_camera.is_startup_cam(cam_shp) is True: LOG.error("Cannot create Markers in 'persp' camera.") return # Get transforms nodes = maya.cmds.ls( selection=True, long=True, type='transform', ) or [] if len(nodes) == 0: LOG.warning('Please select one or more transform nodes.') return mmapi.load_plugin() try: utils_viewport.viewport_turn_off() # Compute the Marker Data. start_frame, end_frame = utils_time.get_maya_timeline_range_outer() mkr_data_list = lib.convert_nodes_to_marker_data_list( cam_tfm, cam_shp, nodes, start_frame, end_frame, ) # Get Camera cam = mmapi.Camera(shape=cam_shp) # Get or create Marker Group. mkr_grp = None mkr_grp_nodes = maya.cmds.ls( cam_tfm, dag=True, long=True, type='mmMarkerGroupTransform') or [] mkr_grp_nodes = sorted(mkr_grp_nodes) if len(mkr_grp_nodes) == 0: mkr_grp = mmapi.MarkerGroup().create_node(cam=cam) else: mkr_grp = mmapi.MarkerGroup(node=mkr_grp_nodes[0]) # Create Marker nodes mkr_list = mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, ) mkr_nodes = [mkr.get_node() for mkr in mkr_list] finally: utils_viewport.viewport_turn_on() if len(mkr_nodes) > 0: maya.cmds.select(mkr_nodes, replace=True) return
def main(): """ Create a new marker under the current viewport camera, or under the selected camera, if a camera is selected. """ mmapi.load_plugin() sel = maya.cmds.ls(sl=True, long=True) node_filtered = mmapi.filter_nodes_into_categories(sel) cams = node_filtered['camera'] cams = filter(utils_camera.is_not_startup_cam, cams) mkr_grps = node_filtered['markergroup'] cam = None mkr_grp = None if len(cams) > 0 and len(mkr_grps) > 0: msg = ('Please select a camera or marker group; ' 'both node types are selected.') LOG.error(msg) elif len(cams) == 0 and len(mkr_grps) == 0: # Create a Marker under the active viewport camera. model_editor = utils_viewport.get_active_model_editor() if model_editor is None: msg = 'Please select an active 3D viewport.' LOG.warning(msg) return cam_tfm, cam_shp = utils_viewport.get_viewport_camera(model_editor) node = cam_shp if node is None: msg = 'Please select an active viewport to get a camera.' LOG.error(msg) return if utils_camera.is_startup_cam(node) is True: msg = "Cannot create Markers in 'persp' camera." LOG.error(msg) return if maya.cmds.nodeType(node) == 'transform': cam = mmapi.Camera(transform=node) elif maya.cmds.nodeType(node) == 'camera': cam = mmapi.Camera(shape=node) else: LOG.error('Camera node is invalid; %r', node) return elif len(cams) > 0 and len(mkr_grps) == 0: # Create a Marker under the selected camera. node = cams[0] if maya.cmds.nodeType(node) == 'transform': cam = mmapi.Camera(transform=node) elif maya.cmds.nodeType(node) == 'camera': cam = mmapi.Camera(shape=node) else: LOG.error('Camera node is invalid; %r', node) return elif len(cams) == 0 and len(mkr_grps) > 0: # Create a marker under the first selected Marker Group. node = mkr_grps[0] mkr_grp = mmapi.MarkerGroup(node=node) else: LOG.error('Should not get here.') bnd_name = mmapi.get_new_bundle_name('bundle1') bnd = mmapi.Bundle().create_node(name=bnd_name) mkr_name = mmapi.get_new_marker_name('marker1') mkr = mmapi.Marker().create_node(name=mkr_name, cam=cam, mkr_grp=mkr_grp, bnd=bnd) maya.cmds.select(mkr.get_node(), replace=True) return
def main(frame_range_mode=None, start_frame=None, end_frame=None, bundle_position_mode=None, delete_static_anim_curves=None): """ Convert all selected transforms into 2D markers under a camera. :param frame_range_mode: The type of frame range to use, see 'mmSolver.utils.constant.FRAME_RANGE_MODE_*_VALUE' for more details. :type frame_range_mode: FRAME_RANGE_MODE_*_VALUE :param start_frame: The first frame to start converting the transform to a Marker. :type start_frame: int or None :param end_frame: The last frame to end converting the transform to a Marker. :type end_frame: int or None :param bundle_position_mode: The position for the newly created Bundle (connected to the Marker). :type bundle_position_mode: None or BUNDLE_POSITION_MODE_* :param delete_static_anim_curves: When enabled, this will remove all keyframes from the bundle, if the bundle is not animated. :type delete_static_anim_curves: bool """ if frame_range_mode is None: value = configmaya.get_scene_option( const.CONFIG_FRAME_RANGE_MODE_KEY, default=const.DEFAULT_FRAME_RANGE_MODE) assert value in const.FRAME_RANGE_MODE_VALUES frame_range_mode = value if start_frame is None or end_frame is None: start_frame = configmaya.get_scene_option( const.CONFIG_FRAME_START_KEY, default=const.DEFAULT_FRAME_START) end_frame = configmaya.get_scene_option( const.CONFIG_FRAME_END_KEY, default=const.DEFAULT_FRAME_END) if bundle_position_mode is None: value = configmaya.get_scene_option( const.CONFIG_BUNDLE_POSITION_MODE_KEY, default=const.DEFAULT_BUNDLE_POSITION_MODE) bundle_position_mode = value if delete_static_anim_curves is None: value = configmaya.get_scene_option( const.CONFIG_DELETE_STATIC_ANIM_CURVES_KEY, default=const.DEFAULT_DELETE_STATIC_ANIM_CURVES) delete_static_anim_curves = value # Frame range time_utils.get_frame_range(frame_range_mode, start_frame=start_frame, end_frame=end_frame) # Get camera model_editor = utils_viewport.get_active_model_editor() if model_editor is None: msg = 'Please select an active 3D viewport.' LOG.warning(msg) return cam_tfm, cam_shp = utils_viewport.get_viewport_camera(model_editor) if cam_shp is None: LOG.error('Please select an active viewport to get a camera.') return if utils_camera.is_startup_cam(cam_shp) is True: LOG.error("Cannot create Markers in 'persp' camera.") return # Get transforms tfm_nodes = maya.cmds.ls( selection=True, long=True, type='transform', ) or [] if len(tfm_nodes) == 0: LOG.warning('Please select one or more transform nodes.') return # Must ensure the plug-in is loaded, otherwise we won't have all # the functionality required. mmapi.load_plugin() with tools_utils.tool_context(pre_update_frame=True): mkr_nodes, bnd_nodes = lib.create_markers_from_transforms( cam_tfm, cam_shp, tfm_nodes, start_frame, end_frame, bundle_position_mode, delete_static_anim_curves) if len(mkr_nodes) > 0: maya.cmds.select(mkr_nodes, replace=True) return