def create_scale_rig_button_clicked(self): name = self.scaleRigNameLineEdit.text() or None camera = self.cameraListComboBox.currentText() or None scene = self.sceneLineEdit.text() or None rig_controls = self.rigsLineEdit.text() or None if rig_controls: rig_controls = rig_controls.split(',') ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True, disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) with ctx: if self.bodyTrackScaleRadioButton.isChecked() == True: if None in [name, camera, rig_controls]: LOG.warn('Please select scale rig name, camera and rigs.') return lib.create_camera_body_track_scale_rig( name, camera, scene, rig_controls, const.SCALE_RIG_TYPE_BODY_TRACK) if self.cameraTrackScaleRadioButton.isChecked() == True: if None in [name, camera, scene, rig_controls]: LOG.warn( 'Please select scale rig name, camera, scene and rigs.' ) return lib.create_camera_body_track_scale_rig( name, camera, scene, rig_controls, const.SCALE_RIG_TYPE_CAMERA_TRACK)
def apply(self): """ This button launches a solve, but can also be used to cancel a solve. """ running_state = lib_state.get_solver_is_running_state() if running_state is True: # Cancel out of a running solve if the user presses # the button again. lib_state.set_solver_user_interrupt_state(True) return undo_id = 'mmSolver: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with tools_utils.tool_context(use_undo_chunk=True, undo_chunk_name=undo_id, restore_current_frame=False, pre_update_frame=False, post_update_frame=False, use_dg_evaluation_mode=True, disable_viewport=False): block = self.blockSignals(True) try: mmapi.set_solver_running(True) options = lib_collection.gather_execute_options() log_level = lib_state.get_log_level() col = lib_state.get_active_collection() lib_collection.run_solve_ui(col, options, log_level, self) finally: mmapi.set_solver_running(False) self.blockSignals(block) return
def update(): """ User runs this tool to update the camera calibration line up. """ sel = maya.cmds.ls(selection=True, long=True) or [] cam = _get_camera_for_update(sel) if cam is None: msg = ('No valid nodes selected; ' 'Select a Camera, Marker Group or Markers.') LOG.warn(msg) return calib_node = None if cam is not None: calib_node = lib.get_calibrate_node_from_camera(cam) else: LOG.warn('Could not find camera with calibration node connected.') if calib_node is not None: with tools_utils.tool_context(use_undo_chunk=True, disable_viewport=False): lib.update_calibrate_values(calib_node) else: LOG.warn('Could not find calibration node.') if len(sel) > 0: maya.cmds.select(sel, replace=True) else: # If the user never had anything selected at the start of the # function, we ensure we maintain that for the user. maya.cmds.select(clear=True) return
def clean(self): what_to_delete_dict = { 'markers': self.subForm.markers_checkBox.isChecked(), 'bundles': self.subForm.bundles_checkBox.isChecked(), 'marker_groups': self.subForm.markerGroup_checkBox.isChecked(), 'collections': self.subForm.collections_checkBox.isChecked(), 'other_nodes': self.subForm.otherNodes_checkBox.isChecked() } all_list_to_delete, unknown_node_found = tool.filter_nodes( what_to_delete_dict) LOG.info(str(all_list_to_delete)) LOG.warning(('unknown_node_found: ', unknown_node_found)) if unknown_node_found: title = 'Confirmation' msg = 'Non-bundle nodes found parented under one or more bundle\n'\ 'nodes. It is suggested that you unparent and bake nodes \n'\ 'you want to keep.\n'\ 'Are you sure you want to delete them?' clicked_button = QtWidgets.QMessageBox.question(self, title, msg) if clicked_button == QtWidgets.QMessageBox.No: return undo_id = 'removesolvernodes: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with tools_utils.tool_context(use_undo_chunk=True, undo_chunk_name=undo_id, restore_current_frame=True): tool.delete_nodes(all_list_to_delete)
def reparent_under_node(): """ Re-parent the selection under the last selected node. """ frame = maya.cmds.currentTime(query=True) nodes = maya.cmds.ls(selection=True, long=True, type='transform') or [] if len(nodes) < 2: msg = ('Not enough objects selected, ' 'select at least 1 child and 1 parent node.') LOG.warn(msg) return with tools_utils.tool_context(disable_viewport=True, use_undo_chunk=False, use_dg_evaluation_mode=False, restore_current_frame=False, pre_update_frame=False): children = nodes[:-1] parent = nodes[-1] children_tfm_nodes = [ tfm_utils.TransformNode(node=n) for n in children ] parent_tfm_node = tfm_utils.TransformNode(node=parent) lib.reparent(children_tfm_nodes, parent_tfm_node, sparse=True) children = [tn.get_node() for tn in children_tfm_nodes] maya.cmds.select(children, replace=True) # Trigger Maya to refresh. maya.cmds.currentTime(frame, update=True) maya.cmds.refresh(currentView=True, force=False) return
def unparent_to_world(): """ Un-parent the selected nodes into world space. """ frame = maya.cmds.currentTime(query=True) nodes = maya.cmds.ls(selection=True, long=True, type='transform') or [] if len(nodes) == 0: msg = ('Not enough objects selected, ' 'select at least 1 transform node.') LOG.warn(msg) return with tools_utils.tool_context(disable_viewport=True, use_undo_chunk=True, use_dg_evaluation_mode=False, restore_current_frame=False, pre_update_frame=False): tfm_nodes = [tfm_utils.TransformNode(node=n) for n in nodes] lib.reparent(tfm_nodes, None, sparse=True) nodes = [tn.get_node() for tn in tfm_nodes] maya.cmds.select(nodes, replace=True) # Trigger Maya to refresh. maya.cmds.currentTime(frame, update=True) maya.cmds.refresh(currentView=True, force=False) return
def calcDistance(self, cam_tfm, tfm_node, offset): """ Calculate the distance between cam_tfm and tfm_node. .. note:: 'offset' is not yet used, but may be implemented in future. """ try: cmds.refresh(suspend=True) mel.eval('paneLayout -e -manage false $gMainPane') ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=False) with ctx: depth_list = [] frames_list = self.getPreBakeFramesListFromNode(tfm_node) if len(frames_list) > 0: current_time = cmds.currentTime(query=True) for frame in frames_list: oma.MAnimControl.setCurrentTime(om.MTime(float(frame))) vector = self.offsetVector(cam_tfm, tfm_node) depth_list.append(vector + offset) oma.MAnimControl.setCurrentTime( om.MTime(float(current_time))) except(NameError, ValueError, TypeError) as e: print e finally: mel.eval('paneLayout -e -manage true $gMainPane') cmds.refresh(suspend=False) return depth_list
def main(): nodes = maya.cmds.ls(selection=True, long=True, type='transform') or [] if len(nodes) == 0: LOG.warn("Please select at least 1 transform.") return start_frame, end_frame = time_utils.get_maya_timeline_range_inner() # Sort nodes by depth, deeper nodes first, so we do do not remove # parents before children. nodes = node_utils.sort_nodes_by_depth(nodes, reverse=True) # Channels to bake. attrs = lib._get_selected_channel_box_attrs() if len(attrs) == 0: attrs = lib.TRANSFORM_ATTRS baked_nodes = [] ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True, disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) with ctx: for node in nodes: if maya.cmds.objExists(node) is False: continue baked_nodes += lib.remove_controller(node, start_frame, end_frame, attrs=attrs) maya.cmds.select(baked_nodes, replace=True) return
def create_controller(self): form = self.getSubForm() ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True, disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) with ctx: form.create_controller_button_clicked() return
def main(): selection = cmds.ls(selection=True, long=True, type='transform') or [] if not selection: LOG.warn('Please select scale rig(s) only.') return ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True, disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) with ctx: lib.remove_camera_body_track_scale_rig(selection)
def bake_selected_attributes(attr_list): LOG.debug('bake_selected_attributes: %r', attr_list) frame_range = time_utils.get_maya_timeline_range_outer() plug_names = _get_plug_names_as_set(attr_list) plug_names = list(sorted(plug_names)) with tools_utils.tool_context(pre_update_frame=True, restore_current_frame=True, use_undo_chunk=True, use_dg_evaluation_mode=True, disable_viewport=True): maya.cmds.bakeResults(plug_names, time=(frame_range.start, frame_range.end)) return
def set_keyframe_on_selected_attributes(attr_list): LOG.debug('set_keyframe_on_selected_attributes: %r', attr_list) def func(plug_name): maya.cmds.setKeyframe(plug_name) with tools_utils.tool_context(pre_update_frame=False, restore_current_frame=False, use_undo_chunk=True, use_dg_evaluation_mode=False, disable_viewport=False): _apply_function_to_attrs(attr_list, func) return
def delete_static_channel_on_selected_attributes(attr_list): LOG.debug('delete_static_channel_on_selected_attributes: %r', attr_list) def func(plug_name): node_name, sep, attr_name = plug_name.partition('.') maya.cmds.delete(node_name, attribute=attr_name, staticChannels=True) with tools_utils.tool_context(pre_update_frame=False, restore_current_frame=False, use_undo_chunk=True, use_dg_evaluation_mode=False, disable_viewport=False): _apply_function_to_attrs(attr_list, func) return
def main(): selection = maya.cmds.ls(selection=True) if not len(selection) == 1: LOG.warn("Please select only one controller.") return start_frame, end_frame = time_utils.get_maya_timeline_range_inner() ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True, disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) with ctx: lib.remove_controller(selection[0], start_frame, end_frame) return
def main(): """ Create a default set up ready for camera calibration/ """ sel = maya.cmds.ls(selection=True, long=True) or [] with tools_utils.tool_context(use_undo_chunk=True): lib.create_new_setup() if len(sel) > 0: maya.cmds.select(sel, replace=True) else: # If the user never had anything selected at the start of the # function, we ensure we maintain that for the user. maya.cmds.select(clear=True) return
def delete_keyframe_current_frame_on_selected_attributes(attr_list): LOG.debug('delete_keyframe_current_frame_on_selected_attributes: %r', attr_list) def func(plug_name): current_frame = maya.cmds.currentTime(query=True) node_name, sep, attr_name = plug_name.partition('.') time_range = (current_frame, ) maya.cmds.cutKey(node_name, attribute=attr_name, time=time_range) with tools_utils.tool_context(pre_update_frame=False, restore_current_frame=False, use_undo_chunk=True, use_dg_evaluation_mode=False, disable_viewport=False): _apply_function_to_attrs(attr_list, func) return
def run_solve_on_all_frames(): """ Run the solver, forcing 'Override Current Frame' off. """ undo_id = 'mmSolver: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with tools_utils.tool_context(use_undo_chunk=True, undo_chunk_name=undo_id, restore_current_frame=False, pre_update_frame=False, post_update_frame=False, use_dg_evaluation_mode=True, disable_viewport=False): run_solve(override_current_frame=False) return
def smooth_selected_keyframes(): """ Smooth the selected keyframes in the Graph Editor. Usage: 1. Select keyframes in Graph Editor. 2. Run tool 3. Keyframe values will be smoothed. """ key_attrs = maya.cmds.keyframe(query=True, name=True) or [] if len(key_attrs) == 0: msg = ('Please select keyframes ' '(in the Graph Editor) to smooth.') LOG.warning(msg) return smooth_type = configmaya.get_scene_option(const.CONFIG_MODE_KEY, default=const.DEFAULT_MODE) width = configmaya.get_scene_option(const.CONFIG_WIDTH_KEY, default=const.DEFAULT_WIDTH) blend_smooth_type = utils_const.SMOOTH_TYPE_AVERAGE blend_width = width undo_id = 'smoothkeyframes: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with tools_utils.tool_context(use_undo_chunk=True, undo_chunk_name=undo_id, restore_current_frame=True, use_dg_evaluation_mode=False, disable_viewport=False): for key_attr in key_attrs: selected_keyframes = maya.cmds.keyframe( key_attr, query=True, selected=True) or [] if len(selected_keyframes) == 0: msg = ('Please select keyframes ' '(in the Graph Editor) to smooth.') LOG.warning(msg) continue lib.smooth_animcurve(key_attr, selected_keyframes, smooth_type, width, blend_smooth_type, blend_width) return
def delete_keyframe_all_frames_on_selected_attributes(attr_list): LOG.debug('delete_keyframe_all_frames_on_selected_attributes: %r', attr_list) def func(plug_name): node_name, sep, attr_name = plug_name.partition('.') frame_range = time_utils.get_maya_timeline_range_outer() time_range = (frame_range.start, frame_range.end) maya.cmds.cutKey(node_name, attribute=attr_name, time=time_range) with tools_utils.tool_context(pre_update_frame=True, restore_current_frame=True, use_undo_chunk=True, use_dg_evaluation_mode=True, disable_viewport=True): _apply_function_to_attrs(attr_list, func) return
def reset_values_on_selected_attributes(attr_list): LOG.debug('reset_values_on_selected_attributes: %r', attr_list) def func(plug_name): node_name, sep, attr_name = plug_name.partition('.') values = maya.cmds.attributeQuery( attr_name, node=node_name, listDefault=True) or [] if len(values) > 0: maya.cmds.setAttr(plug_name, values[0]) with tools_utils.tool_context(pre_update_frame=False, restore_current_frame=False, use_undo_chunk=True, use_dg_evaluation_mode=False, disable_viewport=False): _apply_function_to_attrs(attr_list, func) return
def remove(): """ Remove selected controllers and bake data on controlled nodes. """ nodes = maya.cmds.ls(selection=True, long=True) or [] with tools_utils.tool_context(use_undo_chunk=True, pre_update_frame=True, post_update_frame=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True): orig_nodes = lib.remove(nodes) if len(orig_nodes) > 0: maya.cmds.select(orig_nodes, replace=True) # Trigger Maya to refresh. maya.cmds.refresh(currentView=True, force=False) return
def create(): """ Create a controller for selected nodes. """ nodes = maya.cmds.ls(selection=True, long=True) or [] with tools_utils.tool_context(use_undo_chunk=True, pre_update_frame=True, post_update_frame=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True): ctrls = lib.create(nodes) if len(ctrls) > 0: maya.cmds.select(ctrls, replace=True) # Trigger Maya to refresh. maya.cmds.refresh(currentView=True, force=False) return
def main(): nodes = maya.cmds.ls(selection=True) if len(nodes) == 0: LOG.warn("Please select at least 1 object.") return # Get configuration values frame_range_mode = configmaya.get_scene_option( const.CONFIG_FRAME_RANGE_MODE_KEY, const.DEFAULT_FRAME_RANGE_MODE) custom_start_frame = configmaya.get_scene_option( const.CONFIG_FRAME_START_KEY, const.DEFAULT_FRAME_START) custom_end_frame = configmaya.get_scene_option(const.CONFIG_FRAME_END_KEY, const.DEFAULT_FRAME_END) smart_bake_state = configmaya.get_scene_option( const.CONFIG_SMART_BAKE_KEY, const.DEFAULT_SMART_BAKE_STATE) from_channelbox_state = configmaya.get_scene_option( const.CONFIG_FROM_CHANNELBOX_KEY, const.DEFAULT_FROM_CHANNELBOX_STATE) frame_range = lib.get_bake_frame_range(frame_range_mode, custom_start_frame, custom_end_frame) attrs = _get_attributes(from_channelbox_state) # Bake attributes s = time.time() ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=True, disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) with ctx: try: lib.bake_attributes(nodes, attrs, frame_range.start, frame_range.end, smart_bake_state) except Exception as e: LOG.error(e) finally: e = time.time() LOG.warn('Bake attribute success. Time elapsed: %r secs', e - s) return
def break_connections_on_selected_attributes(attr_list): LOG.debug('break_connections_on_selected_attributes: %r', attr_list) def func(plug_name): src = maya.cmds.connectionInfo(plug_name, sourceFromDestination=True) or None if src is None: return dst = plug_name connected = maya.cmds.isConnected(src, dst) if connected: maya.cmds.disconnectAttr(src, dst) return with tools_utils.tool_context(pre_update_frame=False, restore_current_frame=False, use_undo_chunk=True, use_dg_evaluation_mode=False, disable_viewport=False): _apply_function_to_attrs(attr_list, func) return
def _run_tool(window_parent, save_scene, what_to_delete_dict): assert isinstance(save_scene, bool) assert isinstance(what_to_delete_dict, dict) found_nodes_map, unknown_node_found = tool.filter_nodes( what_to_delete_dict) marker_nodes = found_nodes_map.get('markers', []) bundle_nodes = found_nodes_map.get('bundles', []) mkr_group_nodes = found_nodes_map.get('marker_groups', []) collection_nodes = found_nodes_map.get('collections', []) other_nodes = found_nodes_map.get('other_nodes', []) nodes_to_delete = [] for key in found_nodes_map: nodes_to_delete += found_nodes_map[key] # Remove non-unique nodes. nodes_to_delete = list(sorted(set(nodes_to_delete))) title = const.WINDOW_TITLE if len(nodes_to_delete) == 0: msg = ('No nodes found, ' 'please choose different options in the window.\n') QtWidgets.QMessageBox.warning(window_parent, title, msg) return False details = _generate_details_text(marker_nodes=marker_nodes, bundle_nodes=bundle_nodes, mkr_group_nodes=mkr_group_nodes, collection_nodes=collection_nodes, other_nodes=other_nodes) msg = _generate_message_text(unknown_node_found=unknown_node_found, nodes_to_delete=nodes_to_delete, marker_nodes=marker_nodes, bundle_nodes=bundle_nodes, mkr_group_nodes=mkr_group_nodes, collection_nodes=collection_nodes, other_nodes=other_nodes) inform_text = 'Are you sure you want to delete?' dialog = QtWidgets.QMessageBox(window_parent, ) dialog.setWindowTitle(title) dialog.setIcon(QtWidgets.QMessageBox.Question) dialog.setText(msg) dialog.setInformativeText(inform_text) dialog.setDetailedText(details) clicked_button = dialog.exec_() if clicked_button == QtWidgets.QMessageBox.No: return False if save_scene is True: maya.cmds.file(save=True) undo_id = 'removesolvernodes: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with tools_utils.tool_context(use_undo_chunk=True, undo_chunk_name=undo_id, restore_current_frame=True): tool.delete_nodes(nodes_to_delete) return True
def bakeRigBtn(self): bake_options = self.bakeOptions() selected_items = self.rigs_list.selectedItems() start_frame, end_frame = time_utils.get_maya_timeline_range_inner() if len(selected_items) == 0: _display_warning_ui( 'at least one rig must be selected from Rigs list.') return try: cmds.refresh(suspend=True) mel.eval('paneLayout -e -manage false $gMainPane') ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=False) with ctx: cmds.select(clear=True) for sel_item in selected_items: children = self.getAllChildren(sel_item) for j in children: rigName = j.text(0) object = cmds.getAttr( rigName + '.' + ATTRIBUTE_IDENTIFIER_NAME) if FREEZE_RIG_SUFFIX_NAME in rigName: self.full_bake_rdo_btn.setChecked(True) if RIG_SUFFIX_NAME in rigName: name = rigName.split(RIG_SUFFIX_NAME)[0] if FREEZE_RIG_SUFFIX_NAME in rigName: name = rigName.split(FREEZE_RIG_SUFFIX_NAME)[0] if bake_options == 'full_bake': # cmds.bakeResults(object, time=(start_frame, end_frame), simulation=True) fastbake_lib.bake_attributes([object], [], start_frame, end_frame, False) if bake_options == 'smart_bake': nodes_list = cmds.listConnections( name + SCREEN_Z_MASTER_NAME) for node in nodes_list: if 'screenX_condition' in node: x_node = node if 'screenY_condition' in node: y_node = node cmds.select(object) attrs = ['tx', 'ty', 'tz'] # First key on objects existing key frames for frame in self.getPreBakeFramesListFromNode( object): oma.MAnimControl.setCurrentTime(om.MTime(frame)) cmds.setKeyframe(attribute=attrs) # Key screen z depth attribute frames keys_list = cmds.keyframe( rigName + '.' + SCREEN_Z_DEPTH_ATTR_NAME, query=True) if keys_list: for frame in keys_list: oma.MAnimControl.setCurrentTime( om.MTime(frame)) cmds.setKeyframe(attribute=attrs) # Check condition result node and set keyframe for i in range(start_frame, end_frame + 1): oma.MAnimControl.setCurrentTime(om.MTime(i)) x_changed = \ cmds.getAttr(x_node + '.outColor')[0][0] y_changed = \ cmds.getAttr(y_node + '.outColor')[0][0] if x_changed or y_changed: cmds.setKeyframe(attribute=attrs) cmds.select(clear=True) self.deleteRigBtn() self.refreshRigsList() except(NameError, ValueError, TypeError) as e: print e finally: mel.eval('paneLayout -e -manage true $gMainPane') cmds.refresh(suspend=False) return
def main(): # Get selected camera node. sel = maya.cmds.ls(selection=True, long=True, type='transform') or [] if len(sel) == 0: sel += maya.cmds.ls(selection=True, long=True, type='camera') or [] if len(sel) != 1: LOG.warn('Please select one camera: selection=%r', sel) return cam_tfm, cam_shp = camera_utils.get_camera(sel[0]) if cam_tfm is None or cam_shp is None: LOG.warn('Selected node is not a camera, please select one camera.') return # Get the connected image planes # If more than one image plane exists, print a warning. img_pl_shps = camera_utils.get_image_plane_shapes_from_camera( cam_tfm, cam_shp) img_pl_shp = None if len(img_pl_shps) == 0: msg = 'No image plane nodes found.' LOG.warn(msg) elif len(img_pl_shps) > 1: img_pl_shp = img_pl_shps[0] msg = 'More than one image plane was found, using first image plane.' LOG.warn(msg) else: # Exactly one image plane node. img_pl_shp = img_pl_shps[0] # Query plate data from the image plane test_disk = const.TEST_DISK frame_range = time_utils.get_maya_timeline_range_inner() plate_data = {} if img_pl_shp is not None: plate_data = lib.query_plate_data(cam_tfm, cam_shp, img_pl_shp, test_disk) # Calculate the frame range. image_file_path = plate_data.get('file_path') if image_file_path is not None: frame_range = lib.get_frame_range_from_file_pattern( image_file_path, fallback_range=frame_range) assert isinstance(frame_range, (time_utils.FrameRange, tuple)) frames = list(range(frame_range.start, frame_range.end + 1)) assert len(frames) > 0 # Node must be transform and have a camera shape node to be valid. rotate_order = const.ROTATE_ORDER with tools_utils.tool_context(use_undo_chunk=False, use_dg_evaluation_mode=True, disable_viewport=True): cam_data = lib.query_camera_data(cam_tfm, cam_shp, frames, rotate_order, test_disk) # Generate file contents. data_str = lib.generate(cam_data, plate_data, frame_range) # Write out file. file_path = lib.write_temp_file(data_str) if not os.path.isfile(file_path): msg = 'Failed to write temp file. path=%r' LOG.error(msg, file_path) return msg = 'Successfully wrote to temporary file. path=%r' LOG.info(msg, file_path) # Set Copy/Paste Clipboard buffer. try: clippy = QtGui.QClipboard() clippy.setText(file_path) except Exception as e: msg = 'Could not set file path on clipboard. path=%r' LOG.warn(msg, file_path) LOG.info(str(e)) return file_path
def reparent(children, parent): """ Reparent 'children' nodes under 'parent' node. If 'parent' is None, the children are unparented to world. All settings are taken from the UI's defaults. To change these, please use the UI (or 'configmaya' module) """ children_nodes = [tfm_utils.TransformNode(node=n) for n in children] parent_node = None if parent is not None: parent_node = tfm_utils.TransformNode(node=parent) # Get all saved re-parent options. frame_range_mode = configmaya.get_scene_option( const.CONFIG_FRAME_RANGE_MODE_KEY, default=const.DEFAULT_FRAME_RANGE_MODE) 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) bake_mode = configmaya.get_scene_option( const.CONFIG_BAKE_MODE_KEY, default=const.DEFAULT_BAKE_MODE) rotate_order = configmaya.get_scene_option( const.CONFIG_ROTATE_ORDER_MODE_KEY, default=const.DEFAULT_ROTATE_ORDER_MODE) delete_static_anim_curves = configmaya.get_scene_option( const.CONFIG_DELETE_STATIC_ANIM_CURVES_KEY, default=const.DEFAULT_DELETE_STATIC_ANIM_CURVES) viewport_mode = const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE # Check the children nodes and prompt the user what to do prompt_user, settable_map, full_msg, confirm_msg = \ __check_modify_nodes(children) if prompt_user is True: LOG.warn(full_msg) cancel_button = 'Cancel' continue_button = 'Continue' button = maya.cmds.confirmDialog( title='Warning: Cannot Modify Nodes.', message=confirm_msg, button=[continue_button, cancel_button], defaultButton=continue_button, cancelButton=cancel_button, dismissString=cancel_button) if button == cancel_button: LOG.warn('User canceled Re-parent.') return with tools_utils.tool_context(disable_viewport=True, use_undo_chunk=True, use_dg_evaluation_mode=False, restore_current_frame=True, pre_update_frame=False, disable_viewport_mode=viewport_mode): lib.reparent( children_nodes, parent_node, frame_range_mode=frame_range_mode, start_frame=start_frame, end_frame=end_frame, bake_mode=bake_mode, rotate_order_mode=rotate_order, delete_static_anim_curves=bool(delete_static_anim_curves), ) nodes = [tn.get_node() for tn in children_nodes] maya.cmds.select(nodes, replace=True) # Trigger Maya to refresh. maya.cmds.refresh(currentView=True, force=False) 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() with tools_utils.tool_context(pre_update_frame=True): # 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] if len(mkr_nodes) > 0: maya.cmds.select(mkr_nodes, replace=True) return
def main(): """Ray-casts each bundle connected to the selected markers on to the mesh from the associated camera. Select markers and mesh objects to ray-cast on to, if no mesh objects are selected the tool will ray-cast on to all visible mesh objects. If a bundle translate attribute is locked, it will be unlocked, then projected, and then the lock state will be reverted to the original value. .. note:: The Marker node is the origin point of the ray-cast, *not* the camera's pivot position. This is intentional. If the user has a single dense (LIDAR) model node it can be helpful to project from a distance away from the camera origin. With a single dense mesh it is difficult to split the model up to use different mesh selections. Example:: >>> import mmSolver.tools.raycastmarker.tool as tool >>> tool.main() """ selection = maya.cmds.ls(selection=True) or [] if not selection: LOG.warning('Please select a marker to rayCast.') return node_categories = mmapi.filter_nodes_into_categories(selection) mkr_node_list = node_categories['marker'] bnd_node_list = node_categories['bundle'] cam_node_list = node_categories['camera'] if len(mkr_node_list) == 0 and len(bnd_node_list) == 0: LOG.warn('Please select markers or bundles to ray-cast.') return # The camera used to determine where bundles will be projected from. active_cam_tfm, active_cam_shp = _get_active_or_selected_camera( cam_node_list) # Get Markers mkr_list, use_camera = _get_markers(mkr_node_list, bnd_node_list, active_cam_shp) if use_camera and active_cam_shp is None: LOG.warn('Please activate a viewport to ray-cast Bundles from.') frame_range_mode = configmaya.get_scene_option( const.CONFIG_FRAME_RANGE_MODE_KEY, default=const.DEFAULT_FRAME_RANGE_MODE) frame_start = configmaya.get_scene_option( const.CONFIG_FRAME_START_KEY, default=const.DEFAULT_FRAME_START) frame_end = configmaya.get_scene_option(const.CONFIG_FRAME_END_KEY, default=const.DEFAULT_FRAME_END) if frame_range_mode == const.FRAME_RANGE_MODE_CURRENT_FRAME_VALUE: frame_start = int(maya.cmds.currentTime(query=True)) frame_end = frame_start elif frame_range_mode == const.FRAME_RANGE_MODE_TIMELINE_INNER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_inner() elif frame_range_mode == const.FRAME_RANGE_MODE_TIMELINE_OUTER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_outer() frame_range = time_utils.FrameRange(frame_start, frame_end) use_smooth_mesh = True bundle_unlock_relock = configmaya.get_scene_option( const.CONFIG_BUNDLE_UNLOCK_RELOCK_KEY, default=const.DEFAULT_BUNDLE_UNLOCK_RELOCK) # Do not disable the viewport if we're only baking a single frame. disable_viewport = True if frame_range.start == frame_range.end: disable_viewport = False mesh_nodes = _get_selected_meshes() with tools_utils.tool_context(use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=disable_viewport): bnd_nodes = lib.raycast_markers_onto_meshes( mkr_list, mesh_nodes, frame_range=frame_range, unlock_bnd_attrs=bundle_unlock_relock, relock_bnd_attrs=bundle_unlock_relock, use_smooth_mesh=use_smooth_mesh) if len(bnd_nodes) > 0: maya.cmds.select(bnd_nodes) else: maya.cmds.select(selection) return