def get_attribute_list(self): result = [] members = self._set.get_all_members(flatten=False, full_path=True) for member in members: object_type = api_utils.get_object_type(member) if object_type == const.OBJECT_TYPE_ATTRIBUTE: attr = attribute.Attribute(name=member) result.append(attr) return result
def get_marker_list(self): result = [] members = self._set.get_all_members(flatten=False, full_path=True) for member in members: object_type = api_utils.get_object_type(member) if object_type == const.OBJECT_TYPE_MARKER: mkr = marker.Marker(member) result.append(mkr) return result
def clear_attribute_list(self): members = self._set.get_all_members(flatten=False, full_path=True) rm_list = [] for member in members: object_type = api_utils.get_object_type(member) if object_type == const.OBJECT_TYPE_ATTRIBUTE: rm_list.append(member) if len(rm_list) > 0: self._set.remove_members(rm_list) self._kwargs_list = [] # reset argument flag cache. return
def test_get_object_type(self): """ Test getting string object types from a given Maya node. TODO: Does not provide a 'collection' example. """ # Camera Type cam_tfm = maya.cmds.createNode('transform') cam_tfm = node_utils.get_long_name(cam_tfm) cam_shp = maya.cmds.createNode('camera', parent=cam_tfm) cam_shp = node_utils.get_long_name(cam_shp) tfm_obj_type = api_utils.get_object_type(cam_tfm) shp_obj_type = api_utils.get_object_type(cam_shp) self.assertEqual(tfm_obj_type, const.OBJECT_TYPE_CAMERA) self.assertEqual(shp_obj_type, const.OBJECT_TYPE_CAMERA) # Marker Type mkr = marker.Marker().create_node() mkr_node = mkr.get_node() obj_type = api_utils.get_object_type(mkr_node) self.assertEqual(obj_type, const.OBJECT_TYPE_MARKER) # Marker shape node must also return as OBJECT_TYPE_MARKER mkr_shp_node = maya.cmds.listRelatives(mkr_node, shapes=True)[0] obj_type = api_utils.get_object_type(mkr_shp_node) self.assertEqual(obj_type, const.OBJECT_TYPE_UNKNOWN) # Marker Group node = maya.cmds.createNode('mmMarkerGroupTransform') obj_type = api_utils.get_object_type(node) self.assertEqual(obj_type, const.OBJECT_TYPE_MARKER_GROUP) # A Bundle must be more than just a transform and locator. # Use mmSolver.api.Bundle.create_node() to create a Bundle. # # GitHub Issue #6. bnd_node = maya.cmds.createNode('transform') bnd_shp_node = maya.cmds.createNode('locator', parent=bnd_node) obj_type = api_utils.get_object_type(bnd_node) self.assertEqual(obj_type, const.OBJECT_TYPE_UNKNOWN) # Giving a shape will not work. obj_type = api_utils.get_object_type(bnd_shp_node) self.assertEqual(obj_type, const.OBJECT_TYPE_UNKNOWN) # Attribute Type node_attr = node + '.scaleX' obj_type = api_utils.get_object_type(node_attr) self.assertEqual(obj_type, const.OBJECT_TYPE_ATTRIBUTE)
def clear_attribute_list(self): members = self._set.get_all_members(flatten=False, full_path=True) rm_list = [] for member in members: object_type = api_utils.get_object_type(member) if object_type == const.OBJECT_TYPE_ATTRIBUTE: rm_list.append(member) if len(rm_list) > 0: self._set.remove_members(rm_list) self._actions_list = [] # reset argument flag cache. event_utils.trigger_event(const.EVENT_NAME_COLLECTION_ATTRS_CHANGED, col=self) return
def collect_bundles(node_categories): unknown_node_found = False list_to_delete = list() for node in node_categories['bundle']: if cmds.objectType(node) != 'transform': continue list_to_delete.append(node) children = cmds.listRelatives(node, children=True, type='transform', fullPath=True) if children: for child in children: if api_utils.get_object_type(child) != 'bundle': unknown_node_found = True return list_to_delete, unknown_node_found
def __init__(self, name=None, node=None, attr=None): """ Initialise an Attribute object. Attribute can use a 'name', or 'node' and 'attr'. A 'name' is a string of both node and attribute path; `node.attr`. :param name: Node and attribute path as a single string: 'node.attr' :type name: str :param node: DG Maya node path. :type node: str :param attr: Long or short attribute name. :type attr: str """ if isinstance(name, (str, unicode)): assert api_utils.get_object_type( name) == const.OBJECT_TYPE_ATTRIBUTE part = name.partition('.') node = part[0] attr = part[-1] self._plug = None self._dependFn = None if isinstance(node, (str, unicode)) and isinstance(attr, (str, unicode)): assert maya.cmds.objExists(node) # Long and short names must be checked. attr_list_long = maya.cmds.listAttr(node, shortNames=False) or [] attr_list_short = maya.cmds.listAttr(node, shortNames=True) or [] if attr not in (attr_list_long + attr_list_short): msg = 'Attribute not found on node. node=%r attr=%r' LOG.error(msg, node, attr) raise RuntimeError(msg) node_attr = node + '.' + attr plug = api_utils.get_as_plug(node_attr) self._plug = plug node_obj = self._plug.node() self._dependFn = OpenMaya.MFnDependencyNode(node_obj) # The minimum and maximum values allowed for the attribute. self._min_value = None self._max_value = None return
def filter_nodes_into_categories(nodes): """ Return nodes sorted into mmSolver-specific object type categories. Supported categories are: - 'camera' - 'marker' - 'markergroup' - 'bundle' - 'attribute' - 'collection' - 'other' :param nodes: Maya nodes to categorise. :type nodes: list of str :returns: Dictionary with lists for each object type. :rtype: dict """ assert isinstance(nodes, (list, tuple)) result = { 'camera': [], 'marker': [], 'markergroup': [], 'bundle': [], 'attribute': [], 'collection': [], 'other': [] } for node in nodes: obj_type = api_utils.get_object_type(node) if obj_type == const.OBJECT_TYPE_MARKER: result['marker'].append(node) elif obj_type == const.OBJECT_TYPE_MARKER_GROUP: result['markergroup'].append(node) elif obj_type == const.OBJECT_TYPE_BUNDLE: result['bundle'].append(node) elif obj_type == const.OBJECT_TYPE_CAMERA: result['camera'].append(node) elif obj_type == const.OBJECT_TYPE_ATTRIBUTE: result['attribute'].append(node) elif obj_type == const.OBJECT_TYPE_COLLECTION: result['collection'].append(node) else: result['other'].append(node) return result
def set_node(self, node): """ Set the MarkerGroup to use this Maya node. :param node: Maya node path. :type node: str """ assert isinstance(node, pycompat.TEXT_TYPE) assert maya.cmds.objExists(node) assert api_utils.get_object_type(node) == const.OBJECT_TYPE_MARKER_GROUP self._mfn_tfm = None tfm_dag = node_utils.get_as_dag_path(node) if tfm_dag is not None: assert maya.cmds.nodeType(tfm_dag.fullPathName()) == 'mmMarkerGroupTransform' self._mfn_tfm = OpenMaya.MFnDagNode(tfm_dag) if self._mfn_tfm is None: self._mfn_tfm = OpenMaya.MFnDagNode() return
def __init__(self, name=None, node=None, attr=None): """ Initialise an Attribute object. Attribute can use a 'name', or 'node' and 'attr'. A 'name' is a string of both node and attribute path; `node.attr`. :param name: Node and attribute path as a single string: 'node.attr' :type name: str :param node: DG Maya node path. :type node: str :param attr: Long or short attribute name. :type attr: str """ if isinstance(name, pycompat.TEXT_TYPE): assert api_utils.get_object_type( name) == const.OBJECT_TYPE_ATTRIBUTE part = name.partition('.') node = part[0] attr = part[-1] self._plug = None if (isinstance(node, pycompat.TEXT_TYPE) and isinstance(attr, pycompat.TEXT_TYPE)): assert maya.cmds.objExists(node) # Long and short names must be checked. attr_list_long = maya.cmds.listAttr(node, shortNames=False) or [] attr_list_short = maya.cmds.listAttr(node, shortNames=True) or [] if attr not in (attr_list_long + attr_list_short): msg = 'Attribute not found on node. node=%r attr=%r' LOG.error(msg, node, attr) raise RuntimeError(msg) node_attr = node + '.' + attr plug = node_utils.get_as_plug_apione(node_attr) self._plug = plug return
def compile(self, col, mkr_list, attr_list, withtest=False): actions = [] # TODO: Triangulate the (open) bundles here. We triangulate all # valid bundles after the root frames have solved. # # NOTE: Bundle triangulation can only happen if the camera # is not nodal. # # NOTE: We currently assume the camera is NOT nodal. valid_bnd_node_list = [] for mkr in mkr_list: bnd = mkr.get_bundle() bnd_node = bnd.get_node() valid_bnd_node_list.append(bnd_node) valid_node_list = collections.defaultdict(int) for attr in attr_list: assert isinstance(attr, attribute.Attribute) is True attr_name = attr.get_attr() if attr_name not in BUNDLE_ATTR_NAMES: continue attr_node = attr.get_node() if attr_node not in valid_bnd_node_list: continue obj_type = api_utils.get_object_type(attr_node) if obj_type == const.OBJECT_TYPE_BUNDLE: valid_node_list[attr_node] += 1 for node, count in valid_node_list.items(): if count != 3: continue bnd = bundle.Bundle(node=node) bnd_node = bnd.get_node() mkr_node_list = [x.get_node() for x in mkr_list] bnd_mkr_list = [x for x in bnd.get_marker_list() if x.get_node() in mkr_node_list] bnd_mkr_node_list = [x.get_node() for x in bnd_mkr_list] bnd_cam_node_list = [x.get_camera().get_transform_node() for x in bnd_mkr_list] bnd_mkr_frm_list = [_get_marker_first_last_frame_list(x, self.root_frame_list) for x in bnd_mkr_node_list] bnd_mkr_cam_frm_list = zip( bnd_mkr_node_list, bnd_cam_node_list, bnd_mkr_frm_list ) # TODO: We must detect if the newly calculated position is # behind the camera, if so, we reject the new values. args = [bnd_node, bnd_mkr_cam_frm_list] kwargs = {} action = api_action.Action( _triangulate_bundle, args=args, kwargs=kwargs ) LOG.debug('adding _triangulate_bundle: func=%r', _triangulate_bundle, args, kwargs ) # actions.append(action) yield action, None return