-
Notifications
You must be signed in to change notification settings - Fork 1
/
modlBuild.py
88 lines (76 loc) · 2.5 KB
/
modlBuild.py
1
2
import maya.cmds as cmdsimport syssys.path = ['/Users/eric/grim-proj'] + sys.pathfrom lecFormats import modlmodl = reload(modl)import itertoolsmannySuit = modl.ModlFile('/Users/eric/grim-proj/grim-data/mannysuit.3do')#buildTransforms(mannySuit)def buildTransforms(modl): nodes = [] parentMap = {} for i,node in enumerate(modl.nodes): # Create the node newNode = cmds.createNode('transform', name=node.name) loc = cmds.createNode('locator') locXform = cmds.listRelatives(loc, parent=True)[0] for attr in ['scaleX','scaleY','scaleZ']: cmds.setAttr(locXform+'.'+attr, 1.0/42) cmds.parent(locXform, newNode) # Account for the node nodes.append(newNode) # Apply the transforms cmds.xform(newNode, t=node.position) # @TODO: add rot values # Save the node for parenting later if node.has_parent: parentMap[newNode] = node.parent_id # Parent all the nodes for node,i in parentMap.items(): parentNode = nodes[i] cmds.parent(node, parentNode) # Return a mapping of source node names to maya transforms return zip([node.name for node in modl.nodes], [nodes])#cmds.select(cmds.createNode('locator'))headMesh = mannySuit.geosets[0].meshes[6]cmds.delete(['polySurface1'])buildMesh(headMesh)headMesh.geometry_mode#dir(headMesh.faces[0])def reorderVerts(mesh, modlMesh): ''' Re-orders the verts on sceneMesh to match the reference modlMesh ''' # This uses the meshReorder plugin from the maya sdk examples cmds.loadPlugin('meshReorder') vertexMap = {} for i in range(cmds.polyEvaluate(mesh, vertex=True)): vertexT = cmds.xform(mesh+'.vtx[%d]', t=True) matchFound = False for orig_i, pos in enumerate(modlMesh.vertices): for axis in range(3): if round(pos[0], 3) == round(vertexT[0], 3): matchFound = matchFound and True else: break if matchFound: break if not matchFound: raise ValueError("could not find match for vert %d"%i) vertexMap[orig_i] = i def buildMesh(mesh): ''' builds the ModlMesh mesh in scene ''' meshes = [] for face in mesh.faces: verts = [mesh.vertices[i] for i in face.vertex_indices] newMesh = cmds.polyCreateFacet(p=verts, ch=False)[0] #Apply vertex normals #for i,orig_i in enumerate(face.vertex_indices): #vertNormal = mesh.vertex_normals[orig_i] #cmds.select( newMesh+'.vtxFace[0][%d]'%i, r=True )
#cmds.polyNormalPerVertex(xyz=vertNormal) meshes.append(newMesh) finalMesh = cmds.polyUnite(*meshes, ch=False, name=mesh.name) return finalMesh