-- RMT 3d fileformat exporter v. 1.1 -- Author: Lauri Mäki - http://random.gfxile.net -- website: http://random.gfxile.net/RMT/ -- free for any use - tellware - tell me if you use it. -- (Triangle strips and vertex colors has not been fully tested yet) -- NOTICE: I don't take any responsibility on any damage that using this script does for anything. macroscript RMTexporter category:"RNDtools" buttontext:"RMT_Exporter" tooltip:"RMT_Exporter" ( objectlist = #() meshlist = #() facelist = #(#(),#(),#(),#(),#(),#(),#(),#(),#(),#()) normallist = #(#(),#(),#(),#(),#(),#(),#(),#(),#(),#()) fillcol = color 255 255 255 backcol = color 166 160 150 randombitmaparray = #(#(fillcol,fillcol,fillcol,fillcol,fillcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,fillcol,fillcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol),#(fillcol,fillcol,backcol,backcol,fillcol,fillcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,fillcol,fillcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol),#(fillcol,fillcol,backcol,backcol,fillcol,fillcol,backcol,backcol,backcol,fillcol,fillcol,fillcol,fillcol,backcol,fillcol,fillcol,fillcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,fillcol,fillcol,backcol,fillcol,fillcol,fillcol,fillcol,fillcol,fillcol,fillcol,backcol),#(fillcol,fillcol,fillcol,fillcol,backcol,backcol,backcol,backcol,backcol,backcol,fillcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol),#(fillcol,fillcol,backcol,fillcol,fillcol,backcol,backcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol),#(fillcol,fillcol,backcol,backcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,fillcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol)) randombitmap = bitmap 40 6 for y=1 to 6 do ( setpixels randombitmap [0,(y-1)] randombitmaparray[y] ) RMTbitmaparray = #(#(backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,backcol,fillcol,backcol),#(fillcol,fillcol,fillcol,fillcol,backcol,backcol,fillcol,fillcol,fillcol,fillcol,fillcol,fillcol,fillcol,backcol,backcol,backcol,fillcol,fillcol,fillcol),#(fillcol,fillcol,backcol,backcol,backcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,backcol,backcol,fillcol,backcol),#(fillcol,fillcol,backcol,backcol,backcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,backcol,backcol,fillcol,backcol),#(fillcol,fillcol,backcol,backcol,backcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,fillcol,fillcol,backcol,backcol,backcol,fillcol,fillcol)) RMTbitmap = bitmap 19 5 for y=1 to 5 do ( setpixels RMTbitmap [0,(y-1)] RMTbitmaparray[y] ) struct AdjTriangle (VertexRef=#(), TriRef=#(), used=false) struct AdjEdge (V1,V2,Owner) fn WstringWlength xfile thestring = ( writebyte xfile thestring.count #unsigned for c=1 to thestring.count do ( writebyte xfile (bit.charAsInt thestring[c]) #unsigned ) ) fn pokemapslot slot = ( if slot == undefined do ( return undefined ) if slot.bitmap != undefined then ( return slot.filename ) else ( return undefined ) ) fn getFaceSmoothBin obj face = ( local sgroup_val=getFaceSmoothGroup obj face local sg_bitarray=#{} if sgroup_val < 0 do ( sg_bitarray[32]=true sgroup_val -= 2^31 ) for i = 1 to 31 do ( sg_bitarray[i]= (mod sgroup_val 2 > .5) sgroup_val /= 2 ) sg_bitarray ) fn SplitMeshBySGS mese = ( local finalmesh = editable_mesh() finalmesh.transform = mese.transform local facearray = #() local facearrays = #() for i=1 to mese.numfaces do ( facearray[i] = #() facearray[i] = ((getFaceSmoothBin mese i) as array) if facearray[i].count == 0 do ( facearray[i] = #(i) ) if facearray[i].count>1 do messagebox "Multiple Smoothing Groups per face found!\nFirst one taken\nThe mesh might look rather silly" title:"Warning!" facearrays[facearray[i][1]] = #() ) for i=1 to mese.numfaces do ( append facearrays[facearray[i][1]] i ) for sg=1 to facearrays.count do ( if facearrays[sg] != undefined do ( local obj = copy mese converttomesh obj local newmesh = editable_mesh() newmesh.transform = mese.transform newmesh.mesh = meshop.detachfaces obj facearrays[sg] delete:true asmesh:true attach finalmesh newmesh delete obj ) ) finalmesh ) fn splitMeshByMapElements mese channel = ( meshop.setmapsupport mese channel true local obj = copy mese --copy the original object convertToMesh obj --convert to editable mesh local finalmesh = editable_mesh() finalmesh.transform = mese.transform while obj.numfaces > 0 do --repeat until all elements have been detached ( face_array = #(1) --init. an array including only face 1 cnt = 0 --init. a counter --repeat until the counter is higher than the faces stored in the array while cnt < face_array.count do ( cnt += 1 --increase the counter --get all map vertices used by the current map face in the collection array: theVerts = meshop.getMapVertsUsingMapFace obj channel #(face_array[cnt]) --get all map faces used by these map vertices - --this gives us all neighbours of the current map face theFaces = meshop.getMapFacesUsingMapVert obj channel theVerts --make sure only unique faces are written to the array for f in theFaces where findItem face_array f == 0 do append face_array f )--end while new_emesh = Editable_mesh() --detach the collected faces and assign to the EMesh's TriMesh new_emesh.mesh = meshop.detachFaces obj face_array delete:true asMesh:true --Copy the transformation of the original object and attach to finalmesh new_emesh.transform = mese.transform attach finalmesh new_emesh ) delete obj --delete the clone finalmesh ) fn getMapVertRef mese channel = ( local tempfaces = #() local meshindices = #() local meshocc = 0 local TVindices = #() local UVvertRef = #() meshop.setmapsupport mese channel true for v=1 to mese.numverts do ( tempfaces = (meshop.getfacesusingvert mese v) as array meshindices = getface mese tempfaces[1] -- let's find the occurence for ind=1 to 3 do ( if meshindices[ind] == v do meshocc = ind ) -- meshocc = finditem meshindices v -- somehow point3 is not identified as array ?!?!?!?!?!? TVindices = meshop.getmapface mese channel tempfaces[1] UVvertRef[v] = TVindices[meshocc] -- haxxorz list of mesh to texture vertex connections ) UVvertRef ) fn findedge adjedgelist vert1 vert2 notri = ( for e=1 to AdjEdgeList.count do ( if AdjEdgelist[e].V1 == vert1 OR AdjEdgelist[e].V1 == vert2 do ( if AdjEdgelist[e].V2 == vert1 OR AdjEdgelist[e].V2 == vert2 do ( if AdjEdgelist[e].owner != notri do ( return e ) ) ) ) return undefined ) fn GiveStrip adjedgelist adjtris basestrip nexttriangle = ( nexttri = #(adjtris[nexttriangle].vertexref[1], adjtris[nexttriangle].vertexref[2], adjtris[nexttriangle].vertexref[3]) nexttri = deleteitem nexttri (finditem nexttri basestrip[basestrip.count-1]) nexttri = deleteitem nexttri (finditem nexttri basestrip[basestrip.count]) if adjtris[nexttriangle].used == false do ( append basestrip nexttri[1] adjtris[nexttriangle].used = true sharededge = undefined sharededge = findedge adjedgelist basestrip[basestrip.count-1] basestrip[basestrip.count] nexttriangle if sharededge!=undefined do basestrip = GiveStrip adjedgelist adjtris basestrip AdjEdgelist[sharededge].owner ) basestrip ) fn CreateAdjEdges mese indexlist = ( AdjEdgelist = #() for t=1 to indexlist.count do ( Tedgelist = ((meshop.getedgesusingface mese indexlist[t]) as array) -- adjacency edges for e=1 to Tedgelist.count do ( tempAedge = AdjEdge 0 0 1 tempedgeverts = (meshop.getvertsusingedge mese Tedgelist[e]) as array sort tempedgeverts tempAedge.V1 = tempedgeverts[1] tempAedge.V2 = tempedgeverts[2] if tempAedge.V1==undefined do tempAedge.V1 = 1 if tempAedge.V2==undefined do tempAedge.V2 = 1 tempAedge.owner = 1 tempAedge.Owner = indexlist[t] AdjEdgeList[Tedgelist[e]] = tempAedge ) ) for adja=1 to adjedgelist.count do ( if adjedgelist[adja]==undefined do adjedgelist[adja] = adjedge 0 0 0 ) AdjEdgeList ) fn CreateAdjTris mese indexlist = ( adjtris = #() adjedgelist = #() local Tedgelist = #() local TTedgelist = #() -- adjacency triangles for t=1 to mese.numfaces do ( tempATri = AdjTriangle #() #() false tempAtri.vertexref = ((meshop.getvertsusingface mese t) as array) for v=1 to tempAtri.vertexref.count do ( if v==undefined do ( v=1 onkelma = string onkelma = ("invalid mesh! vertexreference missing in triangle " + (t as string)) messagebox onkelma title:"Warning" ) ) Tedgelist = ((meshop.getedgesusingface mese t) as array) -- adjacency edges for e=1 to Tedgelist.count do ( tempAedge = AdjEdge point3 point3 0 tempedgeverts = meshop.getvertsusingedge mese Tedgelist[e] as array tempAedge.V1 = tempedgeverts[1] tempAedge.V2 = tempedgeverts[2] if tempAedge.V1==undefined do tempAedge.V1 = 1 if tempAedge.V2==undefined do tempAedge.V2 = 1 tempAedge.owner = 1 tempAedge.Owner = t AdjEdgeList[Tedgelist[e]] = tempAedge ) TTedgelist = ((meshop.getedgesreverseedge mese Tedgelist) as array) join Tedgelist TTedgelist tempAtri.TriRef = ((meshop.getfacesusingedge mese Tedgelist) as array) tempAtri.TriRef = (deleteitem tempAtri.TriRef (finditem tempAtri.TriRef t)) inlist = 0 tinlist = #() for triref=1 to tempAtri.Triref.count do ( inlist = 0 inlist = finditem indexlist tempAtri.TriRef[triref] if inlist != 0 do append tinlist tempAtri.TriRef[triref] ) tempAtri.TriRef = tinlist adjtris[t] = tempAtri ) adjtris ) fn SeparateByMatID mese = ( -- put faces in arrays by matid mesetriset = #() for tri = 1 to mese.numfaces do ( maid = getfacematid mese tri if mesetriset[maid] == undefined do mesetriset[maid] = #() append mesetriset[maid] tri ) mesetriset ) fn GiveMaterial mese ib = ( tempmat = mese.material matcount = getnumsubmtls tempmat if matcount>0 then ( tempmat[ib] ) else ( tempmat ) ) utility RMTporter "RMT export" width:400 height:300 ( imgtag rmtb bitmap:RMTbitmap pos:[10,290] imgtag rndb bitmap:randombitmap pos:[350,290] groupbox gp_data "" pos:[5,5] width:125 height:230 label lb_data "DATA" pos:[20,5] label lb_meshes "Meshes" pos:[25,25] label lb_vertices "Vertices" pos:[40,50] label lb_normals "VertexNormals" pos:[40,70] label lb_UVs "UVs" pos:[40,90] label lb_indices "IndexBuffers" pos:[40,110] label lb_vcols "VertexColors" pos:[40,130] label lb_mats "Materials" pos:[25,160] label lb_bitmapinfos "BitmapInfos" pos:[40,190] label lb_shaderinfos "ShaderInfos" pos:[40,210] checkbox ch_meshes "" pos:[10,25] width:13 height:15 checked:true checkbox ch_vertices "" pos:[25,50] width:13 height:14 checked:true checkbox ch_normals "" pos:[25,70] width:13 height:14 checked:true checkbox ch_UVs "" pos:[25,90] width:13 height:14 checked:true checkbox ch_indices "" pos:[25,110] width:13 height:14 checked:true checkbox ch_vcols "" pos:[25,130] width:13 height:14 checked:true checkbox ch_mats "" pos:[10,160] width:13 height:14 checked:true checkbox ch_bitmapinfos "" pos:[25,190] width:13 height:14 checked:true checkbox ch_shaderinfos "" pos:[25,210] width:13 height:14 checked:true groupbox gp_options "" pos:[135,5] width:260 height:230 label lb_options "OPTIONS" pos:[155,5] label lb_realsasfloats "Reals As Floats" pos:[160,25] label lb_UVW "Export 3d-UVs (UVW)" pos:[265,25] label lb_ascii "Export ASCII-file" pos:[265,45] checkbox ch_realsasfloats "" pos:[145,25] width:13 height:14 checked:true checkbox ch_UVW "" pos:[250,25] width:13 height:14 checked:false checkbox ch_ascii "" pos:[250,45] width:13 height:14 checked:true groupbox accuracies "" pos:[138,60] width:254 height:86 radiobuttons VBaccuracy "Vertex-bytes:" labels:#("1","2","4") pos:[145,70] radiobuttons NRMaccuracy "Normal-bytes:" labels:#("1","2","4") pos:[145,110] radiobuttons UVaccuracy "UV-bytes:" labels:#("1","2","4") pos:[250,110] radiobuttons VCOLaccuracy "V_Color-bytes (per RGBA):" labels:#("1","2","4","16") pos:[250,70] radiobuttons Ibuffertype "Indexbuffer-type:" labels:#("List","Strips") pos:[145,150] checkbox ch_SGcons "" pos:[250,168] width:13 height:14 checked:true checkbox ch_UVcons "" pos:[250,188] width:13 height:14 checked:true checkbox ch_VCOLcons "" pos:[250,208] width:13 height:14 checked:false checkbox ch_VAcons "" pos:[320,208] width:13 height:14 checked:false groupbox vertexdata "" pos:[245,150] width:147 height:80 label lb_vertexdata "VERTEX DATA" pos:[265,150] label lb_SGcons "Smoothing groups" pos:[265,168] label lb_UVcons "UV split" pos:[265,188] label lb_VCOLcons "V-Col split" pos:[265,208] label lb_VAcons "Alpha" pos:[335,208] button export "Export" pos:[100,256] width:200 height:21 on ch_meshes changed state do ( if ch_meshes.state == true then ( ch_vertices.enabled = true ch_normals.enabled = true ch_UVs.enabled = true ch_indices.enabled = true ch_vcols.enabled = true ch_vertices.state = true ch_normals.state = true ch_UVs.state = true ch_indices.state = true ch_vcols.state = true ) else ( ch_vertices.enabled = false ch_normals.enabled = false ch_UVs.enabled = false ch_indices.enabled = false ch_vcols.enabled = false ch_vertices.state = false ch_normals.state = false ch_UVs.state = false ch_indices.state = false ch_vcols.state = false ) ) on ch_mats changed state do ( if ch_mats.state == true then ( ch_bitmapinfos.enabled = true ch_shaderinfos.enabled = true ch_bitmapinfos.state = true ch_shaderinfos.state = true ) else ( ch_bitmapinfos.enabled = false ch_shaderinfos.enabled = false ch_bitmapinfos.state = false ch_shaderinfos.state = false ) ) on export pressed do ( -- filename and file open rmtfilename = getsavefilename caption:"export file" types:"RandomMeshThings(*.rmt)|*.rmt" if rmtfilename!=undefined then ( rmtfile = fopen rmtfilename "wb" ) else ( return 0 ) -- asciifile if ch_ascii.state == true do ( tempstring = filterstring rmtfilename "." rmafilename = (tempstring[1] + ".rma") rmafile = openfile rmafilename mode:"w+" ) -- materialarray rmtmaterials = #() -- parse meshes max select all objectlist = getcurrentselection() -- find editable meshes and editable polys for a=1 to objectlist.count do ( if (classof objectlist[a] == editable_mesh) OR (classof objectlist[a] == editable_poly) do ( append meshlist objectlist[a] ) ) -- go thru accuracies VBacc_int = case VBaccuracy.state of ( 1: 1 2: 2 3: 4 ) NRMacc_int = case NRMaccuracy.state of ( 1: 1 2: 2 3: 4 ) UVacc_int = case UVaccuracy.state of ( 1: 1 2: 2 3: 4 ) VCOLacc_int = case VCOLaccuracy.state of ( 1: 1 2: 2 3: 4 4: 16 ) -- write .rmt file if ch_ascii.state==true do ( format "version: 1\nRealsAsFloats: %\nMeshcount: %\n\n" ch_realsasfloats.state meshlist.count to:rmafile format "VertexBuffer Accuracy: % bytes\nNormal Accuracy: % bytes\nUV accuracy: % bytes\nVertexColor accuracy: % bytes\n\n" VBacc_int NRMacc_int UVacc_int VCOLacc_int to:rmafile ) rmtsize = 0 -- RMT chunk -- header writeshort rmtfile 0x5ad0 #unsigned RMTsizepos = ftell rmtfile -- we'll be back. (materialsize+meshsize+10) writelong rmtfile 0 #unsigned -- chunk writebyte rmtfile 1 #unsigned if ch_realsasfloats.state == true then ( writebyte rmtfile 1 #unsigned ) else ( writebyte rmtfile 0 #unsigned ) writeshort rmtfile meshlist.count #unsigned -- RMT: 4 bytes written for a=1 to meshlist.count do ( meshsize = 0 tempmesh = snapshot meshlist[a] converttomesh tempmesh meshop.setmapsupport tempmesh 1 true meshop.setmapsupport tempmesh 0 true meshop.setmapsupport tempmesh -2 true -- mesh consolidation if ch_UVcons.state == true do ( tmesh = snapshot tempmesh delete tempmesh tempmesh = splitMeshByMapElements tmesh 1 delete tmesh ) if ch_VCOLcons.state == true do ( tmesh = snapshot tempmesh delete tempmesh tempmesh = splitMeshByMapElements tmesh 0 delete tmesh ) if ch_VAcons.state == true do ( tmesh = snapshot tempmesh delete tempmesh tempmesh = splitMeshByMapElements tmesh -2 delete tmesh ) if ch_SGcons.state == true then ( tmesh = snapshot tempmesh delete tempmesh tempmesh = SplitMeshBySGS tmesh delete tmesh ) else ( for i=1 to tempmesh.numfaces do setfacesmoothgroup tempmesh i 1 ) vertexcount = getnumverts tempmesh tricount = getnumfaces tempmesh UVcount = meshop.getnummaps tempmesh if tempmesh.material == undefined do ( tempmesh.material = standard() ) tempmaterial = tempmesh.material -- ascii if ch_ascii.state==true do ( format "UV-Consolidation: %\nVertexColor-Consolidation: %\nVertexAlpha-Consolidation: %\nSmoothing Group Consolidation: %\n\n" ch_UVcons.state ch_VCOLcons.state ch_VAcons.state ch_SGcons.state to:rmafile ) if ch_meshes.state == true do ( -- MESH chunk if ch_ascii.state==true do ( format "MESH\n\nMeshName: %\nVertexCount: %\nTriangleCount: %\nUV-Count: %\nIndexbuffer type: %\n" meshlist[a].name tempmesh.numverts tempmesh.numfaces UVcount Ibuffertype.state to:rmafile ) --header writeshort rmtfile 0x1000 #unsigned MESHsizepos = ftell rmtfile -- We'll be back! writelong rmtfile 0 #unsigned -- chunk --writebyte rmtfile (meshlist[a].name.count+1) #unsigned --writestring rmtfile meshlist[a].name WstringWlength rmtfile meshlist[a].name if ch_realsasfloats.state==true then ( in coordsys world ( writefloat rmtfile tempmesh.pos.x writefloat rmtfile tempmesh.pos.z -- z and y are swapped writefloat rmtfile tempmesh.pos.y if ch_ascii.state==true do format "Initial Position: % % %\n\n" tempmesh.pos.x tempmesh.pos.z tempmesh.pos.y to:rmafile ) ) else ( in coordsys world ( writelong rmtfile (tempmesh.pos.x as integer) #signed writelong rmtfile (tempmesh.pos.z as integer) #signed -- z and y are swapped writelong rmtfile (tempmesh.pos.y as integer) #signed if ch_ascii.state==true do format "Initial Position: % % %\n\n" (tempmesh.pos.x as integer) (tempmesh.pos.z as integer) (tempmesh.pos.y as integer) to:rmafile ) ) writelong rmtfile tempmesh.numverts #signed -- note that the vertexcount affects vertexbuffer and indexbuffer accuracy! writebyte rmtfile Ibuffertype.state #unsigned writebyte rmtfile UVcount #unsigned -- add to mesh size meshsize += (19+meshlist[a].name.count) if ch_vertices.state == true do ( -- VERTEXBUFFER chunk -- VBscale: xmax=0 ymax=0 zmax=0 for v=1 to vertexcount do ( in coordsys tempmesh.transform tempvertex = getvert tempmesh v if xmax<(abs tempvertex.x) do xmax=(abs tempvertex.x) if ymax<(abs tempvertex.y) do ymax=(abs tempvertex.y) if zmax<(abs tempvertex.z) do zmax=(abs tempvertex.z) ) tempmeshscale=point3 xmax ymax zmax -- header writeshort rmtfile 0x1100 #unsigned writelong rmtfile (13+tempmesh.numverts*VBacc_int*3) #unsigned --data if ch_realsasfloats.state==true then ( writefloat rmtfile tempmeshscale.x writefloat rmtfile tempmeshscale.z -- z and y swapped writefloat rmtfile tempmeshscale.y if ch_ascii.state==true do format "VERTEXBUFFER\n\nVertexBuffer Scale: % % %\n\nVertices: " tempmeshscale.x tempmeshscale.z tempmeshscale.y to:rmafile ) else ( writelong rmtfile (tempmeshscale.x as integer) #signed writelong rmtfile (tempmeshscale.z as integer) #signed -- z and y swapped writelong rmtfile (tempmeshscale.y as integer) #signed if ch_ascii.state==true do format "VERTEXBUFFER\n\nVertexBuffer Scale: % % %\n\nVertices: " (tempmeshscale.x as integer) (tempmeshscale.z as integer) (tempmeshscale.y as integer) to:rmafile ) writebyte rmtfile VBaccuracy.state #unsigned qvertex = point3 0 0 0 case VBaccuracy.state of ( 1: ( for b=1 to vertexcount do ( in coordsys tempmesh.transform tempvertex = getvert tempmesh b qvertex.x = floor(((tempvertex.x/tempmeshscale.x)*127)+0.5) qvertex.y = floor(((tempvertex.y/tempmeshscale.y)*127)+0.5) qvertex.z = floor(((tempvertex.z/tempmeshscale.z)*127)+0.5) writebyte rmtfile qvertex.x #signed writebyte rmtfile qvertex.z #signed -- z and y swapped writebyte rmtfile qvertex.y #signed in coordsys tempmesh.transform if ch_ascii.state==true do format "[%,%,%]," (qvertex.x as integer) (qvertex.z as integer) (qvertex.y as integer) to:rmafile ) ) 2: ( for b=1 to vertexcount do ( in coordsys tempmesh.transform tempvertex = getvert tempmesh b qvertex.x = ((tempvertex.x/tempmeshscale.x)*32767) qvertex.y = ((tempvertex.y/tempmeshscale.y)*32767) qvertex.z = ((tempvertex.z/tempmeshscale.z)*32767) writeshort rmtfile (qvertex.x as integer) #signed writeshort rmtfile (qvertex.z as integer) #signed -- z and y swapped writeshort rmtfile (qvertex.y as integer) #signed in coordsys tempmesh.transform if ch_ascii.state==true do format "[%,%,%]," (qvertex.x as integer) (qvertex.z as integer) (qvertex.y as integer) to:rmafile ) ) 3: ( if ch_RealsAsFloats.state==true then ( for b=1 to vertexcount do ( in coordsys tempmesh.transform tempvertex = getvert tempmesh b writefloat rmtfile tempvertex.x writefloat rmtfile tempvertex.z -- z and y swapped writefloat rmtfile tempvertex.y in coordsys tempmesh.transform if ch_ascii.state==true do format "[%,%,%]," tempvertex.x tempvertex.z tempvertex.y to:rmafile ) ) else ( for b=1 to vertexcount do ( in coordsys tempmesh.transform tempvertex = getvert tempmesh b qvertex.x = ((tempvertex.x/tempmeshscale.x)*2147483647) qvertex.y = ((tempvertex.y/tempmeshscale.y)*2147483647) qvertex.z = ((tempvertex.z/tempmeshscale.z)*2147483647) writelong rmtfile (qvertex.x as integer) #signed writelong rmtfile (qvertex.z as integer) #signed -- z and y swapped writelong rmtfile (qvertex.y as integer) #signed in coordsys tempmesh.transform if ch_ascii.state==true do format "[%,%,%]," (qvertex.x as integer) (qvertex.z as integer) (qvertex.y as integer) to:rmafile ) ) ) ) if ch_ascii.state==true do format "\n\n" to:rmafile ) -- mesh size append meshsize+=(19+tempmesh.numverts*VBacc_int*3) if ch_normals.state == true do ( -- NORMALBUFFER chunk -- header writeshort rmtfile 0x1200 #unsigned writelong rmtfile (1+tempmesh.numverts*NRMacc_int*3) #unsigned -- data writebyte rmtfile NRMaccuracy.state #unsigned tempnormal = #() if ch_ascii.state==true do format "NORMALBUFFER\n\nNormals: " to:rmafile case NRMaccuracy.state of ( 1: ( for t=1 to tempmesh.numverts do ( tempnormal = getnormal tempmesh t tempnormal = normalize tempnormal tempnormal.x = tempnormal.x*127 tempnormal.y = tempnormal.y*127 tempnormal.z = tempnormal.z*127 writebyte rmtfile (tempnormal.x as integer) #signed writebyte rmtfile (tempnormal.z as integer) #signed -- z and y swapped writebyte rmtfile (tempnormal.y as integer) #signed if ch_ascii.state==true do format "[%,%,%]," (tempnormal.x as integer) (tempnormal.z as integer) (tempnormal.y as integer) to:rmafile ) ) 2: ( for t=1 to tempmesh.numverts do ( tempnormal = getnormal tempmesh t tempnormal = normalize tempnormal tempnormal.x = tempnormal.x*32767 tempnormal.y = tempnormal.y*32767 tempnormal.z = tempnormal.z*32767 writeshort rmtfile (tempnormal.x as integer) #signed writeshort rmtfile (tempnormal.z as integer) #signed -- z and y swapped writeshort rmtfile (tempnormal.y as integer) #signed if ch_ascii.state==true do format "[%,%,%]," (tempnormal.x as integer) (tempnormal.z as integer) (tempnormal.y as integer) to:rmafile ) ) 3: ( if ch_RealsAsFloats.state == true then ( for t=1 to tempmesh.numverts do ( tempnormal = getnormal tempmesh t tempnormal = normalize tempnormal writefloat rmtfile tempnormal.x writefloat rmtfile tempnormal.z -- z and y swapped writefloat rmtfile tempnormal.y if ch_ascii.state==true do format "[%,%,%]," tempnormal.x tempnormal.z tempnormal.y to:rmafile ) ) else ( for t=1 to tempmesh.numverts do ( tempnormal = getnormal tempmesh t tempnormal = normalize tempnormal tempnormal.x = tempnormal.x*2147483647 tempnormal.y = tempnormal.y*2147483647 tempnormal.z = tempnormal.z*2147483647 writebyte rmtfile (tempnormal.x as integer) #signed writebyte rmtfile (tempnormal.z as integer) #signed -- z and y swapped writebyte rmtfile (tempnormal.y as integer) #signed if ch_ascii.state==true do format "[%,%,%]," (tempnormal.x as integer) (tempnormal.z as integer) (tempnormal.y as integer) to:rmafile ) ) ) ) if ch_ascii.state==true do format "\n\n" to:rmafile ) -- meshsize append meshsize += 7+tempmesh.numverts*NRMacc_int*3 -- UV chunk if ch_UVs.state == true do ( UVvertRef = #() channelcount = nummapsused tempmesh texturevertexcount = getnumTVerts tempmesh UVvertRef = getMapvertref tempmesh 1 -- header for uv=1 to (channelcount-1) do ( writeshort rmtfile 0x1300 #unsigned -- size depends on if 3d UV's enabled if ch_ascii.state==true do format "UVBUFFER\n\nChannel: %\nUVWs enabled: %\n" uv ch_UVW.state to:rmafile if ch_UVW.state == true then ( writelong rmtfile (4+tempmesh.numverts*3*UVacc_int) #unsigned -- meshsize append meshsize += 10+tempmesh.numverts*UVacc_int*3 -- data writebyte rmtfile uv #unsigned -- UV channel writebyte rmtfile 1 #unsigned -- W channel incl. -- find the biggest UVW's for scale. biggestone = 0 for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] for kei=1 to 3 do ( if (abs tvert[kei])>(abs biggestone) do biggestone = tvert[kei] ) ) biggestone=(abs biggestone) as integer writebyte rmtfile biggestone #unsigned -- UVW-scale writebyte rmtfile UVaccuracy.state #unsigned -- UVW-accuracy qvert = point3 0 0 0 if ch_ascii.state==true do format "MapCoordinate scale: %\nUVWs: " biggestone to:rmafile -- actual UVW-data case UVaccuracy.state of ( 1: ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] qvert.x = floor (((tvert.x/biggestone)*127)+0.5) qvert.y = floor (((tvert.y/biggestone)*127)+0.5) qvert.z = floor (((tvert.z/biggestone)*127)+0.5) writebyte rmtfile (qvert.x as integer) #unsigned writebyte rmtfile (qvert.y as integer) #unsigned writebyte rmtfile (qvert.z as integer) #unsigned if ch_ascii.state==true do format "[%,%,%]," (qvert.x as integer) (qvert.y as integer) (qvert.z as integer) to:rmafile ) ) 2: ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] qvert.x = floor (((tvert.x/biggestone)*32767)+0.5) qvert.y = floor (((tvert.y/biggestone)*32767)+0.5) qvert.z = floor (((tvert.z/biggestone)*32767)+0.5) writeshort rmtfile (qvert.x as integer) #unsigned writeshort rmtfile (qvert.y as integer) #unsigned writeshort rmtfile (qvert.z as integer) #unsigned if ch_ascii.state==true do format "[%,%,%]," (qvert.x as integer) (qvert.y as integer) (qvert.z as integer) to:rmafile ) ) 3: ( if ch_RealsAsFloats.state==true then ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] writefloat rmtfile tvert.x writefloat rmtfile tvert.y -- no flip?!?! writefloat rmtfile tvert.z if ch_ascii.state==true do format "[%,%,%]," tvert.x tvert.y tvert.z to:rmafile ) ) else ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] qvert.x = ((tvert.x/biggestone)*2147483647) qvert.y = ((tvert.y/biggestone)*2147483647) qvert.z = ((tvert.z/biggestone)*2147483647) writelong rmtfile (qvert.x as integer) #unsigned writelong rmtfile (qvert.y as integer) #unsigned writelong rmtfile (qvert.z as integer) #unsigned if ch_ascii.state==true do format "[%,%,%]," (qvert.x as integer) (qvert.y as integer) (qvert.z as integer) to:rmafile ) ) ) ) if ch_ascii.state==true do format "\n\n" to:rmafile ) else -- UV-version (2d-UV) ( writelong rmtfile (4+tempmesh.numverts*2*UVacc_int) #unsigned -- meshsize append meshsize += 10+tempmesh.numverts*UVacc_int*2 -- data writebyte rmtfile uv #unsigned -- UV channel writebyte rmtfile 0 #unsigned -- no W -- find the biggest UV's for scale. biggestone = 0 for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] for kei=1 to 2 do ( if (abs tvert[kei])>(abs biggestone) do biggestone = tvert[kei] ) ) biggestone=(abs biggestone) as integer writebyte rmtfile biggestone #unsigned -- UV-scale writebyte rmtfile UVaccuracy.state #unsigned -- UV-accuracy qvert = point3 0 0 0 if ch_ascii.state==true do format "MapCoordinate scale: %\nUVs: " biggestone to:rmafile -- actual UV-data case UVaccuracy.state of ( 1: ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] qvert.x = floor(((tvert.x/biggestone)*127)+0.5) qvert.y = floor(((tvert.y/biggestone)*127)+0.5) writebyte rmtfile (qvert.x as integer) #unsigned writebyte rmtfile (qvert.y as integer) #unsigned if ch_ascii.state==true do format "[%,%]," (qvert.x as integer) (qvert.y as integer) to:rmafile ) ) 2: ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] qvert.x = floor (((tvert.x/biggestone)*32767)+0.5) qvert.y = floor (((tvert.y/biggestone)*32767)+0.5) writeshort rmtfile (qvert.x as integer) #unsigned writeshort rmtfile (qvert.y as integer) #unsigned if ch_ascii.state==true do format "[%,%]," (qvert.x as integer) (qvert.y as integer) to:rmafile ) ) 3: ( if ch_RealsAsFloats.state==true then ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] writefloat rmtfile tvert.x writefloat rmtfile tvert.y -- no flip?!?! if ch_ascii.state==true do format "[%,%]," tvert.x tvert.y to:rmafile ) ) else ( for v=1 to vertexcount do ( tvert = getTVert tempmesh UVvertRef[v] qvert.x = ((tvert.x/biggestone)*2147483647) qvert.y = ((tvert.y/biggestone)*2147483647) writelong rmtfile (qvert.x as integer) #unsigned writelong rmtfile (qvert.y as integer) #unsigned if ch_ascii.state==true do format "[%,%]," (qvert.x as integer) (qvert.y as integer) to:rmafile ) ) ) ) -- end of case if ch_ascii.state==true do format "\n\n" to:rmafile ) -- end of else ) -- end of UV-channel ) -- indexbuffers if ch_indices.state == true do ( indexpieces = #() indexpieces = SeparateByMatID tempmesh if indexpieces[1]==undefined do indexpieces[1] = #() -- inspect the indexbuffer accuracy by vertexcount oneindexsize = 0 if tempmesh.numverts<257 do oneindexsize = 1 if tempmesh.numverts>256 AND tempmesh.numverts<65536 do oneindexsize=2 if tempmesh.numverts>65536 do oneindexsize=4 if oneindexsize==0 do ( messagebox "Hälarm! indexsize not set!" return "oneindexsize=0_o" ) if Ibuffertype.state == 1 then ( for ib=1 to indexpieces.count do ( -- header writeshort rmtfile 0x1400 #unsigned writelong rmtfile (7+indexpieces[ib].count*3*oneindexsize) #unsigned -- data writeshort rmtfile ib #unsigned if meshlist[a].material==undefined do meshlist[a].material = standard() currentmat = GiveMaterial meshlist[a] ib if rmtmaterials.count!=0 then ( if currentmat == rmtmaterials[rmtmaterials.count] AND currentmat != undefined then ( writebyte rmtfile rmtmaterials.count #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: %\n" ib rmtmaterials.count to:rmafile ) else ( if currentmat != undefined then ( append rmtmaterials currentmat writebyte rmtfile rmtmaterials.count #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: %\n" ib rmtmaterials.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: 0\n" ib to:rmafile ) ) ) else ( if currentmat != undefined then ( append rmtmaterials currentmat writebyte rmtfile rmtmaterials.count #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: %\n" ib rmtmaterials.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: 0\n" ib to:rmafile ) ) -- indexcount writelong rmtfile (indexpieces[ib].count*3) #unsigned if ch_ascii.state==true do format "IndexCount: %\n\nIndices: " (indexpieces[ib].count*3) to:rmafile -- triangle list case oneindexsize of ( 1: ( for tri = 1 to indexpieces[ib].count do ( tempface = getface tempmesh indexpieces[ib][tri] writebyte rmtfile (tempface.x as integer) #unsigned writebyte rmtfile (tempface.y as integer) #unsigned writebyte rmtfile (tempface.z as integer) #unsigned if ch_ascii.state==true do format "[%,%,%]," (tempface.x as integer) (tempface.y as integer) (tempface.z as integer) to:rmafile ) ) 2: ( for tri = 1 to indexpieces[ib].count do ( tempface = getface tempmesh indexpieces[ib][tri] writeshort rmtfile (tempface.x as integer) #unsigned writeshort rmtfile (tempface.y as integer) #unsigned writeshort rmtfile (tempface.z as integer) #unsigned if ch_ascii.state==true do format "[%,%,%]," (tempface.x as integer) (tempface.y as integer) (tempface.z as integer) to:rmafile ) ) 4: ( for tri = 1 to indexpieces[ib].count do ( tempface = getface tempmesh indexpieces[ib][tri] writelong rmtfile (tempface.x as integer) #signed writelong rmtfile (tempface.y as integer) #signed writelong rmtfile (tempface.z as integer) #signed if ch_ascii.state==true do format "[%,%,%]," (tempface.x as integer) (tempface.y as integer) (tempface.z as integer) to:rmafile ) ) ) if ch_ascii.state==true do format "\n\n" to:rmafile -- meshsize append meshsize += 13+indexpieces[ib].count*3*oneindexsize ) -- end of indexpieces ) else -- triangle strips ( for ib=1 to indexpieces.count do ( writeshort rmtfile 0x1400 #unsigned ibuffersizepos = ftell rmtfile writelong rmtfile 0 #unsigned writeshort rmtfile ib #unsigned if rmtmaterials.count!=0 then ( if currentmat == rmtmaterials[rmtmaterials.count] AND currentmat != undefined then ( writebyte rmtfile rmtmaterials.count #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: %\n" ib rmtmaterials.count to:rmafile ) else ( if currentmat != undefined then ( append rmtmaterials currentmat writebyte rmtfile rmtmaterials.count #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: %\n" ib rmtmaterials.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: 0\n" ib to:rmafile ) ) ) else ( if currentmat != undefined then ( append rmtmaterials currentmat writebyte rmtfile rmtmaterials.count #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: %\n" ib rmtmaterials.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "INDEXBUFFER\n\nIBID: %\nMaterialID: 0\n" ib to:rmafile ) ) AdjTrilist = CreateAdjTris tempmesh indexpieces[ib] for atr=1 to adjtrilist.count do ( hannes=0 hannes = finditem indexpieces[ib] atr if hannes==0 do adjtrilist[atr].used = true ) AdjEdgelist = CreateAdjEdges tempmesh indexpieces[ib] allstripsdone = false finalstripset = #() striplist = #() while allstripsdone!=true do ( tempatrilist = #(#(),#(),#()) -- copy AdjTriList for ar=1 to AdjTriList.count do ( tempatrilist[1][ar] = AdjTriList[ar] tempatrilist[2][ar] = AdjTriList[ar] tempatrilist[3][ar] = AdjTriList[ar] ) tempi = 0 startAtri = 0 -- pick first non-used adjtri for atri=1 to AdjTriList.count do ( if AdjTriList[atri].used==false do ( tempi = AdjTriList[atri] StartAtri = atri exit ) ) if tempi == 0 do ( allstripsdone=true exit ) -- search for lower deg adjtri for atri=1 to AdjTriList.count do ( if AdjTriList[atri].TriRef.countfinalstrip.count do ( finalstrip=strips[str] number = str ) ) case number of ( 1: AdjTriList = tempatrilist[1] 2: AdjTrilist = tempatrilist[2] 3: AdjTrilist = tempatrilist[3] ) if invalid == 0 do append striplist finalstrip ) -- connecting strips of the indexbuffer finalstriplist = #() for st=1 to striplist.count do ( for i=1 to striplist[st].count do ( if striplist[st][i] == undefined do print "NO! NO!" append finalstriplist striplist[st][i] ) if st!=striplist.count do ( append finalstriplist striplist[st][striplist[st].count] append finalstriplist striplist[st+1][1] ) ) -- indexcount for strips writelong rmtfile finalstriplist.count #unsigned if ch_ascii.state==true do format "IndexCount: %\n\nIndices: " finalstriplist.count to:rmafile -- write stripdata case oneindexsize of ( 1: ( for i=1 to finalstriplist.count do ( writebyte rmtfile (finalstriplist[i]-1) #unsigned if ch_ascii.state==true do format "%," (finalstriplist[i]-1) to:rmafile ) ) 2: ( for i=1 to finalstriplist.count do ( writeshort rmtfile (finalstriplist[i]-1) #unsigned if ch_ascii.state==true do format "%," (finalstriplist[i]-1) to:rmafile ) ) 4: ( for i=1 to finalstriplist.count do ( writelong rmtfile (finalstriplist[i]-1) #signed if ch_ascii.state==true do format "%," (finalstriplist[i]-1) to:rmafile ) ) ) if ch_ascii.state==true do format "\n\n" to:rmafile hereiam = ftell rmtfile fseek rmtfile ibuffersizepos #seek_set writelong rmtfile (7+finalstriplist.count*oneindexsize) #unsigned fseek rmtfile hereiam #seek_set -- meshsize append meshsize += 13+finalstriplist.count*oneindexsize ) -- end of indexpieces )-- end of strips )-- end of indexbuffers -- Vertex colors if ch_VCOLs.state==true do ( VCvertRef = #() VAvertRef = #() meshop.setmapsupport tempmesh 0 true meshop.setmapsupport tempmesh -2 true VCvertRef = getMapVertRef tempmesh 0 VAvertRef = getMapVertRef tempmesh -2 -- header writeshort rmtfile 0x1500 #unsigned writelong rmtfile (1+VColacc_int*tempmesh.numverts) #unsigned meshsize += 7+VCOLacc_int*tempmesh.numverts -- data writebyte rmtfile VCOLaccuracy.state #unsigned if ch_ascii.state==true do format "VERTEXCOLORBUFFER\n\nVertexColors: " to:rmafile case VCOLaccuracy.state of ( 1: ( tempvertcolor = #() for v=1 to tempmesh.numverts do ( tempvertcolor = meshop.getmapvert tempmesh 0 VCvertref[v] tempalpha = meshop.getMapVert tempmesh -2 VAvertref[v] col_R = floor((tempvertcolor[1]*3)+0.5) col_G = floor((tempvertcolor[2]*3)+0.5) col_B = floor((tempvertcolor[3]*3)+0.5) col_A = floor((tempalpha[1]+tempalpha[2]+tempalpha[3])+0.5) combinedint = (col_R+col_G*4+col_B*16+col_A*64) writebyte rmtfile combinedint #unsigned if ch_ascii.state==true do format "%," combinedint to:rmafile ) ) 2: ( tempvertcolor = #() for v=1 to tempmesh.numverts do ( tempvertcolor = meshop.getmapvert tempmesh 0 VCvertref[v] tempalpha = meshop.getmapvert tempmesh -2 VAvertref[v] col_R = floor((tempvertcolor[1]*15)+0.5) col_G = floor((tempvertcolor[2]*15)+0.5) col_B = floor((tempvertcolor[3]*15)+0.5) col_A = floor((((tempalpha[1]+tempalpha[2]+tempalpha[3])/3)*15)+0.5) combinedint = (col_R+col_G*16+col_B*256+col_A*4096) writeshort rmtfile combinedint #unsigned if ch_ascii.state==true do format "%," combinedint to:rmafile ) ) 3: ( tempvertcolor = #() for v=1 to tempmesh.numverts do ( tempvertcolor = meshop.getmapvert tempmesh 0 VCvertref[v] tempalpha = meshop.getmapvert tempmesh -2 VAvertref[v] col_R = floor(tempvertcolor[1]*255+0.5) col_G = floor(tempvertcolor[2]*255+0.5) col_B = floor(tempvertcolor[3]*255+0.5) col_A = floor((((tempalpha[1]+tempalpha[2]+tempalpha[3])/3)*255)+0.5) writebyte rmtfile col_R #unsigned writebyte rmtfile col_G #unsigned writebyte rmtfile col_B #unsigned writebyte rmtfile col_A #unsigned if ch_ascii.state==true do format "[%,%,%,%]," col_R col_G col_B col_A to:rmafile ) ) 4: ( tempvertcolor = #() if ch_realsasfloats.state == true then ( for v=1 to tempmesh.numverts do ( tempvertcolor = meshop.getmapvert tempmesh 0 VCvertref[v] tempalpha = meshop.getmapvert tempmesh -2 VAvertref[v] col_R = tempvertcolor[1] col_G = tempvertcolor[2] col_B = tempvertcolor[3] col_A = ((tempalpha[1]+tempalpha[2]+tempalpha[3])/3) writefloat rmtfile col_R writefloat rmtfile col_G writefloat rmtfile col_B writefloat rmtfile col_A if ch_ascii.state==true do format "[%,%,%,%]," col_R col_G col_B col_A to:rmafile ) ) else -- remember to test full unsigned int! ( for v=1 to tempmesh.numverts do ( tempvertcolor = meshop.getmapvert tempmesh 0 VCvertref[v] tempalpha = meshop.getmapvert tempmesh -2 VAvertref[v] col_R = floor((tempvertcolor[1]*2147483647)+0.5) col_G = floor((tempvertcolor[2]*2147483647)+0.5) col_B = floor((tempvertcolor[3]*2147483647)+0.5) col_A = floor((((tempalpha[1]+tempalpha[2]+tempalpha[3])/3)*2147483647)+0.5) writelong rmtfile col_R #unsigned writelong rmtfile col_G #unsigned writelong rmtfile col_B #unsigned writelong rmtfile col_A #unsigned if ch_ascii.state==true do format "[%,%,%,%]," col_R col_G col_B col_A to:rmafile ) ) ) )-- end of case of if ch_ascii.state==true do format "\n\n" to:rmafile )-- end of vertexcolors hereiam = ftell rmtfile fseek rmtfile meshsizepos #seek_set writelong rmtfile meshsize #unsigned fseek rmtfile hereiam #seek_set )-- end of mesh rmtsize += meshsize+10 delete tempmesh ) -- end of a-loop bitmaps = #() shaders = #() if ch_mats.state == true do ( materialsize = 0 for mat=1 to rmtmaterials.count do ( tempmat = rmtmaterials[mat] -- header writeshort rmtfile 0x2000 #unsigned writelong rmtfile 11 #unsigned -- materialID writebyte rmtfile mat #unsigned -- materialdata -- shade shade = 3 if tempmat.faceted == true do shade = 2 if tempmat.selfillumamount>50.0 do shade = 1 -- blend blend = 1 if tempmat.opacity!=100.0 do ( if tempmat.opacitytype == 2 do blend = 3 if tempmat.opacitytype == 1 do blend = 4 if blend == 1 do blend = 2 ) -- perspective correction can be disabled using face map option perspcorr = 1 if tempmat.facemap == true do perspcorr = 0 writebyte rmtfile shade #unsigned writebyte rmtfile blend #unsigned writebyte rmtfile ((tempmat.opacity/100*255) as integer) #unsigned writebyte rmtfile perspcorr #unsigned if ch_ascii.state==true do format "MATERIAL\n\nID: %\nShading: %\nBlending: %\nOpacity: %\nPerspective Correction: %\n\n" mat shade blend tempmat.opacity perspcorr to:rmafile -- poking maps. diffusemap = pokemapslot tempmat.diffusemap reflectionmap = pokemapslot tempmat.reflectionmap lightmap = pokemapslot tempmat.selfillummap glossymap = pokemapslot tempmat.glossinessmap normalmap = pokemapslot tempmat.bumpmap shaderfile = pokemapslot tempmat.filtermap if diffusemap != undefined then ( append bitmaps diffusemap writebyte rmtfile bitmaps.count #unsigned if ch_ascii.state==true do format "DiffuseMap: %\n" bitmaps.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "DiffuseMap: 0\n" to:rmafile ) if reflectionmap != undefined then ( append bitmaps reflectionmap writebyte rmtfile bitmaps.count #unsigned if ch_ascii.state==true do format "ReflectionMap: %\n" bitmaps.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "ReflectionMap: 0\n" to:rmafile ) if lightmap != undefined then ( append bitmaps lightmap writebyte rmtfile bitmaps.count #unsigned if ch_ascii.state==true do format "LightMap: %\n" bitmaps.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "LightMap: 0\n" to:rmafile ) if glossymap != undefined then ( append bitmaps glossymap writebyte rmtfile bitmaps.count #unsigned if ch_ascii.state==true do format "GlossyMap: %\n" bitmaps.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "GlossyMap: 0\n" to:rmafile ) if normalmap != undefined then ( append bitmaps normalmap writebyte rmtfile bitmaps.count #unsigned if ch_ascii.state==true do format "NormalMap: %\n" bitmaps.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "NormalMap: 0\n" to:rmafile ) if shaderfile != undefined then ( append shaders shaderfile writebyte rmtfile shaders.count #unsigned if ch_ascii.state==true do format "ShaderID: %\n" bitmaps.count to:rmafile ) else ( writebyte rmtfile 0 #unsigned if ch_ascii.state==true do format "ShaderID: 0\n" to:rmafile ) if ch_ascii.state==true do format "\n" to:rmafile materialsize+=17 ) -- end of materials if ch_bitmapinfos.state == true do ( for bm=1 to bitmaps.count do ( -- header writeshort rmtfile 0x2100 #unsigned writelong rmtfile (2+bitmaps[bm].count) #unsigned -- data writebyte rmtfile bm #unsigned --writebyte rmtfile (bitmaps[bm].count+1) #unsigned --writestring rmtfile bitmaps[bm] WstringWlength rmtfile bitmaps[bm] if ch_ascii.state==true do format "BITMAPINFO\n\nMapID: %\nFilename: %\n\n" bm bitmaps[bm] to:rmafile materialsize+=(8+bitmaps[bm].count) ) )-- end of bitmapinfos if ch_shaderinfos.state == true do ( for shd=1 to shaders.count do ( -- header writeshort rmtfile 0x2200 #unsigned writelong rmtfile (2+shaders[shd].count) #unsigned -- data writebyte rmtfile shd #unsigned --writebyte rmtfile shaders[shd].count #unsigned --writestring rmtfile shaders[shd] WstringWlength rmtfile shaders[shd] if ch_ascii.state==true do format "SHADERINFO\n\nShaderID: %\nFilename: %\n\n" shd shaders[shd] to:rmafile materialsize+=(8+shaders[shd].count) ) )-- end of shaderinfos rmtsize +=materialsize )-- end of materialstuff hereiam = ftell rmtfile fseek rmtfile rmtsizepos #seek_set writelong rmtfile rmtsize #unsigned fseek rmtfile hereiam #seek_set fclose rmtfile if ch_ascii.state == true do format "\nRMT filesize: %\n" (rmtsize+6) to:rmafile if ch_ascii.state == true do close rmafile ) ) createdialog RMTporter width:400 height:300 bgcolor:backcol )