--tlist = script("3d_import").ReadMAXData (member("gallery").text) --script("3d_import").buildMaxScene (tlist, member("gallery02")) --script("3d_import").buildMaxScene (tlist, member("gallery02"),#smooth) --import Max ASCII on ReadMaxData (me, rMaxString) --the floatPrecision = 9 --string chuncks to parse rString = "" --command string nWord = "" --word in line --list to be return createNodeList = [:] --init attribute vars tCommand = "" errCount = 0 tList = createNodeList tParentList = [] the itemdelimiter = "_" maxLoops = 65536 --Parse repeat with n = 1 to maxLoops tLine = rMaxString.line[1]--n delete rMaxString.line[1]--* --get Command (class or property) word from line fChar = offset("*", tLine) if fChar > 0 then delete tLine.char[1..fChar] tCommand = tLine.word[1] --process line case tCommand of "3DSMAX_ASCIIEXPORT", "COMMENT": nothing \ "SCENE",\ "MATERIAL_LIST", "MATERIAL", "MAP_DIFFUSE",\ "GEOMOBJECT",\ "NODE_TM",\ "MESH", "MESH_VERTEX_LIST", "MESH_FACE_LIST", "MESH_CVERTLIST", "MESH_CFACELIST",\ "MESH_TVERTLIST", "MESH_TFACELIST", "MESH_NORMALS",\ "LIGHTOBJECT", "LIGHT_SETTINGS": --Class Definitions if tLine.word[tLine.word.count] = "{" then --move down a level tParentList.add(tList) tempList = [:] if tCommand <> "MATERIAL" then tList.addprop( symbol(tCommand), tempList ) else tList.addprop( integer(tLine.word[2]), tempList ) end if tList = tempList else put "Expected {. Line" && n & return & tLine & return end if \ "}": --end class tCount = tParentList.count if tCount > 0 then tList = tParentList.getAt(tCount) tParentList.deleteAt(tCount) else put "Expected Parent List. Line:" && n & return & tLine & return end if \ "SCENE_FILENAME", "BITMAP",\ "MATERIAL_NAME", "MAP_NAME", "NODE_NAME",\ "MATERIAL_CLASS", "MAP_CLASS": --strings "quoted" tList.setaprop( symbol(tCommand), value(tLine.word[2..tLine.word.count]) ) \ "BITMAP_FILTER", "MATERIAL_SHADING", "MATERIAL_FALLOFF", "MATERIAL_XP_TYPE",\ "MAP_TYPE",\ "LIGHT_TYPE", "LIGHT_SHADOWS", "LIGHT_SPOTSHAPE", "LIGHT_SHADOWS": --string values: tList.setaprop( symbol(tCommand), tLine.word[2] ) \ "SCENE_FIRSTFRAME", "SCENE_LASTFRAME", "SCENE_FRAMESPEED", "SCENE_TICKSPERFRAME",\ "MATERIAL_COUNT",\ "TIMEVALUE",\ "MESH_NUMVERTEX", "MESH_NUMFACES", "MESH_NUMCVERTEX", "MESH_NUMCVFACES",\ "MESH_NUMTVFACES", "MESH_NUMTVFACES", "MESH_NUMTVERTEX",\ "MATERIAL_REF",\ "MAP_SUBNO", "UVW_NOISE_LEVEL",\ "LIGHT_USELIGHT", "LIGHT_USEGLOBAL", "LIGHT_ABSMAPBIAS", "LIGHT_OVERSHOOT", "LIGHT_MAPSIZE", \ "PROP_MOTIONBLUR", "PROP_CASTSHADOW", "PROP_RECVSHADOW": --integers tList.setaprop( symbol(tCommand), integer(tLine.word[2]) ) \ "MATERIAL_SHINE", "MATERIAL_SHINESTRENGTH", "MATERIAL_TRANSPARENCY", "MATERIAL_SELFILLUM",\ "MATERIAL_WIRESIZE", "MATERIAL_XP_FALLOFF",\ "TM_ROTANGLE", "TM_SCALEAXISANG",\ "MAP_AMOUNT", "UVW_U_OFFSET", "UVW_V_OFFSET", "UVW_U_TILING", "UVW_V_TILING",\ "UVW_ANGLE", "UVW_BLUR", "UVW_BLUR_OFFSET", "UVW_NOUSE_AMT", "UVW_NOISE_SIZE", "UVW_NOISE_PHASE",\ "LIGHT_INTENS", "LIGHT_ASPECT", "LIGHT_TDIST", "LIGHT_MAPBIAS", "LIGHT_MAPRANGE", "LIGHT_RAYBIAS": --floats tList.setaprop( symbol(tCommand), float(tLine.word[2]) ) \ "SCENE_BACKGROUND_STATIC", "SCENE_AMBIENT_STATIC",\ "MATERIAL_AMBIENT", "MATERIAL_DIFFUSE", "MATERIAL_SPECULAR", \ "LIGHT_COLOR",\ "WIREFRAME_COLOR": --rgb values tList.setaprop( symbol(tCommand), rgb(float(tLine.word[2])*255, float(tLine.word[3])*255, float(tLine.word[4])*255) ) \ "INHERIT_POS", "INHERIT_ROT", "INHERIT_SCL",\ "TM_ROW0", "TM_ROW1", "TM_ROW2", "TM_ROW3",\ "TM_POS", "TM_ROTAXIS", "TM_SCALE", "TM_SCALEAXIS": --vectors tList.setaprop( symbol(tCommand), vector(float(tLine.word[2]), float(tLine.word[3]), float(tLine.word[4])) ) \ "MESH_VERTEX", "MESH_TVERT": --vectors indexed tList.setaprop( integer(tLine.word[2]), vector(float(tLine.word[3]), float(tLine.word[4]), float(tLine.word[5])) ) \ "MESH_VERTCOL": --rgb values indexed tList.setaprop( integer(tLine.word[2]), rgb(float(tLine.word[3])*255, float(tLine.word[4])*255, float(tLine.word[5])*255) ) --BGR --tList.setaprop( integer(tLine.word[2]), rgb(float(tLine.word[4])*255, float(tLine.word[3])*255, float(tLine.word[5])*255) ) \ "MESH_TFACE", "MESH_CFACE": tList.setaprop( integer(tLine.word[2]), [integer(tLine.word[5]), integer(tLine.word[4]), integer(tLine.word[3])] ) \ "MESH_FACENORMAL": fnList = [:] tList.setaprop( integer(tLine.word[2]), fnList ) fnList.setaprop( symbol(tCommand), vector(float(tLine.word[3]), float(tLine.word[4]), float(tLine.word[5])) ) ------******** "MESH_VERTEXNORMAL": --add to VertexNormal list vnList = tList.getaprop(symbol(tCommand)) if voidP(vnList) then vnList=[:] tList.setaprop(symbol(tCommand), vnList) end if i = integer(tLine.word[2]) vn = vector(float(tLine.word[3]), float(tLine.word[4]), float(tLine.word[5])) vnList.setaprop( i, vn ) --add to FaceNormal list if not(voidP(fnList)) then if fnList.count < 4 then fnList.setaprop( i, vn ) else put "ERROR: MESH_VERTEXNORMAL count. Line:" && n & return & tLine & return end if else put "ERROR: MESH_VERTEXNORMAL void. Line:" && n & return & tLine & return end if \ "MESH_FACE": --face data* fData = [:] --face num tWord = tLine.word[2] tList.setaprop( integer(tWord.char[1..tWord.char.count-1]), fData ) --face vertices A,B,C tWord = tLine.word[3] fData.setaprop( symbol(tWord.char[1..tWord.char.count-1]), integer(tLine.word[4]) ) tWord = tLine.word[5] fData.setaprop( symbol(tWord.char[1..tWord.char.count-1]), integer(tLine.word[6]) ) tWord = tLine.word[7] fData.setaprop( symbol(tWord.char[1..tWord.char.count-1]), integer(tLine.word[8]) ) --face edges AB,BC,CA tWord = tLine.word[9] fData.setaprop( symbol(tWord.char[1..tWord.char.count-1]), integer(tLine.word[10]) ) tWord = tLine.word[11] fData.setaprop( symbol(tWord.char[1..tWord.char.count-1]), integer(tLine.word[12]) ) tWord = tLine.word[13] fData.setaprop( symbol(tWord.char[1..tWord.char.count-1]), integer(tLine.word[14]) ) --smoothing tWord = tLine.word[15] fData.setaprop( symbol(tWord.char[2..tWord.char.count]), integer(tLine.word[16]) ) --material ID tWord = tLine.word[17] fData.setaprop( symbol(tWord.char[2..tWord.char.count]), integer(tLine.word[18]) ) otherwise --Class Definitions if tLine.word[tLine.word.count] = "{" then --move down a level tParentList.add(tList) tempList = [:] if tLine.word.count = 2 then tList.setaprop( symbol(tCommand), tempList ) else tList.setaprop( integer(tLine.word[2]), tempList ) end if tList = tempList end if put "Unknown Command. Line:" && n & return & tLine & return end case if rMaxString = "" then exit repeat end repeat ------------------------------------ return createNodeList end --build meshes from imported list------------------------------------------------------------------------ on buildMaxScene (me, rMaxProplist, r3dMember, rGenerateNormalStyle) nodeCount = rMaxProplist.count repeat with n = 1 to nodeCount nodetype = rMaxProplist.getpropat(n) nodedata = rMaxProplist.getat(n) if nodetype = #GEOMOBJECT then --make model node_name = nodedata.getaprop( #NODE_NAME ) if voidP(node_name) then node_name = "UNNAMED" if not(voidP(r3dMember.model(node_name))) then r3dMember.deletemodel(node_name) end if tmodel = r3dMember.newmodel(node_name) ------------------------------------- -- t = nodedata.getaprop("t") -- if t <> 0 then -- tmodel.transform.position = t -- end if -- r = nodedata.getaprop("t") -- if r <> 0 then -- tmodel.transform.rotation = r -- end if --------------------------------------- meshList = nodedata.getaprop(#MESH) if not(voidP(meshList)) then --lists tvertexlist = [] tcolorlist = [] tnormallist = [] UVlist = [] --counts vertexcount = 0 --MESH_NUMVERTEX facecount = 0 --MESH_NUMFACES normalcount = 0 colorcount = 0 --MESH_NUMCVERTEX --MESH_NUMCVFACES uvcount = 0 --textureCoordinateList---------------------- -- uvmaps = nodedata.getaprop("uvst") -- if uvmaps <> 0 then -- UVlist = uvmaps.getaprop("uvsp") -- if UVlist <> 0 then -- uvcount = UVlist.count -- -- end if -- end if ----------------------------------------------- --vertexList tvertexlist = meshList.getaprop( #MESH_VERTEX_LIST )--).duplicate()--don't mess with original if not(voidP(tvertexlist)) then vertexcount = tvertexlist.count end if --normallist if voidP(rGenerateNormalStyle) then nVector = vector(1.0, 1.0, 1.0)--vector(1e+020, 1e+020, 1e+020) --tempNLIST = nodedata.getaprop(#MESH_NORMALS)--** tnormallist = [] tnormallist.add(nVector) normalcount = 1 else normalcount = 0 end if --colorList tcolorlist = meshList.getaprop( #MESH_CVERTLIST )--).duplicate()--don't mess with original if not(voidP(tcolorlist)) then colorcount = tcolorlist.count if colorcount > 0 then faceColorlist = [] tfacelist = meshList.getaprop( #MESH_CFACELIST ) fcolorcount = tfacelist.count-- repeat with fc = 1 to fcolorcount faceN_data = tfacelist[fc] ftlist = faceN_data.duplicate() +1 faceColorlist.add(ftlist) end repeat end if end if --create face lists tfacelist = meshList.getaprop( #MESH_FACE_LIST ) if not(voidP(tfacelist)) then dlist = [1,1,1] faceVTlist = [] faceNMlist = faceVTlist--[] faceUVlist = faceUVlist--[] nmindex = 0 facecount = tfacelist.count repeat with fc = 1 to facecount faceN_data = tfacelist[fc] ftlist = dlist.duplicate() ftlist[1] = faceN_data.getaprop(#a)+1 ftlist[2] = faceN_data.getaprop(#b)+1 ftlist[3] = faceN_data.getaprop(#c)+1 faceVTlist.add(ftlist) end repeat end if --calculate normals that are not custom set in Maya (smooth/hard) if normalcount then --nVector = vector(1e+020,1e+020,1e+020) -- repeat with nm = 1 to normalcount -- if tnormallist[nm] = nVector then -- vt = vertexNormalList.getpropat(nm) -- edgelist = vertexToEdgeList.getaprop(vt) -- facelist = vertexToFaceList.getaprop(vt) -- -- v1 = vector(1,0,0)--**face vetexes -- v2 = vector(1,0,1) -- v3 = vector(0,0,1) -- -- Compute Cross Product to give surface normal -- tnormallist[nm] = getNormalized(crossProduct(v2-v1,v3-v1)) -- -- end if -- end repeat end if --mesh resource --node_name = nodedata.getaprop("name") if r3dMember.modelresource(node_name) <> 0 then r3dMember.deletemodelresource(node_name) end if tResource = r3dMember.newMesh(node_name, facecount, vertexcount, normalcount, colorcount, uvcount) if uvcount then tResource.textureCoordinateList = UVlist if colorcount then tResource.colorList = tcolorlist tResource.vertexList = tvertexlist if normalcount then tResource.normallist = tnormallist -- repeat with tface = 1 to facecount if uvcount then tResource.face[tface].textureCoordinates = faceUVlist[tface] if colorcount then tResource.face[tface].colors = faceColorlist[tface] tResource.face[tface].vertices = faceVTlist[tface] --if normalcount then tResource.face[tface].normals = faceNMlist[tface]--** --tResource.face[tface].shader = pTileShaderList[faceSlist[tface]] end repeat --build mesh if not(voidP(rGenerateNormalStyle)) then tResource.generateNormals(rGenerateNormalStyle) end if tResource.build() --attach resource tmodel.resource = tResource --parent model -- tparent = nodedata.getaprop("parent") -- if tparent <> 0 then -- if r3dMember.model(tparent) <> 0 then -- r3dMember.model(tparent).resource = tResource -- end if -- end if end if end if end repeat end