Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- XnaLara Converter.ms
- -- Maxscript for importing and exporting geometry between 3ds Max and XNALara.
- -- Code beautified by sunnydavis
- -- a newer version for 3ds Max 2013 can be found at http://pastebin.com/pJSriVf9
- -- @author mariokart64n
- -- @date August 2, 2011
- -- @see http://www.tombraiderforums.com/showthread.php?t=181251
- version=maxVersion();if version[1]>=8000 then
- (
- -- Check Version of 3DSMAX
- rollout appGUI "XNALara Converter" width:175 height:315
- (
- button btn1 "IMPORT" pos:[16,8] width:120 height:32
- groupBox grp1 "Import Options" pos:[8,111] width:160 height:86
- editText edt1 "Scale:" pos:[40,89] width:86 height:16 bold:true text:"1.0000"
- checkbox chk1 "Single mesh" pos:[24,129] width:128 height:17 checked:true
- checkbox chk2 "Hide Unused Bones" pos:[24,149] width:140 height:17 checked:true
- checkbox chk3 "Vertex Normals" pos:[24,169] width:128 height:17 enabled:false
- groupBox grp2 "Export Options" pos:[8,201] width:160 height:86
- checkbox chk4 "Selection Only" pos:[24,219] width:128 height:17
- checkbox chk5 "Reparent Bones" pos:[24,239] width:128 height:17
- checkbox chk6 "Optimized Output" pos:[24,259] width:128 height:17 checked:true
- button btn3 "About" pos:[123,291] width:42 height:18
- label lbl2 "v1.1b (08.02.11)" pos:[11,293] width:98 height:17
- button btn1b "+" pos:[140,12] width:24 height:24
- button btn2 "EXPORT" pos:[16,48] width:120 height:32
- button btn2b "+" pos:[140,52] width:24 height:24
- local fsource=""
- local ssource=""
- local boneWarning=""
- local rescale=1
- local boneLimit=58
- local metric_scale=39.3700787
- local imperial_scale=0.0254982
- local boneSize=0.03
- local guessBone=false
- local bsenable=true
- local matNames=true
- local impFixed=false
- local expFixed=false
- on edt1 entered txt do
- (
- if (txt as float)!=undefined then
- (
- if (txt as float)!=0 then(rescale=(txt as float))else(messagebox "Input Invalid\nNumber Must Be Larger Than 0")
- )
- else
- (
- if txt=="bones" then
- (
- rollout exoptions "Extra Options (Some May Not Work)"width:298 height:263
- (
- groupBox grp4_1 "Peanutbutter Jelly Time!" pos:[11,11] width:277 height:243
- editText edt4_1 "Bone Size" pos:[26,37] width:114 height:16 enabled:bsenable text:(boneSize as string) bold:true
- checkbox chk4_1 "Guess Size Instead" pos:[150,36] width:128 height:17 checked:guessBone
- checkbox chk4_2 "Rhand to LHand Coordinates" pos:[27,63] width:221 height:19 enabled:false checked:true
- checkbox chk4_3 "Flip Texture Coordinates" pos:[27,83] width:221 height:19 enabled:false checked:true
- checkbox chk4_4 "Disable Skin on Import" pos:[27,123] width:221 height:19
- checkbox chk4_5 "Disable Mesh on Import" pos:[27,143] width:221 height:19
- checkbox chk4_6 "Disable Bones on Import" pos:[27,163] width:221 height:19
- checkbox chk4_7 "Disable Mats on Import" pos:[27,183] width:221 height:19
- checkbox chk4_8 "Export With Material Names" pos:[27,103] width:221 height:19 enabled:true checked:true
- editText edt4_2 "in<->cm" pos:[36,210] width:103 height:16 text:(metric_scale as string) bold:true
- editText edt4_3 "cm<->in" pos:[153,210] width:103 height:16 text:(imperial_scale as string) bold:true
- editText edt4_4 "Bone Limit" pos:[36,230] width:103 height:16 text:(boneLimit as string) bold:true
- on edt4_2 entered txt4 do (if (txt4 as float)!=undefined do metric_scale=(txt4 as float))
- on edt4_3 entered txt4 do (if (txt4 as float)!=undefined do imperial_scale=(txt4 as float))
- on edt4_4 entered txt4 do (if (txt4 as float)!=undefined do boneLimit=(txt4 as float))
- on chk4_1 changed theState do
- (
- if theState==false do edt4_1.enabled=true; bsenable=true;guessBone=false
- if theState==true do(edt4_1.enabled=false; bsenable=false;guessBone=true; boneSize=0)
- )
- on edt4_1 entered txt4 do(if (txt4 as float)!=undefined do boneSize=(txt4 as float))
- )
- createDialog exoptions
- )
- else(messagebox "Input Invalid\nPlease Supply A Number")
- )
- )
- on chk4_8 changed theState do matNames=theState
- on btn1b pressed do
- (
- if fsource==undefined do fsource=""
- rollout impPath "Open from Fixed Path" width:303 height:69
- (
- editText edt1b_1 "Path: " pos:[9,8] width:282 height:16 text:fsource
- button btn1b_1 "Browse" pos:[225,29] width:63 height:21
- checkbox chk1b_1 "Use Fixed Path" pos:[48,27] width:126 height:20 checked:impFixed
- on chk1b_1 changed theState do impFixed=theState
- on edt1b_1 entered txt do fsource=txt
- on btn1b_1 pressed do
- (
- fsource = GetOpenFileName \
- caption:"Open XnaLara MESH Model File" \
- types: "Binary(*.mesh)|*.MESH|Text(*.ascii)|*.ASCII|"
- if fsource!=undefined do edt1b_1.text=fsource
- )
- )
- createDialog impPath
- )
- on btn2b pressed do
- (
- if ssource==undefined do ssource=""
- rollout expPath "Save to Fixed Path" width:303 height:69
- (
- editText edt2b_1 "Path: " pos:[9,8] width:282 height:16 text:ssource
- button btn2b_1 "Browse" pos:[225,29] width:63 height:21
- checkbox chk2b_1 "Use Fixed Path" pos:[48,27] width:126 height:20 checked:expFixed
- on chk2b_1 changed theState do expFixed=theState
- on edt2b_1 entered txt do ssource=txt
- on btn2b_1 pressed do
- (
- ssource = getSaveFileName \
- caption:"Save XnaLara ASCII Model File" \
- types: "Text(*.ascii)|*.ASCII|All files (*.*)|*.*|"
- if ssource!=undefined do edt2b_1.text=ssource
- )
- )
- createDialog expPath
- )
- on btn1 pressed do
- (
- if impFixed==false OR fsource==""do
- (
- fsource = GetOpenFileName \
- caption:"Open XnaLara MESH Model File" \
- types: "Binary(*.mesh)|*.MESH|Text(*.ascii)|*.ASCII|"
- )
- if fsource!=""AND fsource!=undefined then
- (
- if (doesFileExist fsource)==true then
- (
- fext= getFilenameType fsource
- fpath= getFilenamePath fsource
- fname= getFilenameFile fsource
- fsize= getFileSize fsource
- if fext==".mesh" do
- (
- f = fopen fsource "rb"
- st = timestamp() --get start time in milliseconds
- ts = timestamp()
- --===========================================================================
- undo off
- (
- fn ReadFixedString bstream fixedLen =
- (
- local str = ""
- for i = 1 to fixedLen do
- (
- str += bit.intAsChar (ReadByte bstream #unsigned)
- )
- str
- )
- --===========================================================================
- with redraw off
- (
- scaling=metric_scale*rescale -- converts inces to centimeters !! damn Imperial System, Metric FTW
- mshHde=chk2.checked
- mshSingle=chk1.checked
- normON=chk3.checked
- skinON=true
- meshON=true
- boneON=true
- matON=true
- struct vertex_data
- (
- position,normal,texture,texture2,texture3,channels,colour,boneids,weights
- )
- struct bone_data
- (
- bName,parent,child,posX,posY,posZ
- )
- BNArr = #()
- -- Bone Section
- -- ===========================================================================
- Print ("Section 01: Bones @ 0x"+((bit.intAsHex(ftell f))as string))
- boneCount=readlong f #unsigned
- boneBuffer = (bone_data bName:#() parent:#() child:#() posX:#() posY:#() posZ:#())
- for i = 1 to boneCount do
- (
- append boneBuffer.bName (ReadFixedString f (readbyte f #unsigned))
- append boneBuffer.parent (readshort f+1)
- append boneBuffer.child -1
- append boneBuffer.posX (readfloat f*scaling)
- append boneBuffer.posZ (readfloat f*scaling)
- append boneBuffer.posY (readfloat f*-scaling)
- )
- if boneON==true do
- (
- for i = 1 to boneCount do
- (
- childIndex=boneBuffer.parent[i]
- if childIndex!=0 do
- (
- if boneBuffer.child[childIndex]==-1 then
- (
- boneBuffer.child[childIndex] = i
- )
- else
- (
- boneBuffer.child[childIndex] = 0
- )
- )
- )
- for i = 1 to boneCount do
- (
- startPos=[(boneBuffer.posX[i]),(boneBuffer.posY[i]),(boneBuffer.posZ[i])]
- endPos=startPos
- childIndex=boneBuffer.child[i]
- if childIndex>=1 then
- (
- endPos=[(boneBuffer.posX[childIndex]),(boneBuffer.posY[childIndex]),(boneBuffer.posZ[childIndex])]
- )
- else
- (
- if boneBuffer.parent[i]!=0 do
- (
- endPos=[(boneBuffer.posX[(boneBuffer.parent[i])]),(boneBuffer.posY[(boneBuffer.parent[i])]),(boneBuffer.posZ[(boneBuffer.parent[i])])]
- endPos=startPos+((startPos-endPos))
- )
- )
- bonSize=boneSize*scaling
- if bsenable==true or boneSize==0 or boneSize==undefined do
- (
- bonSize=((distance startPos endPos)/100)*scaling
- )
- newBone = bonesys.createbone startPos endPos [0,0,1]
- newBone.name = boneBuffer.bName[i]
- newBone.width = bonSize
- newBone.height = bonSize
- if boneBuffer.parent[i] !=0 do newBone.parent = BNArr[boneBuffer.parent[i]]
- append BNArr newBone
- if childIndex<=1 do newBone.length=0.06*scaling
- if mshHde==true do
- (
- bName=skipToString (boneBuffer.bName[i] as stringstream) "unused"
- if bName==OK do
- (
- hide newBone
- )
- )
- )
- )
- -- bone enable loop
- Print("Bone Collection: ("+(((timestamp())-ts)as string)+" Milli Seconds)");ts = timestamp()
- -- Mesh Section
- -- ===========================================================================
- Print ("Section 02: Meshes @ 0x"+((bit.intAsHex(ftell f))as string))
- meshCount=readlong f #unsigned
- mm = MultiMaterial()
- mm.numsubs=meshCount
- faceAdder=1
- -- meshCount=1
- texArray=#()
- faceArray=#()
- faceDimArray=#()
- boneArray=#()
- uvChnArray=#()
- vertBuffer = (vertex_data position:#() normal:#() channels:#() texture:#() texture2:#() texture3:#() colour:#() boneids:#() weights:#())
- for i = 1 to meshCount do
- (
- mat=mm.materialList[i]
- matSpec=30
- matBump1=1
- matBump2=1
- matType=undefined
- texOpacity=false
- texLight=false
- texBump=false
- texSpec=false
- texIllum=false
- texSpecMap=false
- texMask=false
- texDetail1=false
- texDetail2=false
- texReflect=false
- texStatic=false
- matSpec=30
- matBump1=4
- matBump2=4
- texArray=#()
- if mshSingle==false do
- (
- --reset arrays
- faceArray=#()
- boneArray=#()
- uvChnArray=#()
- vertBuffer = (vertex_data position:#() normal:#() channels:#() texture:#() texture2:#() texture3:#() colour:#() boneids:#() weights:#())
- )
- mshName=ReadFixedString f (readbyte f #unsigned)
- if (findString mshName "_")!=undefined do
- (
- genItmName=filterString mshName "_"
- matType=genItmName[1] as integer
- mshName=genItmName[2]
- if (genItmName.count)>=3 do
- (
- if (genItmName[3] as float)!=undefined then
- (
- matSpec=(genItmName[3] as float)*100
- matBump1=genItmName[4] as float
- matBump2=genItmName[5] as float
- )
- else
- (
- -- this can get fucked up if there are too many _ in the mesh name .. ohwell
- matSpec=10
- matBump1=1
- matBump2=1
- )
- -- append texProp [matSpec,matBump1,matBump1]
- for c = 6 to genItmName.count do
- (
- mshCamTar=genItmName[c]
- )
- )
- )
- -- Camera Is Ignored, who the fuck saves cam info on a char model.
- uvwCount=readlong f #unsigned
- texCount=readlong f #unsigned
- for x = 1 to texCount do
- (
- texName=ReadFixedString f (readbyte f #unsigned)
- uvLayer=(readlong f #unsigned)+1 -- which UV layer to use.
- if uvLayer>=2 do uvLayer+=1 --max compatiblity.. cannot use layer 2
- append uvChnArray uvLayer
- append texArray (fpath+(filenameFromPath texName))
- )
- if matON==true do
- (
- if matType==undefined then
- (
- -- Not GenericItem, Trying to Detect Material Type
- texOpacity=true
- texSpec=true
- for x = 1 to texArray.count do
- (
- if (skipToString (texArray[x] as stringstream) "_lightmap")==OK do(texLight=true)
- if (skipToString (texArray[x] as stringstream) "_bump")==OK do(texBump=true)
- if (skipToString (texArray[x] as stringstream) "_mask")==OK do(texMask=true)
- if (skipToString (texArray[x] as stringstream) "_bump1")==OK do(texDetail1=true)
- if (skipToString (texArray[x] as stringstream) "_bump2")==OK do(texDetail2=true)
- -- 7 Yes Yes Yes No No No 1 Diffuse
- -- 9 Yes Yes Yes No No No 2 Diffuse, Lightmap
- -- 6 Yes Yes Yes Yes No No 2 Diffuse, Bumpmap
- -- 8 Yes Yes Yes Yes No No 3 Diffuse, Lightmap, Bumpmap
- -- 20 Yes Yes Yes Yes Yes Yes 6 Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2
- )
- if (skipToString (mshName as stringstream) "collar")==OK do
- (
- matSpec=10
- matBump1=12
- matBump2=12
- )
- if (skipToString (mshName as stringstream) "gear")==OK do
- (
- matSpec=10
- matBump1=12
- matBump2=12
- )
- if (skipToString (mshName as stringstream) "belt")==OK do
- (
- matSpec=10
- matBump1=10
- matBump2=20
- )
- if (skipToString (mshName as stringstream) "suit")==OK do
- (
- matSpec=30
- matBump1=24
- matBump2=48
- )
- )
- else
- (
- -- ================================================================
- -- Standard Materials (CANNOT DO TRANSPARANCY)
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if matType == 10 do
- (
- -- Diffuse Only, High Emssive. Good For Anime Models
- texIllum=true
- )
- if matType == 5 do
- (
- -- Diffuse Only. Good As A Quick Material
- )
- if matType == 3 do
- (
- -- Lightmap
- texLight=true
- )
- if matType == 4 do
- (
- -- NormalMap + Spec
- texSpec=true
- texBump=true
- )
- if matType == 2 do
- (
- -- NormalMap + Spec + LightMap
- texSpec=true
- texLight=true
- texBump=true
- )
- if matType == 24 do
- (
- -- NormalMap + SpecMap + LightMap
- texSpec=true
- texSpecMap=true
- texLight=true
- texBump=true
- )
- if matType == 26 do
- (
- -- NormalMap + EnvMap
- texSpec=true
- texReflect=true
- texLight=true
- texBump=true
- )
- if matType == 28 do
- (
- -- NormalMap + DetailMap + EnvMap
- texReflect=true
- texSpec=true
- texBump=true
- texMask=true
- texDetail1=true
- texDetail2=true
- )
- if matType == 1 do
- (
- -- NormalMap + DetailMap + Spec + LightMap
- texSpec=true
- texLight=true
- texBump=true
- texMask=true
- texDetail1=true
- texDetail2=true
- )
- if matType == 22 do
- (
- -- NormalMap + DetailMap + SpecMap + LightMap
- texSpec=true
- texSpecMap=true
- texLight=true
- texBump=true
- texMask=true
- texDetail1=true
- texDetail2=true
- )
- -- ================================================================
- -- Transparent Materials
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if matType == 21 do
- (
- -- Diffuse Only, High Emissive. Good For Anime Models
- texOpacity=true
- texIllum=true
- )
- if matType == 7 do
- (
- -- Diffuse Only. Good As A Quick Material
- texOpacity=true
- )
- if matType == 9 do
- (
- -- Lightmap
- texOpacity=true
- texLight=true
- )
- if matType == 6 do
- (
- -- NormalMap + Spec
- texOpacity=true
- texSpec=true
- texBump=true
- )
- if matType == 8 do
- (
- -- NormalMap + Spec + LightMap
- texOpacity=true
- texSpec=true
- texLight=true
- texBump=true
- )
- if matType == 25 do
- (
- -- NormalMap + SpecMap + LightMap
- texOpacity=true
- texSpec=true
- texSpecMap=true
- texLight=true
- texBump=true
- )
- if matType == 27 do
- (
- -- NormalMap + EnvMap
- texOpacity=true
- texSpec=true
- texReflect=true
- texBump=true
- )
- if matType == 29 do
- (
- -- NormalMap + DetailMap + EnvMap
- texOpacity=true
- texReflect=true
- texSpec=true
- texBump=true
- texMask=true
- texDetail1=true
- texDetail2=true
- )
- if matType == 20 do
- (
- -- NormalMap + DetailMap + Spec + LightMap
- texOpacity=true
- texSpec=true
- texLight=true
- texBump=true
- texMask=true
- texDetail1=true
- texDetail2=true
- )
- if matType == 23 do
- (
- -- NormalMap + DetailMap + SpecMap + LightMap
- texOpacity=true
- texSpec=true
- texSpecMap=true
- texLight=true
- texBump=true
- texMask=true
- texDetail1=true
- texDetail2=true
- )
- -- ================================================================
- -- Extra Materials (Redunant Materials Mirrored for Static Models?)
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if matType == 13 do
- (
- -- Diffuse Only, High Emissive (Good for SkyBoxes)
- texStatic=true
- texIllum=true
- )
- if matType == 14 do
- (
- -- NormalMap, High Emissive
- texStatic=true
- texIllum=true
- texSpec=true
- texBump=true
- )
- if matType == 16 do
- (
- -- Diffuse Only
- texStatic=true
- )
- if matType == 11 do
- (
- -- NormalMap
- texStatic=true
- texSpec=true
- texBump=true
- )
- if matType == 17 do
- (
- -- LightMap
- texStatic=true
- texLight=true
- )
- if matType == 18 do
- (
- -- Transparent, Diffuse Only
- texStatic=true
- texOpacity=true
- )
- if matType == 19 do
- (
- -- Transparent, LightMap
- texStatic=true
- texOpacity=true
- texLight=true
- )
- if matType == 12 do
- (
- -- Transparent, NormalMap
- texStatic=true
- texOpacity=true
- texSpec=true
- texBump=true
- )
- if matType == 15 do
- (
- -- Transparent, NormalMap + High Emissive (Good For SkyBoxes)
- texStatic=true
- texOpacity=true
- texIllum=true
- texSpec=true
- texBump=true
- )
- -- ================================================================
- )
- if texSpec==true then
- (
- if texOpacity==false then
- (
- mat.specularLevel = matSpec
- )
- else
- (
- if texSpecMap==false then
- (
- mat.specularLevelMapAmount = matSpec
- mat.specularLevelMap = Bitmaptexture fileName:texArray[1]
- -- mat.specularLevelMap.effectsChannel = uvChnArray[1]
- mat.specularLevelMap.coords.mapChannel = uvChnArray[1]
- -- mat.monoOutput = 1
- -- mat.alphaSource = 0
- -- mat.preMultAlpha = off
- )
- else
- (
- if texMask==false then
- (
- mat.specularLevelMap = Bitmaptexture fileName:texArray[4]
- -- mat.specularLevelMap.effectsChannel = uvChnArray[4]
- mat.specularLevelMap.coords.mapChannel = uvChnArray[4]
- )
- else
- (
- mat.specularLevelMap = Bitmaptexture fileName:texArray[7]
- -- mat.specularLevelMap.effectsChannel = uvChnArray[7]
- mat.specularLevelMap.coords.mapChannel = uvChnArray[7]
- )
- )
- )
- )
- else(mat.specularLevel = 0)
- if texIllum==true do
- (
- mat.selfIllumAmount = 100
- )
- mat.diffuseMap = Bitmaptexture fileName:texArray[1]
- -- mat.diffuseMap.effectsChannel = uvChnArray[1]
- mat.diffuseMap.coords.mapChannel = uvChnArray[1]
- mat.diffuseMap.monoOutput = 1
- mat.diffuseMap.alphaSource = 2
- mat.diffuseMap.preMultAlpha = on
- if texOpacity==true do
- (
- mat.opacityMap = Bitmaptexture fileName:texArray[1]
- -- mat.opacityMap.effectsChannel = uvChnArray[1]
- mat.opacityMap.coords.mapChannel = uvChnArray[1]
- mat.opacityMap.monoOutput = 1
- mat.opacityMap.alphaSource = 0
- mat.opacityMap.preMultAlpha = off
- )
- if texLight==true do
- (
- matMod=RGB_Multiply ()
- matMod.map1 = mat.diffuseMap
- -- matMod.map1.effectsChannel = texArray[1]
- matMod.map2 = Bitmaptexture fileName:texArray[2]
- -- matMod.map2.effectsChannel = texArray[2]
- matMod.map1.coords.mapChannel = uvChnArray[1]
- matMod.map2.coords.mapChannel = uvChnArray[2]
- matMod.map1Enabled = true
- matMod.map2Enabled = true
- matMod.alphaFrom = 0
- mat.diffuseMap = matMod
- )
- if texBump==true do
- (
- mat.bumpMapEnable = on
- mat.bumpMapAmount = 100
- matMod=Normal_Bump ()
- if texLight==false then
- (
- matMod.map1on = true
- matMod.normal_map = Bitmaptexture fileName:texArray[2]
- -- matMod.normal_map.effectsChannel = uvChnArray[2]
- matMod.normal_map.coords.mapChannel = uvChnArray[2]
- if texMask==true do
- (
- maskMod1 = Mask ()
- maskMod2 = Mask ()
- layerMod = CompositeTexturemap ()
- tintMod = RGB_Tint ()
- tintMod.red = color 255 255 255
- tintMod.green = color 0 0 0
- tintMod.blue = color 0 0 0
- tintMod.map1 = Bitmaptexture fileName:texArray[3]
- -- tintMod.map1.effectsChannel = uvChnArray[4]
- tintMod.map1.coords.mapChannel = uvChnArray[3]
- tintMod.map1Enabled = true
- maskMod1.mask = tintMod
- tintMod = RGB_Tint ()
- tintMod.red = color 0 0 0
- tintMod.green = color 255 255 255
- tintMod.blue = color 0 0 0
- tintMod.map1 = Bitmaptexture fileName:texArray[3]
- -- tintMod.map1.effectsChannel = uvChnArray[5]
- tintMod.map1.coords.mapChannel = uvChnArray[3]
- tintMod.map1Enabled = true
- maskMod2.mask = tintMod
- maskMod1.map = Bitmaptexture fileName:texArray[4]
- maskMod2.map = Bitmaptexture fileName:texArray[5]
- -- maskMod1.map.effectsChannel = uvChnArray[3]
- -- maskMod2.map.effectsChannel = uvChnArray[3]
- maskMod1.map.coords.mapChannel = uvChnArray[4]
- maskMod2.map.coords.mapChannel = uvChnArray[5]
- maskMod1.map.coords.u_tiling = matBump1
- maskMod1.map.coords.v_tiling = matBump1
- maskMod2.map.coords.u_tiling = matBump2
- maskMod2.map.coords.v_tiling = matBump2
- maskMod1.mapEnabled = true
- maskMod2.mapEnabled = true
- maskMod1.maskEnabled = true
- maskMod2.maskEnabled = true
- maskMod1.maskInverted = false
- maskMod2.maskInverted = false
- layerMod.mapList.count=2
- layerMod.mapEnabled[1] = on
- layerMod.mapEnabled[2] = on
- layerMod.mapList[1] = maskMod1
- layerMod.mapList[2] = maskMod2
- matMod.bump_map = layerMod
- matMod.map2on = true
- )
- )
- else
- (
- matMod.map1on = true
- matMod.normal_map = Bitmaptexture fileName:texArray[3]
- -- matMod.normal_map.effectsChannel = uvChnArray[3]
- matMod.normal_map.coords.mapChannel = uvChnArray[3]
- if texMask==true do
- (
- maskMod1 = Mask ()
- maskMod2 = Mask ()
- layerMod = CompositeTexturemap ()
- tintMod = RGB_Tint ()
- tintMod.red = color 255 255 255
- tintMod.green = color 0 0 0
- tintMod.blue = color 0 0 0
- tintMod.map1 = Bitmaptexture fileName:texArray[4]
- -- tintMod.map1.effectsChannel = uvChnArray[5]
- tintMod.map1.coords.mapChannel = uvChnArray[4]
- tintMod.map1Enabled = true
- maskMod1.mask = tintMod
- tintMod = RGB_Tint ()
- tintMod.red = color 0 0 0
- tintMod.green = color 255 255 255
- tintMod.blue = color 0 0 0
- tintMod.map1 = Bitmaptexture fileName:texArray[4]
- tintMod.map1.coords.mapChannel = uvChnArray[4]
- tintMod.map1Enabled = true
- maskMod2.mask = tintMod
- maskMod1.map = Bitmaptexture fileName:texArray[5]
- maskMod2.map = Bitmaptexture fileName:texArray[6]
- -- maskMod1.map.effectsChannel = uvChnArray[4]
- -- maskMod2.map.effectsChannel = uvChnArray[4]
- maskMod1.map.coords.mapChannel = uvChnArray[5]
- maskMod2.map.coords.mapChannel = uvChnArray[6]
- maskMod1.map.coords.u_tiling = matBump1
- maskMod1.map.coords.v_tiling = matBump1
- maskMod2.map.coords.u_tiling = matBump2
- maskMod2.map.coords.v_tiling = matBump2
- maskMod1.mapEnabled = true
- maskMod2.mapEnabled = true
- maskMod1.maskEnabled = true
- maskMod2.maskEnabled = true
- maskMod1.maskInverted = false
- maskMod2.maskInverted = false
- layerMod.mapList.count=2
- layerMod.mapEnabled[1] = on
- layerMod.mapEnabled[2] = on
- layerMod.mapList[1] = maskMod1
- layerMod.mapList[2] = maskMod2
- matMod.bump_map = layerMod
- matMod.map2on = true
- )
- )
- -- matMod.alphaSource = 2
- -- matMod.filtering = 2
- -- matMod.alphaSource = 2
- mat.bumpMap = matMod
- )
- if texReflect==true do
- (
- mat.reflectionMapEnable = on
- mat.reflectionMapAmount = 30
- if texMask==false then
- (
- mat.reflectionMap = Bitmaptexture fileName:texArray[3]
- -- matMod.map2.effectsChannel = texArray[3]
- matMod.map2.coords.mapChannel = uvChnArray[3]
- )
- else
- (
- mat.reflectionMap = Bitmaptexture fileName:texArray[6]
- -- matMod.map2.effectsChannel = texArray[6]
- matMod.map2.coords.mapChannel = uvChnArray[6]
- )
- )
- showTextureMap mat true
- )
- vertCount=readlong f #unsigned
- for x = 1 to vertCount do
- (
- vx=readfloat f*scaling
- vz=readfloat f*scaling
- vy=readfloat f*-scaling
- nx=readfloat f*scaling
- nz=readfloat f*scaling
- ny=readfloat f*-scaling
- cr=readbyte f #unsigned
- cg=readbyte f #unsigned
- cb=readbyte f #unsigned
- ca=readbyte f #unsigned/255
- for y = 1 to uvwCount do
- (
- if y==1 do append vertBuffer.texture [(readfloat f),(readfloat f*-1),0]
- if y==2 do append vertBuffer.texture2 [(readfloat f),(readfloat f*-1),0]
- if y==3 do append vertBuffer.texture3 [(readfloat f),(readfloat f*-1),0]
- )
- for y = 1 to uvwCount do
- (
- -- Skips Vertex Tangents, (3dsmax doesn't support tangents.)
- fseek f (4*4) #seek_cur
- )
- if boneCount!=0 do
- (
- b1 = readshort f #unsigned+1
- b2 = readshort f #unsigned+1
- b3 = readshort f #unsigned+1
- b4 = readshort f #unsigned+1
- w1 = readfloat f
- w2 = readfloat f
- w3 = readfloat f
- w4 = readfloat f
- if b1!=0 do
- (
- find=findItem boneArray b1
- if find==0 do( append boneArray b1)
- )
- if b2!=0 do
- (
- find=findItem boneArray b2
- if find==0 do( append boneArray b2)
- )
- if b3!=0 do
- (
- find=findItem boneArray b3
- if find==0 do( append boneArray b3)
- )
- if b4!=0 do
- (
- find=findItem boneArray b4
- if find==0 do( append boneArray b4)
- )
- append vertBuffer.boneids [b1,b2,b3,b4]
- append vertBuffer.weights [w1,w2,w3,w4]
- )
- append vertBuffer.position [vx,vy,vz]
- append vertBuffer.normal [nx,ny,nz]
- append vertBuffer.colour [cr,cg,cb,ca]
- )
- faceCount=readlong f #unsigned
- for x = 1 to faceCount do
- (
- fc = readlong f + faceAdder
- fb = readlong f + faceAdder
- fa = readlong f + faceAdder
- append faceArray[fa,fb,fc]
- )
- if meshON==true do
- (
- if mshSingle==false then
- (
- msh = mesh vertices:vertBuffer.position faces:faceArray
- msh.numTVerts = vertCount
- buildTVFaces msh
- msh.name = mshName
- msh.material=mat
- for j = 1 to vertCount do meshop.setVertColor msh 0 j (color vertBuffer.colour[j][1] vertBuffer.colour[j][2] vertBuffer.colour[j][3])
- for j = 1 to vertCount do meshop.setVertAlpha msh -2 j vertBuffer.colour[j][4]
- for j = 1 to vertCount do setTVert msh j vertBuffer.texture[j]
- -- for j = 1 to vertCount do setNormal msh j vertBuffer.normal[j] -- Normals Don't Stick, lost when modifers are added
- for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
- if uvwCount==2 do
- (
- meshop.setNumMaps msh 3 keep:true
- for j = 1 to vertCount do (meshOp.setMapVert msh 2 j vertBuffer.texture2[j])
- )
- if uvwCount==3 do
- (
- meshop.setNumMaps msh 4 keep:true
- for j = 1 to vertCount do (meshOp.setMapVert msh 3 j vertBuffer.texture3[j])
- )
- max modify mode
- if skinON==true do
- (
- clearSelection()
- select msh
- skinMod = skin ()
- addModifier msh skinMod
- for i = 1 to boneArray.count do
- (
- if 1 != boneArray.count then
- (
- skinOps.addBone skinMod BNArr[(boneArray[i])] 0
- )
- else
- (
- skinOps.addBone skinMod BNArr[(boneArray[i])] 1
- )
- )
- modPanel.setCurrentObject skinMod
- for i = 1 to vertCount do
- (
- bi = #()
- wv = #()
- for j = 1 to 4 do
- (
- boneid = vertBuffer.boneids[i][j]
- weight = vertBuffer.weights[i][j]
- if weight!=0 do
- (
- append bi (findItem boneArray boneid)
- append wv weight
- )
- )
- skinOps.ReplaceVertexWeights skinMod i bi wv
- )
- )
- --enable skin loop
- if normON==true do
- (
- clearSelection()
- select msh
- normMod = Edit_Normals()
- addModifier msh normMod
- normMod.displayLength = 1
- -- subobjectLevel = 1
- -- modPanel.setCurrentObject normMod
- for n = 1 to (normMod.GetNumFaces node:msh) do
- (
- -- norm=normMod.GetNormal n node:msh
- -- print norm
- vertID=getFace msh n
- normMod.displayLength = 0
- subobjectLevel = 1
- modPanel.setCurrentObject normMod
- for c = 1 to 3 do
- (
- normID=normMod.GetNormalID n c node:msh
- normMod.EditNormalsMod.SetSelection #{normID}
- normMod.EditNormalsMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
- normMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
- normMod.EditNormalsMod.MakeExplicit ()
- normMod.EditNormalsMod.SetSelection #{}
- )
- )
- subobjectLevel = 0
- -- update msh
- modPanel.setCurrentObject normMod
- )
- -- enable normals loop
- )
- else
- (
- mat.name = mshName
- faceAdder+=vertCount
- append faceDimArray faceCount
- )
- )
- --useless loop lol
- )
- -- ends mesh loop
- if mshSingle==true do
- (
- vertCount=vertBuffer.position.count
- msh = mesh vertices:vertBuffer.position faces:faceArray
- msh.numTVerts = vertCount
- buildTVFaces msh
- msh.name = fname
- msh.material=mm
- faceAdder=0
- for j = 1 to meshCount do (for x = 1 to faceDimArray[j] do(faceAdder+=1;setFaceMatID msh faceAdder j))
- for j = 1 to vertCount do meshop.setVertColor msh 0 j (color vertBuffer.colour[j][1] vertBuffer.colour[j][2] vertBuffer.colour[j][3])
- for j = 1 to vertCount do meshop.setVertAlpha msh -2 j vertBuffer.colour[j][4]
- for j = 1 to vertCount do setTVert msh j vertBuffer.texture[j]
- -- for j = 1 to vertCount do setNormal msh j vertBuffer.normal[j] -- Normals Don't Stick, lost when modifers are added
- for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
- if uvwCount==2 do
- (
- meshop.setNumMaps msh 3 keep:true
- for j = 1 to vertCount do (meshOp.setMapVert msh 2 j vertBuffer.texture2[j])
- )
- if uvwCount==3 do
- (
- meshop.setNumMaps msh 4 keep:true
- for j = 1 to vertCount do (meshOp.setMapVert msh 3 j vertBuffer.texture3[j])
- )
- max modify mode
- if skinON==true do
- (
- clearSelection()
- select msh
- skinMod = skin ()
- addModifier msh skinMod
- for i = 1 to boneArray.count do
- (
- if 1 != boneArray.count then
- (
- skinOps.addBone skinMod BNArr[(boneArray[i])] 0
- )
- else
- (
- skinOps.addBone skinMod BNArr[(boneArray[i])] 1
- )
- )
- modPanel.setCurrentObject skinMod
- for i = 1 to vertCount do
- (
- bi = #()
- wv = #()
- for j = 1 to 4 do
- (
- boneid = vertBuffer.boneids[i][j]
- weight = vertBuffer.weights[i][j]
- if weight!=0 do
- (
- append bi (findItem boneArray boneid)
- append wv weight
- )
- )
- skinOps.ReplaceVertexWeights skinMod i bi wv
- )
- )
- --enable skin loop
- if normON==true do
- (
- clearSelection()
- select msh
- normMod = Edit_Normals()
- addModifier msh normMod
- normMod.displayLength = 1
- -- subobjectLevel = 1
- -- modPanel.setCurrentObject normMod
- for n = 1 to (normMod.GetNumFaces node:msh) do
- (
- -- norm=normMod.GetNormal n node:msh
- -- print norm
- vertID=getFace msh n
- normMod.displayLength = 0
- subobjectLevel = 1
- modPanel.setCurrentObject normMod
- for c = 1 to 3 do
- (
- normID=normMod.GetNormalID n c node:msh
- normMod.EditNormalsMod.SetSelection #{normID}
- normMod.EditNormalsMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
- normMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
- normMod.EditNormalsMod.MakeExplicit ()
- normMod.EditNormalsMod.SetSelection #{}
- )
- )
- subobjectLevel = 0
- -- update msh
- modPanel.setCurrentObject normMod
- )
- -- enable normals loop
- )
- if fsize!=(ftell f) then
- (
- Print ("Done ! @ 0x"+((bit.intAsHex(ftell f))as string))
- )
- else(Print "END OF FILE REACHED")
- gc()
- fclose f
- flushLog()
- closeLog()
- enableSceneRedraw()
- )
- )
- )
- -- Close mesh ext Loop
- if fext==".ascii" do
- (
- f=MemStreamMgr.openFile fsource
- fext= getFilenameType fsource
- fpath= getFilenamePath fsource
- fname= getFilenameFile fsource
- st = timestamp() --get start time in milliseconds
- ts = timestamp()
- clearlistener()
- openLog (fpath+fname+"_log.txt") mode:"w" outputOnly:true
- print (localTime+"\n"+fname+fext)
- --===========================================================================
- undo off
- (
- --===========================================================================
- with redraw off
- (
- struct bone_data
- (
- bName,parent,child,position
- )
- boneBuffer = (bone_data bName:#() parent:#() child:#() position:#())
- boneCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
- for i = 1 to boneCount do
- (
- boneName=f.readLine()
- boneParent=f.readLine()
- bonePosition=f.readLine()
- -- bonePosition=bonePosition as stringstream
- append boneBuffer.bName boneName
- -- append boneBuffer.parent ((boneParent as integer)+1)
- -- append boneBuffer.position [(readDelimitedString bonePosition " " as float), \
- -- (readDelimitedString bonePosition " " as float),(readDelimitedString bonePosition "" as float)]
- )
- renderGroups=#()
- renderSettings=#()
- meshCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
- Print ("\nBone Count: "+(boneCount as string)+"\nMesh Count: "+(meshCount as string)+"\n")
- for i = 1 to meshCount do
- (
- meshName=f.readLine(); Print meshName
- append renderGroups ((readDelimitedString (meshName as stringstream) "_") as integer)
- append renderSettings ((readDelimitedString (meshName as stringstream) "_") as float)
- append renderSettings ((readDelimitedString (meshName as stringstream) "_") as float)
- uvwCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
- texCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
- print ((texCount as string)+" Textures, "+(uvwCount as string)+" UV Layers")
- for x = 1 to texCount do
- (
- texName=f.readLine()
- uvLayer=((readDelimitedString (f.readLine() as stringstream) " ") as integer)+1
- print ((filenameFromPath texName)+" ["+(uvLayer as string)+"]")
- )
- print ""
- vertCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
- for x = 1 to vertCount do
- (
- meshPosition=f.readLine()
- meshNormal=f.readLine()
- meshColour=f.readLine()
- for y = 1 to uvwCount do
- (
- meshUVW=f.readLine()
- )
- if boneCount!=0 do
- (
- boneIndices=f.readLine()
- boneWeights=f.readLine()
- -- b1 = (readDelimitedString boneIndices " " as integer)+1
- -- b2 = (readDelimitedString boneIndices " " as integer)+1
- -- b3 = (readDelimitedString boneIndices " " as integer)+1
- -- b4 = (readDelimitedString boneIndices "" as integer)+1
- -- w1 = (readDelimitedString boneWeights " " as float)
- -- w2 = (readDelimitedString boneWeights " " as float)
- -- w3 = (readDelimitedString boneWeights " " as float)
- -- w4 = (readDelimitedString boneWeights "" as float)
- -- if b1!=0 do
- (
- find=findItem boneArray b1
- -- if find==0 do( append boneArray b1)
- )
- -- if b2!=0 do
- (
- find=findItem boneArray b2
- -- if find==0 do( append boneArray b2)
- )
- -- if b3!=0 do
- (
- find=findItem boneArray b3
- -- if find==0 do( append boneArray b3)
- )
- -- if b4!=0 do
- (
- find=findItem boneArray b4
- -- if find==0 do( append boneArray b4)
- )
- -- append vertBuffer.boneids [b1,b2,b3,b4]
- -- append vertBuffer.weights [w1,w2,w3,w4]
- )
- -- vx=(readDelimitedString meshPosition " " as float)
- -- vz=(readDelimitedString meshPosition " " as float)
- -- vy=(readDelimitedString meshPosition "" as float)
- -- nx=(readDelimitedString meshNormal " " as float)
- -- nz=(readDelimitedString meshNormal " " as float)
- -- ny=(readDelimitedString meshNormal "" as float)
- -- cr=(readDelimitedString meshPosition " " as integer)
- -- cg=(readDelimitedString meshPosition " " as integer)
- -- cb=(readDelimitedString meshPosition " " as integer)
- -- ca=(readDelimitedString meshPosition "" as integer)/255
- -- append vertBuffer.position [vx,vy,vz]
- -- append vertBuffer.normal [nx,ny,nz]
- -- append vertBuffer.colour [cr,cg,cb,ca]
- )
- faceCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
- for x = 1 to faceCount do
- (
- faceIndices=f.readLine()
- -- fc = (readDelimitedString faceIndices " " as integer)+1
- -- fb = (readDelimitedString faceIndices " " as integer)+1
- -- fa = (readDelimitedString faceIndices "" as integer)+1
- -- append faceArray[fa,fb,fc]
- )
- -- INSERT MESH IMPORT OP HERE
- )
- -- Mesh Loop
- print "Detected Render Groups"
- print renderGroups
- print ""
- print ""
- print "Skeleton\n"
- print boneBuffer.bName
- gc()
- fclose f
- flushLog()
- closeLog()
- MemStreamMgr.close f
- enableSceneRedraw()
- Print ("\nDone! ("+((((timestamp())-st)/60)as string)+" Seconds)") --print time to finish
- )
- )
- )
- -- Close ascii ext Loop
- if fext!=".ascii" AND fext!=".mesh" do MessageBox "File Extension Error"
- )
- else(MessageBox "Error Opening File!")
- )
- else (Print "Aborted.")
- )
- -- Close Button for IMPORT
- on btn2 pressed do
- (
- -- EXPORT
- st = timestamp() --get start time in milliseconds
- -- ssource= "C:\\Users\\ACER_PREDATOR\\Desktop\\test.obj"
- -- ssource= "C:\\Program Files (x86)\\XNALara\\data\\Max_Export\\goldenaxe_bikini\\generic_item.mesh.ascii"
- if expFixed==false OR ssource==""do
- (
- ssource = getSaveFileName \
- caption:"Save XnaLara ASCII Model File" \
- types: "Text File (*.ASCII)|*.ascii|All files (*.*)|*.*|"
- )
- -- ssource=((getFilenameFile ssource)+".mesh.ascii") -- checks the name
- -- ssource = getSaveFileName \
- -- caption:"WaveFront OBJ Exporter" \
- -- types: "OBJ(*.obj)|*.OBJ|All files (*.*)|*.*|"
- if ssource!=""AND ssource!=undefined then
- (
- out_file = createfile ssource
- fpath=(getFilenamePath ssource)
- if (doesFileExist ssource)==true then
- (
- -- mshScale=1
- mshScale=imperial_scale/rescale -- converts centimeters to inches ? my unit system is in inches ? is detection needed?
- mshFlipUV=false -- not setup/wont do anything
- mshRightH=true -- not setup/wont do anything
- mshBySelection=chk4.checked
- mshOptimise=chk6.checked-- wtf its faster with this on?
- mshAddRoot=chk5.checked -- reparents all bones to a single root bone
- mshBoneLimit=false -- as for now, only warns you if you've gonve over the bone limit (59 bones MAX)
- fn checkname str =
- (
- -- removes special characters from names
- local str0=""
- for i = 1 to str.count do
- (
- if str[i]!="_" and str[i]!="#" and str[i]!=" " and str[i]!="." and str[i]!="/" and str[i]!="_" and str[i]!="\"" and str[i]!="\\"
- do str0+=str[i]
- )
- str0
- )
- fn renamedup aray idx =
- (
- -- renames duplicated names
- local namCount=1
- newname= aray[idx]+"("+(namCount as string)+")"
- find=findItem aray newname
- if find!=0 do
- (
- while(findItem aray newname)!=0 do
- (
- namCount+=1
- newname=aray[idx]+"("+(namCount as string)+")"
- )
- )
- newname
- )
- fn getMaterial msh matid =
- (
- -- tries to sort a material into a correct render group
- local matArray=#()
- matArray[14]=""
- -- matArray[1]-> ESTIMATED RENDER GROUP
- -- matArray[2] -> texDiffuse
- -- matArray[3] -> texOpacity
- -- matArray[4] -> texIllum
- -- matArray[5] -> texSpecMap
- -- matArray[6] -> texSpec
- -- matArray[7] -> texLight
- -- matArray[8] -> texBump
- -- matArray[9] -> texDetail1
- -- matArray[10] -> texDetail2
- -- matArray[11]-> matBump1
- -- matArray[12]-> matBump2
- -- matArray[13]-> texMask
- -- matArray[14]-> texReflect
- -- $.material.originalMaterial.diffuseMap
- local matslot=msh.material
- if classOf matslot==standardmaterial do matslot=msh.material
- if classOf matslot==Shell_Material do matslot=msh.material.originalMaterial
- if classOf matslot==multimaterial do matslot=msh.material[matid]
- if matslot!=undefined then
- (
- if classOf matslot.diffuseMap==Bitmaptexture do matArray[2]=filenameFromPath matslot.diffuseMap.filename
- if classOf matslot.diffuseMap==RGB_Multiply do
- (
- matArray[2]=filenameFromPath matslot.diffuseMap.map1.filename
- matArray[7]=filenameFromPath matslot.diffuseMap.map2.filename
- )
- if classOf matslot.ambientMap==Bitmaptexture do matArray[7]=filenameFromPath matslot.ambientMap.filename
- if classOf matslot.opacityMap==Bitmaptexture or matslot.opacity!=100 do matArray[3]="true"
- if classOf matslot.specularLevelMap==Bitmaptexture do matArray[5]=filenameFromPath matslot.specularLevelMap.filename
- if matslot.selfIllumAmount!=0 do matArray[4]="true";matArray[6]=(matslot.specularLevel as string)
- if classOf matslot.bumpMap==Bitmaptexture do matArray[8]=filenameFromPath matslot.bumpMap.filename
- if classOf matslot.reflectionMap==Bitmaptexture do matArray[14]=filenameFromPath matslot.reflectionMap.filename
- if classOf matslot.bumpMap==Normal_Bump do
- (
- if classOf matslot.bumpMap.normal_map==Bitmaptexture do matArray[8]=filenameFromPath matslot.bumpMap.normal_map.filename
- if classOf matslot.bumpMap.bump_map==Bitmaptexture do
- (
- matArray[9]=filenameFromPath matslot.bumpMap.bump_map.filename
- matArray[11]=(matslot.bumpMap.bump_map.coords.u_tiling) as string
- matArray[10]="norm_null.tga";matArray[13]="mask_null.tga"
- )
- if classOf matslot.bumpMap.bump_map==CompositeTexturemap do
- (
- if classOf matslot.bumpMap.bump_map.mapList[2]==Mask \
- AND classOf matslot.bumpMap.bump_map.mapList[3]==Mask do
- (
- if classOf matslot.bumpMap.bump_map.mapList[2].mask==Bitmaptexture \
- OR classOf matslot.bumpMap.bump_map.mapList[2].mask==RGB_Tint then
- (
- if classOf matslot.bumpMap.bump_map.mapList[2].mask==Bitmaptexture do matArray[13]=matslot.bumpMap.bump_map.mapList[2].mask.filename
- if classOf matslot.bumpMap.bump_map.mapList[2].mask==RGB_Tint do matArray[13]=matslot.bumpMap.bump_map.mapList[2].mask.map1.filename
- if classOf matslot.bumpMap.bump_map.mapList[2].map==Bitmaptexture \
- AND classOf matslot.bumpMap.bump_map.mapList[3].map==Bitmaptexture then
- (
- matArray[9]=matslot.bumpMap.bump_map.mapList[2].map.filename
- matArray[10]=matslot.bumpMap.bump_map.mapList[3].map.filename
- matArray[11]=(matslot.bumpMap.bump_map.mapList[2].map.u_tiling) as string
- matArray[12]=(matslot.bumpMap.bump_map.mapList[3].map.u_tiling) as string
- )
- else(matArray[9]="norm_null.tga";matArray[10]="norm_null.tga";matArray[11]="1";matArray[12]="1")
- )
- )
- )
- )
- )
- else
- (
- messagebox "ERROR!!\nUnable To Read Material\n>>Only Standard and Multimaterials Are Supported<<"
- if matslot!=undefined then (matArray[3]=matslot.diffuse as string;matArray[6]=matslot.specularLevel as string)else(matArray[3]="diff_null.tga")
- )
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- RENDERING GROUP CHART, WRITTEN AND DESIGNED BY "XNAaraL" AS SPECIFIED FOR XNALARA VERSION 9.6
- -- http://www.tombraiderforums.com/showpost.php?p=5254498&postcount=1735
- -- Group | Shading | Alpha | Poseable | Specular higlight | Bump1 repeater | bump2 repeater | Textures | Texture types | Since | First model / mesh part | Downloadlink
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- 1 | Yes | No | Yes | Yes | Yes | Yes | 6 | Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2 | 1.0 | LaraJungleShorts /tshirt | http://www.mediafire.com/?gc5cu5dtd2h 1_tshirt_0.1_24_48
- -- 2 | Yes | No | Yes | Yes | No | No | 3 | Diffuse, Lightmap, Bumpmap | 1.0 | LaraJungleShorts /face | http://www.mediafire.com/?gc5cu5dtd2h 2_eyeducts_0.1_0_0_hand left_arm left wrist
- -- 3 | Yes | No | Yes | No | No | No | 2 | Diffuse, Lightmap | 1.0 | LaraJungleShorts /backring | http://www.mediafire.com/?gc5cu5dtd2h 3_backring_0.1_0_0
- -- 4 | Yes | No | Yes | Yes | No | No | 2 | Diffuse, Bumpmap | 1.0 | LaraJungleShorts /metal | http://www.mediafire.com/?gc5cu5dtd2h 4_metal_0.6_0_0
- -- 5 | Yes | No | Yes | No | No | No | 1 | Diffuse | 1.0 | LaraJungleShorts /eyewhites | http://www.mediafire.com/?gc5cu5dtd2h 5_eyewhites_0.1_0_0_body upper_breast left_breast right
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- 6 | Yes | Yes | Yes | Yes | No | No | 2 | Diffuse, Bumpmap | 1.0 | LaraJungleShorts /hair2 | http://www.mediafire.com/?gc5cu5dtd2h 6_hair2_0.1_0_0
- -- 7 | Yes | Yes | Yes | No | No | No | 1 | Diffuse | 1.0 | LaraJungleShorts /eyelashes | http://www.mediafire.com/?gc5cu5dtd2h 7_eyeshading_0.1_0_0_head_head jaw
- -- 8 | Yes | Yes | Yes | Yes | No | No | 3 | Diffuse, Lightmap, Bumpmap | 1.8 | Natla / hair4 | http://www.mediafire.com/?4wmzyzxwj5y 8_hair4_0.1_0_0_wing right_wing right 7c
- -- 9 | Yes | Yes | Yes | No | No | No | 2 | Diffuse, Lightmap | 1.8 | Natla / hair5 | http://www.mediafire.com/?4wmzyzxwj5y 9_hair5_0.1_0_0
- -- 10 | No | No | Yes | No | No | No | 1 | Diffuse | 1.85 | Doppelganger /eyepupils | http://www.mediafire.com/?m0q9yctdris
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- 11 | Vertex | No | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.1 | CroftManorHall /Group1 | http://www.mediafire.com/?jlt33lalmjj
- -- 12 | Vertex | Yes | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.1 | CroftManorHall /Group35 | http://www.mediafire.com/?jlt33lalmjj
- -- 13 | No | No | No | No | No | No | 1 | Diffuse | 4.1 | CroftManorHall /Group91 | http://www.mediafire.com/?jlt33lalmjj
- -- 14 | No | No | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.2 | CroftManorHallLQ /Group1 | http://www.mediafire.com/?zjeznnzcgaz
- -- 15 | No | Yes | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.2 | CroftManorHallLQ /Group35 | http://www.mediafire.com/?zjeznnzcgaz
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- 16 | Yes | No | No | No | No | No | 1 | Diffuse | 4.7 | Yacht / part1 | http://www.mediafire.com/?mwakzzz1djy
- -- 17 | Yes | No | No | No | No | No | 2 | Diffuse, Lightmap | 4.7 | Yacht / part5 | http://www.mediafire.com/?mwakzzz1djy
- -- 18 | Yes | Yes | No | No | No | No | 1 | Diffuse | 4.7 | Yacht / part13 | http://www.mediafire.com/?mwakzzz1djy
- -- 19 | Yes | Yes | No | No | No | No | 2 | Diffuse, Lightmap | 5.6 | ShipNatlaRoom /Mesh005 | http://www.mediafire.com/?ztjozjnninn
- -- 20 | Yes | Yes | Yes | Yes | Yes | Yes | 6 | Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2 | 7.8 | KnightThrall /Mesh001 | http://www.mediafire.com/?z4uwig2dzum
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- 21 | No | Yes | Yes | No | No | No | 1 | Diffuse | 9.1 | kerrigan /$AtlantiB$ |
- -- 22 | Yes | No | Yes | Yes | Yes | Yes | 7 | Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2, Specular | 9.3 | ICE-7E /suit | http://www.mediafire.com/?leipjbpmeyn2w2p
- -- 23 | Yes | Yes | Yes | Yes | Yes | Yes | 7 | Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2, Specular | 9.3 | ICE-7E /ice | http://www.mediafire.com/?leipjbpmeyn2w2p
- -- 24 | Yes | No | Yes | Yes | No | No | 4 | Diffuse, Lightmap, Bumpmap, Specular | 9.42 |
- -- 25 | Yes | Yes | Yes | Yes | No | No | 4 | Diffuse, Lightmap, Bumpmap, Specular | 9.42 |
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- -- 26 | YES/No | No | Yes | Yes intensity | No | No | 3 | Diffuse, Bumpmap, enviroment | 9.5 | MetallicExample /trousers1 | http://www.mediafire.com/?g8gah73w0mv45q7
- -- 27 | YES/No | Yes | Yes | Yes intensity | No | No | 3 | Diffuse, Bumpmap, enviroment | 9.5.5 |
- -- 28 | YES/No | No | Yes | Yes intensity | YES | YES | 6 | Diffuse, Bumpmap, Mask, Bump1, Bump2, enviroment | 9.6 |
- -- 29 | YES/No | Yes | Yes | Yes intensity | YES | YES | 6 | Diffuse, Bumpmap, Mask, Bump1, Bump2, enviroment | 9.6 |
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- if matArray[3]!="diff_null.tga"do
- (
- if matArray[3]!="true"then
- (
- -- Opaque
- if matArray[4]!="true"then
- (
- -- not illum
- if matArray[13]==undefined then
- (
- -- no detail map / masks
- -- 5 Diffuse Only.
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="5"
- -- 3 Diffuse + Lightmap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="3"
- -- 24 Diffuse + NormalMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="24"
- -- 24 Diffuse + NormalMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[14]=="" do
- (
- matArray[7]="dirt_null.tga"
- matArray[8]="norm_null.tga"
- matArray[1]="24"
- )
- -- 24 Diffuse + NormalMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do
- (
- matArray[7]="dirt_null.tga"
- matArray[1]="24"
- )
- -- 26 Diffuse + NormalMap + EnvMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]!="" do matArray[1]="26"
- -- 4 Diffuse + NormalMap + Spec
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="4"
- -- 2 Diffuse + NormalMap + Spec + LightMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="2"
- )
- else
- (
- -- detail maps / masks
- -- 28 Diffuse + NormalMap + DetailMap + EnvMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]!="" do matArray[1]="28"
- -- 1 Diffuse + NormalMap + DetailMap + Spec + LightMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]!="" do matArray[1]="1"
- -- 22 Diffuse + NormalMap + DetailMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="22"
- )
- )
- else
- (
- -- 10 Diffuse Only, High Emssive.
- if matArray[2]!=undefined \ -- texDiffuse
- and matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[9]==undefined \ -- texDetail1
- and matArray[10]==undefined \ -- texDetail2
- and matArray[11]==undefined \ -- matBump1
- and matArray[12]==undefined \ -- matBump2
- and matArray[13]==undefined \ -- texMask
- and matArray[14]=="" do matArray[1]="10"
- )
- )
- else
- (
- -- Opacity
- if matArray[4]!="true"then
- (
- -- not illum
- if matArray[13]==undefined then
- (
- -- no detail map / masks
- -- 5 Diffuse Only.
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="7"
- -- 3 Diffuse + Lightmap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="9"
- -- 24 Diffuse + NormalMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="25"
- -- 24 Diffuse + NormalMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[14]=="" do
- (
- matArray[7]="dirt_null.tga"
- matArray[8]="norm_null.tga"
- matArray[1]="25"
- )
- -- 24 Diffuse + NormalMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do
- (
- matArray[7]="dirt_null.tga"
- matArray[1]="25"
- )
- -- 26 Diffuse + NormalMap + EnvMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]!="" do matArray[1]="27"
- -- 4 Diffuse + NormalMap + Spec
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="6"
- -- 2 Diffuse + NormalMap + Spec + LightMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="8"
- )
- else
- (
- -- detail maps / masks
- -- 28 Diffuse + NormalMap + DetailMap + EnvMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]!="" do matArray[1]="29"
- -- 1 Diffuse + NormalMap + DetailMap + Spec + LightMap
- if matArray[5]==undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]!="" do matArray[1]="20"
- -- 22 Diffuse + NormalMap + DetailMap + SpecMap + LightMap
- if matArray[5]!=undefined \ -- texSpecMap
- and matArray[7]!=undefined \ -- texLight
- and matArray[8]!=undefined \ -- texBump
- and matArray[14]=="" do matArray[1]="23"
- )
- )
- else
- (
- -- 10 Diffuse Only, High Emssive.
- if matArray[2]!=undefined \ -- texDiffuse
- and matArray[5]==undefined \ -- texSpecMap
- and matArray[7]==undefined \ -- texLight
- and matArray[8]==undefined \ -- texBump
- and matArray[9]==undefined \ -- texDetail1
- and matArray[10]==undefined \ -- texDetail2
- and matArray[11]==undefined \ -- matBump1
- and matArray[12]==undefined \ -- matBump2
- and matArray[13]==undefined \ -- texMask
- and matArray[14]=="" do matArray[1]="21"
- )
- )
- )
- -- matArray[2] -> texDiffuse
- -- matArray[3] -> texOpacity
- -- matArray[4] -> texIllum
- -- matArray[5] -> texSpecMap
- -- matArray[6] -> texSpec
- -- matArray[7] -> texLight
- -- matArray[8] -> texBump
- -- matArray[9] -> texDetail1
- -- matArray[10] -> texDetail2
- -- matArray[11]-> matBump1
- -- matArray[12]-> matBump2
- -- matArray[13]-> texMask
- -- matArray[14]-> texReflect
- -- matArray[15]-> ESTIMATED RENDER GROUP
- if matArray[1]==undefined do
- (
- matArray[2]="diff_null.tga"
- matArray[1]="5"
- )
- if matArray[2]==undefined do matArray[2]="diff_null.tga"
- if matArray[6]==undefined do matArray[6]="100"
- if (matArray[6] as float)<=0 do matArray[6]="10" -- texSpec
- if matArray[3]==undefined do matArray[3]="" -- texOpacity
- if matArray[4]==undefined do matArray[4]="" -- texIllum
- if matArray[5]!=undefined do matArray[6]="100"
- if matArray[5]==undefined do matArray[5]="" -- texSpecMap
- if matArray[7]==undefined do matArray[7]="" -- texLight
- if matArray[8]==undefined do matArray[8]="" -- texBump
- if matArray[9]==undefined do matArray[9]="" -- texDetail1
- if matArray[10]==undefined do matArray[10]="" -- texDetail2
- if matArray[11]==undefined do matArray[11]="" -- matBump1
- if matArray[12]==undefined do matArray[12]="" -- matBump2
- if matArray[13]==undefined do matArray[13]="" -- texMask
- if matArray[14]==undefined do matArray[14]="" -- texReflect
- matArray
- )
- fn maketext s p =
- (
- -- makes a 8x8 tga any colour, usage: (maketext savefile pixelcolour)
- if (doesFileExist s)==false do
- (
- createFile s
- s = fopen s "ab"
- a=19;b=1
- nullTex=#
- (
- 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x20,0x00,0xFF,0xFF, \
- 0xFF,0x8A,0xFF,0xFF,0xFF,0x44,0xFF,0xFF,0xFF,0x68,0xFF,0xFF,0xFF,0x89,0xFF,0xFF,0xFF,0x86,0xFF,0xFF, \
- 0xFF,0xC5,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE5,0xFF,0xFF,0xFF,0xCC,0xFF,0xFF, \
- 0xFF,0xDE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFC,0xFF,0xFF,0xFF,0xF9,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF, \
- 0xFF,0xFE,0xFF,0xFF,0xFF,0xEF,0xFF,0xFF,0xFF,0xE6,0xFF,0xFF,0xFF,0xED,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF, \
- 0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xF9,0xFF,0xFF, \
- 0xFF,0xF6,0xFF,0xFF,0xFF,0xFA,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
- 0xFF,0xFE,0xFF,0xFF,0xFF,0xBB,0xFF,0xFF,0xFF,0xA3,0xFF,0xFF,0xFF,0x8C,0xFF,0xFF,0xFF,0x93,0xFF,0xFF, \
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xAA,0xFF,0xFF, \
- 0xFF,0x8E,0xFF,0xFF,0xFF,0x92,0xFF,0xFF,0xFF,0x8F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
- 0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF
- )
- -- A small 8x8 White TGA Texture
- for i = 1 to (8*8) do
- (
- nullTex[a]=p.blue;b+=1
- nullTex[(a+1)]=p.green;b+=1
- nullTex[(a+2)]=p.red;b+=1
- a+=4
- )
- -- replaces pixels
- for x=1 to nullTex.count do writebyte s nullTex[x]
- fclose s
- )
- )
- undo off
- (
- with redraw off
- (
- classesArr = #(BoneGeometry,Biped_Object,Dummy,IK_Chain_Object,Point)
- getBone=for o in objects where findItem classesArr (classof o) > 0 collect o
- classesArr = #(Editable_Mesh,Editable_Poly,PolyMeshObject)
- if mshBySelection==false then
- (
- getMesh=for o in objects where findItem classesArr (classof o) > 0 collect o
- if getMesh.count==0 do messagebox "FAIL!!\nNothing Valid to Export"
- )
- else
- (
- getMesh=for o in selection where findItem classesArr (classof o) > 0 collect o
- if getMesh.count==0 do messagebox "FAIL!!\nNothing In Selection Valid to Export"
- )
- if getMesh.count!=0 do
- (
- struct bone_data(name,position,parent,child)
- boneBuffer = (bone_data name:#() position:#() parent:#() child:#())
- staticMsh=#()
- skin_bone_limit=#()
- skin_bone_limit[getMesh.count]=false
- faceCount=0
- for i = 1 to getMesh.count do
- (
- skinPresent=false
- PhyiqArray=""
- faceCount+=getMesh[i].numfaces
- for x = 1 to getMesh[i].modifiers.count do
- (
- skinMod=getMesh[i].modifiers[x]
- if classOf skinMod==Skin do
- (
- skinPresent=true
- if (skinOps.GetNumberBones skinMod)>=boneLimit do
- (
- skin_bone_limit[i]=true;boneWarning+=(getMesh[i].name+"\n")
- )
- )
- if classOf skinMod==Physique do PhyiqArray+=(" - "+getMesh[i].name+"\n")
- )
- if skinPresent==false do append staticMsh getMesh[i]
- if PhyiqArray!="" do MessageBox ("WARNING!! Physique Not Supported\n\nFollowing Objects Have Failed to Convert:\n"+PhyiqArray)
- )
- if (getBone.count+staticMsh.count)!=0 do
- (
- boneBuffer.name[(getBone.count+staticMsh.count)]=""
- boneBuffer.position[(getBone.count+staticMsh.count)]=[0,0,0]
- boneBuffer.parent[(getBone.count+staticMsh.count)]=0
- boneBuffer.child[(getBone.count+staticMsh.count)]=0
- for i = 1 to getBone.count do
- (
- obj=getBone[i]
- p=findItem getBone obj.parent
- c=findItem getBone obj.children[1]
- -- if p==0 do p=-1
- p-=1 -- convert to base 0
- if c==undefined do c=0
- boneBuffer.name[i]=obj.name
- boneBuffer.position[i]=obj.transform[4]
- boneBuffer.parent[i]=p
- boneBuffer.child[i]=c
- )
- for i = (getBone.count+1) to (getBone.count+staticMsh.count) do
- (
- obj=staticMsh[(i-getBone.count)]
- boneBuffer.name[i]=obj.name
- boneBuffer.position[i]=obj.transform[4]
- boneBuffer.parent[i]=-1
- boneBuffer.child[i]=0
- )
- )
- if mshAddRoot==true do
- (
- -- reorder crap
- find=findItem boneBuffer.name "root ground"
- if find==0 then
- (
- -- Need to add Ground Root
- insertItem "root ground" boneBuffer.name 1
- insertItem [0,0,0] boneBuffer.position 1
- insertItem -2 boneBuffer.parent 1
- insertItem 0 boneBuffer.child 1
- for i = 1 to boneBuffer.name.count do
- (
- boneBuffer.parent[i]+=1
- )
- )
- else
- (
- -- Reorder all bones to Ground Root (Not tested? dont know if this even works)
- if find!=1 then
- (
- -- the Root needs to be moved back to top
- -- NOT WRITTEN -> would mean unlinking the root? not safe?
- )
- else
- (
- -- reparent everything else to the top
- for i = 1 to boneBuffer.name.count do
- (
- if boneBuffer.parent[i]==-1 AND i!=find do
- (
- boneBuffer.parent[i]=0
- )
- )
- )
- )
- )
- if getMesh.count!=0 do
- (
- struct mesh_data(faces,vertices)
- struct mesh_data(name,matname,faces,vertices,matinfo)
- struct vertex_data(position,normal,tangent,colour,texture1,texture2,texture3,boneids,weights)
- struct material_data(diffmap,dirtmap,specmap,normmap,bumpmap1,bumpmap2,maskmap,envmap)
- meshBuffer = (mesh_data faces:#() vertices:#())
- matBuffer = (material_data diffmap:#() dirtmap:#() specmap:#() normmap:#() bumpmap1:#() bumpmap2:#() maskmap:#() envmap:#())
- meshBuffer = (mesh_data name:#() matname:#() faces:#() vertices:#() matinfo:#())
- vertBuffer = (vertex_data position:#() normal:#() tangent:#() colour:#() texture1:#() texture2:#() texture3:#() boneids:#() weights:#())
- vertBuffer.position [(faceCount*3)] = [0,0,0]
- vertBuffer.normal [(faceCount*3)] = [0,0,0]
- vertBuffer.tangent [(faceCount*3)] = [0,0,0]
- vertBuffer.colour [(faceCount*3)] = [0,0,0]
- vertBuffer.texture1 [(faceCount*3)] = [0,0,0]
- vertBuffer.texture2 [(faceCount*3)] = [0,0,0]
- vertBuffer.texture3 [(faceCount*3)] = [0,0,0]
- vertBuffer.boneids [(faceCount*3)] = [0,0,0,0]
- vertBuffer.weights [(faceCount*3)] = [0,0,0,0]
- faceBuffer=#()
- faceBuffer[(faceCount*3)]=0
- )
- vertCount=0 -- Counts used to index through my arrays
- faceCount=0
- for m = 1 to getMesh.count do
- (
- --loop meshcount
- tvCount=getNumTVerts getMesh[m]
- select getMesh[m]
- max modify mode
- modMesh = Edit_Mesh () --mkes sure mesh is triMesh
- uvwMesh = Unwrap_UVW () --makes sure mesh has UVs !! fuck causes bad uv's >_<
- addModifier getMesh[m] modMesh
- if tvCount==0 do addModifier getMesh[m] uvwMesh
- mat=getMesh[m].material
- tmesh = getMesh[m]
- -- tmesh = snapshotAsMesh getMesh[m] -- no material access wtf
- UVLayers=1 -- should return 2, the 2nd channel is reserved for vertex colours
- UVIndex=0
- if (numMapsUsed tmesh)>=3 do
- (
- ;UVLayers=0 -- do a double check for vaild UV Channels
- for i = 1 to (numMapsUsed tmesh) do
- (
- -- loop through each uv channel
- if meshop.getMapSupport tmesh i == true do UVLayers+=1
- )
- )
- if uvLayers>=3 do messagebox ("ERROR!!\n"+tmesh.name+" uses more then 2 UV Layers\n Script was not setup for more then 2\n\n-Sorry will Add Support in the future")
- vColors=getNumCPVVerts tmesh -- returns 0 if there are no colours stored
- cvert=(color 255 255 255) --white
- num_verts = tmesh.numverts
- num_faces = tmesh.numfaces
- weightBuffer=#();weightBuffer[tmesh.numverts]=0.0
- boneIDBuffer=#();boneIDBuffer[tmesh.numverts]=0
- skinPresent=false
- skinMod=undefined
- if tmesh.modifiers.count!=0 then
- (
- for i = 1 to tmesh.modifiers.count do
- (
- -- Get Skin Data
- if classOf tmesh.modifiers[i]==Skin do
- (
- skinPresent=true
- skinMod=tmesh.modifiers[i]
- )
- )
- if skinPresent==true then
- (
- modPanel.setCurrentObject skinMod
- skinOps.RemoveZeroWeights skinMod
- for i = 1 to tmesh.numverts do
- (
- vertex_bone_count = skinOps.GetVertexWeightCount skinMod i -- #of weights per vert
- if vertex_bone_count!=0 then
- (
- weightCollection=#();weightCollection[vertex_bone_count]=0.0
- boneidCollection=#();boneidCollection[vertex_bone_count]=0
- for x = 1 to vertex_bone_count do
- (
- bone_weight = skinops.getvertexweight skinMod i x
- bone_index = findItem boneBuffer.name
- (
- skinOps.GetBoneName skinMod \
- (skinOps.GetVertexWeightBoneID skinMod i x) 0
- )
- if bone_index==0 do bone_index=1
- if x<=4 do
- (
- -- limits to four bones weights per vertex
- weightCollection[x]=bone_weight
- boneidCollection[x]=bone_index
- )
- )
- )
- else
- (
- --dead weight found, nothing fancy just append weight to bone1
- weightCollection=#();weightCollection[1]=0.0
- boneidCollection=#();boneidCollection[1]=0
- bone_index = 1
- weightCollection[1]=1.0
- boneidCollection[1]=1
- )
- if vertex_bone_count<=4 then
- (
- for x = (vertex_bone_count+1) to 4 do
- (
- weightCollection[x]=0
- boneidCollection[x]=0
- )
- )
- else
- (
- w=weightCollection[1]+weightCollection[2]+weightCollection[3]+weightCollection[4]
- d=1-w;weightCollection[1]=(weightCollection[1]+d)
- )
- b1=boneidCollection[1]-1 -- convert to base 0
- b2=boneidCollection[2]-1
- b3=boneidCollection[3]-1
- b4=boneidCollection[4]-1
- if b1<=0 do b1=0
- if b2<=0 do b2=0
- if b3<=0 do b3=0
- if b4<=0 do b4=0
- boneIDBuffer[i]=[b1,b2,b3,b4]
- -- boneIDBuffer[i]=[(boneidCollection[1]),(boneidCollection[2]),(boneidCollection[3]),(boneidCollection[4])]
- weightBuffer[i]=[(weightCollection[1]),(weightCollection[2]),(weightCollection[3]),(weightCollection[4])]
- )
- )
- else
- (
- for x = 1 to tmesh.numverts do
- (
- -- static mesh, fix skin info
- weightBuffer[x]=[1,0,0,0]
- if tmesh.parent!=undefined
- then boneid=findItem boneBuffer.name tmesh.parent.name -- weight to a possible parent
- else boneid=findItem boneBuffer.name tmesh.name -- if no parent weight to scene root
- boneid-=1 -- convert to base 0
- if boneid<=0 do boneid=0 -- convert to base 0
- boneIDBuffer[x]=[boneid,0,0,0]
- )
- )
- )
- else
- (
- for x = 1 to tmesh.numverts do
- (
- weightBuffer[x]=[1,0,0,0]
- if tmesh.parent!=undefined
- then boneid=findItem getBone tmesh.parent.name
- else boneid=findItem getBone tmesh.name
- boneid-=1 -- convert to base 0
- if boneid<=0 do boneid=0 -- convert to base 0
- boneIDBuffer[x]=[boneid,0,0,0]
- )
- )
- modNorm = Edit_Normals ()
- addModifier tmesh modNorm
- vertCollection=#() -- arrays reset on each mesh / material ID
- normCollection=#()
- tvertCollection=#()
- faceCollection=#()
- boneCheck=#()
- vertCollection[(num_faces*3)] = [0,0,0,0]
- normCollection[(num_faces*3)] = [0,0,0]
- tvertCollection[(num_faces*3)] = [0,0,0,0]
- faceCollection[num_faces] = [0,0]
- if classOf mat==Multimaterial then
- (
- -- If MultiMaterial, Sort Faces By IDs
- for x = 1 to num_faces do
- (
- faceCollection[x]=[(getFaceMatId tmesh x),(tmesh.faces[x].index)]
- )
- fn sortFN v1 v2 =
- (
- local d=v1[1]-v2[1];
- case of
- (
- (d < 0.): -1
- (d > 0.): 1
- default: 0
- );
- );
- qsort faceCollection sortFN
- )
- else(for x = 1 to num_faces do (faceCollection[x]= [1,x]))
- faceStart=faceCollection[1][1]
- faceCounter=0
- count=0 -- count for resetable arrays
- boneLimitReached=false
- for x = 1 to num_faces do
- (
- if boneLimitReached==true do
- (
- matcrap=getMaterial tmesh faceStart
- append meshBuffer.matinfo [(matcrap[1] as integer),(matcrap[6] as float),(matcrap[11] as float),(matcrap[12] as float)]
- append matBuffer.diffmap matcrap[2]
- append matBuffer.dirtmap matcrap[7]
- append matBuffer.specmap matcrap[5]
- append matBuffer.normmap matcrap[8]
- append matBuffer.bumpmap1 matcrap[9]
- append matBuffer.bumpmap2 matcrap[10]
- append matBuffer.maskmap matcrap[13]
- append matBuffer.envmap matcrap[14]
- if matNames==true then mshName=(checkname tmesh.name) else mshName=(checkname tmesh.name)
- find=findItem meshBuffer.name mshName
- if find!=0 do mshName=renamedup meshBuffer.name find
- append meshBuffer.name mshName
- append meshBuffer.matname mshName
- vertCollection=#() -- reset arrays
- normCollection=#()
- tvertCollection=#()
- boneCheck=#()
- vertCollection[(num_faces*3)] = [0,0,0,0]
- normCollection[(num_faces*3)] = [0,0,0]
- tvertCollection[(num_faces*3)] = [0,0,0,0]
- append meshBuffer.faces faceCounter -- save counts, and reset shit
- append meshBuffer.vertices count
- boneLimitReached=false
- faceCounter=0
- count=0
- )
- case of
- (
- (classOf mat==Multimaterial):
- (
- -- reading materials, also rests arrays on new matID
- d=faceCollection[x][1]-faceStart -- Compares Current MatID vs the Last MatID
- case of
- (
- (d != 0):
- (
- -- Means Unique ID, need to reset
- matcrap=getMaterial tmesh faceStart
- append meshBuffer.matinfo [(matcrap[1] as integer),(matcrap[6] as float),(matcrap[11] as float),(matcrap[12] as float)]
- append matBuffer.diffmap matcrap[2]
- append matBuffer.dirtmap matcrap[7]
- append matBuffer.specmap matcrap[5]
- append matBuffer.normmap matcrap[8]
- append matBuffer.bumpmap1 matcrap[9]
- append matBuffer.bumpmap2 matcrap[10]
- append matBuffer.maskmap matcrap[13]
- append matBuffer.envmap matcrap[14]
- case of
- (
- (mat.material[(faceCollection[x][1])] != undefined):
- (
- if matNames==true then mshName=(checkname tmesh.material[faceStart].name) else mshName=(checkname tmesh.name)
- find=findItem meshBuffer.name mshName
- if find!=0 do mshName=renamedup meshBuffer.name find
- append meshBuffer.name mshName
- append meshBuffer.matname mshName
- )
- (mat.material[(faceCollection[x][1])] == undefined):
- (
- if matNames==true then mshName=("Mat_"+(x as string)+"_"+(faceCollection[x][1] as string)) else mshName=(checkname tmesh.name)
- find=findItem meshBuffer.name mshName
- if find!=0 do mshName=renamedup meshBuffer.name find
- append meshBuffer.name mshName
- append meshBuffer.matname mshName
- )
- )
- -- suppose to ensure that the material name is correct, this is critical.. but not properly set yet. -FIX ME!!
- vertCollection=#() -- reset arrays
- normCollection=#()
- tvertCollection=#()
- boneCheck=#()
- vertCollection[(num_faces*3)] = [0,0,0,0]
- normCollection[(num_faces*3)] = [0,0,0]
- tvertCollection[(num_faces*3)] = [0,0,0,0]
- append meshBuffer.faces faceCounter -- save counts, and reset shit
- append meshBuffer.vertices count
- faceStart=faceCollection[x][1]
- faceCounter=0
- count=0
- )
- )
- )
- (classOf mat!=Multimaterial):
- (
- -- assume this is an invalid material, or some other special type of material
- -- do something here? lol makeup fake mat info
- -- FIX ME!!
- )
- )
- findex=getFace tmesh faceCollection[x][2] -- gets face index of mesh
- tindex=getTVFace tmesh faceCollection[x][2] -- gets face index of texture coordinates
- if vColors!=0 do cindex=getVCFace tmesh faceCollection[x][2] -- gets face index of vertex colours
- -- t2index=getTVFace tmesh faceCollection[x][2] -- gets face for second UV channel (Fixed Channel)
- if mshOptimise==true then
- (
- for y = 1 to 3 do
- (
- vert=getVert tmesh findex[y]
- tvert=getTVert tmesh tindex[y]
- tvert2=getTVert tmesh tindex[y]
- if vColors!=0 do cvert=getVertColor tmesh cindex[y]
- norm=modNorm.GetNormal (modNorm.GetNormalID faceCollection[x][2] y)
- vertCull=findItem vertCollection [vert.x,vert.y,vert.z,(findex[y])]
- tvertCull=findItem tvertCollection [tvert.x,tvert.y,0,(tindex[y])]
- normCull=findItem normCollection norm
- if vertCull!=0 do (if normCollection[vertCull]!=norm do normCull=0)
- if vertCull!=tvertCull OR vertCull==0 OR normCull==0 then
- (
- --not found
- count+=1
- faceCount+=1
- vertCount+=1
- vertCollection[count]=[vert.x,vert.y,vert.z,(findex[y])]
- tvertCollection[count]=[tvert.x,tvert.y,0,(tindex[y])]
- normCollection[count]=norm
- vertBuffer.position[vertCount]=[vert.x,vert.y,vert.z,(findex[y])] -- Face ID is left, relates to the Skin Weight
- vertBuffer.texture1[vertCount]=[tvert.x,tvert.y,0]
- vertBuffer.colour[vertCount]=cvert
- vertBuffer.normal[vertCount]=norm
- vertBuffer.boneids[vertCount]=boneIDBuffer[(findex[y])]
- vertBuffer.weights[vertCount]=weightBuffer[(findex[y])]
- faceBuffer[faceCount]=count
- if skin_bone_limit[m]==true do
- (
- -- if current object exceeds bone limit, start new mesh
- boneids=boneIDBuffer[(findex[y])]
- for b = 1 to 4 do(if (finditem boneCheck boneids[b])==0 do append boneCheck boneids[b])
- if boneCheck.count>=boneLimit do(boneLimitReached=true)
- )
- -- note to self, need to copy any changes to this function to the unoptimized loop
- )
- else
- (
- faceCount+=1
- faceBuffer[faceCount]=vertCull
- )
- )
- )
- else
- (
- for y = 1 to 3 do
- (
- vert=getVert tmesh findex[y]
- tvert=getTVert tmesh tindex[y]
- norm=modNorm.GetNormal (modNorm.GetNormalID faceCollection[x][2] y)
- count+=1
- faceCount+=1
- vertCount+=1
- vertBuffer.position[vertCount]=[vert.x,vert.y,vert.z,(findex[y])] -- Face ID is left, relates to the Skin Weight
- vertBuffer.texture1[vertCount]=[tvert.x,tvert.y,0]
- vertBuffer.normal[vertCount]=norm
- vertBuffer.boneids[vertCount]=boneIDBuffer[(findex[y])]
- vertBuffer.weights[vertCount]=weightBuffer[(findex[y])]
- faceBuffer[faceCount]=count
- )
- )
- faceCounter+=1
- )
- matcrap=getMaterial tmesh faceStart
- append meshBuffer.matinfo [(matcrap[1] as integer),(matcrap[6] as float),(matcrap[11] as float),(matcrap[12] as float)]
- append matBuffer.diffmap matcrap[2]
- append matBuffer.dirtmap matcrap[7]
- append matBuffer.specmap matcrap[5]
- append matBuffer.normmap matcrap[8]
- append matBuffer.bumpmap1 matcrap[9]
- append matBuffer.bumpmap2 matcrap[10]
- append matBuffer.maskmap matcrap[13]
- append matBuffer.envmap matcrap[14]
- append meshBuffer.vertices count --flush counts (this may be improper? replace with if statement if counts are borked)
- append meshBuffer.faces faceCounter
- if classOf mat==Multimaterial then
- (
- if matNames==true then mshName=(checkname tmesh.material[faceStart].name) else mshName=(checkname tmesh.name)
- find=findItem meshBuffer.name mshName
- if find!=0 do mshName=renamedup meshBuffer.name find
- append meshBuffer.name mshName
- append meshBuffer.matname mshName
- )
- else
- (
- if tmesh.material==undefined then
- (
- if matNames==true then mshName=(checkname tmesh.name) else mshName=tmesh.name
- find=findItem meshBuffer.name mshName
- if find!=0 do mshName=renamedup meshBuffer.name find
- append meshBuffer.name mshName
- append meshBuffer.matname mshName
- )
- else
- (
- if matNames==true then mshName=(checkname tmesh.material.name) else mshName=(checkname tmesh.name)
- find=findItem meshBuffer.name mshName
- if find!=0 do mshName=renamedup meshBuffer.name find
- append meshBuffer.name mshName
- append meshBuffer.matname mshName
- )
- )
- deleteModifier tmesh modNorm
- deleteModifier tmesh modMesh
- if tvCount==0 do deleteModifier tmesh uvwMesh
- )
- print meshBuffer
- if getMesh.count!=0 do
- (
- -- xnalara ASCII format
- vertIndex=1
- nextvert=0
- faceIndex=1
- nextface=0
- faceCounter=0
- format "% # bones\n" boneBuffer.name.count to:out_file
- for f = 1 to boneBuffer.name.count do
- (
- format "%\n" boneBuffer.name[f] to:out_file
- format "% # parent index\n" boneBuffer.parent[f] to:out_file
- format "% % %\n" (boneBuffer.position[f][1]*mshScale) (boneBuffer.position[f][3]*mshScale) (boneBuffer.position[f][2]*-mshScale) to:out_file
- )
- format "% # meshes\n" meshBuffer.name.count to:out_file
- for f = 1 to meshBuffer.name.count do
- (
- nextvert+=meshBuffer.vertices[f]
- nextface+=meshBuffer.faces[f]
- format "%_%_%_%_%\n" (meshBuffer.matinfo[f][1]as integer) meshBuffer.name[f] (meshBuffer.matinfo[f][2]/100) meshBuffer.matinfo[f][3] meshBuffer.matinfo[f][4] to:out_file -- THE NAME IS CRITICAL, CURENTLY NOT PROPERLY SETUP!!
- format "% # uv layers\n" 1 to:out_file -- Multiple UV channels not setup yet
- texCount=1
- a=meshBuffer.matinfo[f][1] -- calculated render group
- case of
- (
- (a == 1): texCount=6
- (a == 2): texCount=3
- (a == 3): texCount=2
- (a == 4): texCount=2
- (a == 5): texCount=1
- (a == 6): texCount=2
- (a == 7): texCount=1
- (a == 8): texCount=3
- (a == 9): texCount=2
- (a == 10): texCount=1
- (a == 11): texCount=2
- (a == 12): texCount=2
- (a == 13): texCount=1
- (a == 14): texCount=2
- (a == 15): texCount=2
- (a == 16): texCount=1
- (a == 17): texCount=2
- (a == 18): texCount=1
- (a == 19): texCount=2
- (a == 20): texCount=6
- (a == 21): texCount=1
- (a == 22): texCount=7
- (a == 23): texCount=7
- (a == 24): texCount=4
- (a == 25): texCount=4
- (a == 26): texCount=3
- (a == 27): texCount=3
- (a == 28): texCount=6
- (a == 29): texCount=6
- default: texCount=1
- )
- format "% # textures\n" texCount to:out_file
- case of
- (
- (texCount==1):
- (
- format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
- )
- (texCount==2):
- (
- format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
- if matBuffer.dirtmap[f]!=""
- then format "%\n"matBuffer.dirtmap[f] to:out_file
- else format "%\n"matBuffer.normmap[f] to:out_file
- format "% # uv layer index\n" 0 to:out_file -- layers not implemented yet
- )
- (texCount==3):
- (
- format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
- if matBuffer.envmap[f]!=""
- then format "%\n% # uv layer index\n"matBuffer.normmap[f] 0 matBuffer.envmap[f] to:out_file -- layers not implemented yet
- else format "%\n% # uv layer index\n"matBuffer.dirtmap[f] matBuffer.normmap[f] to:out_file
- )
- (texCount==4):
- (
- format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.dirtmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.normmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.specmap[f] 0 to:out_file
- )
- (texCount==6):
- (
- format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
- if matBuffer.envmap[f]!=""
- then format "%\n% # uv layer index\n%\n% # uv layer index\n%\n% # uv layer index\n%\n% # uv layer index\n%\n% # uv layer index\n"\
- matBuffer.normmap[f] 0 matBuffer.maskmap[f] 0 matBuffer.bumpmap1[f] 0 matBuffer.bumpmap2[f] 0 matBuffer.envmap[f] 0 to:out_file -- layers not implemented yet
- else format "%\n% # uv layer index\n%\n% # uv layer index\n%\n% # uv layer index\n%\n% # uv layer index\n%\n% # uv layer index\n"\
- matBuffer.dirtmap[f] 0 matBuffer.normmap[f] 0 matBuffer.maskmap[f] 0 matBuffer.bumpmap1[f] 0 matBuffer.bumpmap2[f] 0 to:out_file -- layers not implemented yet
- )
- (texCount==7):
- (
- format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.dirtmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.normmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.maskmap[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.bumpmap1[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.bumpmap2[f] 0 to:out_file
- format "%\n% # uv layer index\n" matBuffer.specmap[f] 0 to:out_file
- )
- )
- format "% # vertices\n" meshBuffer.vertices[f] to:out_file
- for i = vertIndex to nextvert do
- (
- format "% % %\n" (vertBuffer.position[i][1]*mshScale) (vertBuffer.position[i][3]*mshScale) (vertBuffer.position[i][2]*-mshScale) to:out_file
- norm=normalize [(vertBuffer.normal[i][1]*mshScale),(vertBuffer.normal[i][3]*mshScale),(vertBuffer.normal[i][2]*-mshScale)]
- format "% % %\n" norm.x norm.y norm.z to:out_file
- -- format "% % %\n" vertBuffer.normal[i][1] vertBuffer.normal[i][3] vertBuffer.normal[i][2] to:out_file
- format "% % % %\n" (vertBuffer.colour[i].red as integer) (vertBuffer.colour[i].green as integer) (vertBuffer.colour[i].blue as integer) 0 to:out_file -- vertex colours not setup yet
- for y = 1 to 1 do
- (
- -- needs UV layer count, net setup yet
- if y==1 do format "% %\n" vertBuffer.texture1[i][1] (vertBuffer.texture1[i][2]*-1) to:out_file
- if y==2 do format "% %\n" vertBuffer.texture2[i][1] (vertBuffer.texture2[i][2]*-1) to:out_file
- if y==3 do format "% %\n" vertBuffer.texture3[i][1] (vertBuffer.texture3[i][2]*-1) to:out_file
- )
- -- -- Vertex Tangents would go here
- format "% % % %\n" (vertBuffer.boneids[i][1]as integer) (vertBuffer.boneids[i][2]as integer) (vertBuffer.boneids[i][3]as integer) (vertBuffer.boneids[i][4]as integer) to:out_file
- format "% % % %\n" vertBuffer.weights[i][1] vertBuffer.weights[i][2] \
- vertBuffer.weights[i][3] vertBuffer.weights[i][4] to:out_file
- )
- format "% # faces\n" meshBuffer.faces[f] to:out_file
- for i = faceIndex to nextface do
- (
- fa=faceBuffer[(faceCounter+1)]-1
- fb=faceBuffer[(faceCounter+2)]-1
- fc=faceBuffer[(faceCounter+3)]-1
- format "% % %\n" fc fb fa to:out_file
- faceCounter+=3
- )
- faceIndex+=meshBuffer.faces[f]
- vertIndex+=meshBuffer.vertices[f]
- )
- -- mesh loop
- for x = 1 to matBuffer.diffmap.count do
- (
- if matBuffer.diffmap[x]=="diff_null.tga" do maketext (fpath+"\\diff_null.tga") (color 115 115 115)
- if matBuffer.dirtmap[x]=="dirt_null.tga" do maketext (fpath+"\\dirt_null.tga") (color 254 254 254)
- if matBuffer.specmap[x]=="spec_null.tga" do maketext (fpath+"\\spec_null.tga") (color 50 50 50)
- if matBuffer.normmap[x]=="norm_null.tga" do maketext (fpath+"\\norm_null.tga") (color 128 128 255)
- if matBuffer.maskmap[x]=="mask_null.tga" do maketext (fpath+"\\mask_null.tga") (color 255 0 0)
- if matBuffer.bumpmap1[x]=="bump1_null.tga" do maketext (fpath+"\\bump1_null.tga") (color 128 128 255)
- if matBuffer.bumpmap2[x]=="bump2_null.tga" do maketext (fpath+"\\bump2_nul.tgal") (color 128 128 255)
- )
- )
- -- vertIndex=1
- -- nextvert=0
- -- faceIndex=1
- -- nextface=0
- -- lastface=0
- -- faceCounter=0
- -- for f = 1 to meshBuffer.name.count do
- (
- --dumps output as a wavefront OBJ format
- -- nextvert+=meshBuffer.vertices[f]
- -- format "# % vertices\n" meshBuffer.vertices[f] to:out_file
- -- for i = vertIndex to nextvert do
- (
- -- format "v % % %\n" (vertBuffer.position[i][1]*mshScale) (vertBuffer.position[i][3]*mshScale) (vertBuffer.position[i][2]*-mshScale) to:out_file
- )
- -- format "\n# % vertex normals\n" meshBuffer.vertices[f] to:out_file
- -- for i = vertIndex to nextvert do
- (
- -- norm=normalize [(vertBuffer.normal[i][1]*mshScale),(vertBuffer.normal[i][3]*mshScale),(vertBuffer.normal[i][2]*-mshScale)]
- -- format "vn % % %\n" norm.x norm.y norm.z to:out_file
- -- -- format "vn % % %\n" (vertBuffer.normal[i][1]*mshScale) (vertBuffer.normal[i][3]*mshScale) (vertBuffer.normal[i][2]*-mshScale) to:out_file
- --
- )
- -- format "\n# % texture coords\n" meshBuffer.vertices[f] to:out_file
- -- for i = vertIndex to nextvert do
- (
- -- format "vt % % 0.0\n" vertBuffer.texture1[i][1] vertBuffer.texture1[i][2] to:out_file
- )
- -- vertIndex+=meshBuffer.vertices[f]
- )
- -- print ("My Face Array has "+(faceBuffer.count as string)+" Entries")
- -- for f = 1 to meshBuffer.name.count do
- (
- -- format "\n# % faces\n" meshBuffer.faces[f] to:out_file
- -- format "g %\n" meshBuffer.name[f] to:out_file
- -- nextface+=meshBuffer.faces[f]
- -- print ("Currently Reading Set "+(f as string)+" from index "+(faceIndex as string)+" to "+(nextface as string)+"\n")
- -- for i = faceIndex to nextface do
- (
- -- fa=faceBuffer[(faceCounter+1)]+lastface
- -- fb=faceBuffer[(faceCounter+2)]+lastface
- -- fc=faceBuffer[(faceCounter+3)]+lastface
- -- format "f %/%/% %/%/% %/%/%\n" fa fa fa fb fb fb fc fc fc to:out_file
- -- faceCounter+=3
- )
- -- faceIndex+=meshBuffer.faces[f]
- -- lastface+=meshBuffer.vertices[f]
- --
- )
- close out_file
- if doesFileExist (fpath+"\\MeshAsciiToBin.exe")==true do
- (
- DOSCommand ("MeshAsciiToBin.exe \""+ssource+"\"")
- )
- messagebox ("DONE!\nOperation Completed in: "+((((timestamp()-st)/1000)+10)as string)+" s")
- if boneWarning!="" do messagebox ("Warning!\nThe Following Meshes Exceed The 59 Bone Limit\n\n"+boneWarning)
- gc() -- this will erase and undo saves, helps? flush files
- enableSceneRedraw()
- )
- )
- )
- -- undo renabled / redraw scene
- )
- else(MessageBox "Error Creating File!")
- )
- else (Print "Aborted.")
- format "% ms\n" (timestamp()-st)
- )
- -- Close Button for EXPORT
- on btn3 pressed do
- (
- rollout AboutBox "About..." width:300 height:200
- (
- label lbl3 "XNALara Converter (v1.1b) (August2011)" pos:[16,15] width:263 height:16
- label lbl4 "__________________________________________________________________________" pos:[18,29] width:263 height:17
- label lbl5 "- Mario_Kart64n ([email protected])" pos:[19,176] width:272 height:19
- label lbl8 "__________________________________________________________________________" pos:[18,153] width:263 height:17
- label lbl9 "Yay ^_^ second exporter I've written so far, and much an improvement\n\nScript is pretty much self-explainatory.. it imports XnaLara Stuff\nIf you have questions head over to the forums www.tombraiderforums.com\n" pos:[19,55] width:262 height:95
- )
- createDialog AboutBox
- )
- )
- createDialog appGUI
- gc() -- flushes cache, also resets undo. but command needed to help release files (not required to be on)
- fclose f
- fclose s
- clearlistener()
- )
- else(MessageBox "ERROR!!\nYour 3DSMAX Is Not Compatible with this Script\n-Sorry")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement