def create_object(verts_pos, face_verts):
"""
Function creates an object with mesh given by vertice and face data.
:type face_verts: Python list
:type verts_pos: Python list
"""
shark_mesh = om.MObject()
points = om.MFloatPointArray() # An array that is storing positions od vertices. Do not include id of vertices
for vert in verts_pos: # add every point to Maya float points array
p = om.MFloatPoint(vert[0], vert[2], -vert[1])
points.append(p)
face_connects = om.MIntArray() # an array for vertice numbers per face.
face_counts = om.MIntArray() # an array for total number of vertices per face
for verts in face_verts:
# In Maya mesh is created on a base of two arrays: list of vertice numbers and list of numbers of vertices
# of faces. Vertice numbers from the first list are not grouped by faces, this is just a one dimmension array.
# Based on this list only it would be impossible to recreate mesh, becouse number of vertices in faces may vary
# (in this example every face have 3 vertices, but this is not obligatory).
# The second array stores the number of vertices of faces. From this list Mata gets a number of vertices of a
# face, let's call it N, then assigns next N vertices to this face. The process is repeated for every face.
face_connects.append(verts[0]) # Append vertices of face.
face_connects.append(verts[1])
face_connects.append(verts[2])
face_counts.append(len(verts)) # append the number of vertices for this face
mesh_fs = om.MFnMesh()
mesh_fs.create(points, face_counts, face_connects, parent=shark_mesh)
mesh_fs.updateSurface()
node_name = mesh_fs.name()
cmds.polySoftEdge(node_name, a=30, ch=1) # Automatically soften the edges of the mesh
# assign new mesh to default shading group
cmds.sets(node_name, e=True, fe='initialShadingGroup')
return cmds.listRelatives(node_name, fullPath=True, parent=True) # node name stores a name of Shape node.
# Most functions need a Transform node. Ths line returns it.
评论列表
文章目录