Sign in to follow this  

importing mesh file into maya

This topic is 1961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone I am trying to import a mesh format into maya and I can get the geometry to import fine but I can not figure out how uv's work correctly to save my life. any help is great [img][/img] Here is my current script I can send a sample file if needed to see what I am doing wrong. [CODE]
# Maya Python script
import maya.cmds as cmds
import maya.OpenMaya as om
import struct
def get_mobject(node):
selectionList = om.MSelectionList()
oNode = om.MObject()
selectionList.getDependNode(0, oNode)
return oNode
fname = cmds.fileDialog2(fm=1, ff='Music Girl:Hatsune Miku .mdl (*.mdl);;All Files (*.*)')[0]
f = open(fname, "rb")
magic = struct.unpack("4s",[0]
header = struct.unpack("4i",, 0)
vertInfo = []
for i in range(0 ,header[3]):
meshInfo = struct.unpack("4i",
meshMatrix = struct.unpack("12f",
meshInfo2 = struct.unpack("4i",
boneInfo = struct.unpack("4i",
texInfo = struct.unpack("4i",
matInfo = struct.unpack("4i",
vertOff = struct.unpack(str(header[3]) + "i",[3] * 4))
faceOff = struct.unpack(str(header[3]) + "i",[3] * 4))
weightOff = struct.unpack(str(header[3]) + "i",[3] * 4))
for i in range(0 ,header[3]):
vertexArray = om.MFloatPointArray()
normalArray = om.MFloatPointArray()
uArray = om.MFloatArray()
vArray = om.MFloatArray()
uvCounts = om.MIntArray()
uvIds = om.MIntArray()[i], 0)
for a in range(0 ,vertInfo[i][0][1]):
verts = struct.unpack("8f",
pt = om.MFloatPoint(verts[0],verts[1], verts[2])
vArray.append((verts[7] * -1) + 1)[i], 0)
pConnects = om.MIntArray()
pCounts = om.MIntArray()
for a in range(0 ,vertInfo[i][0][0]):
faceCount = struct.unpack("H",[0]
matID = struct.unpack("H",[0]
fstart = f.tell()
StartDirection = -1
f1 = struct.unpack("H",[0]
f2 = struct.unpack("H",[0]
FaceDirection = StartDirection
while f.tell() < (fstart + (2 *faceCount )):
f3 = struct.unpack("H",[0]
if f3 == 0xFFFF:
f1 = struct.unpack("H",[0]
f2 = struct.unpack("H",[0]
FaceDirection = StartDirection
FaceDirection *= -1
if (f1 != f2 and f1 != f3 and f3 != f2) :
if FaceDirection > 0:
f1 = f2
f2 = f3[i], 0)
uvCounts = pCounts
mesh = om.MFnMesh()
ShapeMesh = # <-- we create an empty group/ trnasform node that will receive the mesh node as a sibling
parentOwner = get_mobject( ShapeMesh )
meshMObj = mesh.create(vertInfo[i][0][1], len(pCounts), vertexArray, pCounts, pConnects, uArray, vArray ,parentOwner ) #<-- don't forget to add a parent owner
cmds.sets( 'null' + str(i + 1), e=True,forceElement='initialShadingGroup') # <--assign the defaut lambert shader
defaultUVSetName = '"hello"'
mesh.setUVs( uArray, vArray, defaultUVSetName )
#for a in range(0 ,mesh.numPolygons()):
# for point in range(0 ,3):
# mesh.assignUV(a, point, pConnects[a*3+point] )
mesh.assignUVs(pCounts,pConnects, defaultUVSetName)
[/CODE] Edited by chrrox

Share this post

Link to post
Share on other sites
sorry the problem was an error in my reading of triangle strips the script works fine now.

Share this post

Link to post
Share on other sites
Sign in to follow this