def align(*args, **kwargs): """ General align function\n args[0]: the first element to which everithing will be aligned.\n args[1:] the elements that will be aligned.\n kwargs:\n translate: align in translation, default value True\n rotate: align rotation, default value True\n """ translate = kwargs.pop('translate', True) rotate = kwargs.pop('rotate', True) main_object = dataValidators.as_pymel_nodes(args[0]) objects_to_align = dataValidators.as_pymel_nodes(args[1:]) for each in objects_to_align: if translate: obj_position = pm.xform(main_object, q=True, ws=True, rp=True) pm.xform(each, ws=True, t=obj_position) if rotate: rotate_order_obj1 = pm.xform(main_object, q=True, rotateOrder=True) rotate_order_obj2 = pm.xform(each, q=True, rotateOrder=True) if rotate_order_obj1 != rotate_order_obj2: null_object = pm.group(em=True) pm.xform(null_object, rotateOrder=rotate_order_obj1) obj_rotation = pm.xform(main_object, q=True, ws=True, ro=True) pm.xform(null_object, ws=True, ro=obj_rotation) pm.xform(null_object, p=True, rotateOrder=rotate_order_obj2) obj_rotation = pm.xform(null_object, q=1, ws=1, ro=True) pm.xform(each, ws=True, ro=obj_rotation) pm.delete(null_object) else: obj_rotation = pm.xform(main_object, q=True, ws=True, ro=True) pm.xform(each, ws=True, ro=obj_rotation)
def in_between_points(self, obj01, obj02, number_of_points, name="inBetween", align="FirstObj"): """ :align: The object that will all the objects be aligned to. Valid Values in align are FirstObj, SecondObject, and World""" obj01 = dataValidators.as_pymel_nodes(obj01) obj02 = dataValidators.as_pymel_nodes(obj02) locator_list = [] position01, position02 = pm.xform(obj01, q=True, ws=True, rp=True), pm.xform(obj02, q=True, ws=True, rp=True) vector01, vector02 = om.MVector(position01), om.MVector(position02) result_vector = vector02 - vector01 distance = om.MVector(result_vector).length() delta_vector = (distance / (number_of_points + 1)) * result_vector.normal() for index in range(0, number_of_points): new_locator = pm.spaceLocator(name=name) self.name_convention.rename_name_in_format(str(new_locator), name=name) locator_list.append(new_locator) obj_position = vector01 + delta_vector * (index + 1) pm.xform(locator_list[index], ws=True, t=obj_position) if align == "FirstObj": transform.align(obj01, locator_list[index], translate=False) elif align == "SecondObject": transform.align(obj02, locator_list[index], translate=False) return locator_list
def insert_in_hierarchy(base_object, insert_object, insert_type="parent"): base_object = dataValidators.as_pymel_nodes(base_object) insert_object = dataValidators.as_pymel_nodes(insert_object) if insert_type == "parent": parent = base_object.getParent() if parent: pm.parent(insert_object, parent) # fix scale in case the parent is scaled we want it affected by the scale insert_object.scale.set(1, 1, 1) pm.parent(base_object, insert_object) else: children = base_object.getChildren() pm.parent(insert_object, base_object) pm.parent(children, insert_object)
def create_biased_curve(self, curve_points=None): if curve_points is None: curve_points = [[0, 0, 0], [.25, 0, .25], [.75, 0, .75], [1, 0, 1]] self.biased_line = self.create.curve.point_base(*curve_points) self.biased_line = dataValidators.as_pymel_nodes(self.biased_line) self.name_convention.rename_name_in_format(self.biased_line, name='biasedCurve') self.frame_line = self.create.curve.point_base([0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1], [0, 0, 0], degree=1) self.frame_line = dataValidators.as_pymel_nodes(self.frame_line) self.name_convention.rename_name_in_format(self.frame_line, name='frameCurve')
def on_surface_point_base(self, *points, **kwargs): surface = kwargs.pop('surface', None) periodic = kwargs.pop('periodic', False) degree = kwargs.pop('degree', 3) points = [ dataValidators.as_2d_vector(each_point) for each_point in points ] if surface: surface = dataValidators.as_pymel_nodes(surface) if not periodic: curve = pm.curveOnSurface( surface, degree=degree, positionUV=points, name=self.name_convention.set_name_in_format( name='curveOnSurface', objectType='nurbsCurve')) else: full_list_point = points + points[:3] number_of_elements = len(full_list_point) knot_vector = range(-degree + 1, 0) + range(number_of_elements) curve = pm.curveOnSurface( surface, degree=degree, positionUV=full_list_point, periodic=periodic, name=self.name_convention.set_name_in_format( name='curveOnsurface', objectType='nurbsCurve'), k=knot_vector) return curve else: print 'must provide a surface as key word argument' return None
def curve_base(self, curve, **kwargs): super(Curve, self).curve_base(curve, **kwargs) spans = kwargs.pop('spans', 4) rebuild_type = kwargs.pop('rebuildType', 0) keep_range = kwargs.pop('keepRange', 2) curve = dataValidators.as_pymel_nodes(curve) if curve.form() == 'periodic': if spans >= 3: curve = pm.rebuildCurve(curve, rebuildType=rebuild_type, spans=spans, keepRange=keep_range, **kwargs)[0] return curve else: return None else: if spans >= 1: curve = pm.rebuildCurve(curve, rebuildType=rebuild_type, spans=spans, keepRange=keep_range, **kwargs)[0] return curve else: return None return curve
def create_circular_control(self, Obj, **kwargs): radius = kwargs.pop('radius', 1) axis = kwargs.pop('axis', config.axis_order.upper()[0]) name = kwargs.pop('name', 'circle') Obj = dataValidators.as_pymel_nodes(Obj) if name == '': default_name = "circularControl" else: default_name = name if axis in "yY": control, shape = pm.circle(normal=[0, 1, 0], radius=radius, name=default_name) elif axis in "zZ": control, shape = pm.circle(normal=[0, 0, 1], radius=radius, name=default_name) elif axis in "xX": control, shape = pm.circle(normal=[1, 0, 0], radius=radius, name=default_name) if name == 'circularControl': if self.name_convention.is_name_in_format(Obj): self.name_convention.rename_based_on_base_name(Obj, control) else: self.name_convention.rename_name_in_format(control, name=name, objectType='control') else: self.name_convention.rename_name_in_format(control, name=name, objectType='control') transform.align(Obj, control) reset_group = self.rigTools.RMCreateGroupOnObj(control) self.scale_controls(reset_group) return reset_group, control
def add_collision_mesh(self, *mesh): mesh = dataValidators.as_pymel_nodes(mesh) for each_mesh in mesh: new_nrigid = nRigid.Creator(name_conv=self.name_conv, mesh=each_mesh) self.connect(new_nrigid.node) for each_hair_system in self.hair_systems: for each_follicle in each_hair_system.follicles: each_mesh.outMesh >> each_follicle.node.inputMesh each_mesh.worldMatrix[ 0] >> each_follicle.node.inputWorldMatrix self.collision.append(new_nrigid)
def create_box_ctrl(self, Obj, **kwargs): x_ratio = kwargs.pop('x_ratio', 1) y_ratio = kwargs.pop('y_ratio', 1) z_ratio = kwargs.pop('z_ratio', 1) parent_base_size = kwargs.pop('parent_base_size', False) custom_size = kwargs.pop('custom_size', 0) name = kwargs.pop('name', '') centered = kwargs.pop('centered', False) Obj = dataValidators.as_pymel_nodes(Obj) if name == "": default_name = "BoxControl" else: default_name = name Parents = pm.listRelatives(Obj, parent=True) if Parents and len(Parents) != 0 and parent_base_size == True: joint_length = transform.joint_length(Parents[0]) control = self.create_cube_line(joint_length * x_ratio, joint_length * y_ratio, joint_length * z_ratio, name=default_name, centered=centered) else: if custom_size != 0: joint_length = custom_size elif pm.objectType(Obj) == "joint": joint_length = transform.joint_length(Obj) else: joint_length = 1 control = self.create_cube_line(joint_length * x_ratio, joint_length * y_ratio, joint_length * z_ratio, name=default_name, centered=centered) # if name == '' and self.name_convention.is_name_in_format(Obj): # self.name_convention.rename_based_on_base_name(Obj, control) # else: # self.name_convention.rename_based_on_base_name(Obj, control, name=control) self.name_convention.rename_name_in_format(control, objectType='control') # self.name_convention.rename_set_from_name(control, "control", "objectType") transform.align(Obj, control) reset_group = self.rigTools.RMCreateGroupOnObj(control) self.scale_controls(reset_group) return reset_group, control
def point_base(self, *scene_nodes, **kwargs): super(Group, self).point_base(*scene_nodes, **kwargs) r""" :param scene_nodes: uno o mas nodos de la escena :type scene_nodes: ``str`` :param \**kwargs: See below :Keword Arguments: * *type* (``str``)-- A parameter to define how the new group is going to be in the hierarcht, valid values are "world","child","parent","inserted","sibling". """ group_type = kwargs.pop('type', "inserted") name = kwargs.pop('name', None) scene_nodes = dataValidators.as_pymel_nodes(scene_nodes) new_groups_result = [] for each_node in scene_nodes: new_group = pm.group(empty=True) transform.align(each_node, new_group) self.setup_name_convention_node_base(each_node, name=name) self.name_convention.rename_name_in_format(new_group) new_groups_result.append(new_group) parent = pm.listRelatives(each_node, parent=True) if not (group_type == "world"): if group_type == "inserted": if parent: hierarchy.insert_in_hierarchy(each_node, new_group) else: pm.parent(each_node, new_group) elif group_type == "parent": pm.parent(each_node, new_group) elif group_type == "child": pm.parent(new_group, each_node) elif group_type == "sibling": pm.parent(new_group, parent) if len(new_groups_result) > 1: return new_groups_result else: return new_groups_result[0]
def point_base(self, *point_array, **kwargs): # super(Creator, self).point_base(*point_array, **kwargs) """ orient_type: 'default': uses default maya joint orient 'bend_orient': uses the bend vector of the orient to define joint orientation 'point_orient': uses the axis of the point based to define orientation """ custom_name = kwargs.pop('name', 'joint') aim_axis = kwargs.pop('aim_axis', config.axis_order[0]) up_axis = kwargs.pop('up_axis', config.axis_order[1]) orient_type = kwargs.pop('orient_type', 'bend_orient') joint_type = kwargs.pop('joint_type', 'joint') point_array = dataValidators.as_pymel_nodes(point_array) joint_array = [] for index, point in enumerate(point_array): pm.select(cl=True) new_joint = pm.joint(p=[0, 0, 0], name="joint") new_joint.segmentScaleCompensate.set(0) transform.align(point, new_joint) joint_array.append(new_joint) self.name_convention.rename_name_in_format(new_joint, name=custom_name, objectType=joint_type) if index > 0: new_joint.setParent(joint_array[index - 1]) pm.makeIdentity(new_joint, apply=True, t=1, r=1, s=1) if orient_type == 'point_orient': self.point_orient(*joint_array, point_list=point_array) elif orient_type == 'bend_orient': self.bend_orient(*joint_array) elif orient_type == 'default': self.default_orient(*joint_array, aim_axis=aim_axis, up_axis=up_axis) reset_joints = self.group_creator.point_base(joint_array[0], type="parent") return reset_joints, joint_array
def file_control(self, scene_object, **kwargs): scale = kwargs.pop('scale', 1.0) name = kwargs.pop('name', None) control_type = kwargs.pop('control_type', 'Move') scene_object = dataValidators.as_pymel_nodes(scene_object) MoversTypeDic = { "move": {"filename": "ControlMover.mb", "object": "MoverControl"}, "v": {"filename": "ControlV.mb", "object": "VControl"}, "head": {"filename": "ControlHead.mb", "object": "HeadControl"}, "circleDeform": {"filename": "ControlCircularDeform.mb", "object": "CircularDeform"} } path = os.path.dirname(RMRigTools.__file__) RMPYPATH = os.path.split(path) FinalPath = os.path.join(RMPYPATH[0], "RMPY\AutoRig\RigShapes", MoversTypeDic[control_type]["filename"]) if os.path.isfile(FinalPath): pm.importFile(FinalPath, i=True, type="mayaBinary", ignoreVersion=True, mergeNamespacesOnClash=False, rpr="ControlMover", pr=False) else: print "archivo no encontrado %s , %s, %s "% (path, RMPYPATH, FinalPath) return None control = pm.ls(MoversTypeDic[control_type]["object"])[0] if pm.objExists(control): if name: control = pm.rename(control, name) pm.setAttr(control + ".scale", scale, scale, scale) pm.makeIdentity(control, apply=True, t=1, r=1, s=1) self.name_convention.rename_name_in_format(control, objectType='control') transform.align(scene_object, control) reset_group = self.rigTools.RMCreateGroupOnObj(control) self.scale_controls(reset_group) return reset_group, control else: print "Error importing Shape File" return None
def point_base(self, *points, **kwargs): name = kwargs.pop('name', None) points = dataValidators.as_pymel_nodes(points) points_list = [] for each in points: if each.__class__ == pm.general.MeshVertex: for each_vertex in each: vector = dataValidators.as_vector_position(each_vertex) points_list.append([vector[0], vector[1], vector[2]]) else: vector = dataValidators.as_vector_position(each) points_list.append([vector[0], vector[1], vector[2]]) new_locator = pm.spaceLocator() new_locator.translate.set(transform.average(*points_list)) if name: self.name_convention.rename_name_in_format(new_locator, name=name) else: self.name_convention.rename_name_in_format(new_locator) return new_locator
def node_base(self, *transforms_list, **kwargs): transforms_list = dataValidators.as_pymel_nodes(transforms_list) rotation = kwargs.pop('rotation', True) name = kwargs.pop('name', None) locator_list = [] for each in transforms_list: if each.__class__ == pm.general.MeshVertex: for each_vertex in each: locator = pm.spaceLocator() vector = dataValidators.as_vector_position(each_vertex) locator.translate.set(vector) else: locator = pm.spaceLocator() vector = dataValidators.as_vector_position(each) locator.translate.set(vector) if rotation: transform.align(each, locator, translate=False) locator_list.append(locator) if name: self.name_convention.rename_name_in_format(locator, name=name) else: self.name_convention.rename_name_in_format(locator) return locator_list
def node(self, value): self._node = dataValidators.as_pymel_nodes(value)
def __init__(self, *args, **kwargs): kwargs['model'] = kwargs.pop('model', SurfaceInfoModel()) super(SurfaceInfo, self).__init__(*args, **kwargs) follow_v = kwargs.pop('follow_v', False) surface = dataValidators.as_pymel_nodes(args[0]) if pm.objectType(surface) != 'nurbsSurface': if pm.objectType(surface.getShapes()[0]) == 'nurbsSurface': surface = surface.getShapes()[0] else: raise AttributeError self.surface_info = pm.createNode('pointOnSurfaceInfo') self.name_convention.rename_name_in_format(self.surface_info, name='surfaceInfo') self.matrix = pm.createNode('fourByFourMatrix') self.name_convention.rename_name_in_format(self.matrix, name='surfaceInfoMatrix') self.decomposition = pm.createNode('decomposeMatrix') self.name_convention.rename_name_in_format(self.decomposition, name='surfaceInfoResult') self.vector_product = pm.createNode('vectorProduct') self.name_convention.rename_name_in_format(self.vector_product, name='uVectorResult') self.vector_product.operation.set(2) pm.connectAttr('{}.worldSpace[0]'.format(surface), '{}.inputSurface'.format(self.surface_info)) pm.connectAttr('{}.normalizedNormalX'.format(self.surface_info), '{}.in10'.format(self.matrix)) pm.connectAttr('{}.normalizedNormalY'.format(self.surface_info), '{}.in11'.format(self.matrix)) pm.connectAttr('{}.normalizedNormalZ'.format(self.surface_info), '{}.in12'.format(self.matrix)) pm.connectAttr('{}.normalizedTangentVX'.format(self.surface_info), '{}.in20'.format(self.matrix)) pm.connectAttr('{}.normalizedTangentVY'.format(self.surface_info), '{}.in21'.format(self.matrix)) pm.connectAttr('{}.normalizedTangentVZ'.format(self.surface_info), '{}.in22'.format(self.matrix)) pm.connectAttr('{}.normalizedTangentV'.format(self.surface_info), '{}.input1'.format(self.vector_product)) pm.connectAttr('{}.normalizedNormal'.format(self.surface_info), '{}.input2'.format(self.vector_product)) if follow_v: pm.connectAttr('{}.outputX'.format(self.vector_product), '{}.in00'.format(self.matrix)) pm.connectAttr('{}.outputY'.format(self.vector_product), '{}.in01'.format(self.matrix)) pm.connectAttr('{}.outputZ'.format(self.vector_product), '{}.in02'.format(self.matrix)) else: pm.connectAttr('{}.normalizedTangentUX'.format(self.surface_info), '{}.in00'.format(self.matrix)) pm.connectAttr('{}.normalizedTangentUY'.format(self.surface_info), '{}.in01'.format(self.matrix)) pm.connectAttr('{}.normalizedTangentUZ'.format(self.surface_info), '{}.in02'.format(self.matrix)) pm.connectAttr('{}.output'.format(self.matrix), '{}.inputMatrix'.format(self.decomposition))
def aim_vector_based(*args, **kwargs): destination = dataValidators.as_pymel_nodes(args[0]) aim_axis = kwargs.pop('aim_axis', config.axis_order[0]) up_axis = kwargs.pop('up_axis', config.axis_order[1]) scale_x = kwargs.pop('scale_x', 1) scale_y = kwargs.pop('scale_y', 1) scale_z = kwargs.pop('scale_z', 1) position_source01 = dataValidators.as_vector_position(destination) destination_position = kwargs.pop('destination_position', [position_source01[0], position_source01[1], position_source01[2], 1.0]) if len(destination_position) == 3: destination_position.append(1.0) x_dir = dataValidators.as_vector_position(args[1]) x_dir.normalize() if len(args) == 3: up_vector = dataValidators.as_vector_position(args[2]) else: up_vector = [0, 1, 0] z_dir = x_dir.cross(up_vector) z_dir.normalize() y_dir = z_dir.cross(x_dir) orientation = [x_dir, y_dir, z_dir] if aim_axis in 'xX': x_vector_index = 0 if up_axis in 'yY': y_vector_index = 1 z_vector_index = 2 else: y_vector_index = 2 z_vector_index = 1 scale_y = scale_y * -1 elif aim_axis in 'yY': y_vector_index = 0 if up_axis in 'xX': x_vector_index = 1 z_vector_index = 2 scale_z = scale_z * -1 else: x_vector_index = 2 z_vector_index = 1 else: z_vector_index = 0 if up_axis in 'xX': x_vector_index = 1 y_vector_index = 2 else: x_vector_index = 2 y_vector_index = 1 scale_x = scale_x * -1 newMatrix = pm.datatypes.Matrix([[orientation[x_vector_index][0] * scale_x, orientation[x_vector_index][1] * scale_x, orientation[x_vector_index][2] * scale_x, 0.0], [orientation[y_vector_index][0] * scale_y, orientation[y_vector_index][1] * scale_y, orientation[y_vector_index][2] * scale_y, 0.0], [orientation[z_vector_index][0] * scale_z, orientation[z_vector_index][1] * scale_z, orientation[z_vector_index][2] * scale_z, 0.0], destination_position]) inverse = destination.parentInverseMatrix.get() destination.setMatrix(newMatrix * inverse)
def _validate_connection(attribute, input_attribute): input_attribute = dataValidators.as_pymel_nodes(input_attribute) if issubclass(attribute.__class__, pm.general.Attribute): attribute >> input_attribute else: input_attribute.set(attribute)
import maya.api as om from RMPY.core import dataValidators import pymel.core as pm geometry = dataValidators.as_pymel_nodes(pm.ls(selection=True)) # vertex_destination_list = destination.vtx result = {} selection_list = om.MSelectionList() selection_list.add(geometry.fullPath()) selObj = selection_list.getDagPath(0) mfnSourceObject = om.MFnMesh(selObj) mfnSourceObject.getPoints() selObj = selection_list.getDagPath(1) mfnDestinationObject = om.MFnMesh(selObj) vertex_in_source = mfnSourceObject.getPoints(space=om.MSpace.kWorld)
def node_base(self, *nodes, **kwargs): super(MotionPath, self).node_base(*nodes, **kwargs) """ creates a motion path on the provided nodes and attaches them to a curve you can control the up vector, and make it one object, or a list of objects one for each Node List :param nodes: list of nodes that will constraint to the path :param curve: curve that will have the nodes :param UpVectorType: type of UpVector, can be object, array, anything else will be assumed as scene :param UpVectorArray: the array of objects that will be the upVector :param upVectorObject: the object that will be upVector :return: """ motion_path_list = [] if 'curve' in kwargs.keys(): self.curve = dataValidators.as_pymel_nodes(kwargs.pop('curve')) name = kwargs.pop('name', 'motionPath') followAxis = kwargs.pop('followAxis', config.axis_order[0]) upAxis = kwargs.pop('upAxis', config.axis_order[1]) kwargs['followAxis'] = followAxis kwargs['upAxis'] = upAxis UpVectorType = kwargs.pop('UpVectorType', 'world') UpVectorArray = kwargs.pop('UpVectorArray', None) upVectorObject = kwargs.pop('upVectorObject', None) if self.curve: len_node_list = len(nodes) spans = pm.getAttr(self.curve + ".spans") min_value = pm.getAttr(self.curve + ".minValue") max_value = pm.getAttr(self.curve + ".maxValue") form = pm.getAttr(self.curve + ".form") step = 0.0 if len_node_list > 1: if form == 0 or form == 1: step = (max_value - min_value) / (len_node_list - 1) else: step = (max_value - min_value) / len_node_list else: step = 0 node_count = 0 for each_node in nodes: if UpVectorType == 'object': motion_path_node = pm.pathAnimation( each_node, c=self.curve, follow=True, worldUpObject=upVectorObject, worldUpType="objectrotation", **kwargs) elif UpVectorType == 'array': motion_path_node = pm.pathAnimation( each_node, c=self.curve, follow=True, worldUpObject=UpVectorArray[node_count], worldUpType="object", **kwargs) else: motion_path_node = pm.pathAnimation(each_node, c=self.curve, follow=True, worldUpType="scene", **kwargs) motion_path_node = dataValidators.as_pymel_nodes( motion_path_node) motion_path_list.append(motion_path_node) list_add_double_linear = each_node.listConnections( type='addDoubleLinear', source=False) pm.delete(list_add_double_linear) motion_path_node.xCoordinate >> each_node.translateX motion_path_node.yCoordinate >> each_node.translateY motion_path_node.zCoordinate >> each_node.translateZ connection = pm.listConnections(motion_path_node.uValue) if connection: pm.delete(connection) motion_path_node.uValue.set(step * node_count) # pm.setKeyframe(motionPath, v=(step * nodeCount), at="uValue") self.name_convention.rename_name_in_format( str(motion_path_node), name=name) node_count += 1 value = pm.currentTime(q=True) pm.currentTime(value + 1, e=True) pm.currentTime(value, e=True) if len(motion_path_list) == 1: return motion_path_list[0] return motion_path_list
def with_limits(self, attribute_x, attrribute_y, keys, operation=1, in_tangent_type='spline', out_tangent_type='spline', post_infinity_type='linear', pre_infinity_type='linear'): """ Pre/post InfinityType values: 'constant, 'linear', 'cycle', 'cycleRelative', 'oscillate' in/out TangentType values: 'global_', 'fixed', 'linear', 'flat', 'smooth', 'step', 'slow', 'fast', 'clamped', 'plateau', 'stepNext', 'auto' :param attribute_x: :param attrribute_y: :param keys: :param operation: :param in_tangent_type: :param out_tangent_type: :param post_infinity_type: :param pre_infinity_type: :return: """ attribute_x = dataValidators.as_pymel_nodes(attribute_x) attrribute_y = dataValidators.as_pymel_nodes(attrribute_y) value = pm.listConnections(attrribute_y, destination=False, plugs=True, skipConversionNodes=False) plus_minus = None if value: if pm.objectType(value[0].node()) == 'plusMinusAverage': plus_minus = value[0].node() if attribute_x.get(type=True) in [ 'double', 'doubleLinear', 'doubleAngle', 'float' ]: for eachKey in keys: pm.setDrivenKeyframe('%s' % plus_minus.input1D[len( plus_minus.input1D.elements())], currentDriver='%s' % attribute_x, inTangentType=in_tangent_type, outTangentType=out_tangent_type, dv=eachKey[0], v=eachKey[1]) animation_curve_node = \ pm.listConnections('%s' % plus_minus.input1D[len(plus_minus.input1D.elements())])[0] self.name_convention.rename_name_in_format( animation_curve_node) elif attribute_x.get(type=True) in ['double3']: for eachKey in keys: pm.setDrivenKeyframe('%s' % plus_minus.input3D[len( plus_minus.input3D.elements()) % 3], currentDriver='%s' % attribute_x, inTangentType=in_tangent_type, outTangentType=out_tangent_type, dv=eachKey[0], v=eachKey[1]) animation_curve_node = \ pm.listConnections('%s' % plus_minus.input3D[len(plus_minus.input3D.elements()) % 3])[0] self.name_convention.rename_name_in_format( animation_curve_node) else: print 'could not add data type: %s' % attribute_x.get( type=True) else: if attribute_x.get(type=True) in [ 'double', 'doubleLinear', 'doubleAngle', 'float' ]: plus_minus = pm.shadingNode("plusMinusAverage", asUtility=True, name="additiveConnection") self.name_convention.rename_name_in_format(plus_minus) plus_minus.operation.set(operation) value[0] // attrribute_y value[0] >> plus_minus.input1D[0] plus_minus.output1D >> attrribute_y for eachKey in keys: pm.setDrivenKeyframe('%s' % plus_minus.input1D[1], currentDriver='%s' % attribute_x, dv=eachKey[0], v=eachKey[1], inTangentType=in_tangent_type, outTangentType=out_tangent_type) animation_curve_node = pm.listConnections( '%s' % plus_minus.input1D[1])[0] self.name_convention.rename_name_in_format( animation_curve_node) elif attribute_x.get(type=True) in ['double3']: plus_minus = pm.shadingNode("plusMinusAverage", asUtility=True, name="additiveConnection") self.name_convention.rename_name_in_format(plus_minus) plus_minus.operation.set(operation) value[0] // attrribute_y value[0] >> plus_minus.input3D[0] plus_minus.output3D >> attrribute_y for eachKey in keys: pm.setDrivenKeyframe('%s' % plus_minus.input3D[1], currentDriver='%s' % attribute_x, dv=eachKey[0], v=eachKey[1], inTangentType=in_tangent_type, outTangentType=out_tangent_type) animation_curve_node = pm.listConnections( '%s' % plus_minus.input3D[1])[0] self.name_convention.rename_name_in_format( animation_curve_node) else: print 'could not add data type: %s' % attribute_x.get( type=True) else: for eachKey in keys: pm.setDrivenKeyframe('%s' % attrribute_y, currentDriver='%s' % attribute_x, dv=eachKey[0], v=eachKey[1], inTangentType=in_tangent_type, outTangentType=out_tangent_type) animation_curve_node = pm.listConnections('%s' % attrribute_y)[0] self.name_convention.rename_name_in_format(animation_curve_node) if issubclass(animation_curve_node.__class__, pm.nodetypes.AnimCurve): animation_curve_node.setPostInfinityType(post_infinity_type) animation_curve_node.setPreInfinityType(pre_infinity_type) return plus_minus, animation_curve_node
def point_based(self, point_array, z_axis_orientation="Y", **kwargs): custom_name = kwargs.pop('name', None) joint_type = kwargs.pop('joint_type', 'joint') z_axis_orientation = config.axis_order[1] point_array = dataValidators.as_pymel_nodes(point_array) joint_array = [] Obj1Position = pm.xform(point_array[0], q=True, rp=True, ws=True) Obj2Position = pm.xform(point_array[1], q=True, rp=True, ws=True) V1, V2 = om.MVector(Obj1Position), om.MVector(Obj2Position) initVector = V1 - V2 firstJntAngle = V1.angle(om.MVector([0, 1, 0])) Angle = firstJntAngle ParentJoint = self.RMCreateGroupOnObj(point_array[0], Type="world") for index in range(0, len(point_array)): pm.select(cl=True) new_joint = pm.joint(p=[0, 0, 0], name="joint") new_joint.segmentScaleCompensate.set(0) joint_array.append(new_joint) if not custom_name: joint_name = self.name_convention.get_a_short_name( str(point_array[index])) else: joint_name = custom_name self.name_convention.rename_name_in_format( str(new_joint), name=joint_name, side=self.name_convention.get_from_name( str(point_array[index]), 'side'), objectType=joint_type) if index == 0: pm.parent(joint_array[0], ParentJoint) transform.align(point_array[index], joint_array[index]) pm.makeIdentity(joint_array[index], apply=True, t=1, r=1, s=0) if index > 0: if index == 1: AxisOrientJoint = pm.joint() pm.parent(AxisOrientJoint, ParentJoint) transform.align(point_array[0], AxisOrientJoint) pm.makeIdentity(AxisOrientJoint, apply=True, t=1, r=1, s=0) if z_axis_orientation in "Yy": pm.xform(AxisOrientJoint, translation=[0, -1, 0], objectSpace=True) elif z_axis_orientation in "Xx": pm.xform(AxisOrientJoint, translation=[-1, 0, 0], objectSpace=True) elif z_axis_orientation in "Zz": pm.xform(AxisOrientJoint, translation=[0, 0, -1], objectSpace=True) pm.parent(joint_array[0], AxisOrientJoint) pm.parent(joint_array[index], joint_array[index - 1]) pm.joint(joint_array[index - 1], edit=True, orientJoint=config.axis_order) pm.parent(joint_array[index - 1], world=True) pm.delete(AxisOrientJoint) transform.align(joint_array[index - 1], ParentJoint) pm.parent(joint_array[index - 1], ParentJoint) else: pm.parent(joint_array[index], joint_array[index - 1]) pm.joint(joint_array[index - 1], edit=True, orientJoint=config.axis_order) # , sao="yup" ) if index >= 2: parentOrient = pm.joint(joint_array[index - 1], q=True, orientation=True) # pm.joint(jointArray[index - 1], e=True, orientation=[parentOrient[0], parentOrient[1], parentOrient[2]]) if parentOrient[config.orient_index[0]] > 89: parentOrient[config.orient_index[0]] = parentOrient[ config.orient_index[0]] - 180 joint_array[index - 1].attr( 'rotate%s' % config.orient_axis_up[0]).set(180) # pm.joint(jointArray[index-1], e=True, orientation=[parentOrient[0], parentOrient[1], parentOrient[2]]) pm.makeIdentity(joint_array[index - 1], r=True, apply=True) else: if parentOrient[config.orient_index[0]] < -89: parentOrient[ config.orient_index[0]] = parentOrient[ config.orient_index[0]] + 180 joint_array[index - 1].attr( 'rotate%s' % config.orient_axis_up[0]).set(180) pm.makeIdentity(joint_array[index - 1], r=True, apply=True) # pm.joint(jointArray[index-1], e=True, orientation=[parentOrient[0], parentOrient[1], parentOrient[2]]) if index == len(point_array) - 1: transform.align(joint_array[index - 1], joint_array[index], rotate=False) pm.makeIdentity(joint_array[index], apply=True, t=0, r=1, s=0) joint_array[index].rotateOrder.set(config.axis_order) return ParentJoint, joint_array