def updateModel(self): """ Refresh the name_comboBox with the current Maya scene state. """ col = lib_state.get_active_collection() if col is None: return roots_enabled = True roots_string = self.getRootFramesValue(col) if roots_string is None: frame = lib_maya_utils.get_current_frame() start, end = utils_time.get_maya_timeline_range_inner() int_list = list(set([start, frame, end])) roots_string = convert_types.intListToString(int_list) self.setRootFramesValue(col, roots_string) else: int_list = convert_types.stringToIntList(roots_string) roots_string = convert_types.intListToString(int_list) assert roots_string is not None block = self.blockSignals(True) self.rootFrames_lineEdit.setEnabled(roots_enabled) self.rootFrames_lineEdit.setText(roots_string) self.blockSignals(block) return
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 test_allFrameStrategySolve(self): """ Solving only a 'all frames' solver step across multiple frames. """ # Open the Maya file file_name = 'mmSolverBasicSolveA_badSolve02.ma' path = self.get_data_path('scenes', file_name) maya.cmds.file(path, open=True, force=True, ignoreVersion=True) # Collection col = mmapi.Collection(node='collection1') mkr_list = col.get_marker_list() # Frames # # Root Frames are automatically calculated from the markers. root_frm_list = [] not_root_frm_list = [] start_frame, end_frame = time_utils.get_maya_timeline_range_inner() min_frames_per_marker = 3 frame_nums = mmapi.get_root_frames_from_markers( mkr_list, min_frames_per_marker, start_frame, end_frame) for f in frame_nums: frm = mmapi.Frame(f) root_frm_list.append(frm) for f in range(0, 41): frm = mmapi.Frame(f) not_root_frm_list.append(frm) # Define Solver sol_list = [] sol = mmapi.SolverStandard() sol.set_root_frame_list(root_frm_list) sol.set_frame_list(not_root_frm_list) sol.set_only_root_frames(False) sol.set_global_solve(False) sol.set_single_frame(False) sol.set_root_frame_strategy(mmapi.ROOT_FRAME_STRATEGY_GLOBAL_VALUE) sol_list.append(sol) col.set_solver_list(sol_list) # Run solver! s = time.time() lib_col.compile_collection(col) solres_list = mmapi.execute(col) e = time.time() print 'total time:', e - s # Set Deviation mkr_list = col.get_marker_list() mmapi.update_deviation_on_markers(mkr_list, solres_list) mmapi.update_deviation_on_collection(col, solres_list) # save the output path = self.get_data_path('test_solve_allFrameStrategySolve_after.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) self.checkSolveResults(solres_list) return
def test_get_root_frames_from_markers_1(self): # Time Range start = 1001 end = 1101 maya.cmds.playbackOptions(animationStartTime=start, minTime=start, animationEndTime=end, maxTime=end) # Create Camera and Marker Group cam_tfm = maya.cmds.createNode('transform', name='cam_tfm') cam_shp = maya.cmds.createNode('camera', name='cam_shp', parent=cam_tfm) cam = mmapi.Camera(shape=cam_shp) mkr_grp = mmapi.MarkerGroup().create_node(cam=cam) # Marker A mkr_a = mmapi.Marker().create_node() mkr_a_node = mkr_a.get_node() times = [1000, 1001, 1101, 1102] values = [0, 1, 1, 0] anim_utils.create_anim_curve_node_apione(times, values, mkr_a_node + '.enable') # Calculate Root Frames min_frames_per_marker = 2 mkr_list = [mkr_a] start_frame, end_frame = time_utils.get_maya_timeline_range_inner() frame_nums = mod.get_root_frames_from_markers(mkr_list, min_frames_per_marker, start_frame, end_frame) print 'frames:', frame_nums return
def frameRangeModeIndexChanged(self, index): name = const.CONFIG_FRAME_RANGE_MODE_KEY value = const.FRAME_RANGE_MODE_VALUES[index] configmaya.set_scene_option(name, value, add_attr=True) LOG.debug('key=%r value=%r', name, value) enable_custom = value == const.FRAME_RANGE_MODE_CUSTOM_VALUE self.frameRangeStartSpinBox.setEnabled(enable_custom) self.frameRangeEndSpinBox.setEnabled(enable_custom) 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 value == const.FRAME_RANGE_MODE_CURRENT_FRAME_VALUE: frame_start = maya.cmds.currentTime(query=True) frame_end = frame_start elif value == const.FRAME_RANGE_MODE_TIMELINE_INNER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_inner() elif value == const.FRAME_RANGE_MODE_TIMELINE_OUTER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_outer() self.frameRangeStartSpinBox.setValue(frame_start) self.frameRangeEndSpinBox.setValue(frame_end)
def create_solver(): sol = mmapi.Solver() sol.set_max_iterations(10) sol.set_verbose(True) start, end = utils_time.get_maya_timeline_range_inner() for f in xrange(start, end + 1): frm = mmapi.Frame(f) sol.add_frame(frm) return sol
def create_controller_button_clicked(self): loc_grp_node = self.create_locator_group() # Set time start_frame, end_frame = time_utils.get_maya_timeline_range_inner() if self.current_frame_rdo_btn.isChecked(): start_frame = int(cmds.currentTime(query=True)) end_frame = start_frame # Get widgets data controller_name = self.locator_group_text.text() pivot_node = self.pivot_object_text.text() main_node = self.main_object_text.text() camera = _get_viewport_camera() space = None if self.world_space_rdo_btn.isChecked(): space = const.CONTROLLER_TYPE_WORLD_SPACE elif self.object_space_rdo_btn.isChecked(): space = const.CONTROLLER_TYPE_OBJECT_SPACE elif self.screen_space_rdo_btn.isChecked(): space = const.CONTROLLER_TYPE_SCREEN_SPACE else: LOG.error('Invalid space.') return smart_bake = self.smart_bake_rdo_btn.isChecked() if not controller_name or not pivot_node or not main_node: return if not cmds.listRelatives(loc_grp_node, shapes=True): loc_grp_node = [loc_grp_node] if self.screen_space_rdo_btn.isChecked(): if not camera: LOG.warn('Please select camera viewport.') if cmds.objExists(loc_grp_node[0]): cmds.delete(loc_grp_node[0]) return # Check if main node has constraints already has_constraints = _transform_has_constraints(main_node) if has_constraints is True: LOG.warn('Main object has constraints already.') cmds.delete(loc_grp_node) return controller_nodes = lib.create_controller( controller_name, pivot_node, main_node, loc_grp_node, start_frame, end_frame, space, smart_bake, camera) cmds.select(controller_nodes, replace=True) LOG.warn('Success: Create Controller.')
def updateModel(self): """ Refresh the name_comboBox with the current Maya scene state. """ self.populateModel(self.model) col = lib_state.get_active_collection() if col is None: return # range_type_value = self.getRangeTypeValue(col) index = self.getRangeTypeActiveIndex(self.model, col) if index is None: LOG.error('Could not get the active range type index.') return frames_string = '1001-1101' increment = self.getIncrementByFrameValue(col) frames_enabled = False increment_enabled = False if index == const.RANGE_TYPE_CURRENT_FRAME_VALUE: frames_string = 'CURRENT FRAME' frames_enabled = False increment_enabled = False elif index == const.RANGE_TYPE_TIMELINE_INNER_VALUE: start, end = utils_time.get_maya_timeline_range_inner() frames_string = '{0}-{1}'.format(int(start), int(end)) frames_enabled = False increment_enabled = True elif index == const.RANGE_TYPE_TIMELINE_OUTER_VALUE: start, end = utils_time.get_maya_timeline_range_outer() frames_string = '{0}-{1}'.format(int(start), int(end)) frames_enabled = False increment_enabled = True elif index == const.RANGE_TYPE_CUSTOM_FRAMES_VALUE: frames_string = self.getFramesValue(col) if frames_string is None: start, end = utils_time.get_maya_timeline_range_outer() frames_string = '{0}-{1}'.format(int(start), int(end)) frames_enabled = True increment_enabled = True else: msg = "Not a valid 'range type' value: %r" % index raise ValueError(msg) block = self.blockSignals(True) self.rangeType_comboBox.setCurrentIndex(index) self.frames_lineEdit.setEnabled(frames_enabled) self.frames_lineEdit.setText(frames_string) self.incrementByFrame_spinBox.setEnabled(increment_enabled) self.incrementByFrame_spinBox.setValue(increment) self.blockSignals(block) return
def populateUi(self): """ Update the UI for the first time the class is created. """ name = const.CONFIG_FRAME_RANGE_MODE_KEY value = configmaya.get_scene_option( name, default=const.DEFAULT_FRAME_RANGE_MODE) index = const.FRAME_RANGE_MODE_VALUES.index(value) label = const.FRAME_RANGE_MODE_LABELS[index] LOG.debug('key=%r value=%r', name, value) self.frameRangeModeComboBox.setCurrentText(label) enable_custom = value == const.FRAME_RANGE_MODE_CUSTOM_VALUE self.frameRangeStartSpinBox.setEnabled(enable_custom) self.frameRangeEndSpinBox.setEnabled(enable_custom) 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 value == const.FRAME_RANGE_MODE_TIMELINE_INNER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_inner() elif value == const.FRAME_RANGE_MODE_TIMELINE_OUTER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_outer() LOG.debug('key=%r value=%r', const.CONFIG_FRAME_START_KEY, frame_start) LOG.debug('key=%r value=%r', const.CONFIG_FRAME_END_KEY, frame_end) self.frameRangeStartSpinBox.setValue(frame_start) self.frameRangeEndSpinBox.setValue(frame_end) name = const.CONFIG_BAKE_MODE_KEY value = configmaya.get_scene_option(name, default=const.DEFAULT_BAKE_MODE) index = const.BAKE_MODE_VALUES.index(value) label = const.BAKE_MODE_LABELS[index] LOG.debug('key=%r value=%r', name, value) self.rotateOrderModeComboBox.setCurrentText(label) name = const.CONFIG_ROTATE_ORDER_MODE_KEY value = configmaya.get_scene_option( name, default=const.DEFAULT_ROTATE_ORDER_MODE) index = const.ROTATE_ORDER_MODE_VALUES.index(value) label = const.ROTATE_ORDER_MODE_LABELS[index] LOG.debug('key=%r value=%r', name, value) self.rotateOrderModeComboBox.setCurrentText(label) name = const.CONFIG_DELETE_STATIC_ANIM_CURVES_KEY value = configmaya.get_scene_option( name, default=const.DEFAULT_DELETE_STATIC_ANIM_CURVES) LOG.debug('key=%r value=%r', name, value) self.deleteStaticAnimCurvesCheckBox.setChecked(value) return
def __compile_frame_list(range_type, frame_string, by_frame): assert isinstance(range_type, int) assert frame_string is None or isinstance(frame_string, basestring) assert isinstance(by_frame, int) frame_nums = [] if range_type == const.RANGE_TYPE_TIMELINE_INNER_VALUE: start, end = utils_time.get_maya_timeline_range_inner() frame_nums = [f for f in xrange(start, end + 1, by_frame)] elif range_type == const.RANGE_TYPE_TIMELINE_OUTER_VALUE: start, end = utils_time.get_maya_timeline_range_outer() frame_nums = [f for f in xrange(start, end + 1, by_frame)] elif range_type == const.RANGE_TYPE_CUSTOM_FRAMES_VALUE: if frame_string is None: start, end = utils_time.get_maya_timeline_range_inner() frame_string = '{0}-{1}'.format(start, end) frame_nums = converttypes.stringToIntList(frame_string) # Apply 'by_frame' to custom frame ranges. start = min(frame_nums) frame_nums = [ n for n in frame_nums if (float(n - start) % by_frame) == 0 ] return frame_nums
def create_solver_step(): """ Create a SolverStep object and return it. """ data = const.SOLVER_STEP_DATA_DEFAULT.copy() data['name'] = str(uuid.uuid4()) start, end = utils_time.get_maya_timeline_range_inner() frame_list = list(xrange(start, end + 1)) data['frame_list'] = frame_list step = solver_step.SolverStep(data=data) return step
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 get_bake_frame_range(frame_range_mode, custom_start_frame, custom_end_frame): assert isinstance(frame_range_mode, basestring) assert frame_range_mode in const.FRAME_RANGE_MODE_VALUES assert isinstance(custom_start_frame, (int, long)) assert isinstance(custom_end_frame, (int, long)) frame_range = None if frame_range_mode == const.FRAME_RANGE_MODE_TIMELINE_INNER_VALUE: frame_range = time_utils.get_maya_timeline_range_inner() elif frame_range_mode == const.FRAME_RANGE_MODE_TIMELINE_OUTER_VALUE: frame_range = time_utils.get_maya_timeline_range_outer() elif frame_range_mode == const.FRAME_RANGE_MODE_CUSTOM_VALUE: frame_range = time_utils.FrameRange(custom_start_frame, custom_end_frame) else: LOG.error("Invalid frame range mode: %r", frame_range_mode) return frame_range
def _create_main_driver(parent, main): start, end = time_utils.get_maya_timeline_range_inner() main_driver_loc = cmds.duplicate(parent) cmds.setAttr(main_driver_loc[0] + ".visibility", 0) cmds.parent(main_driver_loc, parent) parent_con = cmds.parentConstraint(main, main_driver_loc) # bake attributes attrs = [] fastbake_lib.bake_attributes(main_driver_loc, attrs, start, end, smart_bake=False) cmds.delete(parent_con) # hide in outliner cmds.setAttr(main_driver_loc[0] + ".hiddenInOutliner", 1) return main_driver_loc
def autoClicked(self): col = lib_state.get_active_collection() if col is None: return mkr_list = col.get_marker_list() start_frame, end_frame = utils_time.get_maya_timeline_range_inner() min_frames_per_marker = 2 frame_nums = mmapi.get_root_frames_from_markers( mkr_list, min_frames_per_marker, start_frame, end_frame) if len(frame_nums) < 2: LOG.warn( 'Auto Root Frames failed to calculate - not enough markers.') return roots_string = convert_types.intListToString(frame_nums) self.setRootFramesValue(col, roots_string) self.rootFrames_lineEdit.setText(roots_string) return
def populateUi(self): """ Update the UI for the first time the class is created. """ name = const.CONFIG_FRAME_RANGE_MODE_KEY value = configmaya.get_scene_option( name, default=const.DEFAULT_FRAME_RANGE_MODE) index = const.FRAME_RANGE_MODE_VALUES.index(value) label = const.FRAME_RANGE_MODE_LABELS[index] LOG.debug('key=%r value=%r', name, value) self.frameRangeModeComboBox.setCurrentText(label) enable_custom = value == const.FRAME_RANGE_MODE_CUSTOM_VALUE self.frameRangeStartSpinBox.setEnabled(enable_custom) self.frameRangeEndSpinBox.setEnabled(enable_custom) 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 value == const.FRAME_RANGE_MODE_CURRENT_FRAME_VALUE: frame_start = maya.cmds.currentTime(query=True) frame_end = frame_start elif value == const.FRAME_RANGE_MODE_TIMELINE_INNER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_inner() elif value == const.FRAME_RANGE_MODE_TIMELINE_OUTER_VALUE: frame_start, frame_end = time_utils.get_maya_timeline_range_outer() LOG.debug('key=%r value=%r', const.CONFIG_FRAME_START_KEY, frame_start) LOG.debug('key=%r value=%r', const.CONFIG_FRAME_END_KEY, frame_end) self.frameRangeStartSpinBox.setValue(frame_start) self.frameRangeEndSpinBox.setValue(frame_end) name = const.CONFIG_BUNDLE_ROTATE_MODE_KEY value = configmaya.get_scene_option( name, default=const.DEFAULT_BUNDLE_ROTATE_MODE) index = const.BUNDLE_ROTATE_MODE_VALUES.index(value) label = const.BUNDLE_ROTATE_MODE_LABELS[index] LOG.debug('key=%r value=%r', name, value) self.bundleRotateModeComboBox.setCurrentText(label) name = const.CONFIG_BUNDLE_UNLOCK_RELOCK_KEY value = configmaya.get_scene_option( name, default=const.DEFAULT_BUNDLE_UNLOCK_RELOCK) LOG.debug('key=%r value=%r', name, value) self.bundleUnlockRelockCheckBox.setChecked(value) return
def get_prebake_frames_list_from_node(self, node): frames_list = [] start_frame, end_frame = time_utils.get_maya_timeline_range_inner() keys_list = cmds.keyframe(node, q=True, time=(start_frame, end_frame)) or [] if len(keys_list) == 0: frames_list = [start_frame, end_frame] bake_options = self.get_bake_options() if bake_options == 'full_bake': for frame in range(start_frame, end_frame + 1): if frame not in frames_list: frames_list.append(frame) if bake_options == 'smart_bake': keys_list = cmds.keyframe(node, q=True, time=(start_frame, end_frame)) or [] for frame in keys_list: if frame not in frames_list: frames_list.append(frame) return sorted(frames_list)
def getPreBakeFramesListFromNode(self, node): frames_list = [] start_frame, end_frame = time_utils.get_maya_timeline_range_inner() keys_list = cmds.keyframe(node, q=True, time=(start_frame, end_frame)) if keys_list == None: frames_list = [start_frame, end_frame] bake_options = self.bakeOptions() if bake_options == 'full_bake': for frame in range(start_frame, end_frame + 1): if frame not in frames_list: frames_list.append(frame) if bake_options == 'smart_bake': keys_list = cmds.keyframe(node, q=True, time=(start_frame, end_frame)) or [] for frame in keys_list: if frame not in frames_list: frames_list.append(frame) return sorted(frames_list)
def test_get_root_frames_from_markers_3(self): # Time Range start = 0 end = 41 maya.cmds.playbackOptions(animationStartTime=start, minTime=start, animationEndTime=end, maxTime=end) # Create Camera cam_tfm = maya.cmds.createNode('transform', name='cam_tfm') cam_shp = maya.cmds.createNode('camera', name='cam_shp', parent=cam_tfm) cam = mmapi.Camera(shape=cam_shp) # Create image plane path = self.get_data_path('operahouse', 'frame00.jpg') imgpl = maya.cmds.imagePlane(camera=cam_shp, fileName=path) maya.cmds.setAttr(imgpl[1] + '.useFrameExtension', 1) # Load Marker Data path = self.get_data_path('match_mover', 'loadmarker.rz2') _, mkr_data_list = marker_read.read(path) # Create Markers mkr_grp = mmapi.MarkerGroup().create_node(cam=cam) mkr_list = marker_read.create_nodes(mkr_data_list, cam=cam, mkr_grp=mkr_grp) # Calculate Root Frames min_frames_per_marker = 3 start_frame, end_frame = time_utils.get_maya_timeline_range_inner() frame_nums = mod.get_root_frames_from_markers(mkr_list, min_frames_per_marker, start_frame, end_frame) print 'frames:', frame_nums return
def create_screen_space_motion_trail(cam, tfm, name=None, use_frame_range=None, pre_frame=None, post_frame=None, start_frame=None, end_frame=None, increment=None): """ Create a Screen-Space Maya Locator that may be solved in Screen XYZ. """ assert isinstance(cam, pycompat.TEXT_TYPE) assert isinstance(tfm, pycompat.TEXT_TYPE) if name is None: name = tfm.rpartition('|')[-1] frame_range = time_utils.get_maya_timeline_range_inner() if use_frame_range is None: use_frame_range = const.USE_FRAME_RANGE_DEFAULT if pre_frame is None: pre_frame = const.PRE_FRAME_DEFAULT if post_frame is None: post_frame = const.POST_FRAME_DEFAULT if start_frame is None: start_frame = frame_range.start if end_frame is None: end_frame = frame_range.end if increment is None: if use_frame_range: increment = const.FRAME_RANGE_INCREMENT_DEFAULT else: increment = const.PER_FRAME_INCREMENT_DEFAULT tfm_attrs = [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ' ] maya.cmds.loadPlugin('matrixNodes', quiet=True) cam_tfm, cam_shp = camera_utils.get_camera(cam) # Create temporary group temp_grp_name = const.TEMP_OBJECT_NAME temp_grp = temp_grp_name if not maya.cmds.objExists(temp_grp): temp_grp = maya.cmds.createNode('transform', name=temp_grp_name) maya.cmds.setAttr(temp_grp + '.visibility', False) # Create Temporary transform node to calculate motion path on. temp_tfm_name = name + '_TEMP_NULL' temp_tfm_name = mmapi.find_valid_maya_node_name(temp_tfm_name) temp_tfm = maya.cmds.createNode('transform', parent=temp_grp, name=temp_tfm_name) # Create trail group under the camera. trail_handle_grp_name = const.MOTION_PATH_GROUP_NAME trail_handle_grp = cam_tfm + '|' + trail_handle_grp_name if not maya.cmds.objExists(trail_handle_grp): trail_handle_grp = maya.cmds.createNode('transform', name=trail_handle_grp_name, parent=cam_tfm) # Trails are non-selectable by default. plug_name = trail_handle_grp + '.template' maya.cmds.setAttr(plug_name, True) # Lock transform attributes. for attr in tfm_attrs: plug_name = trail_handle_grp + '.' + attr maya.cmds.setAttr(plug_name, lock=True) # Matrix Multiply mult_mat = maya.cmds.createNode('multMatrix') src = tfm + '.worldMatrix[0]' dst = mult_mat + '.matrixIn[0]' maya.cmds.connectAttr(src, dst) src = cam_tfm + '.worldInverseMatrix[0]' dst = mult_mat + '.matrixIn[1]' maya.cmds.connectAttr(src, dst) # Decompose Matrix decompose = maya.cmds.createNode('decomposeMatrix') src = mult_mat + '.matrixSum' dst = decompose + '.inputMatrix' maya.cmds.connectAttr(src, dst) src = decompose + '.outputTranslate' dst = temp_tfm + '.translate' maya.cmds.connectAttr(src, dst) # Lock the temporary transform node. for attr in tfm_attrs: plug_name = temp_tfm + '.' + attr maya.cmds.setAttr(plug_name, lock=True) # Create Motion Trail update_mode = 'always' handle_tfm, handle_shp, trail_shp = create_motion_trail_setup( temp_tfm, trail_handle_grp, name, use_frame_range, start_frame, end_frame, pre_frame, post_frame, increment, update_mode, ) return handle_tfm, handle_shp, trail_shp
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
import mmSolver.utils.node as node_utils import mmSolver.utils.transform as tfm_utils import mmSolver.utils.time as time_utils import mmSolver.tools.createcamerabodytrackscalerigbake.constant as const import mmSolver.tools.attributebake.lib as fastbake_lib import mmSolver.tools.createcontroller2.lib as createcontroller2_lib import mmSolver.tools.createcontroller2.constant as createcontroller2_const import mmSolver.tools.reparent2.lib as reparent2_lib LOG = mmSolver.logger.get_logger() suffix = const.SCALE_RIG_SUFFIX main_grp_suffix = const.SCALE_RIG_MAIN_GRP_SUFFIX frame_start, frame_end = time_utils.get_maya_timeline_range_inner() def _is_rig_node(node): """Check if the node is a rig node.""" if node_utils.attribute_exists(const.SCALE_RIG_IDENTIFIER_ATTR_NAME, node): return True return False def _get_rig_node_identifier(node, attr): """Get custom attribute value to identify rig node.""" if _is_rig_node(node): plug = node + '.' + attr attr_value = cmds.getAttr(plug) return attr_value return None
def main(): """ Screen-Space Bake. Usage: 1) Select transform nodes. 2) Activate viewport. 3) Run tool. 4) A new locator is created under the active camera """ mmapi.load_plugin() editor = viewport_utils.get_active_model_editor() if editor is None: LOG.error('Please select an active viewport; editor=%r', editor) return cam_tfm, cam_shp = viewport_utils.get_viewport_camera(editor) if cam_tfm is None or cam_shp is None: LOG.error('Please select a camera; cam_tfm=%r cam_shp=%r', cam_tfm, cam_shp) return cam = mmapi.Camera(transform=cam_tfm, shape=cam_shp) img_width = maya.cmds.getAttr(cam_shp + '.horizontalFilmAperture') * 100.0 img_height = maya.cmds.getAttr(cam_shp + '.verticalFilmAperture') * 100.0 nodes = maya.cmds.ls( selection=True, long=True, type='transform' ) or [] if len(nodes) == 0: LOG.error('Please select transform nodes; %r', nodes) return start_frame, end_frame = utils_time.get_maya_timeline_range_inner() times = range(start_frame, end_frame+1) created_loc_tfms = [] for node in nodes: grp_node, depth_tfm, loc_tfm, loc_shp = lib.create_screen_space_locator(cam) created_loc_tfms.append(loc_tfm) # BUG: If a camera has 'camera scale' attribute set other than # 1.0, the reprojected values will not be correct. values = maya.cmds.mmReprojection( node, camera=(cam_tfm, cam_shp), time=times, asMarkerCoordinate=True, imageResolution=(int(img_width), int(img_height)), ) stop = len(values) step = 3 plug = loc_tfm + '.translateX' values_x = values[0:stop:step] animfn_x = anim_utils.create_anim_curve_node_apione( times, values_x, node_attr=plug ) plug = loc_tfm + '.translateY' values_y = values[1:stop:step] animfn_y = anim_utils.create_anim_curve_node_apione( times, values_y, node_attr=plug ) plug = depth_tfm + '.scaleX' values_z = values[2:stop:step] animfn_z = anim_utils.create_anim_curve_node_apione( times, values_z, node_attr=plug ) if len(created_loc_tfms) > 0: maya.cmds.select(created_loc_tfms, replace=True) # Trigger Maya to refresh. maya.cmds.currentTime(update=True) maya.cmds.refresh() return
def compile_collection(col, prog_fn=None): """ Compiles, checks and validates the collection, ready for a solve. :param col: Collection to execute. :type col: Collection :param prog_fn: Progress function that is called each time progress is made. The function should take a single 'int' argument, and the integer is expected to be a percentage value, between 0 and 100. :type prog_fn: None or function """ s = time.time() sol_list = [] solver_tab = col_state.get_solver_tab_from_collection(col) assert isinstance(solver_tab, (str, unicode)) if solver_tab == const.SOLVER_TAB_BASIC_VALUE: sol = mmapi.SolverBasic() range_type = col_state.get_solver_range_type_from_collection(col) if range_type == const.RANGE_TYPE_CURRENT_FRAME_VALUE: frame_num = lib_maya_utils.get_current_frame() frame = mmapi.Frame(frame_num) sol.set_use_single_frame(True) sol.set_single_frame(frame) sol_list.append(sol) else: by_frame = col_state.get_solver_increment_by_frame_from_collection( col) frame_string = col_state.get_solver_frames_from_collection(col) frame_nums = __compile_frame_list(range_type, frame_string, by_frame) frames = [mmapi.Frame(f) for f in frame_nums] sol.set_frame_list(frames) sol_list.append(sol) elif solver_tab == const.SOLVER_TAB_STANDARD_VALUE: sol = mmapi.SolverStandard() range_type = col_state.get_solver_range_type_from_collection(col) if range_type == const.RANGE_TYPE_CURRENT_FRAME_VALUE: frame_num = lib_maya_utils.get_current_frame() frame = mmapi.Frame(frame_num) sol.set_use_single_frame(True) sol.set_single_frame(frame) sol_list.append(sol) else: # Frame numbers by_frame = col_state.get_solver_increment_by_frame_from_collection( col) frame_string = col_state.get_solver_frames_from_collection(col) frame_nums = __compile_frame_list(range_type, frame_string, by_frame) # Root frame numbers root_frame_num_string = col_state.get_solver_root_frames_from_collection( col) if root_frame_num_string is None: start, end = utils_time.get_maya_timeline_range_inner() root_frame_num_string = '{0},{1}'.format(start, end) root_frame_nums = converttypes.stringToIntList( root_frame_num_string) frames = [ mmapi.Frame(f) for f in frame_nums if f not in root_frame_nums ] root_frames = [mmapi.Frame(f) for f in root_frame_nums] sol.set_root_frame_list(root_frames) sol.set_frame_list(frames) global_solve = col_state.get_solver_global_solve_from_collection( col) only_root = col_state.get_solver_only_root_frames_from_collection( col) sol.set_global_solve(global_solve) sol.set_only_root_frames(only_root) sol_list.append(sol) elif solver_tab.lower() == const.SOLVER_TAB_LEGACY_VALUE: step_list = get_solver_steps_from_collection(col) sol_list = compile_solvers_from_steps(col, step_list, prog_fn=prog_fn) else: msg = 'Solver tab value is invalid: %r' raise TypeError(msg % solver_tab) col.set_solver_list(sol_list) e = time.time() LOG.debug('Compile time (GUI): %r seconds', e - s) return
def bake_rig_clicked(self): bake_options = self.get_bake_options() selected_items = self.rigsList.selectedItems() start_frame, end_frame = time_utils.get_maya_timeline_range_inner() if len(selected_items) == 0: LOG.warn('Atleast one rig must be selected from UI.') return """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.get_all_children(sel_item) for j in children: rigName = j.text(0) object = cmds.getAttr( rigName + '.' + const.ATTRIBUTE_IDENTIFIER_NAME) if const.FREEZE_RIG_SUFFIX_NAME in rigName: self.fullBakeRadioButton.setChecked(True) if const.RIG_SUFFIX_NAME in rigName: name = rigName.split(const.RIG_SUFFIX_NAME)[0] if const.FREEZE_RIG_SUFFIX_NAME in rigName: name = rigName.split(const.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 + const.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.get_prebake_frames_list_from_node( object): oma.MAnimControl.setCurrentTime(om.MTime(frame)) cmds.setKeyframe(attribute=attrs) # Key screen z depth attribute frames keys_list = cmds.keyframe( rigName + '.' + const.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.delete_rig_clicked() self.refresh_rigsList() return
def create_freeze_rig_clicked(self): nameLineEdit = self.nameLineEdit.text() rigsList = self.rigsList cam_tfm = self.get_vp_camera() if cam_tfm is None: LOG.warn('Please select a camera.') return check_name = self.check_name_exists(const.FREEZE_RIG_SUFFIX_NAME, nameLineEdit, rigsList) valid_name_list, same_name_used = check_name if valid_name_list is not True or same_name_used is not False: LOG.warn('Invalid freeze rig name.') return do_camera_space = self.camera_space_action.isChecked() do_world_space = self.world_space_action.isChecked() use_anim_layer = self.animlayer_action.isChecked() # When making a freeze rig we always assume the full frame # range will be baked - NO smart bake. LOG.warn('Force full bake for Freeze Rig.') self.fullBakeRadioButton.setChecked(True) start_frame, end_frame = time_utils.get_maya_timeline_range_inner() sel = cmds.ls(orderedSelection=True, transforms=True) or [] names = nameLineEdit.split(',') """ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=False) with ctx:""" for sel_item, name_item in zip(sel, names): freeze_rig_name = name_item + const.FREEZE_RIG_SUFFIX_NAME animLayerName = name_item + const.FREEZE_RIG_ANIM_LAYER # Check if object has existing point constraint already. has_constraints = transform_has_constraints(sel_item) if has_constraints is True: LOG.warn( 'Selected object(s) already have constraints: %r.', sel_item) continue # Get the selected item's depth, if we don't have # anything, we cannot continue. dlist = self.calc_distance(cam_tfm, sel_item, 0) if len(dlist) == 0: continue if do_camera_space: # Camera space bake self.create_rig( cam_tfm, sel_item, dlist, name_item, const.FREEZE_RIG_SUFFIX_NAME) cmds.cutKey( name_item + const.FREEZE_RIG_SUFFIX_NAME, clear=True, at=const.SCREEN_Z_DEPTH_ATTR_NAME) else: # World space bake # Create a static temp group temp_grp = cmds.group(empty=True) con = cmds.parentConstraint( sel_item, temp_grp, maintainOffset=False) cmds.delete(con) fastbake_lib.bake_attributes([temp_grp], [], start_frame, end_frame, False) self.create_rig(cam_tfm, sel_item, dlist, name_item, const.FREEZE_RIG_SUFFIX_NAME) # Calc full freeze list dlist = self.calc_distance(cam_tfm, temp_grp, 0) if use_anim_layer is False: # Set keyframes on screenzdepth attribute, # with no anim layer. set_z_depth_keyframes( freeze_rig_name, start_frame, end_frame, dlist) else: # Make the anim layer, and add our freeze rig # node to the layer. cmds.select(freeze_rig_name, replace=True) cmds.animLayer( animLayerName, addSelectedObjects=True) cmds.select(clear=True) set_z_depth_keyframes( freeze_rig_name, start_frame, end_frame, dlist, anim_layer_name=animLayerName) # Delete temp group cmds.delete(temp_grp) return
def create_rig(self, camera, object, dlist, name, rigName): """ctx = tools_utils.tool_context( use_undo_chunk=True, restore_current_frame=True, use_dg_evaluation_mode=True, disable_viewport=False) with ctx:""" start_frame, end_frame = time_utils.get_maya_timeline_range_inner() # Create main group main_grp = cmds.group(empty=True, n=name + rigName) # Delete all transform attributes attr_list = const.TRANSFORM_ATTR_LIST + ['visibility'] for attr in attr_list: cmds.setAttr(main_grp + '.' + attr, keyable=False, lock=True) # Add custom attributes cmds.addAttr(main_grp, ln='screenX', nn='Screen X', at='float', k=True) cmds.addAttr(main_grp, ln='screenY', nn='Screen Y', at='float', k=True) cmds.addAttr(main_grp, ln=const.SCREEN_Z_DEPTH_ATTR_NAME, nn='Screen Z depth', at='float', k=True) cmds.addAttr(main_grp, ln=const.ATTRIBUTE_IDENTIFIER_NAME, nn=const.ATTRIBUTE_IDENTIFIER_NICE_NAME, dt='string', k=False) cmds.setAttr(main_grp + '.' + const.ATTRIBUTE_IDENTIFIER_NAME, str(object), type='string') # Set keyframes on screezdepth attribute frames_list = self.get_prebake_frames_list_from_node(object) for i, frame in enumerate(frames_list): cmds.setKeyframe(main_grp, at=const.SCREEN_Z_DEPTH_ATTR_NAME, t=frame, v=dlist[i]) # Clear name text self.nameLineEdit.clear() self.nameLineEdit.clearFocus() # Create screez master group screenz_master_grp = cmds.group(em=True, n=name + const.SCREEN_Z_MASTER_NAME) cmds.setAttr(screenz_master_grp + '.visibility', 0) # Add screen X/Y copy attributes cmds.addAttr(screenz_master_grp, ln='copyScreenX', nn='Screen X copy', at='float') cmds.addAttr(screenz_master_grp, ln='copyScreenY', nn='Screen Y copy', at='float') cmds.setAttr(screenz_master_grp + '.copyScreenX', cb=False) cmds.setAttr(screenz_master_grp + '.copyScreenY', cb=False) cmds.parent(screenz_master_grp, main_grp) con = cmds.parentConstraint(self.get_vp_camera(), screenz_master_grp) fastbake_lib.bake_attributes([screenz_master_grp], [], start_frame, end_frame, False) cmds.delete(con) # Create screen Z-depth connections cmds.connectAttr(main_grp + '.' + const.SCREEN_Z_DEPTH_ATTR_NAME, screenz_master_grp + '.scaleX', f=True) cmds.connectAttr(main_grp + '.' + const.SCREEN_Z_DEPTH_ATTR_NAME, screenz_master_grp + '.scaleY', f=True) cmds.connectAttr(main_grp + '.' + const.SCREEN_Z_DEPTH_ATTR_NAME, screenz_master_grp + '.scaleZ', f=True) # Create screen X/Y master group screen_xy_master_grp = cmds.group(em=True, n=name + const.SCREEN_XY_MASTER_NAME) cmds.setAttr(screen_xy_master_grp + '.visibility', 0) attr_list = ['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'visibility'] for attr in attr_list: cmds.setAttr(screen_xy_master_grp + '.' + attr, keyable=False, lock=True) cmds.parent(screen_xy_master_grp, screenz_master_grp, r=True) con = cmds.pointConstraint(object, screen_xy_master_grp) fastbake_lib.bake_attributes([screen_xy_master_grp], [], start_frame, end_frame, False) cmds.delete(con) cmds.setAttr(screen_xy_master_grp + '.translateZ', lock=True) # Create screen X/Y connections cmds.connectAttr(screen_xy_master_grp + '.translateX', main_grp + '.screenX', f=True) cmds.connectAttr(screen_xy_master_grp + '.translateY', main_grp + '.screenY', f=True) cmds.connectAttr(screen_xy_master_grp + '.translateX', screenz_master_grp + '.copyScreenX', f=True) cmds.connectAttr(screen_xy_master_grp + '.translateY', screenz_master_grp + '.copyScreenY', f=True) fastbake_lib.bake_attributes([main_grp], ['screenX', 'screenY'], start_frame, end_frame, False) fastbake_lib.bake_attributes([screenz_master_grp], ['copyScreenX', 'copyScreenY'], start_frame, end_frame, False) cmds.connectAttr(main_grp + '.screenX', screen_xy_master_grp + '.translateX', f=True) cmds.connectAttr(main_grp + '.screenY', screen_xy_master_grp + '.translateY', f=True) # Create condition node network screenx_condition_node = cmds.shadingNode( 'condition', au=True, n=name + '_screenX_condition') screeny_condition_node = cmds.shadingNode( 'condition', au=True, n=name + '_screenY_condition') cmds.connectAttr(main_grp + '.screenX', screenx_condition_node + '.firstTerm', f=True) cmds.connectAttr(screenz_master_grp + '.copyScreenX', screenx_condition_node + '.secondTerm', f=True) cmds.connectAttr(main_grp + '.screenY', screeny_condition_node + '.firstTerm', f=True) cmds.connectAttr(screenz_master_grp + '.copyScreenY', screeny_condition_node + '.secondTerm', f=True) attr_list = const.TRANSFORM_ATTR_LIST + ['visibility'] for attr in attr_list: cmds.setAttr(screenz_master_grp + '.' + attr, lock=True) cmds.pointConstraint(screen_xy_master_grp, object) # Select the master control. cmds.select(main_grp, replace=True) self.refresh_rigsList()
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
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