コード例 #1
0
def getTubeIntersectionPointAndNormal( tubeMesh, baseMesh ):
    
    import math
    import sgBFunction_dag
    
    hairMesh = tubeMesh
    headMesh  = baseMesh
    
    headMeshShape = sgBFunction_dag.getShape( headMesh )
    
    dagPathHead = sgBFunction_dag.getMDagPath( headMeshShape )
    intersector = om.MMeshIntersector()
    intersector.create( dagPathHead.node() )
        
    hairMeshShape = sgBFunction_dag.getShape( hairMesh )
    dagPathHairMesh = sgBFunction_dag.getMDagPath( hairMeshShape )

    fnMesh = om.MFnMesh( dagPathHairMesh )
    
    points = om.MPointArray()
    fnMesh.getPoints( points )
    
    pointOnMesh = om.MPointOnMesh()
    
    minDist = 100000.0
    minDistIndex = 0
    minDistNormal = om.MVector()
    for i in range( points.length() ):
        intersector.getClosestPoint( points[i], pointOnMesh )
        closePoint = om.MPoint( pointOnMesh.getPoint() )
        
        dist = closePoint.distanceTo( points[i] )
        if dist < minDist:
            normal = om.MVector()
            itNormal = om.MVector( pointOnMesh.getNormal() )
            fnMesh.getVertexNormal( i, True, normal )
            
            if math.fabs( itNormal.normal() * normal.normal() ) < 0.4:
                minDist = dist
                minDistIndex = i
                minDistNormal = itNormal

    pointMinDist = points[ minDistIndex ]
    normalMinDist = om.MVector()
    fnMesh.getVertexNormal( minDistIndex, True, normalMinDist )
    
    srcPoint = om.MPoint( pointMinDist + normalMinDist )
    ray      = -normalMinDist
    
    intersectPoints = om.MPointArray()
    fnMesh.intersect( srcPoint, ray, intersectPoints )
    
    if intersectPoints.length() == 1:
        return intersectPoints[0], minDistNormal
    else:
        bb = om.MBoundingBox()
        for k in range( intersectPoints.length() ):
            bb.expand( intersectPoints[k] )
        return bb.center(), minDistNormal
コード例 #2
0
ファイル: sgCFnc_fixRig.py プロジェクト: jonntd/mayadev-1
def replaceRivetMesh(source, target):

    sourceShape = cmds.listRelatives(source, s=1, f=1)[0]
    targetShape = cmds.listRelatives(target, s=1, f=1)[0]

    nodes = list(
        set(
            cmds.listConnections(sourceShape,
                                 d=1,
                                 s=0,
                                 type='sgMatrixFromVertices')))

    import sgBFunction_dag

    fnSourceMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(sourceShape))
    fnTargetMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(targetShape))

    sourceMeshPoints = om.MPointArray()
    targetMeshPoints = om.MPointArray()
    fnSourceMesh.getPoints(sourceMeshPoints)
    fnTargetMesh.getPoints(targetMeshPoints)

    intersector = om.MMeshIntersector()
    intersector.create(fnTargetMesh.object())

    for node in nodes:
        fnNode = om.MFnDependencyNode(sgBFunction_dag.getMObject(node))
        plugVerticeId = fnNode.findPlug('verticeId')

        pointOnMesh = om.MPointOnMesh()
        for i in range(plugVerticeId.numElements()):
            logicalIndex = plugVerticeId[i].logicalIndex()
            pointSource = sourceMeshPoints[logicalIndex]

            intersector.getClosestPoint(pointSource, pointOnMesh)

            faceIndex = pointOnMesh.faceIndex()
            indicesVertices = om.MIntArray()
            fnTargetMesh.getPolygonVertices(faceIndex, indicesVertices)

            minDist = 100000.0
            closeIndex = indicesVertices[0]
            for j in range(indicesVertices.length()):
                pointTarget = targetMeshPoints[indicesVertices[j]]
                dist = pointTarget.distanceTo(pointSource)
                if dist < minDist:
                    minDist = dist
                    closeIndex = indicesVertices[j]

            print plugVerticeId[i].name(), closeIndex
            cmds.setAttr(plugVerticeId[i].name(), closeIndex)

        cmds.connectAttr(targetShape + '.outMesh', node + '.inputMesh', f=1)
        cmds.connectAttr(targetShape + '.worldMatrix[0]',
                         node + '.inputMeshMatrix',
                         f=1)
コード例 #3
0
def addSquashFromCurve( target, curve ):
    
    import sgBFunction_curve
    import sgBFunction_dag
    import sgBFunction_mscriptUtil
    import math
    
    sgBFunction_curve.addDistanceAttribute( curve )
    
    squashNode = cmds.createNode( 'squash' )
    cmds.connectAttr( curve + '.initCurveLength', squashNode+'.lengthOriginal' )
    cmds.connectAttr( curve + '.curveLength', squashNode+'.lengthModify' )
    
    divNode = cmds.createNode( 'multiplyDivide' )
    cmds.setAttr( divNode+'.operation', 2 )
    cmds.connectAttr( curve+'.curveLength', divNode+'.input1X' )
    cmds.connectAttr( curve+'.initCurveLength', divNode+'.input2X' )
    
    curveShape = sgBFunction_dag.getShape( curve )
    mtxTarget = sgBFunction_dag.getMDagPath( target ).inclusiveMatrix()
    fnCurve   = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( curveShape ) )
    mtxCurve = sgBFunction_dag.getMDagPath( curveShape ).inclusiveMatrix()

    pointTarget = om.MPoint( mtxTarget( 3, 0 ), mtxTarget( 3, 1 ), mtxTarget( 3, 2 ) ) * mtxCurve.inverse()

    ptrParam, utilParam = sgBFunction_mscriptUtil.getDoublePtr()
    fnCurve.getParamAtPoint( pointTarget, ptrParam )
    
    param = utilParam.getDouble( ptrParam )
    tangent = fnCurve.tangent( param )
    
    vX = om.MVector( mtxTarget( 0, 0 ), mtxTarget( 0, 1 ), mtxTarget( 0, 2 ) )
    vY = om.MVector( mtxTarget( 1, 0 ), mtxTarget( 1, 1 ), mtxTarget( 1, 2 ) )
    vZ = om.MVector( mtxTarget( 2, 0 ), mtxTarget( 2, 1 ), mtxTarget( 2, 2 ) )
    
    dotX = math.fabs( tangent * vX )
    dotY = math.fabs( tangent * vY )
    dotZ = math.fabs( tangent * vZ )
    
    if dotX > dotY and dotX > dotZ:
        cmds.connectAttr( divNode+'.outputX', target+'.scaleX', f=1 )
        cmds.connectAttr( squashNode+'.output', target+'.scaleY', f=1 )
        cmds.connectAttr( squashNode+'.output', target+'.scaleZ', f=1 )
    elif dotY > dotZ and dotY > dotX:
        cmds.connectAttr( squashNode+'.output', target+'.scaleX', f=1 )
        cmds.connectAttr( divNode+'.outputX', target+'.scaleY', f=1 )
        cmds.connectAttr( squashNode+'.output', target+'.scaleZ', f=1 )
    elif dotZ > dotX and dotZ > dotY:
        cmds.connectAttr( squashNode+'.output', target+'.scaleX', f=1 )
        cmds.connectAttr( squashNode+'.output', target+'.scaleY', f=1 )
        cmds.connectAttr( divNode+'.outputX', target+'.scaleZ', f=1 )
コード例 #4
0
ファイル: sgCFnc_fixRig.py プロジェクト: jonntd/mayadev-1
def replaceRivetMesh( source, target ):
    
    sourceShape = cmds.listRelatives( source, s=1, f=1 )[0]
    targetShape = cmds.listRelatives( target, s=1, f=1 )[0]
    
    nodes = list( set( cmds.listConnections( sourceShape, d=1, s=0, type='sgMatrixFromVertices' ) ) )
    
    import sgBFunction_dag
    
    fnSourceMesh  = om.MFnMesh( sgBFunction_dag.getMDagPath( sourceShape ) )
    fnTargetMesh = om.MFnMesh( sgBFunction_dag.getMDagPath( targetShape ) )
    
    sourceMeshPoints = om.MPointArray()
    targetMeshPoints = om.MPointArray()
    fnSourceMesh.getPoints( sourceMeshPoints )
    fnTargetMesh.getPoints( targetMeshPoints )
    
    intersector = om.MMeshIntersector()
    intersector.create( fnTargetMesh.object() )
    
    for node in nodes:
        fnNode = om.MFnDependencyNode( sgBFunction_dag.getMObject( node ) )
        plugVerticeId = fnNode.findPlug( 'verticeId' )
        
        pointOnMesh = om.MPointOnMesh()
        for i in range( plugVerticeId.numElements() ):
            logicalIndex = plugVerticeId[i].logicalIndex()
            pointSource = sourceMeshPoints[ logicalIndex ]
            
            intersector.getClosestPoint( pointSource, pointOnMesh )
            
            faceIndex = pointOnMesh.faceIndex()
            indicesVertices = om.MIntArray()
            fnTargetMesh.getPolygonVertices( faceIndex, indicesVertices )
            
            minDist = 100000.0
            closeIndex = indicesVertices[0]
            for j in range( indicesVertices.length() ):
                pointTarget = targetMeshPoints[ indicesVertices[j] ]
                dist = pointTarget.distanceTo( pointSource )
                if dist < minDist:
                    minDist = dist
                    closeIndex = indicesVertices[j]
            
            print plugVerticeId[i].name(), closeIndex
            cmds.setAttr( plugVerticeId[i].name(), closeIndex )

        cmds.connectAttr( targetShape+'.outMesh', node+'.inputMesh', f=1 )
        cmds.connectAttr( targetShape+'.worldMatrix[0]', node+'.inputMeshMatrix', f=1 )
コード例 #5
0
ファイル: sgBRig_character.py プロジェクト: jonntd/mayadev-1
    def __init__(self, meshName ):

        dagPathMesh = sgBFunction_dag.getMDagPath( meshName )
        self.fnMesh = om.MFnMesh( dagPathMesh )
        self.meshMatrix = dagPathMesh.inclusiveMatrix()
        
        self.checkPolygonMap  = om.MIntArray()
        self.startVtxIndexMap = om.MIntArray()
        self.checkVertexMap   = om.MIntArray()
        
        self.vtxCountPerPoly = om.MIntArray()
        self.vtxIndicesList  = om.MIntArray()
        
        self.fnMesh.getVertices( self.vtxCountPerPoly, self.vtxIndicesList )
        self.checkVertexMap.setLength( self.fnMesh.numVertices() )
        self.checkPolygonMap.setLength( self.fnMesh.numPolygons() )
        self.startVtxIndexMap.setLength( self.fnMesh.numPolygons() )
        
        startVtxIndex = 0
        
        for i in range( self.fnMesh.numVertices() ):
            self.checkVertexMap.set( 0, i )
        
        for i in range( self.fnMesh.numPolygons() ):
            self.checkPolygonMap.set( 0, i )
            self.startVtxIndexMap.set( startVtxIndex, i )
            startVtxIndex += self.vtxCountPerPoly[i]
        
        self.indicesCheckedPolygon  = []
        self.indicesCheckedVertices = []
コード例 #6
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getCurveLength(target):

    import sgBFunction_dag
    targetShape = sgBFunction_dag.getShape(target)

    fnCurve = om.MFnNurbsCurve(sgBFunction_dag.getMDagPath(targetShape))
    return fnCurve.length()
コード例 #7
0
ファイル: sgBRig_character.py プロジェクト: jonntd/mayadev-1
    def __init__(self, meshName):

        dagPathMesh = sgBFunction_dag.getMDagPath(meshName)
        self.fnMesh = om.MFnMesh(dagPathMesh)
        self.meshMatrix = dagPathMesh.inclusiveMatrix()

        self.checkPolygonMap = om.MIntArray()
        self.startVtxIndexMap = om.MIntArray()
        self.checkVertexMap = om.MIntArray()

        self.vtxCountPerPoly = om.MIntArray()
        self.vtxIndicesList = om.MIntArray()

        self.fnMesh.getVertices(self.vtxCountPerPoly, self.vtxIndicesList)
        self.checkVertexMap.setLength(self.fnMesh.numVertices())
        self.checkPolygonMap.setLength(self.fnMesh.numPolygons())
        self.startVtxIndexMap.setLength(self.fnMesh.numPolygons())

        startVtxIndex = 0

        for i in range(self.fnMesh.numVertices()):
            self.checkVertexMap.set(0, i)

        for i in range(self.fnMesh.numPolygons()):
            self.checkPolygonMap.set(0, i)
            self.startVtxIndexMap.set(startVtxIndex, i)
            startVtxIndex += self.vtxCountPerPoly[i]

        self.indicesCheckedPolygon = []
        self.indicesCheckedVertices = []
コード例 #8
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getCurveLength(target ):
    
    import sgBFunction_dag
    targetShape = sgBFunction_dag.getShape( target )
    
    fnCurve = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( targetShape ) )
    return fnCurve.length()
コード例 #9
0
    def loadSelectedStartIndices(*args):

        import sgBFunction_dag
        mesh, indices = sgBFunction_mesh.getMeshAndIndicesPoints(cmds.ls(sl=1))
        cmds.textField(Window_Global.fld_targetMesh, e=1, tx=mesh)

        indicesStr = ''
        for i in indices:
            indicesStr += str(i) + ','

        cmds.textField(Window_Global.fld_startPoints, e=1, tx=indicesStr[:-1])

        fnMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(mesh))
        points = om.MPointArray()
        fnMesh.getPoints(points)

        bb = om.MBoundingBox()

        for i in range(len(indices)):
            bb.expand(points[indices[i]])

        center = om.MPoint(bb.center())

        farIndex = 0
        farDist = 0.0
        for i in range(points.length()):
            dist = center.distanceTo(points[i])
            if farDist < dist:
                farDist = dist
                farIndex = i

        print farIndex
        cmds.textField(Window_Global.fld_endPoints, e=1, tx=str(farIndex))
コード例 #10
0
def importAlembicData(prefix, filePath):

    import sgBFunction_base
    sgBFunction_base.autoLoadPlugin('AbcExport')

    beforeTopNodes = sgBFunction_dag.getTopTransformNodes()
    cmds.AbcImport(filePath, mode='import')
    afterTopNodes = sgBFunction_dag.getTopTransformNodes()

    fnTargets = []
    for afterTopNode in afterTopNodes:
        if afterTopNode in beforeTopNodes: continue

        children = cmds.listRelatives(afterTopNode,
                                      c=1,
                                      ad=1,
                                      f=1,
                                      type='transform')
        if not children: children = []
        children.append(afterTopNode)
        for child in children:
            fnTarget = om.MFnTransform(sgBFunction_dag.getMDagPath(child))
            fnTargets.append(fnTarget)

    for target in fnTargets:
        targetName = target.name()
        fullName = target.fullPathName()
        cmds.rename(fullName, prefix + targetName)
コード例 #11
0
 def __init__(self, centerCurves, mesh ):
     
     import sgBFunction_dag
     
     self.centerCurves = centerCurves
     meshShape = sgBFunction_dag.getShape( mesh )
     dagPath = sgBFunction_dag.getMDagPath( meshShape )
     self.fnMesh = om.MFnMesh( dagPath )
     self.mtxMesh = dagPath.inclusiveMatrix()
コード例 #12
0
ファイル: sgBRig_character.py プロジェクト: jonntd/mayadev-1
def separateMeshBySkinWeight2(meshObj):

    import sgBFunction_connection

    skinClusters = sgBFunction_dag.getNodeFromHistory(meshObj, 'skinCluster')
    meshShape = sgBFunction_dag.getShape(meshObj)

    if not skinClusters: return []
    skinCluster = skinClusters[0]
    fnMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(meshShape))

    jntsPerVertices = JointsPerVertices(skinCluster)
    polygonsPerJointArray = [
        PolygonsPerJoint2(meshShape)
        for i in range(len(jntsPerVertices.existConnectJoints))
    ]

    vtxCountsPerPolygon = om.MIntArray()
    vtxIndices = om.MIntArray()
    fnMesh.getVertices(vtxCountsPerPolygon, vtxIndices)

    for i in range(fnMesh.numVertices()):
        jointLogicalIndex = jntsPerVertices.getJointIndex(i)
        physicalIndex = jntsPerVertices.jointLogicalIndexMap[jointLogicalIndex]
        polygonsPerJointArray[physicalIndex].check(i)

    meshs = []
    for i in range(len(polygonsPerJointArray)):
        targetJoint = om.MFnDagNode(
            jntsPerVertices.existConnectJoints[i]).fullPathName()
        mesh = polygonsPerJointArray[i].buildMesh2()
        meshShape = sgBFunction_dag.getShape(mesh)

        fnMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(meshShape))
        print fnMesh.numPolygons(), targetJoint

        mesh = cmds.rename(mesh, targetJoint.split('|')[-1] + '_mesh')

        cmds.sets(mesh, e=1, forceElement='initialShadingGroup')
        meshs.append(mesh)
        sgBFunction_connection.bindConnect(mesh, targetJoint)

    return meshs
コード例 #13
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getMatricesFromCurve(curve, aimIndex=0, vUpVector=None):

    import sgBFunction_dag

    curveShape = sgBFunction_dag.getShape(curve)
    curvePath = sgBFunction_dag.getMDagPath(curveShape)
    mtxCurve = curvePath.inclusiveMatrix()

    fnCurve = om.MFnNurbsCurve(curvePath)

    minParam = fnCurve.findParamFromLength(0)
    maxParam = fnCurve.findParamFromLength(fnCurve.length())
    numSpans = fnCurve.numSpans()

    lengthParam = maxParam - minParam
    eachParam = lengthParam / (numSpans - 1)

    if not vUpVector:
        vUp = om.MVector(0, 1, 0)
    else:
        vUp = vUpVector
    mtxArr = []
    for i in range(numSpans):
        point = om.MPoint()
        fnCurve.getPointAtParam(eachParam * i, point)
        vTangent = fnCurve.tangent(eachParam * i) * mtxCurve
        vCross = vTangent ^ vUp
        vUp = vCross ^ vTangent

        vTangent.normalize()
        vUp.normalize()
        vCross.normalize()

        mtx = [float(i % 5 == 0) for i in range(16)]

        indexAim = (3 + aimIndex) % 3
        indexUp = (3 + aimIndex + 1) % 3
        indexCross = (3 + aimIndex + 2) % 3

        mtx[indexAim * 4 + 0] = vTangent.x
        mtx[indexAim * 4 + 1] = vTangent.y
        mtx[indexAim * 4 + 2] = vTangent.z
        mtx[indexUp * 4 + 0] = vUp.x
        mtx[indexUp * 4 + 1] = vUp.y
        mtx[indexUp * 4 + 2] = vUp.z
        mtx[indexCross * 4 + 0] = vCross.x
        mtx[indexCross * 4 + 1] = vCross.y
        mtx[indexCross * 4 + 2] = vCross.z
        mtx[3 * 4 + 0] = point.x
        mtx[3 * 4 + 1] = point.y
        mtx[3 * 4 + 2] = point.z

        mtxArr.append(mtx)

    return mtxArr
コード例 #14
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getMatricesFromCurve( curve, aimIndex = 0, vUpVector=None ):
    
    import sgBFunction_dag
    
    curveShape = sgBFunction_dag.getShape( curve )
    curvePath = sgBFunction_dag.getMDagPath( curveShape )
    mtxCurve = curvePath.inclusiveMatrix()
    
    fnCurve = om.MFnNurbsCurve( curvePath )
    
    minParam = fnCurve.findParamFromLength( 0 )
    maxParam = fnCurve.findParamFromLength( fnCurve.length() )
    numSpans = fnCurve.numSpans()
    
    lengthParam = maxParam - minParam
    eachParam = lengthParam / ( numSpans - 1 )
    
    if not vUpVector:
        vUp = om.MVector( 0, 1, 0 )
    else:
        vUp = vUpVector
    mtxArr = []
    for i in range( numSpans ):
        point = om.MPoint()
        fnCurve.getPointAtParam( eachParam * i, point )
        vTangent = fnCurve.tangent( eachParam * i ) * mtxCurve 
        vCross = vTangent ^ vUp
        vUp = vCross ^ vTangent
        
        vTangent.normalize()
        vUp.normalize()
        vCross.normalize()
        
        mtx = [ float(i%5 == 0) for i in range( 16 ) ]
        
        indexAim   = (3+aimIndex)%3
        indexUp    = (3+aimIndex+1)%3
        indexCross = (3+aimIndex+2)%3
        
        mtx[ indexAim*4+0 ] = vTangent.x
        mtx[ indexAim*4+1 ] = vTangent.y
        mtx[ indexAim*4+2 ] = vTangent.z
        mtx[ indexUp*4+0 ] = vUp.x
        mtx[ indexUp*4+1 ] = vUp.y
        mtx[ indexUp*4+2 ] = vUp.z
        mtx[ indexCross*4+0 ] = vCross.x
        mtx[ indexCross*4+1 ] = vCross.y
        mtx[ indexCross*4+2 ] = vCross.z
        mtx[ 3*4+0 ] = point.x
        mtx[ 3*4+1 ] = point.y
        mtx[ 3*4+2 ] = point.z
        
        mtxArr.append( mtx )
    
    return mtxArr
コード例 #15
0
 def replace(self, *args ):
     
     import sgBFunction_dag
     
     sourceName = cmds.textField( WinA_Global.fld_source, q=1, tx=1 )
     targetName = cmds.textField( WinA_Global.fld_target, q=1, tx=1 )
     isNamespace = cmds.checkBox( WinA_Global.chk_isNamespace, q=1, v=1 )
     
     if not sourceName: return None
     
     if isNamespace:
         targets = cmds.ls()
         fnTargets = []
         for target in targets:
             if target[:len(sourceName)] != sourceName: continue
             if cmds.attributeQuery( 'wm', node=target, ex=1 ):
                 fnTarget = om.MFnDagNode( sgBFunction_dag.getMDagPath( target ) )
             else:
                 fnTarget = om.MFnDependencyNode( sgBFunction_dag.getMObject( target ) )
             fnTargets.append( fnTarget )
         for fnTarget in fnTargets:
             if type( fnTarget ) == type( om.MFnDagNode() ):
                 cmds.rename( fnTarget.fullPathName(), targetName + fnTarget.name()[len(sourceName):] )
             else:
                 cmds.rename( fnTarget.name(), targetName + fnTarget.name()[len(sourceName):] )
         
     else:
         targets = cmds.ls()
         fnTargets = []
         for target in targets:
             if target.find( sourceName ) == -1: continue
             if cmds.attributeQuery( 'wm', node=target, ex=1 ):
                 fnTarget = om.MFnDagNode( sgBFunction_dag.getMDagPath( target ) )
             else:
                 fnTarget = om.MFnDependencyNode( sgBFunction_dag.getMObject( target ) )
             fnTargets.append( fnTarget )
         for fnTarget in fnTargets:
             if type( fnTarget ) == type( om.MFnDagNode() ):
                 cmds.rename( fnTarget.fullPathName(), fnTarget.name().replace( sourceName, targetName ) )
             else:
                 cmds.rename( fnTarget.name(), fnTarget.name().replace( sourceName, targetName ) )
コード例 #16
0
def makeSparateShader( targetObject ):

    import random
    import maya.OpenMaya as om
    import sgBFunction_dag
    import sgBFunction_base
    import copy
    
    sgBFunction_base.autoLoadPlugin( 'sgMesh' )
    
    cmds.sgGetMeshElementInfo( targetObject, set=1 )
    
    targetShape = sgBFunction_dag.getShape( targetObject )
    dagPathShape = sgBFunction_dag.getMDagPath( targetShape )
    
    numElement  = cmds.sgGetMeshElementInfo( ne=1 )
    numFaces    = cmds.sgGetMeshElementInfo( np=1 )
    faceIndices = cmds.sgGetMeshElementInfo( fi=1 )
    
    for i in range( numElement ):
        startFaceIndex = 0
        lastFaceIndex  = 0
        
        for j in range( i ):
            startFaceIndex += int( numFaces[j] )
        for j in range( i+1 ):
            lastFaceIndex += int( numFaces[j] )
    
        compArray = om.MIntArray()
        compArray.setLength( int( numFaces[i] ) )    
        for j in range( startFaceIndex, lastFaceIndex ):
            compArray.set( faceIndices[j], j-startFaceIndex )
    
        blinnShader = cmds.shadingNode( 'blinn', asShader=1 )
        blinnSet = cmds.sets( renderable=1, noSurfaceShader=1, empty=1, name='blinnSG' )
        cmds.connectAttr( blinnShader+'.outColor', blinnSet+'.surfaceShader', f=1 )
        
        colorR = random.uniform( 0, 1 )
        colorG = random.uniform( 0, 1 )
        colorB = random.uniform( 0, 1 )
        
        cmds.setAttr( blinnShader+'.color', colorR, colorG, colorB, type='double3' )
        
        singleComp = om.MFnSingleIndexedComponent()
        singleCompObj = singleComp.create( om.MFn.kMeshPolygonComponent )
        singleComp.addElements( compArray )
        
        selList = om.MSelectionList()
        selList.add( dagPathShape, singleCompObj )
        om.MGlobal.selectCommand( selList )
    
        cmds.sets( e=1, forceElement=blinnSet )
コード例 #17
0
ファイル: sgBRig_character.py プロジェクト: jonntd/mayadev-1
def separateMeshBySkinWeight2( meshObj ):
    
    import sgBFunction_connection
    
    skinClusters = sgBFunction_dag.getNodeFromHistory( meshObj, 'skinCluster' )
    meshShape    = sgBFunction_dag.getShape( meshObj )
    
    if not skinClusters: return []
    skinCluster = skinClusters[0]
    fnMesh = om.MFnMesh( sgBFunction_dag.getMDagPath( meshShape ) )
    
    jntsPerVertices = JointsPerVertices( skinCluster )
    polygonsPerJointArray = [ PolygonsPerJoint2( meshShape ) for i in range( len( jntsPerVertices.existConnectJoints ) ) ]
    
    vtxCountsPerPolygon = om.MIntArray()
    vtxIndices = om.MIntArray()
    fnMesh.getVertices( vtxCountsPerPolygon, vtxIndices )
    
    for i in range( fnMesh.numVertices() ):
        jointLogicalIndex = jntsPerVertices.getJointIndex( i )
        physicalIndex = jntsPerVertices.jointLogicalIndexMap[ jointLogicalIndex ]
        polygonsPerJointArray[ physicalIndex ].check( i )

    meshs = []
    for i in range( len( polygonsPerJointArray ) ):
        targetJoint = om.MFnDagNode( jntsPerVertices.existConnectJoints[i] ).fullPathName()
        mesh = polygonsPerJointArray[i].buildMesh2()
        meshShape = sgBFunction_dag.getShape( mesh )
        
        fnMesh = om.MFnMesh( sgBFunction_dag.getMDagPath( meshShape ) )
        print fnMesh.numPolygons(), targetJoint
        
        mesh = cmds.rename( mesh, targetJoint.split( '|' )[-1] + '_mesh' )
        
        cmds.sets( mesh, e=1, forceElement='initialShadingGroup' )
        meshs.append( mesh )
        sgBFunction_connection.bindConnect( mesh, targetJoint )
    
    return meshs
コード例 #18
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getClosestParameter(targetObj, curve):

    import sgBFunction_dag

    crvShape = sgBFunction_dag.getShape(curve)

    dagPathTarget = sgBFunction_dag.getMDagPath(targetObj)
    mtxTarget = dagPathTarget.inclusiveMatrix()
    dagPathCurve = sgBFunction_dag.getMDagPath(crvShape)
    mtxCurve = dagPathCurve.inclusiveMatrix()

    pointTarget = om.MPoint(mtxTarget[3])
    pointTarget *= mtxCurve.inverse()

    fnCurve = om.MFnNurbsCurve(sgBFunction_dag.getMDagPath(crvShape))

    util = om.MScriptUtil()
    util.createFromDouble(0.0)
    ptrDouble = util.asDoublePtr()
    fnCurve.closestPoint(pointTarget, 0, ptrDouble)

    paramValue = om.MScriptUtil().getDouble(ptrDouble)

    return paramValue
コード例 #19
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getClosestParameter( targetObj, curve ):
    
    import sgBFunction_dag
    
    crvShape = sgBFunction_dag.getShape( curve )
    
    dagPathTarget = sgBFunction_dag.getMDagPath( targetObj )
    mtxTarget = dagPathTarget.inclusiveMatrix()
    dagPathCurve  = sgBFunction_dag.getMDagPath( crvShape )
    mtxCurve  = dagPathCurve.inclusiveMatrix()
    
    pointTarget = om.MPoint( mtxTarget[3] )
    pointTarget *= mtxCurve.inverse()
    
    fnCurve = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( crvShape ) )
    
    util = om.MScriptUtil()
    util.createFromDouble( 0.0 )
    ptrDouble = util.asDoublePtr()
    fnCurve.closestPoint( pointTarget, 0, ptrDouble )
    
    paramValue = om.MScriptUtil().getDouble( ptrDouble )
    
    return paramValue
コード例 #20
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def rebuildByMinMaxSpans(curves, minSpans, maxSpans):

    import sgBFunction_dag

    sels = sgBFunction_dag.getChildrenShapeExists(curves)

    lengthList = []

    minLength = 10000000.0
    maxLength = 0.0

    targetCurves = []
    for sel in sels:
        selShape = sgBFunction_dag.getShape(sel)
        if not selShape: continue
        if not cmds.nodeType(selShape) == 'nurbsCurve': continue

        fnCurve = om.MFnNurbsCurve(sgBFunction_dag.getMDagPath(selShape))

        curveLength = fnCurve.length()

        if curveLength < minLength:
            minLength = curveLength
        if curveLength > maxLength:
            maxLength = curveLength

        targetCurves.append(sel)
        lengthList.append(fnCurve.length())

    diffSpans = maxSpans - minSpans
    diffLength = maxLength - minLength

    for i in range(len(targetCurves)):
        lengthRate = (lengthList[i] - minLength) / diffLength

        spansRate = lengthRate * diffSpans
        spans = spansRate + minSpans
        cmds.rebuildCurve(targetCurves[i],
                          rpo=1,
                          rt=0,
                          end=1,
                          kr=2,
                          kcp=0,
                          kep=1,
                          kt=1,
                          s=spans,
                          d=3,
                          tol=0.01)
コード例 #21
0
    def create(*args):

        strTargetMesh = cmds.textField(Window_Global.fld_targetMesh, q=1, tx=1)
        strIndicesStart = cmds.textField(Window_Global.fld_startPoints,
                                         q=1,
                                         tx=1)
        strIndicesEnd = cmds.textField(Window_Global.fld_endPoints, q=1, tx=1)
        detail = cmds.intField(Window_Global.fld_detail, q=1, v=1)

        eStrStartIndices = strIndicesStart.split(',')
        eStrEndIndices = strIndicesEnd.split(',')

        indicesStart = []
        for strIndex in eStrStartIndices:
            indicesStart.append(int(strIndex.strip()))

        indicesEnd = []
        for strIndex in eStrEndIndices:
            indicesEnd.append(int(strIndex.strip()))

        import sgBFunction_dag

        dagPathMesh = sgBFunction_dag.getMDagPath(strTargetMesh)
        fnMesh = om.MFnMesh(dagPathMesh)

        pointsMesh = om.MPointArray()
        fnMesh.getPoints(pointsMesh)

        bbStarts = om.MBoundingBox()
        bbEnds = om.MBoundingBox()

        for index in indicesStart:
            bbStarts.expand(pointsMesh[index])

        for index in indicesEnd:
            bbEnds.expand(pointsMesh[index])

        startCenter = bbStarts.center() * dagPathMesh.inclusiveMatrix()
        endCenter = bbEnds.center() * dagPathMesh.inclusiveMatrix()

        sgBFunction_mesh.createJointLineFromMeshApi(dagPathMesh, startCenter,
                                                    endCenter, detail)
コード例 #22
0
ファイル: sgBRig_character.py プロジェクト: jonntd/mayadev-1
    def __init__(self, meshName):

        dagPathMesh = sgBFunction_dag.getMDagPath(meshName)
        self.fnMesh = om.MFnMesh(dagPathMesh)
        self.itMesh = om.MItMeshPolygon(dagPathMesh.node())
        self.meshMatrix = dagPathMesh.inclusiveMatrix()
        self.numVertices = self.fnMesh.numVertices()
        self.numEdges = self.fnMesh.numEdges()
        self.numPolygons = self.fnMesh.numPolygons()
        self.points = om.MPointArray()
        self.fnMesh.getPoints(self.points)

        self.checkVertexMap = om.MIntArray()
        self.checkPolygonMap = om.MIntArray()

        self.checkVertexMap.setLength(self.numVertices)
        for i in range(self.numVertices):
            self.checkVertexMap.set(0, i)
        self.checkPolygonMap.setLength(self.numPolygons)
        for i in range(self.numPolygons):
            self.checkPolygonMap.set(0, i)

        self.centerVtxExistsEdges = [0 for i in range(self.numEdges)]
        self.centerVtxPointPerEdges = [
            om.MPoint() for i in range(self.numEdges)
        ]
        self.edgesPerPolygon = [
            om.MIntArray() for i in range(self.numPolygons)
        ]
        while not self.itMesh.isDone():
            self.itMesh.getEdges(self.edgesPerPolygon[self.itMesh.index()])
            self.itMesh.next()

        self.renumberedVerticesMap = om.MIntArray()
        self.renumberedVerticesMap.setLength(self.numVertices)

        self.addVtxCurrentNum = 0
        self.addVerticesIndices = om.MIntArray()
        self.addVerticesPoints = om.MPointArray()
        self.addVerticesCounts = om.MIntArray()
        self.addVerticesIndices = om.MIntArray()
コード例 #23
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def rebuildByMinMaxSpans( curves, minSpans, maxSpans ):
    
    import sgBFunction_dag
    
    sels = sgBFunction_dag.getChildrenShapeExists( curves )
    
    lengthList = []
    
    minLength = 10000000.0
    maxLength = 0.0
    
    targetCurves = []
    for sel in sels:
        selShape = sgBFunction_dag.getShape( sel )
        if not selShape: continue
        if not cmds.nodeType( selShape ) == 'nurbsCurve': continue
        
        fnCurve = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( selShape ) )
        
        curveLength = fnCurve.length()
        
        if curveLength < minLength:
            minLength = curveLength
        if curveLength > maxLength:
            maxLength = curveLength
        
        targetCurves.append( sel )
        lengthList.append( fnCurve.length() )
    
    
    diffSpans = maxSpans - minSpans
    diffLength = maxLength - minLength
    
    for i in range( len( targetCurves ) ):
        lengthRate = ( lengthList[i] - minLength ) / diffLength
        
        spansRate = lengthRate * diffSpans
        spans = spansRate + minSpans
        cmds.rebuildCurve( targetCurves[i], rpo=1, rt=0, end=1, kr=2, kcp=0, kep=1, kt=1, s=spans, d=3, tol=0.01 )
コード例 #24
0
ファイル: sgBRig_character.py プロジェクト: jonntd/mayadev-1
    def __init__(self, meshName ):

        dagPathMesh = sgBFunction_dag.getMDagPath( meshName )
        self.fnMesh = om.MFnMesh( dagPathMesh )
        self.itMesh = om.MItMeshPolygon( dagPathMesh.node() )
        self.meshMatrix = dagPathMesh.inclusiveMatrix()
        self.numVertices = self.fnMesh.numVertices()
        self.numEdges    = self.fnMesh.numEdges()
        self.numPolygons = self.fnMesh.numPolygons()
        self.points = om.MPointArray()
        self.fnMesh.getPoints( self.points )
        
        self.checkVertexMap   = om.MIntArray()
        self.checkPolygonMap   = om.MIntArray()
        
        self.checkVertexMap.setLength( self.numVertices )
        for i in range( self.numVertices ):
            self.checkVertexMap.set( 0, i )
        self.checkPolygonMap.setLength( self.numPolygons )
        for i in range( self.numPolygons ):
            self.checkPolygonMap.set( 0, i )

        self.centerVtxExistsEdges = [ 0 for i in range( self.numEdges ) ]
        self.centerVtxPointPerEdges = [ om.MPoint() for i in range( self.numEdges ) ] 
        self.edgesPerPolygon = [ om.MIntArray() for i in range( self.numPolygons ) ]
        while not self.itMesh.isDone():
            self.itMesh.getEdges( self.edgesPerPolygon[self.itMesh.index()] )
            self.itMesh.next()

        self.renumberedVerticesMap = om.MIntArray()
        self.renumberedVerticesMap.setLength( self.numVertices )

        self.addVtxCurrentNum = 0
        self.addVerticesIndices = om.MIntArray()
        self.addVerticesPoints  = om.MPointArray()
        self.addVerticesCounts  = om.MIntArray()
        self.addVerticesIndices = om.MIntArray()
コード例 #25
0
ファイル: sgBExcute_data.py プロジェクト: jonntd/mayadev-1
def importAlembicData( prefix, filePath ):
    
    import sgBFunction_base
    sgBFunction_base.autoLoadPlugin( 'AbcExport' )
    
    beforeTopNodes = sgBFunction_dag.getTopTransformNodes()
    cmds.AbcImport( filePath, mode='import' )
    afterTopNodes = sgBFunction_dag.getTopTransformNodes()
    
    fnTargets = []
    for afterTopNode in afterTopNodes:
        if afterTopNode in beforeTopNodes: continue
        
        children = cmds.listRelatives( afterTopNode, c=1, ad=1, f=1, type='transform' )
        if not children: children = []
        children.append( afterTopNode )
        for child in children:
            fnTarget = om.MFnTransform( sgBFunction_dag.getMDagPath( child ) )
            fnTargets.append( fnTarget )

    for target in fnTargets:
        targetName = target.name()
        fullName   = target.fullPathName()
        cmds.rename( fullName, prefix + targetName )
コード例 #26
0
ファイル: sgBFunction_rivet.py プロジェクト: jonntd/mayadev-1
def createCurveFromSelVertices_mirror( targetCurve ):
    
    import sgBFunction_dag
    
    def getMeshAndIndices( targetCurve ):
        curveShape = sgBFunction_dag.getShape( targetCurve )
        
        inputNode = curveShape
        crvToPointNode = None
        mtxFromVtxNode = None
        num = 0
        while True:
            num += 1
            if num >= 100: break
            cons = cmds.listConnections( inputNode, s=1, d=0, p=1, c=1 )
            if not cons: return None
            outputCon = cons[1]
            node = outputCon.split( '.' )[0]
            targetNodeType = cmds.nodeType( node )
            if targetNodeType == 'sgCurveFromPoints':
                crvToPointNode = node
                inputNode = node
                continue
            if targetNodeType == 'sgMatrixFromVertices':
                mtxFromVtxNode = node
                break
            inputNode = node

        mesh = cmds.listConnections( mtxFromVtxNode+'.inputMesh', s=1, d=0 )[0]
        
        print "crvToPointNode : ", crvToPointNode
        fnNode = om.MFnDependencyNode( sgBFunction_dag.getMObject( crvToPointNode ) )
        plugInputs = fnNode.findPlug( 'input' )
        
        indices = []
        for i in range( plugInputs.numElements() ):
            connections = om.MPlugArray()
            plugInputPoint = plugInputs[i].child( 1 )
            plugInputPoint.connectedTo( connections, True, False )
            indices.append( connections[0].logicalIndex() )
        
        return mesh, indices
        
    
    def createCurve( mesh, indices ):
        
        vtsToCrv = cmds.createNode( 'sgMatrixFromVertices'  )
        pointToCrv = cmds.createNode( 'sgCurveFromPoints' )
        crv = cmds.createNode( 'nurbsCurve' )
        
        cmds.connectAttr( pointToCrv+'.outputCurve', crv+'.create' )
        
        cmds.connectAttr( mesh+'.outMesh', vtsToCrv+'.inputMesh' )
        cmds.connectAttr( mesh+'.wm', vtsToCrv+'.inputMeshMatrix' )
        
        for i in range( len( indices ) ):
            cmds.setAttr( vtsToCrv+'.verticeId[%d]' % indices[i], indices[i] )
            cmds.connectAttr( vtsToCrv+'.outputTranslate[%d]' % indices[i], pointToCrv+'.input[%d].inputPoint' % i )
        
        return crv, pointToCrv
    
    mesh, indices = getMeshAndIndices( targetCurve )
    mesh = sgBFunction_dag.getShape( mesh )

    dagPathMesh = sgBFunction_dag.getMDagPath( mesh )
    
    intersector = om.MMeshIntersector()
    intersector.create( dagPathMesh.node() )
    
    meshMtx = dagPathMesh.inclusiveMatrix()
    meshMtxInv = dagPathMesh.inclusiveMatrixInverse()
    fnMesh = om.MFnMesh( dagPathMesh )
    
    pArr = om.MPointArray()
    fnMesh.getPoints( pArr )
    
    targetIndices = []
    pointOnMesh = om.MPointOnMesh()
    for index in indices:
        worldPoint = pArr[ index ] * meshMtx
        mirrorPoint = om.MPoint( -worldPoint.x, worldPoint.y, worldPoint.z )*meshMtxInv
        intersector.getClosestPoint( mirrorPoint, pointOnMesh )
        fIndex = pointOnMesh.faceIndex()
        
        vtxIndices = om.MIntArray()
        fnMesh.getPolygonVertices( fIndex, vtxIndices )
        
        closeDist = 1000000.0
        closeIndex = vtxIndices[0]
        for vtxIndex in vtxIndices:
            point = pArr[ vtxIndex ]
            dist = point.distanceTo( mirrorPoint )
            if dist < closeDist:
                closeDist = dist
                closeIndex = vtxIndex
        
        targetIndices.append( closeIndex )
    
    node = sgBFunction_dag.getNodeFromHistory( targetCurve, 'sgCurveFromPoints' )[0]
    createType = cmds.getAttr( node + '.createType' )
    degrees    = cmds.getAttr( node+'.degrees' )
    
    createdCrv, createdNode = createCurve( mesh, targetIndices )
    cmds.setAttr( createdNode + '.createType', createType )
    cmds.setAttr( createdNode + '.degrees',    degrees )
コード例 #27
0
def setWeightInnerPointsToTargetJoint( baseMesh, baseJoint, targetMeshs ):
    
    import sgBFunction_dag
    
    baseMeshShape = sgBFunction_dag.getShape( baseMesh )
    dagPathBaseMesh = sgBFunction_dag.getMDagPath( baseMeshShape )
    mtxBaseMesh = dagPathBaseMesh.inclusiveMatrix()
    headIntersector = om.MMeshIntersector()
    headIntersector.create( dagPathBaseMesh.node() )
    
    targetMeshs = cmds.ls( sl=1 )
    
    for targetMesh in targetMeshs:
    
        skinNodes = sgBFunction_dag.getNodeFromHistory( targetMesh ,'skinCluster')
        if not skinNodes: continue
        
        skinNode = skinNodes[0]
        fnSkinNode = om.MFnDependencyNode( sgBFunction_dag.getMObject( skinNode ) )
        
        joints = cmds.listConnections( skinNode+'.matrix', s=1, d=0 )
        if not baseJoint in joints: continue
        indexInfluence = joints.index( baseJoint )
        
        plugWeightList = fnSkinNode.findPlug( 'weightList' )
        
        targetMeshShape = sgBFunction_dag.getShape( targetMesh )
        dagPathTargetMesh = sgBFunction_dag.getMDagPath( targetMeshShape )
        fnTargetMesh = om.MFnMesh( dagPathTargetMesh )
        
        mtxTarget = dagPathTargetMesh.inclusiveMatrix()
        mtxToBase = mtxTarget * mtxBaseMesh.inverse()
        
        numVertices = fnTargetMesh.numVertices()
        pointsTarget = om.MPointArray()
        fnTargetMesh.getPoints( pointsTarget )
        
        pointOnMesh = om.MPointOnMesh()
        
        targetVertices = []
        
        for i in range( numVertices ):
            pointLocal = pointsTarget[i] * mtxToBase
            headIntersector.getClosestPoint( pointLocal, pointOnMesh )
            
            point = pointOnMesh.getPoint()
            normal = om.MVector( pointOnMesh.getNormal() )
            
            vDir = om.MVector( pointLocal ) - om.MVector( point )
            
            if vDir * normal > 0: continue
            
            plugWeights = plugWeightList[i].child( 0 )
            for j in range( plugWeights.numElements() ):
                cmds.setAttr( plugWeights.name() + "[%d]" % j, 0 )
            
            cmds.setAttr( plugWeights.name() + "[%d]" % indexInfluence, 1 )
            targetVertices.append( targetMesh+'.vtx[%d]' % i )

        cmds.select( targetVertices )
            
コード例 #28
0
ファイル: sgBFunction_rivet.py プロジェクト: jonntd/mayadev-1
def createRivetFromVertex_mirror( rivetObj ):
    
    import sgBFunction_dag
    import sgBFunction_base
    import sgBFunction_convert
    
    sgBFunction_base.autoLoadPlugin( 'sgRigAddition' )
    
    def getNodeFromMesh( mesh, isFirst=True ):
        
        if cmds.objectType( mesh ) == 'transform':
            mesh = sgBFunction_dag.getShape( mesh )
        
        cons = cmds.listConnections( mesh+'.wm', type='sgMatrixFromVertices' )
        if cons: return cons[0]
        
        node = cmds.createNode( 'sgMatrixFromVertices' )
        cmds.connectAttr( mesh+'.outMesh', node+'.inputMesh' )
        cmds.connectAttr( mesh+'.wm', node+'.inputMeshMatrix' )
        
        return node


    cons = cmds.listConnections( rivetObj, s=1, d=0, type='sgMatrixFromVertices', p=1, c=1 )
    if not cons: return None
    
    node, attr = cons[1].split( '.' )
    vtxNum = int( attr.split( '[' )[1].replace( ']', '' ) )
    
    mesh = cmds.listConnections( node, s=1, d=0, type='mesh', shapes=1 )
    if not mesh: return None
    
    mesh = mesh[0]
    
    fnMesh = om.MFnMesh( sgBFunction_dag.getMDagPath( mesh ) )
    intersector = om.MMeshIntersector()
    intersector.create( fnMesh.object() )
    
    pointArr = om.MPointArray()
    fnMesh.getPoints( pointArr )
    pointMirror = om.MPoint( -pointArr[ vtxNum ].x, pointArr[ vtxNum ].y, pointArr[ vtxNum ].z )
    
    pointOnMesh = om.MPointOnMesh()
    intersector.getClosestPoint( pointMirror, pointOnMesh )
    
    faceIndex = pointOnMesh.faceIndex()
    vertices = om.MIntArray()
    fnMesh.getPolygonVertices( faceIndex, vertices )
    
    closeIndex = 0
    closeDist = 1000000.0
    for i in range( vertices.length() ):
        dist = pointArr[ vertices[i] ].distanceTo( pointMirror )
        if closeDist > dist:
            closeDist = dist
            closeIndex = vertices[i]
    
    cmds.setAttr( node+'.verticeId[%d]' % closeIndex, closeIndex )
    
    rivetObjName = rivetObj.split( '|' )[-1]
    rivetObjName = rivetObjName.replace( str( vtxNum ), str( closeIndex ) )
    newObject = cmds.createNode( 'transform', n= sgBFunction_convert.convertSide( rivetObjName ) )
    cmds.setAttr( newObject+'.dh', 1 )
    cmds.setAttr( newObject+'.inheritsTransform', 0 )
    
    cmds.connectAttr( node+'.outputTranslate[%d]' % closeIndex, newObject+'.t' )
コード例 #29
0
def combineSkinCluster( skinedObjs ):
    
    import sgBFunction_dag
    
    numVertices = None
    for skinedObj in skinedObjs:
        objShape = sgBFunction_dag.getShape( skinedObj )
        fnMesh = om.MFnMesh( sgBFunction_dag.getMDagPath( objShape ) )
        if not numVertices:
            numVertices = fnMesh.numVertices()
        else:
            if numVertices != fnMesh.numVertices():
                cmds.error( "Selected meshs not same objects" )
    
    skinJoints = []
    weightList = [ [] for i in range( numVertices ) ]
    for skinedObj in skinedObjs:
        
        skinCluster = sgBFunction_dag.getNodeFromHistory( skinedObj, 'skinCluster' )
        if not skinCluster: continue
        
        skinCluster = skinCluster[0]
        
        fnNode = om.MFnDependencyNode( sgBFunction_dag.getMObject( skinCluster ) )
        
        plugMatrix = fnNode.findPlug( 'matrix' )
        
        plugMatrixMaxLogicalIndex = 0
        for i in range( plugMatrix.numElements() ):
            logicalIndex = plugMatrix[i].logicalIndex()
            if logicalIndex > plugMatrixMaxLogicalIndex:
                plugMatrixMaxLogicalIndex = logicalIndex 
        
        connections = om.MPlugArray()
        skinedJointIndices = []
        origSkinedJointIndicesMap = [ -1 for i in range( plugMatrixMaxLogicalIndex+1 ) ]
        for i in range( plugMatrix.numElements() ):
            
            plugMatrix[i].connectedTo( connections, True, False )
            if not connections.length():
                continue
            
            skinJointName = om.MFnDagNode( connections[0].node() ).fullPathName()
            
            if not skinJointName in skinJoints:
                skinJoints.append( skinJointName )
            
            jntIndex = skinJoints.index( skinJointName )
            origSkinedJointIndicesMap[ plugMatrix[i].logicalIndex() ] = jntIndex
            skinedJointIndices.append( jntIndex )
    
        plugWeightList = fnNode.findPlug( 'weightList' )
        
        for i in range( plugWeightList.numElements() ):
            
            plugWeights = plugWeightList[i].child( 0 )
            for j in range( plugWeights.numElements() ):
                
                logicalIndex = plugWeights[j].logicalIndex()
                weightValue = plugWeights[j].asFloat()
                jntIndex = origSkinedJointIndicesMap[ logicalIndex ]
                
                weightList[i].append( [jntIndex, weightValue] )
    
    newMesh = cmds.createNode( 'mesh' )
    srcShape = sgBFunction_dag.getShape( skinedObjs[0] )
    newMeshObj = sgBFunction_dag.getParent( newMesh )
    cmds.connectAttr( srcShape+'.outMesh', newMesh+'.inMesh' )
    cmds.refresh()
    cmds.disconnectAttr( srcShape+'.outMesh', newMesh+'.inMesh' )
    node = cmds.deformer( newMeshObj, type='skinCluster' )[0]
    
    for i in range( len( skinJoints ) ):
        cmds.connectAttr( skinJoints[i]+'.wm', node+'.matrix[%d]' % i )
        bindPreMatrix = cmds.getAttr( skinJoints[i]+'.wim' )
        cmds.setAttr( node+'.bindPreMatrix[%d]' % i, bindPreMatrix, type='matrix' )
    
    for i in range( len( weightList ) ):
        for logicalIndex, value in weightList[i]:
            cmds.setAttr( node+'.weightList[%d].weights[%d]' %( i, logicalIndex ), value )
    
    cmds.skinPercent( node, normalize=True )
コード例 #30
0
 def createVolume_byCurvesLine(self, level=6 ):
     
     import sgBFunction_dag
     
     avSpans = 0
     eachMinParams = []
     eachMaxParams = []
     
     for i in range( len( self.centerCurves ) ):
         curve = self.centerCurves[i]
         curveShape = sgBFunction_dag.getShape( curve )
         fnCurve = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( curveShape ) )
         
         avSpans += fnCurve.numSpans()
         eachMinParam = fnCurve.findParamFromLength( 0 )
         eachMaxParam = fnCurve.findParamFromLength( fnCurve.length() )
         
         eachMinParams.append( eachMinParam )
         eachMaxParams.append( eachMaxParam )
     
     avSpans = int( avSpans / len( self.centerCurves ) )
     
     eachParamRates = []
     for i in range( len( self.centerCurves ) ):
         paramRate = float( eachMaxParams[i] - eachMinParams[i] )
         paramRate /= (avSpans-1)
         eachParamRates.append( paramRate )
     
     curvePointsList = [ [] for j in range( (level/2)*2 ) ]
     
     for i in range( avSpans ):
         epPoints = om.MPointArray()
         epPoints.setLength( len( self.centerCurves ) )
         
         avTangent = om.MVector( 0,0,0 )
         for j in range( len( self.centerCurves ) ):
             curveShape = sgBFunction_dag.getShape( self.centerCurves[j] )
             fnCurve = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( curveShape ) )
             point = om.MPoint()
             fnCurve.getPointAtParam( eachParamRates[j] * i + eachMinParams[j], point )
             epPoints.set( point, j )
             avTangent += fnCurve.tangent( eachParamRates[j] * i + eachMinParams[j] )
         
         dataCurve = om.MFnNurbsCurveData()
         oCurve = dataCurve.create()
         
         fnCurveCreate = om.MFnNurbsCurve()
         fnCurveCreate.createWithEditPoints( epPoints, 3, 1, False, False, False, oCurve )
         fnCurveCreate.setObject( oCurve )
         
         maxParam  = fnCurveCreate.findParamFromLength( fnCurveCreate.length() )
         eachParam = maxParam / ( level/2 + 2 )
         
         for j in range( level/2 ):
             param = eachParam * ( j+1 )
             
             point = om.MPoint()
             fnCurveCreate.getPointAtParam( param, point )
             vAim = fnCurveCreate.tangent( param )
             vUp  = avTangent
             vCross = vAim ^ vUp
             vInvCross = -vCross
             
             pointsIntersects = om.MPointArray()
             pointsIntersectsInv = om.MPointArray()
             self.fnMesh.intersect( point, vCross, pointsIntersects )
             self.fnMesh.intersect( point, vInvCross, pointsIntersectsInv )
             
             if pointsIntersects.length():
                 targetPoint    = ( pointsIntersects[0] - om.MVector( point ) ) * 0.7 + om.MVector( point )
                 curvePointsList[j].append( [ targetPoint.x, targetPoint.y, targetPoint.z ] )
             else:
                 curvePointsList[j].append( [ point.x, point.y, point.z ] )
             if pointsIntersectsInv.length():
                 targetPointInv = ( pointsIntersectsInv[0] - om.MVector( point ) ) * 0.7 + om.MVector( point )
                 curvePointsList[j+( level/2 )].append( [ targetPointInv.x, targetPointInv.y, targetPointInv.z ]  )
             else:
                 curvePointsList[j+( level/2 )].append( [ point.x, point.y, point.z ] )
     
     createCurves = []
     for curvePoints in curvePointsList:
         createCurves.append( cmds.curve( ep=curvePoints ) )
     
     return createCurves
コード例 #31
0
def assignReferenceShader( infoPath, objectNamespace, shaderNamespace=None ):
    
    import cPickle
    import maya.OpenMaya as om
    import copy
    import sgBModel_data
    
    
    f = open( infoPath, 'r' )
    refShaderInfos, userDefinedMeshAttrInfos = cPickle.load( f )
    f.close()
    
    if not shaderNamespace: shaderNamespace = copy.copy( objectNamespace )
    
    objectNamespace = objectNamespace.replace( ':', '_' )
    shaderNamespace = shaderNamespace.replace( ':', '_' )
    
    objNs = copy.copy( objectNamespace )
    shaderNs = copy.copy( shaderNamespace )
    
    if objNs: objNs +='_'
    if shaderNs: shaderNs +=':'
    
    existingPaths = []
    for data in refShaderInfos:
        refPath = data.referencePath.replace( '\\', '/' )
        for ref in cmds.ls( type='reference' ):
            existingPath = cmds.referenceQuery( ref, filename=1 )
            if not existingPath in existingPaths: existingPaths.append( existingPath )

        if not refPath in existingPaths:
            if not shaderNamespace : cmds.file( refPath, r=1, ignoreVersion=True, gl=1, mergeNamespacesOnClash = False, namespace=':', options="v=0;" )
            else: cmds.file( refPath, r=1, ignoreVersion=True, gl=1, mergeNamespacesOnClash = False, namespace=shaderNamespace, options="v=0;" )
            print "referenced path : ", refPath
        
        shaderName = data.shaderName
        disName = data.displaceName
        volumeName = data.volumeName
        targets = data.assignedTargets
        
        shaderName = shaderNs + shaderName
        if disName:
            disName = shaderNs + disName
        if volumeName:
            volumeName = shaderNs + volumeName
        
        for shape, indices in targets:
            if not cmds.objExists( objNs+shape ): continue
            dagPath = sgBFunction_dag.getMDagPath( objNs+shape )
            
            if indices:
                intArr = om.MIntArray()
                intArr.setLength( len( indices ) )
                for i in range( len( indices ) ):
                    intArr[i] = indices[i]
                singleIndexedComp = om.MFnSingleIndexedComponent()
                mObject = singleIndexedComp.create( om.MFn.kMeshPolygonComponent )
                singleIndexedComp.addElements( intArr )

                cmds.select( d=1 )
                om.MGlobal.select( dagPath, mObject )
                cmds.hyperShade( assign=shaderName )
                om.MGlobal.unselect( dagPath, mObject )
            else:
                cmds.select( objNs+shape )
                cmds.hyperShade( assign=shaderName )
                cmds.select( d=1 )
        
        shadingEngine = getShadingEngine( shaderName )
        if disName: cmds.connectAttr( disName + '.displacement', shadingEngine + '.displacementShader' )
    
    import sgBFunction_attribute
    
    for mesh, udAttrInfo in userDefinedMeshAttrInfos:
        targetMesh = objNs.replace( ':', '_' ) + mesh
        if not cmds.objExists( targetMesh ): continue
        sgBFunction_attribute.setUdAttrInfo( udAttrInfo, targetMesh )
コード例 #32
0
def combineSkinCluster(skinedObjs):

    import sgBFunction_dag

    numVertices = None
    for skinedObj in skinedObjs:
        objShape = sgBFunction_dag.getShape(skinedObj)
        fnMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(objShape))
        if not numVertices:
            numVertices = fnMesh.numVertices()
        else:
            if numVertices != fnMesh.numVertices():
                cmds.error("Selected meshs not same objects")

    skinJoints = []
    weightList = [[] for i in range(numVertices)]
    for skinedObj in skinedObjs:

        skinCluster = sgBFunction_dag.getNodeFromHistory(
            skinedObj, 'skinCluster')
        if not skinCluster: continue

        skinCluster = skinCluster[0]

        fnNode = om.MFnDependencyNode(sgBFunction_dag.getMObject(skinCluster))

        plugMatrix = fnNode.findPlug('matrix')

        plugMatrixMaxLogicalIndex = 0
        for i in range(plugMatrix.numElements()):
            logicalIndex = plugMatrix[i].logicalIndex()
            if logicalIndex > plugMatrixMaxLogicalIndex:
                plugMatrixMaxLogicalIndex = logicalIndex

        connections = om.MPlugArray()
        skinedJointIndices = []
        origSkinedJointIndicesMap = [
            -1 for i in range(plugMatrixMaxLogicalIndex + 1)
        ]
        for i in range(plugMatrix.numElements()):

            plugMatrix[i].connectedTo(connections, True, False)
            if not connections.length():
                continue

            skinJointName = om.MFnDagNode(connections[0].node()).fullPathName()

            if not skinJointName in skinJoints:
                skinJoints.append(skinJointName)

            jntIndex = skinJoints.index(skinJointName)
            origSkinedJointIndicesMap[plugMatrix[i].logicalIndex()] = jntIndex
            skinedJointIndices.append(jntIndex)

        plugWeightList = fnNode.findPlug('weightList')

        for i in range(plugWeightList.numElements()):

            plugWeights = plugWeightList[i].child(0)
            for j in range(plugWeights.numElements()):

                logicalIndex = plugWeights[j].logicalIndex()
                weightValue = plugWeights[j].asFloat()
                jntIndex = origSkinedJointIndicesMap[logicalIndex]

                weightList[i].append([jntIndex, weightValue])

    newMesh = cmds.createNode('mesh')
    srcShape = sgBFunction_dag.getShape(skinedObjs[0])
    newMeshObj = sgBFunction_dag.getParent(newMesh)
    cmds.connectAttr(srcShape + '.outMesh', newMesh + '.inMesh')
    cmds.refresh()
    cmds.disconnectAttr(srcShape + '.outMesh', newMesh + '.inMesh')
    node = cmds.deformer(newMeshObj, type='skinCluster')[0]

    for i in range(len(skinJoints)):
        cmds.connectAttr(skinJoints[i] + '.wm', node + '.matrix[%d]' % i)
        bindPreMatrix = cmds.getAttr(skinJoints[i] + '.wim')
        cmds.setAttr(node + '.bindPreMatrix[%d]' % i,
                     bindPreMatrix,
                     type='matrix')

    for i in range(len(weightList)):
        for logicalIndex, value in weightList[i]:
            cmds.setAttr(
                node + '.weightList[%d].weights[%d]' % (i, logicalIndex),
                value)

    cmds.skinPercent(node, normalize=True)
コード例 #33
0
    def create(*args):

        import sgBFunction_dag

        reload(sgBFunction_mesh)

        sels = cmds.ls(sl=1)

        baseMesh = cmds.textField(Window_Global.fld_baseMesh, q=1, tx=1)
        detail = cmds.intField(Window_Global.fld_detail, q=1, v=1)

        base = sgBFunction_dag.getShape(baseMesh)
        dagPathBase = sgBFunction_dag.getMDagPath(baseMesh)
        oBase = sgBFunction_dag.getMObject(base)

        baseMtx = dagPathBase.inclusiveMatrix()

        fnBase = om.MFnMesh()
        fnBase.setObject(dagPathBase)

        origPointsBase = om.MPointArray()
        multedPointsBase = om.MPointArray()
        fnBase.getPoints(origPointsBase)

        multedPointsBase.setLength(origPointsBase.length())
        for i in range(multedPointsBase.length()):
            multedPointsBase.set(origPointsBase[i] * baseMtx, i)
        fnBase.setPoints(multedPointsBase)

        intersector = om.MMeshIntersector()
        intersector.create(oBase)

        topJnts = []
        for sel in sels:
            target = sgBFunction_dag.getShape(sel)

            dagPathMesh = sgBFunction_dag.getMDagPath(target)
            fnMeshTarget = om.MFnMesh(dagPathMesh)
            origPointsTarget = om.MPointArray()
            multedPointsTarget = om.MPointArray()
            fnMeshTarget.getPoints(origPointsTarget)

            targetMtx = dagPathMesh.inclusiveMatrix()
            multedPointsTarget.setLength(origPointsTarget.length())
            for i in range(multedPointsTarget.length()):
                multedPointsTarget.set(origPointsTarget[i] * targetMtx, i)

            minDistIndex = 0
            minDist = 100000.0
            pointOnMesh = om.MPointOnMesh()
            for i in range(multedPointsTarget.length()):
                intersector.getClosestPoint(multedPointsTarget[i], pointOnMesh)
                pointClose = om.MPoint(pointOnMesh.getPoint())
                dist = multedPointsTarget[i].distanceTo(pointClose)
                if dist < minDist:
                    minDist = dist
                    minDistIndex = i

            maxDistIndex = 0
            maxDist = 0.0
            for i in range(multedPointsTarget.length()):
                dist = multedPointsTarget[minDistIndex].distanceTo(
                    multedPointsTarget[i])
                if maxDist < dist:
                    maxDist = dist
                    maxDistIndex = i

            startCenter = om.MPoint(
                *cmds.xform(target +
                            '.vtx[%d]' % minDistIndex, q=1, ws=1, t=1))
            endCenter = om.MPoint(
                *cmds.xform(target +
                            '.vtx[%d]' % maxDistIndex, q=1, ws=1, t=1))

            jnts = sgBFunction_mesh.createJointLineFromMeshApi(
                dagPathMesh, startCenter, endCenter, detail)
            topJnts.append(jnts[0])

        fnBase.setPoints(origPointsBase)

        cmds.select(topJnts)
コード例 #34
0
def setWeightInnerPointsToTargetJoint(baseMesh, baseJoint, targetMeshs):

    import sgBFunction_dag

    baseMeshShape = sgBFunction_dag.getShape(baseMesh)
    dagPathBaseMesh = sgBFunction_dag.getMDagPath(baseMeshShape)
    mtxBaseMesh = dagPathBaseMesh.inclusiveMatrix()
    headIntersector = om.MMeshIntersector()
    headIntersector.create(dagPathBaseMesh.node())

    targetMeshs = cmds.ls(sl=1)

    for targetMesh in targetMeshs:

        skinNodes = sgBFunction_dag.getNodeFromHistory(targetMesh,
                                                       'skinCluster')
        if not skinNodes: continue

        skinNode = skinNodes[0]
        fnSkinNode = om.MFnDependencyNode(sgBFunction_dag.getMObject(skinNode))

        joints = cmds.listConnections(skinNode + '.matrix', s=1, d=0)
        if not baseJoint in joints: continue
        indexInfluence = joints.index(baseJoint)

        plugWeightList = fnSkinNode.findPlug('weightList')

        targetMeshShape = sgBFunction_dag.getShape(targetMesh)
        dagPathTargetMesh = sgBFunction_dag.getMDagPath(targetMeshShape)
        fnTargetMesh = om.MFnMesh(dagPathTargetMesh)

        mtxTarget = dagPathTargetMesh.inclusiveMatrix()
        mtxToBase = mtxTarget * mtxBaseMesh.inverse()

        numVertices = fnTargetMesh.numVertices()
        pointsTarget = om.MPointArray()
        fnTargetMesh.getPoints(pointsTarget)

        pointOnMesh = om.MPointOnMesh()

        targetVertices = []

        for i in range(numVertices):
            pointLocal = pointsTarget[i] * mtxToBase
            headIntersector.getClosestPoint(pointLocal, pointOnMesh)

            point = pointOnMesh.getPoint()
            normal = om.MVector(pointOnMesh.getNormal())

            vDir = om.MVector(pointLocal) - om.MVector(point)

            if vDir * normal > 0: continue

            plugWeights = plugWeightList[i].child(0)
            for j in range(plugWeights.numElements()):
                cmds.setAttr(plugWeights.name() + "[%d]" % j, 0)

            cmds.setAttr(plugWeights.name() + "[%d]" % indexInfluence, 1)
            targetVertices.append(targetMesh + '.vtx[%d]' % i)

        cmds.select(targetVertices)
コード例 #35
0
 def create( *args ):
     
     import sgBFunction_dag
     
     reload( sgBFunction_mesh )
     
     sels = cmds.ls( sl=1 )
     
     baseMesh = cmds.textField( Window_Global.fld_baseMesh, q=1, tx=1 )
     detail   = cmds.intField( Window_Global.fld_detail, q=1, v=1 )
     
     base    = sgBFunction_dag.getShape( baseMesh ) 
     dagPathBase = sgBFunction_dag.getMDagPath( baseMesh )
     oBase = sgBFunction_dag.getMObject( base )
     
     baseMtx = dagPathBase.inclusiveMatrix()
     
     fnBase = om.MFnMesh()
     fnBase.setObject( dagPathBase )
     
     origPointsBase = om.MPointArray()
     multedPointsBase = om.MPointArray()
     fnBase.getPoints( origPointsBase )
     
     multedPointsBase.setLength( origPointsBase.length() )
     for i in range( multedPointsBase.length() ):
         multedPointsBase.set( origPointsBase[i]*baseMtx, i )
     fnBase.setPoints( multedPointsBase )
     
     intersector = om.MMeshIntersector()
     intersector.create( oBase )
     
     topJnts = []
     for sel in sels:
         target  = sgBFunction_dag.getShape( sel )
         
         dagPathMesh = sgBFunction_dag.getMDagPath( target )
         fnMeshTarget = om.MFnMesh( dagPathMesh )
         origPointsTarget = om.MPointArray()
         multedPointsTarget = om.MPointArray()
         fnMeshTarget.getPoints( origPointsTarget )
         
         targetMtx = dagPathMesh.inclusiveMatrix()
         multedPointsTarget.setLength( origPointsTarget.length() )
         for i in range( multedPointsTarget.length() ):
             multedPointsTarget.set( origPointsTarget[i] * targetMtx , i )
         
         minDistIndex = 0
         minDist = 100000.0
         pointOnMesh = om.MPointOnMesh()
         for i in range( multedPointsTarget.length() ):
             intersector.getClosestPoint( multedPointsTarget[i], pointOnMesh )
             pointClose = om.MPoint( pointOnMesh.getPoint() )
             dist = multedPointsTarget[i].distanceTo( pointClose )
             if dist < minDist:
                 minDist = dist
                 minDistIndex = i
                 
         maxDistIndex = 0
         maxDist = 0.0
         for i in range( multedPointsTarget.length() ):
             dist = multedPointsTarget[minDistIndex].distanceTo( multedPointsTarget[i] )
             if maxDist < dist:
                 maxDist = dist
                 maxDistIndex = i
         
         startCenter = om.MPoint( *cmds.xform( target+'.vtx[%d]' % minDistIndex, q=1, ws=1, t=1 ) )
         endCenter = om.MPoint( *cmds.xform( target+'.vtx[%d]' % maxDistIndex, q=1, ws=1, t=1 ) )
             
         jnts = sgBFunction_mesh.createJointLineFromMeshApi( dagPathMesh, startCenter, endCenter, detail )
         topJnts.append( jnts[0] )
     
     fnBase.setPoints( origPointsBase )
     
     cmds.select( topJnts )
コード例 #36
0
def createRivetBasedOnSkinWeights( selectedObjs ):
    
    import sgBFunction_convert
    import sgBFunction_mesh
    import sgBFunction_dag
    import sgBFunction_skinCluster
    import maya.OpenMaya as om
    
    def getJointMultMatrix( jnt, mtxBindPre ):
        cons = cmds.listConnections( jnt+'.wm', type='multMatrix' )

        if cons:
            for con in cons:
                if cmds.attributeQuery( 'skinWeightInfluenceMatrix', node=con, ex=1 ):
                    if mtxBindPre == cmds.getAttr( con+'.i[0]' ):
                        return con
        
        mmtxNode = cmds.createNode( 'multMatrix' )
        cmds.setAttr( mmtxNode+'.i[0]', mtxBindPre, type='matrix' )
        cmds.connectAttr( jnt+'.wm', mmtxNode+'.i[1]' )
        
        cmds.addAttr( mmtxNode, ln='skinWeightInfluenceMatrix', at='message' )
        
        return mmtxNode


    mesh, vtxIndices = sgBFunction_mesh.getMeshAndIndicesPoints( selectedObjs )
    
    skinClusterNode = sgBFunction_dag.getNodeFromHistory( mesh, 'skinCluster' )
    if not skinClusterNode: return None
    skinClusterNode = skinClusterNode[0]
    
    influenceAndWeightList, phygicalMap = sgBFunction_skinCluster.getInfluenceAndWeightList( mesh, vtxIndices )
    
    meshMatrix = sgBFunction_dag.getMDagPath( mesh ).inclusiveMatrix()
    meshPoints = sgBFunction_mesh.getLocalPoints( mesh )
    plugMatrix = sgBFunction_skinCluster.getPlugMatrix( mesh )
    plugBindPre = sgBFunction_skinCluster.getPlugBindPre( mesh )
    
    BB = om.MBoundingBox()
    
    wtAddMtx = cmds.createNode( 'wtAddMatrix' )
    mtxPlugIndidcesAndWeights = {}
    allWeights = 0.0
    for i in vtxIndices:
        influenceList, weights = influenceAndWeightList[ phygicalMap[i] ]
        
        for j in range( len( influenceList ) ):
            mtxPlugIndex = influenceList[j]
            if mtxPlugIndex in mtxPlugIndidcesAndWeights.keys():
                mtxPlugIndidcesAndWeights[mtxPlugIndex] += weights[j]
            else:
                mtxPlugIndidcesAndWeights.update( {mtxPlugIndex:weights[j]} )
            allWeights += weights[j]
        BB.expand( meshPoints[i] )
    worldPoint = BB.center()*meshMatrix
    
    items = mtxPlugIndidcesAndWeights.items()
    for i in range( len( items ) ):
        influence, weight = items[i]
        
        plugMatrixElement = plugMatrix.elementByLogicalIndex( influence )
        plugBindPreElement = plugBindPre.elementByLogicalIndex( influence )
        
        jnt = cmds.listConnections( plugMatrixElement.name(), s=1, d=0, type='joint' )[0]
        mtxBindPre = cmds.getAttr( plugBindPreElement.name() )
        mmtxNode = getJointMultMatrix( jnt, mtxBindPre )
        cmds.connectAttr( mmtxNode+'.o', wtAddMtx+'.i[%d].m' % i )
        cmds.setAttr( wtAddMtx+'.i[%d].w' % i, weight/allWeights )
    
    origObj = cmds.createNode( 'transform', n='OrigObject' )
    destObj = cmds.createNode( 'transform', n='destObject' )
    cmds.setAttr( destObj+'.dh' , 1 )
    cmds.setAttr( destObj+'.dla', 1 )
    mmNode = cmds.createNode( 'multMatrix' )
    dcmp = cmds.createNode( 'decomposeMatrix' )
    mtxWtAdd = cmds.getAttr( wtAddMtx+'.o' )
    
    cmds.connectAttr( origObj+'.wm', mmNode+'.i[0]' )
    cmds.connectAttr( wtAddMtx+'.o', mmNode+'.i[1]' )
    cmds.connectAttr( destObj+'.pim', mmNode+'.i[2]' )
    
    cmds.connectAttr( mmNode+'.o', dcmp+'.imat' )
    
    cmds.connectAttr( dcmp+'.ot', destObj+'.t' )
    cmds.connectAttr( dcmp+'.or', destObj+'.r' )
    
    mmtxWtAdd = sgBFunction_convert.convertMatrixToMMatrix( mtxWtAdd )
    worldPoint *= mmtxWtAdd.inverse()
    cmds.setAttr( origObj+'.t', worldPoint.x, worldPoint.y, worldPoint.z )
コード例 #37
0
ファイル: sgBFunction_rivet.py プロジェクト: jonntd/mayadev-1
def createRivetFromVertex_mirror(rivetObj):

    import sgBFunction_dag
    import sgBFunction_base
    import sgBFunction_convert

    sgBFunction_base.autoLoadPlugin('sgRigAddition')

    def getNodeFromMesh(mesh, isFirst=True):

        if cmds.objectType(mesh) == 'transform':
            mesh = sgBFunction_dag.getShape(mesh)

        cons = cmds.listConnections(mesh + '.wm', type='sgMatrixFromVertices')
        if cons: return cons[0]

        node = cmds.createNode('sgMatrixFromVertices')
        cmds.connectAttr(mesh + '.outMesh', node + '.inputMesh')
        cmds.connectAttr(mesh + '.wm', node + '.inputMeshMatrix')

        return node

    cons = cmds.listConnections(rivetObj,
                                s=1,
                                d=0,
                                type='sgMatrixFromVertices',
                                p=1,
                                c=1)
    if not cons: return None

    node, attr = cons[1].split('.')
    vtxNum = int(attr.split('[')[1].replace(']', ''))

    mesh = cmds.listConnections(node, s=1, d=0, type='mesh', shapes=1)
    if not mesh: return None

    mesh = mesh[0]

    fnMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(mesh))
    intersector = om.MMeshIntersector()
    intersector.create(fnMesh.object())

    pointArr = om.MPointArray()
    fnMesh.getPoints(pointArr)
    pointMirror = om.MPoint(-pointArr[vtxNum].x, pointArr[vtxNum].y,
                            pointArr[vtxNum].z)

    pointOnMesh = om.MPointOnMesh()
    intersector.getClosestPoint(pointMirror, pointOnMesh)

    faceIndex = pointOnMesh.faceIndex()
    vertices = om.MIntArray()
    fnMesh.getPolygonVertices(faceIndex, vertices)

    closeIndex = 0
    closeDist = 1000000.0
    for i in range(vertices.length()):
        dist = pointArr[vertices[i]].distanceTo(pointMirror)
        if closeDist > dist:
            closeDist = dist
            closeIndex = vertices[i]

    cmds.setAttr(node + '.verticeId[%d]' % closeIndex, closeIndex)

    rivetObjName = rivetObj.split('|')[-1]
    rivetObjName = rivetObjName.replace(str(vtxNum), str(closeIndex))
    newObject = cmds.createNode(
        'transform', n=sgBFunction_convert.convertSide(rivetObjName))
    cmds.setAttr(newObject + '.dh', 1)
    cmds.setAttr(newObject + '.inheritsTransform', 0)

    cmds.connectAttr(node + '.outputTranslate[%d]' % closeIndex,
                     newObject + '.t')
コード例 #38
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getCenterCurve(curves=None):

    import sgBFunction_dag

    posList = []
    bbox = om.MBoundingBox()

    if not curves: curves = cmds.ls(sl=1)

    numSpans = 0
    for curve in curves:
        curveShape = sgBFunction_dag.getShape(curve)
        fnCurve = om.MFnNurbsCurve(sgBFunction_dag.getMDagPath(curveShape))
        numSpans += fnCurve.numSpans()
    numSpans /= len(curves)

    posList = [[] for i in range(numSpans)]

    for curve in curves:
        curveShape = sgBFunction_dag.getShape(curve)
        curvePath = sgBFunction_dag.getMDagPath(curveShape)
        curveWorldMatrix = curvePath.inclusiveMatrix()
        fnCurve = om.MFnNurbsCurve(curvePath)
        minParam = fnCurve.findParamFromLength(0)
        maxParam = fnCurve.findParamFromLength(fnCurve.length())
        eachParam = (float(maxParam) - float(minParam)) / numSpans
        bbox = om.MBoundingBox()
        for i in range(numSpans):
            eachPoint = om.MPoint()
            fnCurve.getPointAtParam(eachParam * i + minParam, eachPoint)
            posList[i].append(eachPoint * curveWorldMatrix)

    bbCenterList = []
    for i in range(numSpans):
        bbox = om.MBoundingBox()
        for j in range(len(curves)):
            bbox.expand(posList[i][j])
        bbCenterList.append(bbox.center())

    minIndexList = []

    for i in range(numSpans):
        minDist = 1000000.0
        minIndex = 0
        for j in range(len(curves)):
            dist = posList[i][j].distanceTo(bbCenterList[i])
            if dist < minDist:
                minDist = dist
                minIndex = j
        minIndexList.append(minIndex)

    minIndexRateList = [0 for i in range(len(curves))]

    for i in range(numSpans):
        minIndexRateList[minIndexList[i]] += 1

    targetCurveIndex = 0
    maxIndexRate = 0
    for i in range(len(minIndexRateList)):
        if minIndexRateList[i] > maxIndexRate:
            maxIndexRate = minIndexRateList[i]
            targetCurveIndex = i

    cmds.select(curves[targetCurveIndex])
    return curves[minIndex]
コード例 #39
0
ファイル: sgBFunction_curve.py プロジェクト: jonntd/mayadev-1
def getCenterCurve( curves=None ):
    
    import sgBFunction_dag
    
    posList = []
    bbox    = om.MBoundingBox()
    
    if not curves: curves = cmds.ls( sl=1 )
    
    numSpans = 0
    for curve in curves:
        curveShape = sgBFunction_dag.getShape( curve )
        fnCurve    = om.MFnNurbsCurve( sgBFunction_dag.getMDagPath( curveShape ) )
        numSpans  += fnCurve.numSpans()
    numSpans /= len( curves )
    
    posList = [ [] for i in range( numSpans ) ]
    
    for curve in curves:
        curveShape = sgBFunction_dag.getShape( curve )
        curvePath = sgBFunction_dag.getMDagPath( curveShape )
        curveWorldMatrix = curvePath.inclusiveMatrix()
        fnCurve    = om.MFnNurbsCurve( curvePath )
        minParam = fnCurve.findParamFromLength( 0 )
        maxParam = fnCurve.findParamFromLength( fnCurve.length() )
        eachParam = ( float( maxParam ) - float( minParam ) ) / numSpans
        bbox = om.MBoundingBox()
        for i in range( numSpans ):
            eachPoint = om.MPoint()
            fnCurve.getPointAtParam( eachParam * i + minParam, eachPoint )
            posList[i].append( eachPoint * curveWorldMatrix )
    
    bbCenterList = []
    for i in range( numSpans ):
        bbox = om.MBoundingBox()
        for j in range( len( curves ) ):
            bbox.expand( posList[i][j] )
        bbCenterList.append( bbox.center() )
    
    minIndexList = []
    
    for i in range( numSpans ):
        minDist = 1000000.0
        minIndex = 0
        for j in range( len( curves ) ):
            dist = posList[i][j].distanceTo( bbCenterList[i] )
            if dist < minDist:
                minDist = dist
                minIndex = j
        minIndexList.append( minIndex )
    
    minIndexRateList = [ 0 for i in range( len( curves ) ) ]
    
    for i in range( numSpans ):
        minIndexRateList[ minIndexList[i] ] += 1

    targetCurveIndex = 0
    maxIndexRate = 0
    for i in range( len( minIndexRateList ) ):
        if minIndexRateList[i] > maxIndexRate:
            maxIndexRate = minIndexRateList[i]
            targetCurveIndex = i
    
    cmds.select( curves[targetCurveIndex] )
    return curves[minIndex]
コード例 #40
0
ファイル: sgBFunction_rivet.py プロジェクト: jonntd/mayadev-1
def createCurveFromSelVertices_mirror(targetCurve):

    import sgBFunction_dag

    def getMeshAndIndices(targetCurve):
        curveShape = sgBFunction_dag.getShape(targetCurve)

        inputNode = curveShape
        crvToPointNode = None
        mtxFromVtxNode = None
        num = 0
        while True:
            num += 1
            if num >= 100: break
            cons = cmds.listConnections(inputNode, s=1, d=0, p=1, c=1)
            if not cons: return None
            outputCon = cons[1]
            node = outputCon.split('.')[0]
            targetNodeType = cmds.nodeType(node)
            if targetNodeType == 'sgCurveFromPoints':
                crvToPointNode = node
                inputNode = node
                continue
            if targetNodeType == 'sgMatrixFromVertices':
                mtxFromVtxNode = node
                break
            inputNode = node

        mesh = cmds.listConnections(mtxFromVtxNode + '.inputMesh', s=1, d=0)[0]

        print "crvToPointNode : ", crvToPointNode
        fnNode = om.MFnDependencyNode(
            sgBFunction_dag.getMObject(crvToPointNode))
        plugInputs = fnNode.findPlug('input')

        indices = []
        for i in range(plugInputs.numElements()):
            connections = om.MPlugArray()
            plugInputPoint = plugInputs[i].child(1)
            plugInputPoint.connectedTo(connections, True, False)
            indices.append(connections[0].logicalIndex())

        return mesh, indices

    def createCurve(mesh, indices):

        vtsToCrv = cmds.createNode('sgMatrixFromVertices')
        pointToCrv = cmds.createNode('sgCurveFromPoints')
        crv = cmds.createNode('nurbsCurve')

        cmds.connectAttr(pointToCrv + '.outputCurve', crv + '.create')

        cmds.connectAttr(mesh + '.outMesh', vtsToCrv + '.inputMesh')
        cmds.connectAttr(mesh + '.wm', vtsToCrv + '.inputMeshMatrix')

        for i in range(len(indices)):
            cmds.setAttr(vtsToCrv + '.verticeId[%d]' % indices[i], indices[i])
            cmds.connectAttr(vtsToCrv + '.outputTranslate[%d]' % indices[i],
                             pointToCrv + '.input[%d].inputPoint' % i)

        return crv, pointToCrv

    mesh, indices = getMeshAndIndices(targetCurve)
    mesh = sgBFunction_dag.getShape(mesh)

    dagPathMesh = sgBFunction_dag.getMDagPath(mesh)

    intersector = om.MMeshIntersector()
    intersector.create(dagPathMesh.node())

    meshMtx = dagPathMesh.inclusiveMatrix()
    meshMtxInv = dagPathMesh.inclusiveMatrixInverse()
    fnMesh = om.MFnMesh(dagPathMesh)

    pArr = om.MPointArray()
    fnMesh.getPoints(pArr)

    targetIndices = []
    pointOnMesh = om.MPointOnMesh()
    for index in indices:
        worldPoint = pArr[index] * meshMtx
        mirrorPoint = om.MPoint(-worldPoint.x, worldPoint.y,
                                worldPoint.z) * meshMtxInv
        intersector.getClosestPoint(mirrorPoint, pointOnMesh)
        fIndex = pointOnMesh.faceIndex()

        vtxIndices = om.MIntArray()
        fnMesh.getPolygonVertices(fIndex, vtxIndices)

        closeDist = 1000000.0
        closeIndex = vtxIndices[0]
        for vtxIndex in vtxIndices:
            point = pArr[vtxIndex]
            dist = point.distanceTo(mirrorPoint)
            if dist < closeDist:
                closeDist = dist
                closeIndex = vtxIndex

        targetIndices.append(closeIndex)

    node = sgBFunction_dag.getNodeFromHistory(targetCurve,
                                              'sgCurveFromPoints')[0]
    createType = cmds.getAttr(node + '.createType')
    degrees = cmds.getAttr(node + '.degrees')

    createdCrv, createdNode = createCurve(mesh, targetIndices)
    cmds.setAttr(createdNode + '.createType', createType)
    cmds.setAttr(createdNode + '.degrees', degrees)