示例#1
0
    def reParentModule(self, new_parentObject):
        '''
        re parents modules
        '''
        old_parentObject = self.findParentModule()

        self.parent_object = pm.PyNode(self.userSpecifiedName + ":unhookTarget_loc")
        # if None is passed, we are unparenting.
        if new_parentObject != None:
            # make sure we are not trying to connect to another part of the same module
            if new_parentObject.namespace() != self.parent_object.namespace():
                self.parent_object = pm.PyNode(new_parentObject)

        # check to see if parent object is the same as old parent object.
        # we do not want to parent to same module.
        if self.parent_object == old_parentObject:
            return

        # Connect four attributes similar to how a pointConstraint works.
        pm.lockNode(self.module_container, lock=False, lockUnpublished=False)
        hook_constraint = pm.PyNode(self.userSpecifiedName + ":targetParent_pointConstraint")

        #self.parent_object.parentMatrix[0].connect(hook_constraint.target[0].targetParentMatrix)

        pm.connectAttr(self.parent_object + ".parentMatrix[0]", hook_constraint + ".target[0].targetParentMatrix", force=True)
        pm.connectAttr(self.parent_object + ".translate", hook_constraint + ".target[0].targetTranslate", force=True)
        pm.connectAttr(self.parent_object + ".rotatePivot", hook_constraint + ".target[0].targetRotatePivot", force=True)
        pm.connectAttr(self.parent_object + ".rotatePivotTranslate", hook_constraint + ".target[0].targetRotateTranslate", force=True)

        utils.setModuleMetaInfo(self.module_container, "ParentObject", self.parent_object)


        pm.lockNode(self.module_container, lock=True, lockUnpublished=True)
示例#2
0
    def rename_module(self, new_name):
        """
        renames the entire modules namespace
        """
        if new_name == self.userSpecifiedName:
            return

        # Rename the module name
        new_name = utils.moduleNamespace(new_name)
        pm.lockNode(self.module_container, lock=False, lockUnpublished=False)

        pm.namespace(setNamespace=":")
        pm.namespace(add=new_name)
        pm.namespace(setNamespace=":")

        pm.namespace(moveNamespace=[self.userSpecifiedName, new_name])
        pm.namespace(removeNamespace=self.userSpecifiedName)

        self.userSpecifiedName = new_name
        self.module_container = self.userSpecifiedName + ":module_container"

        # change meta node attribute UserSpecifiedName
        utils.setModuleMetaInfo(self.module_container, "Namespace", self.userSpecifiedName)


        pm.lockNode(self.module_container, lock=True, lockUnpublished=True)

        return
示例#3
0
    def initializeParentModuleSetup(self, rootTranslationControl):
        """
        Every module's root translation control will have a set of two joints.  The parent object will equal to the
        unhookTarget_locator if it is not parented to another module.  If it is parented to another module, the parent_object
        will be that modules translation control
        """

        # setup root locator at rootTranslationControl as unHookTarget
        unhookTarget_locator = pm.spaceLocator(name = self.userSpecifiedName + ":unhookTarget_loc")
        pm.addAttr(unhookTarget_locator, longName="ParentObject", at="message")

        unhookTarget_locator.visibility.set(0)
        # set offset slightly off so we don't divide by a zero
        pm.pointConstraint(rootTranslationControl, unhookTarget_locator, offset = [0.001, 0.01, 0.001], name = self.userSpecifiedName + ":unhookTarget_locator_pointConstraint")

        if self.parent_object == None:
            self.parent_object = unhookTarget_locator

        pm.select(cl = True)
        # get the position of base target and the parent target
        # setup setup root joint at rootTranslationControl
        # setup endJoint to be at the location of the new hook object
        target_joint_position = pm.xform(self.parent_object, q = True, ws = True, translation = True)

        root_joint = pm.joint(name = self.userSpecifiedName + ":targetParent_root_joint", position = rootTranslationControl.translate.get())
        target_joint = pm.joint(name = self.userSpecifiedName + ":target_end_joint", position = target_joint_position )

        pm.joint(root_joint, edit=True, orientJoint="xyz", sao="yup")

        ik_nodes = self.stretchy_ik(root_joint, target_joint, container = self.module_container)
        target_locator = ik_nodes["end_locator"]
        doNotTouch_grp =ik_nodes["doNotTouch_grp"]

        # constrain the end parentJoint to the parent module
        pm.pointConstraint(rootTranslationControl, target_locator, maintainOffset=False, name = self.userSpecifiedName + ":targetObject_pointConstraint")
        # constrain the root parentJoint to the child module
        pm.pointConstraint(self.parent_object, root_joint, maintainOffset=False, name = self.userSpecifiedName + ":targetParent_pointConstraint")

        parent_group = pm.group([root_joint, unhookTarget_locator, doNotTouch_grp], name = self.userSpecifiedName + ":parent_group")
        utils.addNodeToContainer(self.module_container, [parent_group], ihb = True)

        for joint in [root_joint, target_joint]:
            joint.template.set(1)
            pm.container(self.module_container, edit=True, publishAndBind=[joint + ".rotate", joint.stripNamespace() + "_r"])

        if self.parent_object != unhookTarget_locator:
            utils.setModuleMetaInfo(self.module_container, "ParentObject", self.findParentModule())