コード例 #1
0
def createSticky(stickyName = 'Deformer', scale = 0.2):   
    """
    Sticky : Creates a rivet with a softmod deformer 
    Returns the sticky locator   
    """  
    rivetData = buildRivet()
    rivet_trans = rivetData[0]
    curveFromMeshEdgeList = rivetData[1]
    MeshName = rivetData[2]                     
    pm.PyNode(rivet_trans).v.set(0) 
        
    ## master and offset grp
    deformer__sys__ = pm.createNode('transform', n = '{}_{}__{}'.format(stickyName, NC.SYSTEM, NC.GRP))
    deformer_offset_grp__ = pm.createNode('transform', n = '{}__offset__{}'.format(stickyName, NC.GRP))
    pm.parent(deformer_offset_grp__, deformer__sys__)
        
    ## create locator
    sticky_locator = pm.spaceLocator(name = '{}_sticky'.format(MeshName))
    adb.changeColor_func(sticky_locator, 'index', col = 18)    
    pm.PyNode(sticky_locator).localScaleX.set(scale)
    pm.PyNode(sticky_locator).localScaleY.set(scale)
    pm.PyNode(sticky_locator).localScaleZ.set(scale)    
    pm.parent(sticky_locator, deformer_offset_grp__)
    pm.matchTransform(deformer_offset_grp__, rivet_trans.getParent(), rot = True, pos=True)    
    
    ## create softmod
    softModName = '{}__softMod__'.format(stickyName)
    softModDeformer = pm.softMod(MeshName,n=softModName)
    pm.softMod(softModDeformer[0], edit = True, wn=(sticky_locator,sticky_locator), fas=False, fm=False )
    pm.PyNode('{}HandleShape'.format(softModDeformer[0])).v.set(0)

    ## connect falloff Center
    adb.connect_axesAttr(deformer_offset_grp__, softModDeformer[0], outputs = ['translate'], inputs = ['falloffCenter'])  
    deformer_offset_grp__.inverseMatrix >> softModDeformer[0].bindPreMatrix
            
    _sticky_Attr = adbAttr.NodeAttr([sticky_locator])  
    _sticky_Attr.addAttr('Softmod_Falloff_Radius', 0.75, min = 0, max = 100 )  
    sticky_locator.Softmod_Falloff_Radius >> softModDeformer[0].falloffRadius
    
    ##giving new input geo to curveFromMeshEdges    
    groupPartsNodeName = pm.listConnections(softModName, t='groupParts') 
    
    for index in range(len(curveFromMeshEdgeList)):
        pm.PyNode('{}GroupParts.outputGeometry'.format(softModName)) >> curveFromMeshEdgeList[index].inputMesh        
    adb.connect_axesAttr(rivet_trans.getParent(), deformer_offset_grp__, outputs = ['translate', 'rotate'], inputs = [])  

    ## clean scene
    pm.delete(softModDeformer[1])
    pm.parent(rivet_trans.getParent(),deformer__sys__)
    pm.select(clear=True)
    
    sys.stdout.write('// Result: Sticky created // \n ')
    return sticky_locator
コード例 #2
0
    def create_point_base(self, *args, **kwargs):
        geometry = kwargs.pop('geo', None)
        if geometry.__class__ is not list:
            geometry = list(geometry)
        for each_geo in geometry:
            if not pm.objExists(each_geo):
                geometry.remove(each_geo)

        if geometry:

            if 'size' in kwargs:
                radius = kwargs['size']
            else:
                radius = 1
            previous_controls = len(self.controls)
            super(SoftModRig, self).create_point_base(*args, **kwargs)

            for each_point, control in zip(args,
                                           self.controls[previous_controls:]):
                position = dataValidators.as_vector_position(each_point)
                soft_mod, soft_mod_transform = pm.softMod(geometry[0])
                for each in geometry[1:]:
                    soft_mod.setGeometry(each)
                soft_mod_transform.setParent(self.rig_system.kinematics)
                soft_mod_transform.origin.set(position)
                self.soft_mod.append([soft_mod, soft_mod_transform])
                pm.xform(soft_mod_transform, pivots=position)
                soft_mod.falloffCenter.set(position)
                control.translate >> soft_mod_transform.translate
                control.rotate >> soft_mod_transform.rotate
                control.scale >> soft_mod_transform.scale
                self.create_sphere_display_control_base(control, radius)
                control.radius >> soft_mod.falloffRadius
        else:
            print 'geo key word arg needs to be specified with valid scene geometry'
コード例 #3
0
ファイル: softTweaks.py プロジェクト: rusn07/mgear
def _createSoftModTweak(baseCtl, tweakCtl, name, targets):

    sm = pm.softMod(targets, wn=[tweakCtl, tweakCtl])
    pm.rename(sm[0], "{}_softMod".format(name))

    # disconnect default connection
    plugs = sm[0].softModXforms.listConnections(p=True)
    for p in plugs:
        pm.disconnectAttr(p, sm[0].softModXforms)
        pm.delete(p.node())

    dm_node = node.createDecomposeMatrixNode(baseCtl.worldMatrix[0])
    pm.connectAttr(dm_node.outputTranslate, sm[0].falloffCenter)
    mul_node = node.createMulNode(dm_node.outputScaleX,
                                  tweakCtl.attr("falloff"))
    pm.connectAttr(mul_node.outputX, sm[0].falloffRadius)
    mulMatrix_node = applyop.gear_mulmatrix_op(tweakCtl.worldMatrix[0],
                                               tweakCtl.parentInverseMatrix[0])
    pm.connectAttr(mulMatrix_node.output, sm[0].weightedMatrix)
    pm.connectAttr(baseCtl.worldInverseMatrix[0], sm[0].postMatrix)
    pm.connectAttr(baseCtl.worldMatrix[0], sm[0].preMatrix)
    attribute.addAttribute(sm[0], "_isSoftTweak", "bool", False, keyable=False)

    sm[0].addAttr("ctlRoot", at='message', m=False)
    sm[0].addAttr("ctlBase", at='message', m=False)
    sm[0].addAttr("ctlTweak", at='message', m=False)
    pm.connectAttr(baseCtl.getParent().attr("message"), sm[0].attr("ctlRoot"))
    pm.connectAttr(baseCtl.attr("message"), sm[0].attr("ctlBase"))
    pm.connectAttr(tweakCtl.attr("message"), sm[0].attr("ctlTweak"))

    return sm[0]
コード例 #4
0
ファイル: SoftModCluster.py プロジェクト: shiyi9/digital37
 def control_to_softMod(self):
     sels = pm.ls(sl=1)
     if len(sels) == 2 :
         control = sels[0]
         geometry = sels[1]
         falloff_radius = control.falloffRadius.get()
         falloff_mode = control.falloffMode.get()
         
         pos = t = pm.xform(control,q=1,ws=1,t=1)
         r = pm.xform(control,q=1,ws=1,ro=1)
         s = pm.xform(control,q=1,r=1,s=1)
         
         pm.select(geometry,r=1)
         #softMod -falloffMode 1 -falloffAroundSelection 0
         (softMod,softMod_handle) = pm.softMod(falloffMode=1, falloffAroundSelection=0)
         #rename $tempString[0] ("convertedSoftMod_"+$sel[0])
         pm.rename(softMod, ( 'convertedSoftMod_'+control.name() ) )
         pm.rename(softMod_handle, ( 'convertedSoftModHandle_'+control.name() ) )
         
         softMod.falloffRadius.set( falloff_radius )
         softMod.falloffMode.set( falloff_mode )
         #setAttr -type float3 ($softModHandle+"Shape.origin") ($pos[0]) $pos[1] $pos[2];
         softMod_handle.getShape().origin.set(pos)
         #setAttr ($softMod+".falloffCenter") ($pos[0]) $pos[1] $pos[2];
         softMod.falloffCenter.set(pos)
         
         #xform -piv ($pos[0]) $pos[1] $pos[2] $softModHandle;
         pm.xform(softMod_handle,piv=pos)
         #xform -ws -t ($t[0]-$pos[0]) ($t[1]-$pos[1]) ($t[2]-$pos[2]) -ro $r[0] $r[1] $r[2] -s $s[0] $s[1] $s[2] $softModHandle;
         pm.xform(softMod_handle,ws=1,t=((t[0]-pos[0]),(t[1]-pos[1]),(t[2]-pos[2])),ro=r,s=s)
         
         pm.select(softMod_handle)
         
     else:
         pm.warning('control_to_softMod:please select one control and one geometry first')
コード例 #5
0
def _createSoftModTweak(baseCtl,
                        tweakCtl,
                        name,
                        targets,
                        nameExt="softMod",
                        is_asset=False):

    sm = pm.softMod(targets, wn=[tweakCtl, tweakCtl])
    pm.rename(sm[0], "{}_{}".format(name, nameExt))

    # disconnect default connection
    plugs = sm[0].softModXforms.listConnections(p=True)
    for p in plugs:
        pm.disconnectAttr(p, sm[0].softModXforms)
        pm.delete(p.node())

    dm_node = node.createDecomposeMatrixNode(baseCtl.worldMatrix[0])
    pm.connectAttr(dm_node.outputTranslate, sm[0].falloffCenter)
    mul_node = node.createMulNode(dm_node.outputScaleX,
                                  tweakCtl.attr("falloff"))
    pm.connectAttr(mul_node.outputX, sm[0].falloffRadius)
    pm.connectAttr(tweakCtl.attr("surfaceMode"), sm[0].falloffMode)
    mulMatrix_node = applyop.gear_mulmatrix_op(tweakCtl.worldMatrix[0],
                                               tweakCtl.parentInverseMatrix[0])
    pm.connectAttr(mulMatrix_node.output, sm[0].weightedMatrix)
    pm.connectAttr(baseCtl.worldInverseMatrix[0], sm[0].postMatrix)
    pm.connectAttr(baseCtl.worldMatrix[0], sm[0].preMatrix)
    if is_asset:
        tag_name = ASSET_TAG
    else:
        tag_name = SHOT_TAG

    attribute.addAttribute(sm[0], tag_name, "bool", False, keyable=False)

    sm[0].addAttr("ctlRoot", at='message', m=False)
    sm[0].addAttr("ctlBase", at='message', m=False)
    sm[0].addAttr("ctlTweak", at='message', m=False)
    pm.connectAttr(baseCtl.getParent().attr("message"), sm[0].attr("ctlRoot"))
    pm.connectAttr(baseCtl.attr("message"), sm[0].attr("ctlBase"))
    pm.connectAttr(tweakCtl.attr("message"), sm[0].attr("ctlTweak"))

    # This connection allow the softTweak to work if we apply the  skin
    # precision fix.
    # TODO: By default only apply to a non asset tweaks.
    if skin.getSkinCluster(targets[0]) and not is_asset:

        skin_cls = skin.getSkinCluster(targets[0])
        cnxs = skin_cls.matrix[0].listConnections()
        if (cnxs and cnxs[0].type() == "mgear_mulMatrix" and
                not sm[0].hasAttr("_fixedSkinFix")):

            # tag the softmod as fixed
            attribute.addAttribute(sm[0], "_fixedSkinFix", "bool")

            # original connections
            matrix_cnx = sm[0].matrix.listConnections(p=True)[0]
            preMatrix_cnx = sm[0].preMatrix.listConnections(p=True)[0]
            wgtMatrix_cnx = sm[0].weightedMatrix.listConnections(p=True)[0]
            postMatrix_cnx = sm[0].postMatrix.listConnections(p=True)[0]

            # pre existing node operators
            mulMtx_node = wgtMatrix_cnx.node()
            dcMtx_node = sm[0].falloffCenter.listConnections(p=True)[0].node()

            # geo offset connnections
            geo_root = targets[0].getParent()
            gr_W = geo_root.worldMatrix[0]
            gr_WI = geo_root.worldInverseMatrix[0]

            # new offset operators
            mmm1 = applyop.gear_mulmatrix_op(preMatrix_cnx, gr_WI)
            mmm2 = applyop.gear_mulmatrix_op(matrix_cnx, gr_WI)
            mmm3 = applyop.gear_mulmatrix_op(gr_W, postMatrix_cnx)

            # re-wire connections
            pm.connectAttr(mmm1.output, dcMtx_node.inputMatrix, f=True)
            pm.connectAttr(mmm1.output, sm[0].preMatrix, f=True)

            pm.connectAttr(mmm2.output, sm[0].matrix, f=True)
            pm.connectAttr(mmm2.output, mulMtx_node.matrixA, f=True)

            pm.connectAttr(mmm3.output, mulMtx_node.matrixB, f=True)
            pm.connectAttr(mmm3.output, sm[0].postMatrix, f=True)

            _neutra_geomMatrix(sm[0])

    return sm[0]
コード例 #6
0
def softModDeformer(vertex):
    deformerNode = pm.softMod(vertex)[0]
    deformerNode.falloffMasking.set(0)

    return deformerNode