def getBasisVectors( obj ): ''' returns 3 world space orthonormal basis vectors that represent the orientation of the given object ''' xPrime, yPrime, zPrime = api.getBases( obj ) return Vector([xPrime.x, xPrime.y, xPrime.z]), Vector([yPrime.x, yPrime.y, yPrime.z]), Vector([zPrime.x, zPrime.y, zPrime.z])
def getWristToWorldRotation( wrist, performRotate=False ): ''' ''' basis = map(api.MVectorToVector, api.getBases( wrist )) rots = [0, 0, 0] for n, axis in enumerate( AXES[:3] ): axis = Vector.Axis( axis ) if axis.dot( basis[n] ) < 0: rots[n] = 180 if performRotate: rots.append( wrist ) cmd.rotate(rots[0], rots[1], rots[2], wrist, a=True, ws=True) return tuple( rots )
def findVertsInVolume( meshes, volume ): ''' returns a dict containing meshes and the list of vert attributes contained within the given <volume> ''' #define a super simple vector class to additionally record vert id with position... class VertPos(vectors.Vector): def __init__( self, x, y, z, vertIdx=None ): vectors.Vector.__init__(self, [x, y, z]) self.id = vertIdx #this dict provides the functions used to determine whether a point is inside a volume or not insideDeterminationMethod = {ExportManager.kVOLUME_SPHERE: isPointInSphere, ExportManager.kVOLUME_CUBE: isPointInCube} #if there are any uniform overrides for the contained method (called if the volume's scale is #unity) it can be registered here insideDeterminationIfUniform = {ExportManager.kVOLUME_SPHERE: isPointInUniformSphere, ExportManager.kVOLUME_CUBE: isPointInCube} #grab any data we're interested in for the volume volumePos = vectors.Vector( cmd.xform(volume, q=True, ws=True, rp=True) ) volumeScale = map(abs, cmd.getAttr('%s.s' % volume)[0]) volumeBasis = map(mayaVectors.MayaVector, api.getBases(volume)) #make sure the basis is normalized volumeBasis = [v.normalize() for v in volumeBasis] #now lets determine the volume type type = ExportManager.kVOLUME_SPHERE try: type = int( cmd.getAttr('%s.exportVolume' % volume) ) except TypeError: pass isContainedMethod = insideDeterminationMethod[type] print 'method for interior volume determination', isContainedMethod.__name__ sx = volumeScale[0] if vectors.Vector(volumeScale).within((sx, sx, sx)): try: isContainedMethod = insideDeterminationIfUniform[type] except KeyError: pass #now lets iterate over the geometry meshVertsWithin = {} for mesh in meshes: #its possible to pass not a mesh but a component in - this is totally valid, as the polyListComponentConversion #should make sure we're always dealing with verts no matter what, but we still need to make sure the dict key is #the actual name of the mesh - hence this bit of jiggery pokery dotIdx = mesh.rfind('.') meshName = mesh if dotIdx == -1 else mesh[:dotIdx] meshPositions = [] meshVertsWithin[meshName] = meshPositions #this gives us a huge list of floats - each sequential triple is the position of a vert try: #if this complains its most likely coz the geo is bad - so skip it... vertPosList = cmd.xform(cmd.ls(cmd.polyListComponentConversion(mesh, toVertex=True), fl=True), q=True, t=True, ws=True) except TypeError: continue count = len(vertPosList)/3 for idx in xrange(count): pos = VertPos(vertPosList.pop(0), vertPosList.pop(0), vertPosList.pop(0), idx) contained = isContainedMethod(pos, volumePos, volumeScale, volumeBasis) if contained: pos.weight = contained[1] meshPositions.append( pos ) return meshVertsWithin