Ejemplo n.º 1
0
 def __aim_joints(self):
     """ Aim the joints """
     for i in range(len(self.jnt_grp[:-1])):
         j = i + 1
         node.aimConstraint(target=self.jnt_grp[j],
                            source=self.jnt_grp[i],
                            name=self.name + ` i `,
                            aimVector=self._aimVector,
                            upVector=self._upVector,
                            worldUpType='object',
                            worldUpObject=self.locator[i])
         if not j == len(self.jnt_grp[:-1]):
             continue
         #--- create a group on top of the last joint
         cmds.select(self.jnt[-1])
         last_grp = cmds.group(name=self.jnt[-1].split('_JNT')[0] +
                               'Last_JNT_GRP')
         #--- set the rotation values of the last joint to zero
         goe.setAttr(self.jnt[-1] + '.r', 0, 0, 0)
         #--- get the mirrored aimVector
         if self._aimVector[0]:
             aimVector = [-1, 0, 0]
         elif aimVector[1]:
             aimVector = [0, -1, 0]
         elif aimVector[2]:
             aimVector = [0, 0, -1]
         node.aimConstraint(target=self.jnt[-2],
                            source=last_grp,
                            name=self.name + ` i `,
                            aimVector=aimVector,
                            upVector=self._upVector,
                            worldUpType='object',
                            worldUpObject=self.locator[i])
Ejemplo n.º 2
0
    def __create_controls(self):
        """ Create the flexiPlane controls """
        #--- create main control
        name = self._mod + self._name[0].upper() + self._name[1:]
        self.control_main = controls.Control(side=self._side,
                                             name=name + 'Main',
                                             size=self._size + 0.75,
                                             shape=5,
                                             color=self._color,
                                             orientation=16,
                                             parent=self.main)
        #--- create up control
        self.control_up = controls.Control(side=self._side,
                                           name=name + 'Up',
                                           size=self._size + 0.25,
                                           shape=1,
                                           color=6,
                                           position=[5, 0, 0],
                                           parent=self.global_move)
        #--- create down control
        self.control_down = controls.Control(side=self._side,
                                             name=name + 'Down',
                                             size=self._size + 0.25,
                                             shape=1,
                                             color=6,
                                             position=[-5, 0, 0],
                                             parent=self.global_move)
        #--- create mid control
        self.control_mid = controls.Control(side=self._side,
                                            name=name + 'Mid',
                                            size=self._size + 0.25,
                                            shape=2,
                                            color=self._color,
                                            parent=self.global_move)
        if self._follow:
            node.pointConstraint(
                objA=[self.control_down.transform, self.control_up.transform],
                objB=self.control_mid.group,
                maintainOffset=False)

        #--- create individual joint controls, parented under the follicle
        for i in range(len(self.follicle)):
            j = i + 1
            #--- create main control
            jnt_ctl = controls.Control(side=self._side,
                                       name=name + "FlexiJnt" + ` j `,
                                       size=self._size / 1.5,
                                       shape=1,
                                       color=13,
                                       rotation=[90, 0, 0],
                                       parent=self.follicle[i])
            goe.setAttr(jnt_ctl.group + '.t', 0, 0, 0)
            attribute.lock_n_hide(jnt_ctl.transform, ['t'])
            self.jnt_ctl.append(jnt_ctl)
Ejemplo n.º 3
0
 def __inherits_transform(self):
     """ Set the inherits transform attribute of the main group """
     goe.setAttr(self.main + '.inheritsTransform', self._inheritsTransform)
Ejemplo n.º 4
0
 def __reposition_flexiplane(self):
     """ Reposition the flexiPlane """
     p = self._position
     r = self._rotation
     goe.setAttr(self.control_main.transform + '.t', p[0], p[1], p[2])
     goe.setAttr(self.control_main.transform + '.r', r[0], r[1], r[2])
Ejemplo n.º 5
0
    def __muscle_system(self):
        """ Create a simple muscle system based on sculptDeformers """
        if not self._muscleSystem:
            return
        #--- check if specified mesh is a mesh
        if self._mesh:
            msg = 'Specified mesh: ' + str(self._mesh) + ' does not exist!'
            assert cmds.objExists(self._mesh), msg
            child = cmds.listRelatives(self._mesh, allDescendents=True)
            node_type = cmds.nodeType(child)
            msg = 'Specified mesh: ' + str(self._mesh) + ' is not a mesh!'
            assert node_type == 'mesh', msg
            if not self._muscles < 1:
                #--- create a nurbsPlane
                self.muscle_surface = cmds.nurbsPlane(degree=1,
                                                      width=10,
                                                      lengthRatio=0.2,
                                                      patchesU=self._length,
                                                      patchesV=1,
                                                      axis=(0, 1, 0),
                                                      name=self.name +
                                                      'Muscle_NRB')[0]
                #--- rotate the muscle surface
                goe.setAttr(self.muscle_surface + '.r', self._rotation)
                #--- parent the muscle surface under extra nodes
                cmds.parent(self.muscle_surface, self.extra_nodes)
                #--- create a follicle by the given amount of the muscles flag
                for i in range(self._muscles):
                    i = i + 1
                    if i == 0:
                        continue
                    #--- MUSCLE FOLLICLE SETUP JUST SCULPT DEFORMER
                    #--- create a follicle on the muscle plane
                    mus_follicle = node.follicle(name=self.name + 'Muscle' +
                                                 ` i `,
                                                 suffix='FOL',
                                                 parameterU=0,
                                                 parameterV=0.5,
                                                 parent=self.follicle_grp,
                                                 show=False,
                                                 lockAttr='parameterV')
                    #--- connect the follicle with the muscle surface
                    goe.connectAttr(self.muscle_surface + '.local',
                                    mus_follicle[1] + '.inputSurface')
                    goe.connectAttr(self.muscle_surface + '.worldMatrix[0]',
                                    mus_follicle[1] + '.inputWorldMatrix')
                    #--- connect the main control and the muscle follicle
                    at = '.muscle' + ` i ` + 'Slide'
                    goe.connectAttr(self.control_main.transform + at,
                                    mus_follicle[1] + '.parameterU')

                    #--- NORMAL FOLLICLE SETUP, MUSCLE CTL DRIVES SCULPT
                    #--- create a follicle on the normal surface
                    norm_follicle = node.follicle(name=self.name +
                                                  'MuscleCtl' + ` i `,
                                                  suffix='FOL',
                                                  parameterU=0,
                                                  parameterV=0.5,
                                                  parent=self.follicle_grp,
                                                  show=False,
                                                  lockAttr='parameterV')
                    #--- connect the follicle with the normal surface
                    goe.connectAttr(self.surface + '.local',
                                    norm_follicle[1] + '.inputSurface')
                    goe.connectAttr(self.surface + '.worldMatrix[0]',
                                    norm_follicle[1] + '.inputWorldMatrix')
                    #--- connect the normal follicle scale attributes to the globalMovement group
                    node.scaleConstraint(objA=self.global_move,
                                         objB=norm_follicle[0],
                                         maintainOffset=True)
                    #--- create connections between the main control and the muscle follicle
                    at = '.muscle' + ` i ` + 'Slide'
                    goe.connectAttr(self.control_main.transform + at,
                                    norm_follicle[1] + '.parameterU')

                    #--- SCULPT DEFORMER
                    #--- create a control for the sculpt deformer and set it up
                    nme = self._mod + self._name[0].upper(
                    ) + self._name[1:] + 'Muscle' + ` i `
                    self.mus_ctl = controls.Control(side=self._side,
                                                    name=nme,
                                                    suffix='FPCTL',
                                                    size=self._size + 0.1,
                                                    shape=2,
                                                    color=self._color,
                                                    parent=norm_follicle[0])
                    #--- connect the size attr of the main control with the
                    #--- scale of the muscle controls' group
                    for axis in 'xyz':
                        at = '.muscle' + ` i ` + 'Size'
                        goe.connectAttr(self.control_main.transform + at,
                                        self.mus_ctl.group + '.s' + axis)
                    #--- connect the visiblity of the control with the
                    #--- muscle attr of the main control
                    goe.connectAttr(
                        self.control_main.transform + '.muscle' + ` i `,
                        self.mus_ctl.transform + '.v')
                    #--- create a sculpt deformer and parent it under the muscle follicle
                    sculpt = deformer.sculpt(mod=self._mod,
                                             side=self._side,
                                             name=self._name + 'Muscle',
                                             suffix='DEF',
                                             geometry=self._mesh,
                                             dropoffDistance=0.14,
                                             parent=mus_follicle[0])

                    #--- CONNECTION MUSCLE CONTROL WITH SCULPT DEFORMER
                    #--- connect the muscle size attr with the sculpt radius
                    at = '.muscle' + ` i ` + 'Size'
                    goe.connectAttr(self.control_main.transform + at,
                                    sculpt[1] + '.radius')
                    attribute.lock_attributes(sculpt[0], ['s'], False)
                    #--- connect the muscle controls scale with the sculpt one
                    goe.connectAttr(self.mus_ctl.transform + '.s',
                                    sculpt[0] + '.s')
                    #--- connect the muscle MaxDisplacement attr with the sculpt one
                    at = '.muscle' + ` i ` + 'MaxDisplace'
                    goe.connectAttr(self.control_main.transform + at,
                                    sculpt[2] + '.maximumDisplacement')
                    #--- connect the muscle dropOff attr with the sculpt one
                    at = '.muscle' + ` i ` + 'DropOff'
                    goe.connectAttr(self.control_main.transform,
                                    sculpt[2] + '.dropoffDistance')
                    #--- connect t and r of the sculpt with the muscle ctl
                    goe.connectAttr(self.mus_ctl.transform + '.t',
                                    sculpt[0] + '.t')
                    goe.connectAttr(self.mus_ctl.transform + '.r',
                                    sculpt[0] + '.r')
                    #--- lock tx attribute of the muscle ctl
                    attribute.lock_attributes(self.mus_ctl.transform, ['tx'])
                    #--- set the sculpts' transform values to default
                    goe.setAttr(sculpt[-1] + '.t', 0, 0, 0)
                    goe.setAttr(sculpt[-1] + '.r', 0, 0, 0)
                    attribute.lock_attributes(sculpt[-1], ['t', 'r'])
                    cmds.setAttr(sculpt[0] + '.visibility', 0, lock=True)

                #--- COMPUTE PART
                #--- compute the steps to go to locate the cv's translateX position
                step = (10 / float(self._length))
                off = (10 / float(self._length))
                cv_pos = [[-5.0, 0.0, 0.0]]
                for i in range(self._length):
                    res = -5 + step
                    pos = [res, 0.0, 0.0]
                    cv_pos.append(pos)
                    step = +step + off
                #--- create the curves based on the computed position
                #--- and create clusters for each cv
                crv = cmds.curve(degree=2, point=cv_pos)
                mus_crv = cmds.rename(crv, self.name + 'Muscle_CRV')
                mus_cvs = cmds.ls(mus_crv + '.cv[*]', flatten=True)
                cmds.parent(mus_crv, self.extra_nodes)
                #--- create a matrix setup to connect the cvs with the control
                for i in range(len(mus_cvs)):
                    dcm = node.decomposeMatrix(name=self.name + 'Muscle' +
                                               ` i `)
                    if i == 0:
                        goe.connectAttr(
                            self.control_down.transform + '.worldMatrix[0]',
                            dcm + '.inputMatrix')
                        goe.connectAttr(dcm + '.outputTranslate',
                                        mus_crv + '.controlPoints[0]')
                    elif i == (len(mus_cvs) - 1):
                        goe.connectAttr(
                            self.control_up.transform + '.worldMatrix[0]',
                            dcm + '.inputMatrix')
                        at = 'controlPoints[' + str(len(mus_cvs) - 1) + ']'
                        goe.connectAttr(dcm + '.outputTranslate', mus_crv + at)
                    else:
                        goe.connectAttr(
                            self.jnt_ctl[i - 1].transform + '.worldMatrix[0]',
                            dcm + '.inputMatrix')
                        at = '.controlPoints[' + ` i ` + ']'
                        goe.connectAttr(dcm + '.outputTranslate', mus_crv + at)
Ejemplo n.º 6
0
    def __create_blendshape_setup(self):
        """ Create the blendShape setup """
        #--- duplicate the surface plane for the blendShape version
        bsp_name = self.surface + 'BlendShape'
        self.bsp_surface = cmds.duplicate(self.surface, name=bsp_name)[0]
        #--- reposition the bsp_plane
        goe.setAttr(self.bsp_surface + '.t', 0, 0, -5)

        #--- create a curve and store it's arcLen info
        crv = curve.Curve(side=self._side,
                          mod=self._mod,
                          name=self._name + 'Wire',
                          suffix='CRV',
                          degree=2,
                          point=[[-5, 0, -5], [0, 0, -5], [5, 0, -5]])
        self.curve = crv
        #--- get the cv of the curve
        cv_start = crv.cv[0]
        cv_mid = crv.cv[1]
        cv_end = crv.cv[2]

        #--- create a cluster on each cv
        clstr_start = deformer.cluster(mod=self._mod,
                                       side=self._side,
                                       name=self._name + 'Start',
                                       suffix='CLS',
                                       geometry=cv_start,
                                       parent=self.cluster_grp)
        clstr_mid = deformer.cluster(mod=self._mod,
                                     side=self._side,
                                     name=self._name + 'Mid',
                                     suffix='CLS',
                                     geometry=cv_mid,
                                     parent=self.cluster_grp)
        clstr_end = deformer.cluster(mod=self._mod,
                                     side=self._side,
                                     name=self._name + 'End',
                                     suffix='CLS',
                                     geometry=cv_end,
                                     parent=self.cluster_grp)

        self.clstr_mid_grp = clstr_mid[0].split('CLS')[0] + 'GRP'
        if self._follow:
            node.pointConstraint(objA=[clstr_start[0], clstr_end[0]],
                                 objB=self.clstr_mid_grp,
                                 maintainOffset=False)

        #--- create a wire deformer on the curve affecting the blendShape surface
        wire = deformer.wire(mod=self._mod,
                             side=self._side,
                             name=self._name,
                             suffix='DEF',
                             wire=crv.transform,
                             geometry=self.bsp_surface,
                             dropoffDistance=20,
                             parent=self.extra_nodes)
        #--- create a twist deformer on the blendShape surface, rename them
        twist = deformer.twist(mod=self._mod,
                               side=self._side,
                               name=self._name,
                               suffix='DEF',
                               geometry=self.bsp_surface,
                               rotation=[0, 0, 90],
                               parent=self.extra_nodes)
        #--- reorder the input order properly
        cmds.reorderDeformers(wire[0], twist[0], self.bsp_surface)

        #--- create the blendShape
        deformer.blendshape(mod=self._mod,
                            side=self._side,
                            name=self._name,
                            suffix='BSP',
                            shapes=self.bsp_surface,
                            target=self.surface,
                            shapeAttr=self.bsp_surface,
                            shapeValue=1,
                            lockAttr=self.bsp_surface)

        #--- do the proper control, cluster and deformer connections
        goe.connectAttr(self.control_down.transform + '.t',
                        clstr_start[0] + '.t')
        goe.connectAttr(self.control_up.transform + '.t', clstr_end[0] + '.t')
        goe.connectAttr(self.control_mid.transform + '.t', clstr_mid[0] + '.t')
        goe.connectAttr(self.control_down.transform + '.rx',
                        twist[-1] + '.endAngle')
        goe.connectAttr(self.control_up.transform + '.rx',
                        twist[-1] + '.startAngle')

        #--- parent the nodes to the extra nodes group
        cmds.parent(self.bsp_surface, self.extra_nodes)
Ejemplo n.º 7
0
    def __follicle_setup(self):
        """ Create the proper follicle, joint and locator setup """
        #--- get the cvs of the surface
        follicle_count = cmds.ls(self.surface + '.cv[*]', flatten=True)
        #--- the begin of the follicle loop setup
        for i in range(len(follicle_count[:self._length])):
            if not i:
                continue
            #--- create a follicle
            follicle = node.follicle(name=self.name + ` i `,
                                     suffix='FOL',
                                     parent=self.follicle_grp,
                                     show=False)
            self.follicle.append(follicle[0])
            #--- connect the follicle to the nurbsSurface
            goe.connectAttr(self.surface + '.local',
                            follicle[1] + '.inputSurface')
            goe.connectAttr(self.surface + '.worldMatrix[0]',
                            follicle[1] + '.inputWorldMatrix')
            #--- connect the follicle scale attributes to the global movement
            node.scaleConstraint(objA=self.global_move,
                                 objB=follicle[0],
                                 suffix='SCN',
                                 maintainOffset=True)

            #--- reposition the follicles in u and v
            #--- get the U position, V is by default 0.5
            x = (10 / float(self._length))
            p = str(i * x)
            p = p.split('.')
            p = p[0] + p[1]
            if p == '00':
                continue
            u = str('0.') + str(p)
            goe.setAttr(follicle[1] + '.parameterU', float(u))
            goe.setAttr(follicle[1] + '.parameterV', 0.5)

            #--- create a joint with the volumeShift groups
            #--- parent them under the follicle
            vol_up = node.transform(name=self.name + ` i ` + '_VolumeShiftUp',
                                    suffix='GRP',
                                    parent=follicle[0])
            vol_down = node.transform(name=self.name + ` i ` +
                                      '_VolumeShiftDown',
                                      suffix='GRP',
                                      parent=vol_up)
            jnt_grp = node.transform(name=self.name + ` i `,
                                     suffix='JNT_GRP',
                                     parent=vol_down)
            jnt = cmds.joint(name=self.name + ` i ` + '_JNT', radius=0.5)
            #--- set the correct jointOrientX axis
            if i == len(follicle_count[:self._length]) - 1:
                getRot = cmds.getAttr(follicle[0] + '.rx')
                getInv = getRot * -1
                goe.setAttr(jnt + '.jointOrientX', getInv)
            #--- store the joint/group and the volume groups in lists
            self.volume_up.append(vol_up)
            self.volume_down.append(vol_down)
            self.jnt_grp.append(jnt_grp)
            self.jnt.append(jnt)

            #--- create a locator as the upVector of the joints
            locator = node.locator(name=self.name + 'UpVec' + ` i `,
                                   suffix='LOC',
                                   position=[0, 0, 6],
                                   rotation=[0, 0, 0],
                                   parent=follicle[0])
            self.locator.append(locator)