• Advertisement
Sign in to follow this  

importing mesh file into maya

This topic is 1967 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 smile.png Here is my current script I can send a sample file if needed to see what I am doing wrong.
# 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",f.read(4))[0]
header = struct.unpack("4i",f.read(16))
f.seek(0x60, 0)
vertInfo = []
for i in range(0 ,header[3]):
meshInfo = struct.unpack("4i",f.read(0x10))
meshMatrix = struct.unpack("12f",f.read(0x30))
meshInfo2 = struct.unpack("4i",f.read(0x10))
boneInfo = struct.unpack("4i",f.read(0x10))
texInfo = struct.unpack("4i",f.read(0x10))
matInfo = struct.unpack("4i",f.read(0x10))
vertOff = struct.unpack(str(header[3]) + "i",f.read(header[3] * 4))
faceOff = struct.unpack(str(header[3]) + "i",f.read(header[3] * 4))
weightOff = struct.unpack(str(header[3]) + "i",f.read(header[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()
f.seek(vertOff, 0)
for a in range(0 ,vertInfo[0][1]):
verts = struct.unpack("8f",f.read(32))
pt = om.MFloatPoint(verts[0],verts[1], verts[2])
vArray.append((verts[7] * -1) + 1)
f.seek(faceOff, 0)
pConnects = om.MIntArray()
pCounts = om.MIntArray()
for a in range(0 ,vertInfo[0][0]):
faceCount = struct.unpack("H",f.read(2))[0]
matID = struct.unpack("H",f.read(2))[0]
fstart = f.tell()
StartDirection = -1
f1 = struct.unpack("H",f.read(2))[0]
f2 = struct.unpack("H",f.read(2))[0]
FaceDirection = StartDirection
while f.tell() < (fstart + (2 *faceCount )):
f3 = struct.unpack("H",f.read(2))[0]
if f3 == 0xFFFF:
f1 = struct.unpack("H",f.read(2))[0]
f2 = struct.unpack("H",f.read(2))[0]
FaceDirection = StartDirection
FaceDirection *= -1
if (f1 != f2 and f1 != f3 and f3 != f2) :
if FaceDirection > 0:
f1 = f2
f2 = f3
f.seek(weightOff, 0)
uvCounts = pCounts
mesh = om.MFnMesh()
ShapeMesh = cmds.group(em=True) # <-- we create an empty group/ trnasform node that will receive the mesh node as a sibling
parentOwner = get_mobject( ShapeMesh )
meshMObj = mesh.create(vertInfo[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)
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  

  • Advertisement