예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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]
예제 #5
0
파일: joint.py 프로젝트: rendermotion/RMPY
    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
예제 #6
0
    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
예제 #7
0
파일: joint.py 프로젝트: rendermotion/RMPY
 def default_orient(self, *joint_list, **kwargs):
     aim_axis = kwargs.pop('aim_axis', config.axis_order[0])
     up_axis = kwargs.pop('up_axis', config.axis_order[1])
     axis = '%s%s%s' % (aim_axis, up_axis,
                        filter(
                            lambda ch: ch not in '%s%s' %
                            (aim_axis, up_axis), 'xyz'))
     for each_joint in joint_list:
         joint_child = each_joint.getChildren(type='joint')
         if joint_child:
             pm.joint(each_joint, e=True, orientJoint=axis)
         else:
             parent = each_joint.getParent()
             if parent:
                 transform.align(parent, each_joint, translate=False)
             pm.makeIdentity(each_joint,
                             t=False,
                             r=True,
                             s=False,
                             apply=True)
예제 #8
0
 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
예제 #9
0
파일: joint.py 프로젝트: rendermotion/RMPY
    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
예제 #10
0
파일: joint.py 프로젝트: rendermotion/RMPY
 def point_orient(self, *joint_list, **kwargs):
     point_list = kwargs.pop('point_list', None)
     for each_joint, each_point in zip(joint_list, point_list):
         transform.align(each_point, each_joint, translate=False)
         pm.makeIdentity(each_joint, t=False, r=True, s=False, apply=True)