def main(): """ Renames selected markers and bundles (and the connected nodes). """ selection = maya.cmds.ls(selection=True, long=True) or [] sel_mkr_nodes = mmapi.filter_marker_nodes(selection) sel_bnd_nodes = mmapi.filter_bundle_nodes(selection) if len(sel_mkr_nodes) == 0 and len(sel_bnd_nodes) == 0: LOG.warning('Please select markers or bundles to rename.') return title = const.TITLE message = const.MESSAGE text = const.MARKER_NAME mkr_name = lib.prompt_for_new_node_name(title, message, text) if mkr_name is None: # If user clicks cancel on prompt window it returns None. LOG.warning('User canceled rename.') return number_format = const.NUMBER_FORMAT mkr_suffix = const.MARKER_SUFFIX bnd_suffix = const.BUNDLE_SUFFIX if mkr_name == text: bnd_name = const.BUNDLE_NAME else: bnd_name = mkr_name nodes = lib.rename_markers_and_bundles(sel_mkr_nodes, sel_bnd_nodes, mkr_name, bnd_name, number_format, mkr_suffix, bnd_suffix) maya.cmds.select(nodes, replace=True) return
def main(): """ This tool renames selected markers and bundles with the internal metadata names stored on the markers. """ selection = maya.cmds.ls(selection=True, long=True) or [] sel_mkr_nodes = mmapi.filter_marker_nodes(selection) sel_bnd_nodes = mmapi.filter_bundle_nodes(selection) if len(sel_mkr_nodes) == 0 and len(sel_bnd_nodes) == 0: LOG.warning('Please select markers or bundles to rename.') return number_format = const.NUMBER_FORMAT mkr_prefix = const.MARKER_PREFIX mkr_suffix = const.MARKER_SUFFIX bnd_prefix = const.BUNDLE_PREFIX bnd_suffix = const.BUNDLE_SUFFIX nodes = lib.rename_markers_and_bundles_with_metadata( sel_mkr_nodes, sel_bnd_nodes, mkr_prefix, bnd_prefix, mkr_suffix, bnd_suffix) if len(nodes) == 0: maya.cmds.select(selection, replace=True) else: maya.cmds.select(nodes, replace=True) return
def main(): """ Toggles selected bundle lock state. """ selection = maya.cmds.ls(selection=True, long=True) or [] selected_bundles = mmapi.filter_bundle_nodes(selection) if len(selected_bundles) == 0: LOG.warning("Please select bundle's to lock or unlock") return attrs = const.ATTRS bundle_attrs = [] for bundle in selected_bundles: for attr in attrs: bundle_attrs.append('%s.%s' % (bundle, attr)) is_locked = False for attr in bundle_attrs: if maya.cmds.getAttr(attr, lock=True): is_locked = True for attr in bundle_attrs: lock_value = not is_locked maya.cmds.setAttr(attr, lock=lock_value) return
def main(): """ Renames selected markers and bundles (and the connected nodes). """ selection = maya.cmds.ls(selection=True, long=True) or [] bnd_nodes = mmapi.filter_bundle_nodes(selection) crv_shp_nodes = lib.get_nurbs_curve_nodes(selection) if len(bnd_nodes) == 0 and len(crv_shp_nodes) != 1: msg = 'Please select at least one Bundle and only one NURBS curve.' LOG.warning(msg) return if len(bnd_nodes) > 0 and len(crv_shp_nodes) != 1: msg = 'Please select one NURBS curve.' LOG.warning(msg) return if len(bnd_nodes) == 0 and len(crv_shp_nodes) == 1: msg = 'Please select at least one Bundle.' LOG.warning(msg) return attr_name = const.ATTR_NAME crv_shp_node = crv_shp_nodes[0] for bnd_node in bnd_nodes: lib.attach_bundle_to_curve(bnd_node, crv_shp_node, attr_name) maya.cmds.select(bnd_nodes) return
def link_marker_bundle(): """ Select a marker node, and a bundle node, run to link both nodes. """ sel = maya.cmds.ls(selection=True, long=True) or [] mkr_nodes = mmapi.filter_marker_nodes(sel) bnd_nodes = mmapi.filter_bundle_nodes(sel) if len(mkr_nodes) != 1 and len(bnd_nodes) != 1: msg = 'Please select only one Marker and one Bundle.' LOG.warning(msg) return if len(mkr_nodes) != 1: msg = 'Please select only one Marker.' LOG.warning(msg) if len(bnd_nodes) != 1: msg = 'Please select only one Bundle.' LOG.warning(msg) if len(mkr_nodes) != 1 or len(bnd_nodes) != 1: return lib.link_marker_bundle(mkr_nodes[0], bnd_nodes[0]) return
def test_solveAllFramesCausesStaticAnimCurves(self): """ Solving with the scene file 'mmSolverBasicSolveB_before.ma', was reported to solve as static values, the same as the initial values. The DG did not evaluate some how and the solve was therefore useless. GitHub Issue #53. """ s = time.time() # Open the Maya file file_name = 'mmSolverBasicSolveB_before.ma' path = self.get_data_path('scenes', file_name) maya.cmds.file(path, open=True, force=True, ignoreVersion=True) # NOTE: We leave these nodes alone, since these are already in # the 'correct' position, we are treating these as surveyed. # When we have less than 3 points as survey the solve goes # crazy. dont_touch_these_nodes = [ '|bundle_12_BND', '|bundle_13_BND', '|bundle_14_BND'] # Triangulate all 3D points. nodes = maya.cmds.ls(type='transform') or [] bnd_nodes = mmapi.filter_bundle_nodes(nodes) bnd_list = [mmapi.Bundle(node=n) for n in bnd_nodes] for bnd in bnd_list: bnd_node = bnd.get_node() if bnd_node in dont_touch_these_nodes: continue attrs = ['translateX', 'translateY', 'translateZ'] for attr_name in attrs: plug = bnd_node + '.' + attr_name maya.cmds.setAttr(plug, lock=False) maya.cmds.setAttr(plug, 0.0) # Get Bundle attributes to compute. bnd_attr_list = [] for bnd in bnd_list: node = bnd.get_node() attrs = ['translateX', 'translateY', 'translateZ'] for attr_name in attrs: attr = mmapi.Attribute(node=node, attr=attr_name) bnd_attr_list.append(attr) # Camera attributes cam_tfm = 'stA_1_1' cam = mmapi.Camera(cam_tfm) cam_shp = cam.get_shape_node() cam_attr_list = [] attrs = ['translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ'] for attr_name in attrs: attr = mmapi.Attribute(node=cam_tfm, attr=attr_name) cam_attr_list.append(attr) attr = mmapi.Attribute(node=cam_shp, attr='focalLength') cam_attr_list.append(attr) # Frame List root_frm_list = [] not_root_frm_list = [] f_list = [14, 35, 50, 85] for f in f_list: frm = mmapi.Frame(f) root_frm_list.append(frm) for f in range(0, 94): frm = mmapi.Frame(f) not_root_frm_list.append(frm) # Run 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._auto_attr_blocks = True sol._triangulate_bundles = False sol.set_single_frame(False) sol.set_root_frame_strategy(mmapi.ROOT_FRAME_STRATEGY_GLOBAL_VALUE) # sol._robust_loss_type = mmapi.ROBUST_LOSS_TYPE_TRIVIAL_VALUE # sol._robust_loss_scale = 1.0 sol_list.append(sol) col = mmapi.Collection(node='collection1') col.set_attribute_list(cam_attr_list + bnd_attr_list) col.set_solver_list(sol_list) e = time.time() print 'pre=solve time:', e - s s = time.time() solres_list = col.execute() 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 name = 'test_solve_solveAllFramesCausesStaticAnimCurves_after.ma' path = self.get_data_path(name) maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) self.checkSolveResults(solres_list) return
def test_solveAllFramesCausesStaticAnimCurves(self): """ Solving with the scene file 'mmSolverBasicSolveB_before.ma', was reported to solve as static values, the same as the initial values. The DG did not evaluate some how and the solve was therefore useless. GitHub Issue #53. """ # Open the Maya file file_name = 'mmSolverBasicSolveB_before.ma' path = self.get_data_path('scenes', file_name) maya.cmds.file(path, open=True, force=True, ignoreVersion=True) # NOTE: We leave these nodes along, since these are already in # the 'correct' position, we are treating these as surveyed. # When we have less than 3 points as survey the solve goes # crazy. dont_touch_these_nodes = [ '|bundle_12_BND', '|bundle_13_BND', '|bundle_14_BND' ] # Triangulate all 3D points. nodes = maya.cmds.ls(type='transform') or [] bnd_nodes = mmapi.filter_bundle_nodes(nodes) bnd_list = [mmapi.Bundle(node=n) for n in bnd_nodes] for bnd in bnd_list: bnd_node = bnd.get_node() if bnd_node in dont_touch_these_nodes: continue attrs = ['translateX', 'translateY', 'translateZ'] for attr_name in attrs: plug = bnd_node + '.' + attr_name maya.cmds.setAttr(plug, lock=False) lib_triangulate.triangulate_bundle(bnd) # Get Bundle attributes to compute. bnd_attr_list = [] for bnd in bnd_list: node = bnd.get_node() attrs = ['translateX', 'translateY', 'translateZ'] for attr_name in attrs: attr = mmapi.Attribute(node=node, attr=attr_name) bnd_attr_list.append(attr) # Camera attributes cam_tfm = 'stA_1_1' cam_attr_list = [] attrs = [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ' ] for attr_name in attrs: attr = mmapi.Attribute(node=cam_tfm, attr=attr_name) cam_attr_list.append(attr) # Run solver! s = time.time() # Solve camera transform based on triangulated bundle # positions. col = mmapi.Collection(node='collection1') col.set_attribute_list(cam_attr_list) lib_col.compile_collection(col) solres_list = col.execute() print 'time (solve #1):', time.time() - s # Refine the bundle positions only s2 = time.time() col.set_attribute_list(bnd_attr_list) lib_col.compile_collection(col) solres_list = col.execute() print 'time (solve #2):', time.time() - s2 # # Solve both camera transform and bundle positions together. # s3 = time.time() # col.set_attribute_list(cam_attr_list + bnd_attr_list) # lib_col.compile_collection(col) # solres_list = col.execute() e = time.time() # print 'time (solve #3):', e - s3 print 'total time:', e - s # save the output name = 'test_solve_solveAllFramesCausesStaticAnimCurves_after.ma' path = self.get_data_path(name) maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) self.checkSolveResults(solres_list) return