def build(self): self.name = mc.createNode("joint", name=self._joint.name) mc.setAttr((self.name + ".rotateOrder"), kRotateOrder2Enum[self.rotateOrderString(False)]) # For now we don't change the Maya 'joint' node's degrees of freedom, # so store the info in a dynamic attribute so it can be written to # disk later mc.addAttr(self.name, longName='msvDOF', attributeType='bool', multi=True) MayaUtil.setMultiAttr("%s.msvDOF" % self.name, self._joint.dof) # Data from the .cdl file that we don't currently represent in Maya # (but that we want to hang on to so it can be written back out to # disk). mc.addAttr(self.name, longName='msvLeftovers', dataType='string') mc.setAttr("%s.msvLeftovers" % self.name, self._joint.leftovers, type='string') if self._joint.translate: mc.move(self._joint.translate[0], self._joint.translate[1], self._joint.translate[2], self.name, objectSpace=True, relative=True) if self._joint.transform: mc.xform(self.name, matrix=self._joint.transform, objectSpace=True, relative=True) if self._joint.parent: [self.name ] = mc.parent(self.name, self.agent.mayaJoint(self._joint.parent).name, relative=True) [self.name] = mc.ls(self.name, long=True) # Need to zero out the transform so that actions are applied correctly. # Unfortunately this also causes us to lose the existing transform info # when we export back to massive we may need this transform info... # TODO: how to keep/recover the transformation information? Another way # to support actions besides zeroing out the transformation information? mc.makeIdentity(self.name, apply=True, translate=True, rotate=True) self.setChannelOffsets() if not self.agent.rootJoint: self.agent.registerRootJoint(self)
def build(self): self.colorMap = self._agent.replaceEmbeddedVariables(self.colorMap) self.specular = self._resolveColor(self.material.specular, self.material.specularVar, self.material.specularSpace) self.ambient = self._resolveColor(self.material.ambient, self.material.ambientVar, self.material.ambientSpace) # The V component Massive diffuse HSV color is represented as the # single 'diffuse' attribute in Maya. # diffuse = self._resolveColor(self.material.diffuse, self.material.diffuseVar, self.material.diffuseSpace) diffuse = MayaUtil.rgbToHsv(diffuse) self.diffuse = diffuse[2] if self.material.roughnessVar: # For now only the color map is allowed to vary. If a variable is # present elsewhere its default value will be used # self.roughness = self._agent.variableValue( self.material.roughnessVar, forceDefault=True) else: self.roughness = self.material.roughness #print "map: %s" % `self.colorMap` #print "specular: %s" % `self.specular` #print "ambient: %s" % `self.ambient` #print "diffuse: %s" % `self.diffuse` self.sgName = self._factory.buildMaterial(self)
def setClusterWeights(self, geometry, cluster): # TODO: optimize the setAttrs so that the wl.w[x] attrs remain sparse mc.setAttr("%s.nw" % cluster, 0) clusterKey = geometry.file() if clusterKey in self.clusterCache: cachedCluster = self.clusterCache[clusterKey] mc.connectAttr("%s.wl" % cachedCluster, "%s.wl" % cluster) mc.disconnectAttr("%s.wl" % cachedCluster, "%s.wl" % cluster) else: weights = geometry.weights() numVerts = len(weights) for vtx in range(numVerts): attr = "%s.wl[%d].w" % (cluster, vtx) MayaUtil.setMultiAttr(attr, weights[vtx]) cachedCluster = mc.createNode("skinCluster") mc.connectAttr("%s.wl" % cluster, "%s.wl" % cachedCluster) mc.disconnectAttr("%s.wl" % cluster, "%s.wl" % cachedCluster) self.clusterCache[clusterKey] = cachedCluster mc.setAttr("%s.nw" % cluster, 1)
def setClusterWeights( self, geometry, cluster ): # TODO: optimize the setAttrs so that the wl.w[x] attrs remain sparse mc.setAttr("%s.nw" % cluster, 0) clusterKey = geometry.file() if clusterKey in self.clusterCache: cachedCluster = self.clusterCache[clusterKey] mc.connectAttr( "%s.wl" % cachedCluster, "%s.wl" % cluster ) mc.disconnectAttr( "%s.wl" % cachedCluster, "%s.wl" % cluster ) else: weights = geometry.weights() numVerts = len(weights) for vtx in range(numVerts): attr = "%s.wl[%d].w" % (cluster, vtx) MayaUtil.setMultiAttr( attr, weights[vtx] ) cachedCluster = mc.createNode("skinCluster") mc.connectAttr( "%s.wl" % cluster, "%s.wl" % cachedCluster ) mc.disconnectAttr( "%s.wl" % cluster, "%s.wl" % cachedCluster ) self.clusterCache[clusterKey] = cachedCluster mc.setAttr("%s.nw" % cluster, 1)
def _createSkinCluster(self, geometry): [shape] = mc.listRelatives(geometry.name(), type='shape', fullPath=True, allDescendents=True) deformers = [ self.mayaJoint(deformer).name for deformer in geometry.deformers() ] [cluster] = mc.deformer(geometry.name(), type="skinCluster") # Assign the inclusive matrix of deformed geometry to the cluster. # worldMatrix[0] assumes the geometry is not instanced. # wm = mc.getAttr("%s.worldMatrix[0]" % geometry.name()) MayaUtil.setMatrixAttr("%s.geomMatrix" % cluster, wm) for i in range(len(deformers)): if not mc.ls("%s.lockInfluenceWeights" % deformers[i]): mc.addAttr(deformers[i], longName="lockInfluenceWeights", shortName="liw", min=0, max=1, at="bool", defaultValue=0) mc.connectAttr("%s.lockInfluenceWeights" % deformers[i], "%s.lockWeights[%d]" % (cluster, i)) mc.connectAttr("%s.worldMatrix[0]" % deformers[i], "%s.matrix[%d]" % (cluster, i)) # Assign the invlusive matrix inverse of the deformer # (i.e. joint) to the cluster. # worldInverseMatrix[0] assumes the joint is not instanced # wim = mc.getAttr("%s.worldInverseMatrix[0]" % deformers[i]) MayaUtil.setMatrixAttr("%s.bindPreMatrix[%d]" % (cluster, i), wim) self._factory.setClusterWeights(geometry, cluster)
def _resolveColor(self, color, colorVar, colorSpace): mayaColor = [0.0, 0.0, 0.0] for i in range(3): if colorVar[i]: # For now only the color map is allowed to vary. If a variable is # present elsewhere its default value will be used # mayaColor[i] = self._agent.variableValue(colorVar[i], forceDefault=True) else: mayaColor[i] = color[i] if colorSpace != "rgb": mayaColor = MayaUtil.hsvToRgb(mayaColor) return mayaColor
def __init__(self, group, name, skinType, parent=""): self.groupName = group self._shapeName = "" self._skinType = skinType self.chunks = {} if "|" == parent: # Parent to world [self.groupName] = mc.parent(self.groupName, world=True) elif "" != parent: # Parent to 'parent' [self.groupName] = mc.parent(self.groupName, parent, relative=True) # Try and set the name - if there's a name clash the actual # name may differ from 'name'. Store the actual name. self.groupName = mc.rename(self.groupName, name) [self.groupName] = mc.ls(self.groupName, long=True) # Find an store the shape name shapes = MayaUtil.getDescendentShapes(self.groupName) if shapes: self._shapeName = shapes[0][len(self.groupName) + 1:]
def __init__(self, group, name, skinType, parent=""): self.groupName = group self._shapeName = "" self._skinType = skinType self.chunks = {} if "|" == parent: # Parent to world [self.groupName] = mc.parent( self.groupName, world=True ) elif "" != parent: # Parent to 'parent' [self.groupName] = mc.parent( self.groupName, parent, relative=True ) # Try and set the name - if there's a name clash the actual # name may differ from 'name'. Store the actual name. self.groupName = mc.rename( self.groupName, name ) [self.groupName] = mc.ls(self.groupName, long=True) # Find an store the shape name shapes = MayaUtil.getDescendentShapes( self.groupName ) if shapes: self._shapeName = shapes[0][len(self.groupName) + 1:]
def createChunks(self, weights, deformers): '''Divide up the geometry into "chunks" where a chunk is the group of vertices most strongly influenced by a given deformer.''' if not weights: return [shape] = mc.listRelatives(self.groupName, type='shape', fullPath=True, allDescendents=True) faceGroups = [None] * len(deformers) numVerts = len(weights) dpMesh = MayaUtil.dagPathFromName(shape) fMesh = MFnMesh(dpMesh) numFaces = fMesh.numPolygons() itFace = MItMeshPolygon(dpMesh) # For each vertex figure out which deformer influences # it the most. Associate the vertex's neighboring faces with # that deformer. # while not itFace.isDone(): face = itFace.index() vertices = MIntArray() itFace.getVertices(vertices) maxWeight = 0 primeDeformer = 0 for i in range(len(deformers)): weight = 0 for j in range(vertices.length()): vtx = vertices[j] weight += weights[vtx][i] if weight > maxWeight: maxWeight = weight primeDeformer = i # Associate all unassigned neighboring faces with # that deformer # if not faceGroups[primeDeformer]: faceGroups[primeDeformer] = [] faceGroups[primeDeformer].append(face) itFace.next() # We now have a series of face groups each one associated # with a deformer. Chop up the original shape into these # face groups by duplicating the original object and removing # groupPrefix = len(self.groupName) for i in range(len(faceGroups)): if not faceGroups[i]: continue [newShape] = mc.duplicate(shape) [newShape] = mc.ls(newShape, long=True) if len(faceGroups[i]) < numFaces: faceGroup = [ "%s.f[%d]" % (newShape, face) for face in faceGroups[i] ] mc.select("%s.f[*]" % newShape, replace=True) mc.select(faceGroup, deselect=True) mc.delete() self._addChunk(deformers[i], newShape) mc.delete(mc.listRelatives(shape, parent=True, fullPath=True))
def buildMaterial(self, mayaMaterial): key = "" if mayaMaterial.colorMap: key = mayaMaterial.colorMap else: # Currently the only variation that is supported is in the # color map. If no color map is specified than it's safe # to assume that the id of the material will uniquely map # to a Maya shading group. (since the color map can vary # a material with a color map may actually map to several # Maya shading groups) # key = str(mayaMaterial.id()) sg = "" try: sg = self.materialCache[key] except: # shadingNode doesn't work right in batch mode, so do it manually # shader = mc.createNode(mayaMaterial.materialType, name=mayaMaterial.name()) # Data that doesn't make it into the Maya scene but that we have # to hold onto so that we can write it back out to disk mc.addAttr(shader, longName='msvId', attributeType='long') mc.setAttr("%s.msvId" % shader, mayaMaterial.id()) mc.addAttr(shader, longName='msvSpecularVar', dataType='string') mc.setAttr("%s.msvSpecularVar" % shader, mayaMaterial.material.specularVar, type='string') mc.addAttr(shader, longName='msvAmbientVar', dataType='string') mc.setAttr("%s.msvAmbientVar" % shader, mayaMaterial.material.ambientVar, type='string') mc.addAttr(shader, longName='msvDiffuseVar', dataType='string') mc.setAttr("%s.msvDiffuseVar" % shader, mayaMaterial.material.diffuseVar, type='string') mc.addAttr(shader, longName='msvSpecularSpace', dataType='string') mc.setAttr("%s.msvSpecularSpace" % shader, mayaMaterial.material.specularSpace, type='string') mc.addAttr(shader, longName='msvAmbientSpace', dataType='string') mc.setAttr("%s.msvAmbientSpace" % shader, mayaMaterial.material.ambientSpace, type='string') mc.addAttr(shader, longName='msvDiffuseSpace', dataType='string') mc.setAttr("%s.msvDiffuseSpace" % shader, mayaMaterial.material.diffuseSpace, type='string') mc.addAttr(shader, longName='msvRoughnessVar', dataType='string') mc.setAttr("%s.msvRoughnessVar" % shader, mayaMaterial.material.roughnessVar, type='string') mc.addAttr(shader, longName='msvLeftovers', dataType='string') mc.setAttr("%s.msvLeftovers" % shader, mayaMaterial.material.leftovers, type='string') if "blinn" != mayaMaterial.materialType: MayaUtil.addColorAttr(shader, 'msvSpecular') MayaUtil.setDouble3Attr("%s.msvSpecular" % shader, mayaMaterial.specular) mc.addAttr(shader, longName='msvRoughness', attributeType='float') mc.setAttr("%s.msvRoughness" % shader, mayaMaterial.roughness) mc.connectAttr("%s.msg" % shader, ":defaultShaderList1.s", nextAvailable=True) sg = mc.sets(renderable=True, empty=True, name="%sSG" % shader) mc.connectAttr("%s.outColor" % shader, "%s.surfaceShader" % sg, force=True) MayaUtil.setDouble3Attr("%s.ambientColor" % shader, mayaMaterial.ambient) mc.setAttr("%s.diffuse" % shader, mayaMaterial.diffuse) if "blinn" == mayaMaterial.materialType: MayaUtil.setDouble3Attr("%s.specularColor" % shader, mayaMaterial.specular) mc.setAttr("%s.specularRollOff" % shader, mayaMaterial.roughness) if mayaMaterial.colorMap: file = mc.createNode("file", name="%sFile" % shader) mc.connectAttr("%s.msg" % file, ":defaultTextureList1.tx", nextAvailable=True) place = mc.createNode("place2dTexture", name="%sPlace" % shader) mc.connectAttr("%s.msg" % place, ":defaultRenderUtilityList1.u", nextAvailable=True) mc.connectAttr("%s.coverage" % place, "%s.coverage" % file, force=True) mc.connectAttr("%s.translateFrame" % place, "%s.translateFrame" % file, force=True) mc.connectAttr("%s.rotateFrame" % place, "%s.rotateFrame" % file, force=True) mc.connectAttr("%s.mirrorU" % place, "%s.mirrorU" % file, force=True) mc.connectAttr("%s.mirrorV" % place, "%s.mirrorV" % file, force=True) mc.connectAttr("%s.stagger" % place, "%s.stagger" % file, force=True) mc.connectAttr("%s.wrapU" % place, "%s.wrapU" % file, force=True) mc.connectAttr("%s.wrapV" % place, "%s.wrapV" % file, force=True) mc.connectAttr("%s.repeatUV" % place, "%s.repeatUV" % file, force=True) mc.connectAttr("%s.offset" % place, "%s.offset" % file, force=True) mc.connectAttr("%s.rotateUV" % place, "%s.rotateUV" % file, force=True) mc.connectAttr("%s.noiseUV" % place, "%s.noiseUV" % file, force=True) mc.connectAttr("%s.vertexUvOne" % place, "%s.vertexUvOne" % file, force=True) mc.connectAttr("%s.vertexUvTwo" % place, "%s.vertexUvTwo" % file, force=True) mc.connectAttr("%s.vertexUvThree" % place, "%s.vertexUvThree" % file, force=True) mc.connectAttr("%s.vertexCameraOne" % place, "%s.vertexCameraOne" % file, force=True) mc.connectAttr("%s.outUV" % place, "%s.uv" % file, force=True) mc.connectAttr("%s.outUvFilterSize" % place, "%s.uvFilterSize" % file, force=True) mc.connectAttr("%s.outColor" % file, "%s.color" % shader, force=True) mc.setAttr("%s.fileTextureName" % file, "%s" % mayaMaterial.colorMap, type="string") self.materialCache[key] = sg return sg
def _loadSim(self, animType, frameStep): """Load the simulation data for this MayaAgent. It will either be loaded as anim curves or through the msvSimLoader node.""" if eAnimType.curves == animType: # ================================================================== # Create Anim Curves # ================================================================== simData = self.simData() for jointSim in simData.joints(): mayaJoint = self.mayaJoint(jointSim.name()) for channelName in jointSim.channelNames(): channelEnum = AgentSpec.channel2Enum[channelName] if mayaJoint.isChannelFree(channelEnum): times = range(jointSim.startFrame(), jointSim.startFrame() + jointSim.numFrames(), frameStep) mc.setKeyframe( mayaJoint.name, attribute=channelName, inTangentType="linear", outTangentType="linear", time=times, value=0.0, ) channelAttr = "%s.%s" % (mayaJoint.name, channelName) [animCurve] = mc.listConnections(channelAttr, source=True) offset = mayaJoint.channelOffsets[channelEnum] channels = [offset + jointSim.sample(channelName, i) for i in times] MayaUtil.setMultiAttr("%s.ktv" % animCurve, channels, "kv") else: # ================================================================== # Create msvSimLoader Nodes # ================================================================== simDir = self._sim.simDir simType = self._sim.simType.strip(".") agentType = self.agentSpec().agentType instance = self.id() simLoader = mc.createNode("msvSimLoader", name="msvSimLoader%d" % instance) mc.setAttr("%s.simDir" % simLoader, simDir, type="string") mc.setAttr("%s.simType" % simLoader, simType, type="string") mc.setAttr("%s.agentType" % simLoader, agentType, type="string") mc.setAttr("%s.instance" % simLoader, instance) mc.connectAttr("time1.outTime", "%s.time" % simLoader) i = 0 for mayaJoint in self.mayaJoints.values(): joint = mayaJoint.joint() mc.setAttr("%s.joints[%d]" % (simLoader, i), joint.name, type="string") j = 0 numTranslateChannels = 0 # Use the joint's degrees-of-freedom and channel order to # determine which channels are present and which # transformations they correspond to for channel in joint.order: if not joint.dof[channel]: continue src = "" offset = "" if AgentSpec.isRotateEnum(channel): src = "%s.output[%d].rotate[%d]" % (simLoader, i, (j - numTranslateChannels)) offset = "%s.offsets[%d].rotateOffset[%d]" % (simLoader, i, (j - numTranslateChannels)) else: src = "%s.output[%d].translate[%d]" % (simLoader, i, j) offset = "%s.offsets[%d].translateOffset[%d]" % (simLoader, i, j) numTranslateChannels += 1 dst = "%s.%s" % (mayaJoint.name, AgentSpec.enum2Channel[channel]) mc.setAttr(offset, mayaJoint.channelOffsets[channel]) mc.connectAttr(src, dst) j += 1 i += 1
def createChunks(self, weights, deformers): '''Divide up the geometry into "chunks" where a chunk is the group of vertices most strongly influenced by a given deformer.''' if not weights: return [ shape ] = mc.listRelatives(self.groupName, type='shape', fullPath=True, allDescendents=True) faceGroups = [None] * len(deformers) numVerts = len(weights) dpMesh = MayaUtil.dagPathFromName(shape) fMesh = MFnMesh(dpMesh) numFaces = fMesh.numPolygons() itFace = MItMeshPolygon(dpMesh) # For each vertex figure out which deformer influences # it the most. Associate the vertex's neighboring faces with # that deformer. # while not itFace.isDone(): face = itFace.index() vertices = MIntArray() itFace.getVertices(vertices) maxWeight = 0 primeDeformer = 0 for i in range(len(deformers)): weight = 0 for j in range(vertices.length()): vtx = vertices[j] weight += weights[vtx][i] if weight > maxWeight: maxWeight = weight primeDeformer = i # Associate all unassigned neighboring faces with # that deformer # if not faceGroups[primeDeformer]: faceGroups[primeDeformer] = [] faceGroups[primeDeformer].append( face ) itFace.next() # We now have a series of face groups each one associated # with a deformer. Chop up the original shape into these # face groups by duplicating the original object and removing # groupPrefix = len(self.groupName) for i in range(len(faceGroups)): if not faceGroups[i]: continue [ newShape ] = mc.duplicate(shape) [ newShape ] = mc.ls(newShape, long=True) if len(faceGroups[i]) < numFaces: faceGroup = [ "%s.f[%d]" % (newShape, face) for face in faceGroups[i] ] mc.select( "%s.f[*]" % newShape, replace=True) mc.select( faceGroup, deselect=True ) mc.delete() self._addChunk(deformers[i], newShape) mc.delete(mc.listRelatives( shape, parent=True, fullPath=True ))
def _loadSim(self, animType, frameStep): '''Load the simulation data for this MayaAgent. It will either be loaded as anim curves or through the msvSimLoader node.''' if eAnimType.curves == animType: #================================================================== # Create Anim Curves #================================================================== simData = self.simData() for jointSim in simData.joints(): mayaJoint = self.mayaJoint(jointSim.name()) for channelName in jointSim.channelNames(): channelEnum = AgentSpec.channel2Enum[channelName] if mayaJoint.isChannelFree(channelEnum): times = range( jointSim.startFrame(), jointSim.startFrame() + jointSim.numFrames(), frameStep) mc.setKeyframe(mayaJoint.name, attribute=channelName, inTangentType="linear", outTangentType="linear", time=times, value=0.0) channelAttr = "%s.%s" % (mayaJoint.name, channelName) [animCurve] = mc.listConnections(channelAttr, source=True) offset = mayaJoint.channelOffsets[channelEnum] channels = [ offset + jointSim.sample(channelName, i) for i in times ] MayaUtil.setMultiAttr("%s.ktv" % animCurve, channels, "kv") else: #================================================================== # Create msvSimLoader Nodes #================================================================== simDir = self._sim.simDir simType = self._sim.simType.strip('.') agentType = self.agentSpec().agentType instance = self.id() simLoader = mc.createNode("msvSimLoader", name="msvSimLoader%d" % instance) mc.setAttr("%s.simDir" % simLoader, simDir, type="string") mc.setAttr("%s.simType" % simLoader, simType, type="string") mc.setAttr("%s.agentType" % simLoader, agentType, type="string") mc.setAttr("%s.instance" % simLoader, instance) mc.connectAttr("time1.outTime", "%s.time" % simLoader) i = 0 for mayaJoint in self.mayaJoints.values(): joint = mayaJoint.joint() mc.setAttr("%s.joints[%d]" % (simLoader, i), joint.name, type="string") j = 0 numTranslateChannels = 0 # Use the joint's degrees-of-freedom and channel order to # determine which channels are present and which # transformations they correspond to for channel in joint.order: if not joint.dof[channel]: continue src = "" offset = "" if AgentSpec.isRotateEnum(channel): src = "%s.output[%d].rotate[%d]" % (simLoader, i, ( j - numTranslateChannels)) offset = "%s.offsets[%d].rotateOffset[%d]" % ( simLoader, i, (j - numTranslateChannels)) else: src = "%s.output[%d].translate[%d]" % (simLoader, i, j) offset = "%s.offsets[%d].translateOffset[%d]" % ( simLoader, i, j) numTranslateChannels += 1 dst = "%s.%s" % (mayaJoint.name, AgentSpec.enum2Channel[channel]) mc.setAttr(offset, mayaJoint.channelOffsets[channel]) mc.connectAttr(src, dst) j += 1 i += 1
def build(self, options): self._buildSkeleton() if options.loadGeometry: self._buildGeometry(options.skinType, options.loadMaterials, options.materialType) # Make sure the agent scale doesn't also scale the translate values of # the sim data. We have to freeze the transform here since we won't # be allowed to after binding the skin # self._freezeAgentScale() if options.loadPrimitives: self._buildPrimitives(options.instancePrimitives) if options.loadGeometry: self._setBindPose() self._bindSkin(options.skinType) # Has to happen after skin is bound self._scaleJoints() self._zeroPose = mc.dagPose(self.rootJoint.name, save=True, name=(self.name() + "Zero")) agentGroup = self.agentGroup() mc.addAttr(agentGroup, longName='msvCdlFile', dataType='string') mc.setAttr("%s.msvCdlFile" % agentGroup, self._agent.agentSpec.cdlFile, type='string') mc.addAttr(agentGroup, longName='msvBindPoseFile', dataType='string') mc.setAttr("%s.msvBindPoseFile" % agentGroup, self._agent.agentSpec.bindPoseFile, type='string') mc.addAttr(agentGroup, longName='msvAgentType', dataType='string') mc.setAttr("%s.msvAgentType" % agentGroup, self._agent.agentSpec.agentType, type='string') mc.addAttr(agentGroup, longName='msvScaleVar', dataType='string') mc.setAttr("%s.msvScaleVar" % agentGroup, self._agent.agentSpec.scaleVar, type='string') for (key, value) in self._agent.agentSpec.leftovers.items(): attrName = 'msv%sLeftovers' % key mc.addAttr(agentGroup, longName=attrName, dataType='string') mc.setAttr("%s.%s" % (agentGroup, attrName), value, type='string') cdlStructure = " ".join(self._agent.agentSpec.cdlStructure) mc.addAttr(agentGroup, longName="msvCdlStructure", dataType='string') mc.setAttr("%s.msvCdlStructure" % agentGroup, cdlStructure, type='string') # Add the variable descriptions to a multi-compound attribute mc.addAttr(agentGroup, longName='msvVariables', attributeType='compound', numberOfChildren=5, multi=True) mc.addAttr(agentGroup, longName='msvVarName', dataType='string', parent='msvVariables') mc.addAttr(agentGroup, longName='msvVarDefault', attributeType='float', parent='msvVariables') mc.addAttr(agentGroup, longName='msvVarMin', attributeType='float', parent='msvVariables') mc.addAttr(agentGroup, longName='msvVarMax', attributeType='float', parent='msvVariables') mc.addAttr(agentGroup, longName='msvVarExpression', dataType='string', parent='msvVariables') values = [ '"%s"' % v.name for v in self._agent.agentSpec.variables.values() ] MayaUtil.setMultiAttr("%s.msvVariables" % agentGroup, values, "msvVarName", "string") values = [v.default for v in self._agent.agentSpec.variables.values()] MayaUtil.setMultiAttr("%s.msvVariables" % agentGroup, values, "msvVarDefault") values = [v.min for v in self._agent.agentSpec.variables.values()] MayaUtil.setMultiAttr("%s.msvVariables" % agentGroup, values, "msvVarMin") values = [v.max for v in self._agent.agentSpec.variables.values()] MayaUtil.setMultiAttr("%s.msvVariables" % agentGroup, values, "msvVarMax") values = [ '"%s"' % v.expression for v in self._agent.agentSpec.variables.values() ] MayaUtil.setMultiAttr("%s.msvVariables" % agentGroup, values, "msvVarExpression", "string")
def buildMaterial(self, mayaMaterial): key = "" if mayaMaterial.colorMap: key = mayaMaterial.colorMap else: # Currently the only variation that is supported is in the # color map. If no color map is specified than it's safe # to assume that the id of the material will uniquely map # to a Maya shading group. (since the color map can vary # a material with a color map may actually map to several # Maya shading groups) # key = str(mayaMaterial.id()) sg = "" try: sg = self.materialCache[key] except: # shadingNode doesn't work right in batch mode, so do it manually # shader = mc.createNode(mayaMaterial.materialType, name=mayaMaterial.name()) # Data that doesn't make it into the Maya scene but that we have # to hold onto so that we can write it back out to disk mc.addAttr( shader, longName='msvId', attributeType='long' ) mc.setAttr( "%s.msvId" % shader, mayaMaterial.id() ) mc.addAttr( shader, longName='msvSpecularVar', dataType='string' ) mc.setAttr( "%s.msvSpecularVar" % shader, mayaMaterial.material.specularVar, type='string' ) mc.addAttr( shader, longName='msvAmbientVar', dataType='string' ) mc.setAttr( "%s.msvAmbientVar" % shader, mayaMaterial.material.ambientVar, type='string' ) mc.addAttr( shader, longName='msvDiffuseVar', dataType='string' ) mc.setAttr( "%s.msvDiffuseVar" % shader, mayaMaterial.material.diffuseVar, type='string' ) mc.addAttr( shader, longName='msvSpecularSpace', dataType='string' ) mc.setAttr( "%s.msvSpecularSpace" % shader, mayaMaterial.material.specularSpace, type='string' ) mc.addAttr( shader, longName='msvAmbientSpace', dataType='string' ) mc.setAttr( "%s.msvAmbientSpace" % shader, mayaMaterial.material.ambientSpace, type='string' ) mc.addAttr( shader, longName='msvDiffuseSpace', dataType='string' ) mc.setAttr( "%s.msvDiffuseSpace" % shader, mayaMaterial.material.diffuseSpace, type='string' ) mc.addAttr( shader, longName='msvRoughnessVar', dataType='string' ) mc.setAttr( "%s.msvRoughnessVar" % shader, mayaMaterial.material.roughnessVar, type='string' ) mc.addAttr( shader, longName='msvLeftovers', dataType='string' ) mc.setAttr( "%s.msvLeftovers" % shader, mayaMaterial.material.leftovers, type='string' ) if "blinn" != mayaMaterial.materialType: MayaUtil.addColorAttr(shader, 'msvSpecular') MayaUtil.setDouble3Attr("%s.msvSpecular" % shader, mayaMaterial.specular) mc.addAttr( shader, longName='msvRoughness', attributeType='float' ) mc.setAttr( "%s.msvRoughness" % shader, mayaMaterial.roughness ) mc.connectAttr( "%s.msg" % shader, ":defaultShaderList1.s", nextAvailable=True) sg = mc.sets(renderable=True, empty=True, name="%sSG" % shader) mc.connectAttr( "%s.outColor" % shader, "%s.surfaceShader" % sg, force=True ) MayaUtil.setDouble3Attr( "%s.ambientColor" % shader, mayaMaterial.ambient ) mc.setAttr( "%s.diffuse" % shader, mayaMaterial.diffuse ) if "blinn" == mayaMaterial.materialType: MayaUtil.setDouble3Attr( "%s.specularColor" % shader, mayaMaterial.specular ) mc.setAttr( "%s.specularRollOff" % shader, mayaMaterial.roughness ) if mayaMaterial.colorMap: file = mc.createNode("file", name="%sFile" % shader) mc.connectAttr( "%s.msg" % file, ":defaultTextureList1.tx", nextAvailable=True) place = mc.createNode("place2dTexture", name="%sPlace" % shader) mc.connectAttr( "%s.msg" % place, ":defaultRenderUtilityList1.u", nextAvailable=True) mc.connectAttr( "%s.coverage" % place, "%s.coverage" % file, force=True ) mc.connectAttr( "%s.translateFrame" % place, "%s.translateFrame" % file, force=True ) mc.connectAttr( "%s.rotateFrame" % place, "%s.rotateFrame" % file, force=True ) mc.connectAttr( "%s.mirrorU" % place, "%s.mirrorU" % file, force=True ) mc.connectAttr( "%s.mirrorV" % place, "%s.mirrorV" % file, force=True ) mc.connectAttr( "%s.stagger" % place, "%s.stagger" % file, force=True ) mc.connectAttr( "%s.wrapU" % place, "%s.wrapU" % file, force=True ) mc.connectAttr( "%s.wrapV" % place, "%s.wrapV" % file, force=True ) mc.connectAttr( "%s.repeatUV" % place, "%s.repeatUV" % file, force=True ) mc.connectAttr( "%s.offset" % place, "%s.offset" % file, force=True ) mc.connectAttr( "%s.rotateUV" % place, "%s.rotateUV" % file, force=True ) mc.connectAttr( "%s.noiseUV" % place, "%s.noiseUV" % file, force=True ) mc.connectAttr( "%s.vertexUvOne" % place, "%s.vertexUvOne" % file, force=True ) mc.connectAttr( "%s.vertexUvTwo" % place, "%s.vertexUvTwo" % file, force=True ) mc.connectAttr( "%s.vertexUvThree" % place, "%s.vertexUvThree" % file, force=True ) mc.connectAttr( "%s.vertexCameraOne" % place, "%s.vertexCameraOne" % file, force=True ) mc.connectAttr( "%s.outUV" % place, "%s.uv" % file, force=True ) mc.connectAttr( "%s.outUvFilterSize" % place, "%s.uvFilterSize" % file, force=True ) mc.connectAttr( "%s.outColor" % file, "%s.color" % shader, force=True ) mc.setAttr( "%s.fileTextureName" % file, "%s" % mayaMaterial.colorMap, type="string" ) self.materialCache[key] = sg return sg