Advertisement
sunnydavis

XnaLara Converter.ms (Original-Beaultified)

Jun 4th, 2012
1,748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 105.55 KB | None | 0 0
  1. -- XnaLara Converter.ms
  2. -- Maxscript for importing and exporting geometry between 3ds Max and XNALara.
  3. -- Code beautified by sunnydavis
  4. -- a newer version for 3ds Max 2013 can be found at http://pastebin.com/pJSriVf9
  5. -- @author mariokart64n
  6. -- @date August 2, 2011
  7. -- @see http://www.tombraiderforums.com/showthread.php?t=181251
  8. version=maxVersion();if version[1]>=8000 then
  9. (
  10. -- Check Version of 3DSMAX
  11. rollout appGUI "XNALara Converter" width:175 height:315
  12. (
  13. button btn1 "IMPORT" pos:[16,8] width:120 height:32
  14. groupBox grp1 "Import Options" pos:[8,111] width:160 height:86
  15. editText edt1 "Scale:" pos:[40,89] width:86 height:16 bold:true text:"1.0000"
  16. checkbox chk1 "Single mesh" pos:[24,129] width:128 height:17 checked:true
  17. checkbox chk2 "Hide Unused Bones" pos:[24,149] width:140 height:17 checked:true
  18. checkbox chk3 "Vertex Normals" pos:[24,169] width:128 height:17 enabled:false
  19. groupBox grp2 "Export Options" pos:[8,201] width:160 height:86
  20. checkbox chk4 "Selection Only" pos:[24,219] width:128 height:17
  21. checkbox chk5 "Reparent Bones" pos:[24,239] width:128 height:17
  22. checkbox chk6 "Optimized Output" pos:[24,259] width:128 height:17 checked:true
  23. button btn3 "About" pos:[123,291] width:42 height:18
  24. label lbl2 "v1.1b (08.02.11)" pos:[11,293] width:98 height:17
  25. button btn1b "+" pos:[140,12] width:24 height:24
  26. button btn2 "EXPORT" pos:[16,48] width:120 height:32
  27. button btn2b "+" pos:[140,52] width:24 height:24
  28. local fsource=""
  29. local ssource=""
  30. local boneWarning=""
  31. local rescale=1
  32. local boneLimit=58
  33. local metric_scale=39.3700787
  34. local imperial_scale=0.0254982
  35. local boneSize=0.03
  36. local guessBone=false
  37. local bsenable=true
  38. local matNames=true
  39. local impFixed=false
  40. local expFixed=false
  41. on edt1 entered txt do
  42. (
  43. if (txt as float)!=undefined then
  44. (
  45. if (txt as float)!=0 then(rescale=(txt as float))else(messagebox "Input Invalid\nNumber Must Be Larger Than 0")
  46. )
  47. else
  48. (
  49. if txt=="bones" then
  50. (
  51. rollout exoptions "Extra Options (Some May Not Work)"width:298 height:263
  52. (
  53. groupBox grp4_1 "Peanutbutter Jelly Time!" pos:[11,11] width:277 height:243
  54. editText edt4_1 "Bone Size" pos:[26,37] width:114 height:16 enabled:bsenable text:(boneSize as string) bold:true
  55. checkbox chk4_1 "Guess Size Instead" pos:[150,36] width:128 height:17 checked:guessBone
  56. checkbox chk4_2 "Rhand to LHand Coordinates" pos:[27,63] width:221 height:19 enabled:false checked:true
  57. checkbox chk4_3 "Flip Texture Coordinates" pos:[27,83] width:221 height:19 enabled:false checked:true
  58. checkbox chk4_4 "Disable Skin on Import" pos:[27,123] width:221 height:19
  59. checkbox chk4_5 "Disable Mesh on Import" pos:[27,143] width:221 height:19
  60. checkbox chk4_6 "Disable Bones on Import" pos:[27,163] width:221 height:19
  61. checkbox chk4_7 "Disable Mats on Import" pos:[27,183] width:221 height:19
  62. checkbox chk4_8 "Export With Material Names" pos:[27,103] width:221 height:19 enabled:true checked:true
  63. editText edt4_2 "in<->cm" pos:[36,210] width:103 height:16 text:(metric_scale as string) bold:true
  64. editText edt4_3 "cm<->in" pos:[153,210] width:103 height:16 text:(imperial_scale as string) bold:true
  65. editText edt4_4 "Bone Limit" pos:[36,230] width:103 height:16 text:(boneLimit as string) bold:true
  66. on edt4_2 entered txt4 do (if (txt4 as float)!=undefined do metric_scale=(txt4 as float))
  67. on edt4_3 entered txt4 do (if (txt4 as float)!=undefined do imperial_scale=(txt4 as float))
  68. on edt4_4 entered txt4 do (if (txt4 as float)!=undefined do boneLimit=(txt4 as float))
  69. on chk4_1 changed theState do
  70. (
  71. if theState==false do edt4_1.enabled=true; bsenable=true;guessBone=false
  72. if theState==true do(edt4_1.enabled=false; bsenable=false;guessBone=true; boneSize=0)
  73. )
  74. on edt4_1 entered txt4 do(if (txt4 as float)!=undefined do boneSize=(txt4 as float))
  75. )
  76. createDialog exoptions
  77. )
  78. else(messagebox "Input Invalid\nPlease Supply A Number")
  79. )
  80. )
  81. on chk4_8 changed theState do matNames=theState
  82. on btn1b pressed do
  83. (
  84. if fsource==undefined do fsource=""
  85. rollout impPath "Open from Fixed Path" width:303 height:69
  86. (
  87. editText edt1b_1 "Path: " pos:[9,8] width:282 height:16 text:fsource
  88. button btn1b_1 "Browse" pos:[225,29] width:63 height:21
  89. checkbox chk1b_1 "Use Fixed Path" pos:[48,27] width:126 height:20 checked:impFixed
  90. on chk1b_1 changed theState do impFixed=theState
  91. on edt1b_1 entered txt do fsource=txt
  92. on btn1b_1 pressed do
  93. (
  94. fsource = GetOpenFileName \
  95. caption:"Open XnaLara MESH Model File" \
  96. types: "Binary(*.mesh)|*.MESH|Text(*.ascii)|*.ASCII|"
  97. if fsource!=undefined do edt1b_1.text=fsource
  98. )
  99. )
  100. createDialog impPath
  101. )
  102. on btn2b pressed do
  103. (
  104. if ssource==undefined do ssource=""
  105. rollout expPath "Save to Fixed Path" width:303 height:69
  106. (
  107. editText edt2b_1 "Path: " pos:[9,8] width:282 height:16 text:ssource
  108. button btn2b_1 "Browse" pos:[225,29] width:63 height:21
  109. checkbox chk2b_1 "Use Fixed Path" pos:[48,27] width:126 height:20 checked:expFixed
  110. on chk2b_1 changed theState do expFixed=theState
  111. on edt2b_1 entered txt do ssource=txt
  112. on btn2b_1 pressed do
  113. (
  114. ssource = getSaveFileName \
  115. caption:"Save XnaLara ASCII Model File" \
  116. types: "Text(*.ascii)|*.ASCII|All files (*.*)|*.*|"
  117. if ssource!=undefined do edt2b_1.text=ssource
  118. )
  119. )
  120. createDialog expPath
  121. )
  122. on btn1 pressed do
  123. (
  124. if impFixed==false OR fsource==""do
  125. (
  126. fsource = GetOpenFileName \
  127. caption:"Open XnaLara MESH Model File" \
  128. types: "Binary(*.mesh)|*.MESH|Text(*.ascii)|*.ASCII|"
  129. )
  130. if fsource!=""AND fsource!=undefined then
  131. (
  132. if (doesFileExist fsource)==true then
  133. (
  134. fext= getFilenameType fsource
  135. fpath= getFilenamePath fsource
  136. fname= getFilenameFile fsource
  137. fsize= getFileSize fsource
  138. if fext==".mesh" do
  139. (
  140. f = fopen fsource "rb"
  141. st = timestamp() --get start time in milliseconds
  142. ts = timestamp()
  143. --===========================================================================
  144. undo off
  145. (
  146. fn ReadFixedString bstream fixedLen =
  147. (
  148. local str = ""
  149. for i = 1 to fixedLen do
  150. (
  151. str += bit.intAsChar (ReadByte bstream #unsigned)
  152. )
  153. str
  154. )
  155. --===========================================================================
  156. with redraw off
  157. (
  158. scaling=metric_scale*rescale -- converts inces to centimeters !! damn Imperial System, Metric FTW
  159. mshHde=chk2.checked
  160. mshSingle=chk1.checked
  161. normON=chk3.checked
  162. skinON=true
  163. meshON=true
  164. boneON=true
  165. matON=true
  166. struct vertex_data
  167. (
  168. position,normal,texture,texture2,texture3,channels,colour,boneids,weights
  169. )
  170. struct bone_data
  171. (
  172. bName,parent,child,posX,posY,posZ
  173. )
  174. BNArr = #()
  175. -- Bone Section
  176. -- ===========================================================================
  177. Print ("Section 01: Bones @ 0x"+((bit.intAsHex(ftell f))as string))
  178. boneCount=readlong f #unsigned
  179. boneBuffer = (bone_data bName:#() parent:#() child:#() posX:#() posY:#() posZ:#())
  180. for i = 1 to boneCount do
  181. (
  182. append boneBuffer.bName (ReadFixedString f (readbyte f #unsigned))
  183. append boneBuffer.parent (readshort f+1)
  184. append boneBuffer.child -1
  185. append boneBuffer.posX (readfloat f*scaling)
  186. append boneBuffer.posZ (readfloat f*scaling)
  187. append boneBuffer.posY (readfloat f*-scaling)
  188. )
  189. if boneON==true do
  190. (
  191. for i = 1 to boneCount do
  192. (
  193. childIndex=boneBuffer.parent[i]
  194. if childIndex!=0 do
  195. (
  196. if boneBuffer.child[childIndex]==-1 then
  197. (
  198. boneBuffer.child[childIndex] = i
  199. )
  200. else
  201. (
  202. boneBuffer.child[childIndex] = 0
  203. )
  204. )
  205. )
  206. for i = 1 to boneCount do
  207. (
  208. startPos=[(boneBuffer.posX[i]),(boneBuffer.posY[i]),(boneBuffer.posZ[i])]
  209. endPos=startPos
  210. childIndex=boneBuffer.child[i]
  211. if childIndex>=1 then
  212. (
  213. endPos=[(boneBuffer.posX[childIndex]),(boneBuffer.posY[childIndex]),(boneBuffer.posZ[childIndex])]
  214. )
  215. else
  216. (
  217. if boneBuffer.parent[i]!=0 do
  218. (
  219. endPos=[(boneBuffer.posX[(boneBuffer.parent[i])]),(boneBuffer.posY[(boneBuffer.parent[i])]),(boneBuffer.posZ[(boneBuffer.parent[i])])]
  220. endPos=startPos+((startPos-endPos))
  221. )
  222. )
  223. bonSize=boneSize*scaling
  224. if bsenable==true or boneSize==0 or boneSize==undefined do
  225. (
  226. bonSize=((distance startPos endPos)/100)*scaling
  227. )
  228. newBone = bonesys.createbone startPos endPos [0,0,1]
  229. newBone.name = boneBuffer.bName[i]
  230. newBone.width = bonSize
  231. newBone.height = bonSize
  232. if boneBuffer.parent[i] !=0 do newBone.parent = BNArr[boneBuffer.parent[i]]
  233. append BNArr newBone
  234. if childIndex<=1 do newBone.length=0.06*scaling
  235. if mshHde==true do
  236. (
  237. bName=skipToString (boneBuffer.bName[i] as stringstream) "unused"
  238. if bName==OK do
  239. (
  240. hide newBone
  241. )
  242. )
  243. )
  244. )
  245. -- bone enable loop
  246. Print("Bone Collection: ("+(((timestamp())-ts)as string)+" Milli Seconds)");ts = timestamp()
  247. -- Mesh Section
  248. -- ===========================================================================
  249. Print ("Section 02: Meshes @ 0x"+((bit.intAsHex(ftell f))as string))
  250. meshCount=readlong f #unsigned
  251. mm = MultiMaterial()
  252. mm.numsubs=meshCount
  253. faceAdder=1
  254. -- meshCount=1
  255. texArray=#()
  256. faceArray=#()
  257. faceDimArray=#()
  258. boneArray=#()
  259. uvChnArray=#()
  260. vertBuffer = (vertex_data position:#() normal:#() channels:#() texture:#() texture2:#() texture3:#() colour:#() boneids:#() weights:#())
  261. for i = 1 to meshCount do
  262. (
  263. mat=mm.materialList[i]
  264. matSpec=30
  265. matBump1=1
  266. matBump2=1
  267. matType=undefined
  268. texOpacity=false
  269. texLight=false
  270. texBump=false
  271. texSpec=false
  272. texIllum=false
  273. texSpecMap=false
  274. texMask=false
  275. texDetail1=false
  276. texDetail2=false
  277. texReflect=false
  278. texStatic=false
  279. matSpec=30
  280. matBump1=4
  281. matBump2=4
  282. texArray=#()
  283. if mshSingle==false do
  284. (
  285. --reset arrays
  286. faceArray=#()
  287. boneArray=#()
  288. uvChnArray=#()
  289. vertBuffer = (vertex_data position:#() normal:#() channels:#() texture:#() texture2:#() texture3:#() colour:#() boneids:#() weights:#())
  290. )
  291. mshName=ReadFixedString f (readbyte f #unsigned)
  292. if (findString mshName "_")!=undefined do
  293. (
  294. genItmName=filterString mshName "_"
  295. matType=genItmName[1] as integer
  296. mshName=genItmName[2]
  297. if (genItmName.count)>=3 do
  298. (
  299. if (genItmName[3] as float)!=undefined then
  300. (
  301. matSpec=(genItmName[3] as float)*100
  302. matBump1=genItmName[4] as float
  303. matBump2=genItmName[5] as float
  304. )
  305. else
  306. (
  307. -- this can get fucked up if there are too many _ in the mesh name .. ohwell
  308. matSpec=10
  309. matBump1=1
  310. matBump2=1
  311. )
  312. -- append texProp [matSpec,matBump1,matBump1]
  313. for c = 6 to genItmName.count do
  314. (
  315. mshCamTar=genItmName[c]
  316. )
  317. )
  318. )
  319. -- Camera Is Ignored, who the fuck saves cam info on a char model.
  320. uvwCount=readlong f #unsigned
  321. texCount=readlong f #unsigned
  322. for x = 1 to texCount do
  323. (
  324. texName=ReadFixedString f (readbyte f #unsigned)
  325. uvLayer=(readlong f #unsigned)+1 -- which UV layer to use.
  326. if uvLayer>=2 do uvLayer+=1 --max compatiblity.. cannot use layer 2
  327. append uvChnArray uvLayer
  328. append texArray (fpath+(filenameFromPath texName))
  329. )
  330. if matON==true do
  331. (
  332. if matType==undefined then
  333. (
  334. -- Not GenericItem, Trying to Detect Material Type
  335. texOpacity=true
  336. texSpec=true
  337. for x = 1 to texArray.count do
  338. (
  339. if (skipToString (texArray[x] as stringstream) "_lightmap")==OK do(texLight=true)
  340. if (skipToString (texArray[x] as stringstream) "_bump")==OK do(texBump=true)
  341. if (skipToString (texArray[x] as stringstream) "_mask")==OK do(texMask=true)
  342. if (skipToString (texArray[x] as stringstream) "_bump1")==OK do(texDetail1=true)
  343. if (skipToString (texArray[x] as stringstream) "_bump2")==OK do(texDetail2=true)
  344. -- 7 Yes Yes Yes No No No 1 Diffuse
  345. -- 9 Yes Yes Yes No No No 2 Diffuse, Lightmap
  346. -- 6 Yes Yes Yes Yes No No 2 Diffuse, Bumpmap
  347. -- 8 Yes Yes Yes Yes No No 3 Diffuse, Lightmap, Bumpmap
  348. -- 20 Yes Yes Yes Yes Yes Yes 6 Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2
  349. )
  350. if (skipToString (mshName as stringstream) "collar")==OK do
  351. (
  352. matSpec=10
  353. matBump1=12
  354. matBump2=12
  355. )
  356. if (skipToString (mshName as stringstream) "gear")==OK do
  357. (
  358. matSpec=10
  359. matBump1=12
  360. matBump2=12
  361. )
  362. if (skipToString (mshName as stringstream) "belt")==OK do
  363. (
  364. matSpec=10
  365. matBump1=10
  366. matBump2=20
  367. )
  368. if (skipToString (mshName as stringstream) "suit")==OK do
  369. (
  370. matSpec=30
  371. matBump1=24
  372. matBump2=48
  373. )
  374. )
  375. else
  376. (
  377. -- ================================================================
  378. -- Standard Materials (CANNOT DO TRANSPARANCY)
  379. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  380. if matType == 10 do
  381. (
  382. -- Diffuse Only, High Emssive. Good For Anime Models
  383. texIllum=true
  384. )
  385. if matType == 5 do
  386. (
  387. -- Diffuse Only. Good As A Quick Material
  388. )
  389. if matType == 3 do
  390. (
  391. -- Lightmap
  392. texLight=true
  393. )
  394. if matType == 4 do
  395. (
  396. -- NormalMap + Spec
  397. texSpec=true
  398. texBump=true
  399. )
  400. if matType == 2 do
  401. (
  402. -- NormalMap + Spec + LightMap
  403. texSpec=true
  404. texLight=true
  405. texBump=true
  406. )
  407. if matType == 24 do
  408. (
  409. -- NormalMap + SpecMap + LightMap
  410. texSpec=true
  411. texSpecMap=true
  412. texLight=true
  413. texBump=true
  414. )
  415. if matType == 26 do
  416. (
  417. -- NormalMap + EnvMap
  418. texSpec=true
  419. texReflect=true
  420. texLight=true
  421. texBump=true
  422. )
  423. if matType == 28 do
  424. (
  425. -- NormalMap + DetailMap + EnvMap
  426. texReflect=true
  427. texSpec=true
  428. texBump=true
  429. texMask=true
  430. texDetail1=true
  431. texDetail2=true
  432. )
  433. if matType == 1 do
  434. (
  435. -- NormalMap + DetailMap + Spec + LightMap
  436. texSpec=true
  437. texLight=true
  438. texBump=true
  439. texMask=true
  440. texDetail1=true
  441. texDetail2=true
  442. )
  443. if matType == 22 do
  444. (
  445. -- NormalMap + DetailMap + SpecMap + LightMap
  446. texSpec=true
  447. texSpecMap=true
  448. texLight=true
  449. texBump=true
  450. texMask=true
  451. texDetail1=true
  452. texDetail2=true
  453. )
  454. -- ================================================================
  455. -- Transparent Materials
  456. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457. if matType == 21 do
  458. (
  459. -- Diffuse Only, High Emissive. Good For Anime Models
  460. texOpacity=true
  461. texIllum=true
  462. )
  463. if matType == 7 do
  464. (
  465. -- Diffuse Only. Good As A Quick Material
  466. texOpacity=true
  467. )
  468. if matType == 9 do
  469. (
  470. -- Lightmap
  471. texOpacity=true
  472. texLight=true
  473. )
  474. if matType == 6 do
  475. (
  476. -- NormalMap + Spec
  477. texOpacity=true
  478. texSpec=true
  479. texBump=true
  480. )
  481. if matType == 8 do
  482. (
  483. -- NormalMap + Spec + LightMap
  484. texOpacity=true
  485. texSpec=true
  486. texLight=true
  487. texBump=true
  488. )
  489. if matType == 25 do
  490. (
  491. -- NormalMap + SpecMap + LightMap
  492. texOpacity=true
  493. texSpec=true
  494. texSpecMap=true
  495. texLight=true
  496. texBump=true
  497. )
  498. if matType == 27 do
  499. (
  500. -- NormalMap + EnvMap
  501. texOpacity=true
  502. texSpec=true
  503. texReflect=true
  504. texBump=true
  505. )
  506. if matType == 29 do
  507. (
  508. -- NormalMap + DetailMap + EnvMap
  509. texOpacity=true
  510. texReflect=true
  511. texSpec=true
  512. texBump=true
  513. texMask=true
  514. texDetail1=true
  515. texDetail2=true
  516. )
  517. if matType == 20 do
  518. (
  519. -- NormalMap + DetailMap + Spec + LightMap
  520. texOpacity=true
  521. texSpec=true
  522. texLight=true
  523. texBump=true
  524. texMask=true
  525. texDetail1=true
  526. texDetail2=true
  527. )
  528. if matType == 23 do
  529. (
  530. -- NormalMap + DetailMap + SpecMap + LightMap
  531. texOpacity=true
  532. texSpec=true
  533. texSpecMap=true
  534. texLight=true
  535. texBump=true
  536. texMask=true
  537. texDetail1=true
  538. texDetail2=true
  539. )
  540. -- ================================================================
  541. -- Extra Materials (Redunant Materials Mirrored for Static Models?)
  542. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  543. if matType == 13 do
  544. (
  545. -- Diffuse Only, High Emissive (Good for SkyBoxes)
  546. texStatic=true
  547. texIllum=true
  548. )
  549. if matType == 14 do
  550. (
  551. -- NormalMap, High Emissive
  552. texStatic=true
  553. texIllum=true
  554. texSpec=true
  555. texBump=true
  556. )
  557. if matType == 16 do
  558. (
  559. -- Diffuse Only
  560. texStatic=true
  561. )
  562. if matType == 11 do
  563. (
  564. -- NormalMap
  565. texStatic=true
  566. texSpec=true
  567. texBump=true
  568. )
  569. if matType == 17 do
  570. (
  571. -- LightMap
  572. texStatic=true
  573. texLight=true
  574. )
  575. if matType == 18 do
  576. (
  577. -- Transparent, Diffuse Only
  578. texStatic=true
  579. texOpacity=true
  580. )
  581. if matType == 19 do
  582. (
  583. -- Transparent, LightMap
  584. texStatic=true
  585. texOpacity=true
  586. texLight=true
  587. )
  588. if matType == 12 do
  589. (
  590. -- Transparent, NormalMap
  591. texStatic=true
  592. texOpacity=true
  593. texSpec=true
  594. texBump=true
  595. )
  596. if matType == 15 do
  597. (
  598. -- Transparent, NormalMap + High Emissive (Good For SkyBoxes)
  599. texStatic=true
  600. texOpacity=true
  601. texIllum=true
  602. texSpec=true
  603. texBump=true
  604. )
  605. -- ================================================================
  606. )
  607. if texSpec==true then
  608. (
  609. if texOpacity==false then
  610. (
  611. mat.specularLevel = matSpec
  612. )
  613. else
  614. (
  615. if texSpecMap==false then
  616. (
  617. mat.specularLevelMapAmount = matSpec
  618. mat.specularLevelMap = Bitmaptexture fileName:texArray[1]
  619. -- mat.specularLevelMap.effectsChannel = uvChnArray[1]
  620. mat.specularLevelMap.coords.mapChannel = uvChnArray[1]
  621. -- mat.monoOutput = 1
  622. -- mat.alphaSource = 0
  623. -- mat.preMultAlpha = off
  624. )
  625. else
  626. (
  627. if texMask==false then
  628. (
  629. mat.specularLevelMap = Bitmaptexture fileName:texArray[4]
  630. -- mat.specularLevelMap.effectsChannel = uvChnArray[4]
  631. mat.specularLevelMap.coords.mapChannel = uvChnArray[4]
  632. )
  633. else
  634. (
  635. mat.specularLevelMap = Bitmaptexture fileName:texArray[7]
  636. -- mat.specularLevelMap.effectsChannel = uvChnArray[7]
  637. mat.specularLevelMap.coords.mapChannel = uvChnArray[7]
  638. )
  639. )
  640. )
  641. )
  642. else(mat.specularLevel = 0)
  643. if texIllum==true do
  644. (
  645. mat.selfIllumAmount = 100
  646. )
  647. mat.diffuseMap = Bitmaptexture fileName:texArray[1]
  648. -- mat.diffuseMap.effectsChannel = uvChnArray[1]
  649. mat.diffuseMap.coords.mapChannel = uvChnArray[1]
  650. mat.diffuseMap.monoOutput = 1
  651. mat.diffuseMap.alphaSource = 2
  652. mat.diffuseMap.preMultAlpha = on
  653. if texOpacity==true do
  654. (
  655. mat.opacityMap = Bitmaptexture fileName:texArray[1]
  656. -- mat.opacityMap.effectsChannel = uvChnArray[1]
  657. mat.opacityMap.coords.mapChannel = uvChnArray[1]
  658. mat.opacityMap.monoOutput = 1
  659. mat.opacityMap.alphaSource = 0
  660. mat.opacityMap.preMultAlpha = off
  661. )
  662. if texLight==true do
  663. (
  664. matMod=RGB_Multiply ()
  665. matMod.map1 = mat.diffuseMap
  666. -- matMod.map1.effectsChannel = texArray[1]
  667. matMod.map2 = Bitmaptexture fileName:texArray[2]
  668. -- matMod.map2.effectsChannel = texArray[2]
  669. matMod.map1.coords.mapChannel = uvChnArray[1]
  670. matMod.map2.coords.mapChannel = uvChnArray[2]
  671. matMod.map1Enabled = true
  672. matMod.map2Enabled = true
  673. matMod.alphaFrom = 0
  674. mat.diffuseMap = matMod
  675. )
  676. if texBump==true do
  677. (
  678. mat.bumpMapEnable = on
  679. mat.bumpMapAmount = 100
  680. matMod=Normal_Bump ()
  681. if texLight==false then
  682. (
  683. matMod.map1on = true
  684. matMod.normal_map = Bitmaptexture fileName:texArray[2]
  685. -- matMod.normal_map.effectsChannel = uvChnArray[2]
  686. matMod.normal_map.coords.mapChannel = uvChnArray[2]
  687. if texMask==true do
  688. (
  689. maskMod1 = Mask ()
  690. maskMod2 = Mask ()
  691. layerMod = CompositeTexturemap ()
  692. tintMod = RGB_Tint ()
  693. tintMod.red = color 255 255 255
  694. tintMod.green = color 0 0 0
  695. tintMod.blue = color 0 0 0
  696. tintMod.map1 = Bitmaptexture fileName:texArray[3]
  697. -- tintMod.map1.effectsChannel = uvChnArray[4]
  698. tintMod.map1.coords.mapChannel = uvChnArray[3]
  699. tintMod.map1Enabled = true
  700. maskMod1.mask = tintMod
  701. tintMod = RGB_Tint ()
  702. tintMod.red = color 0 0 0
  703. tintMod.green = color 255 255 255
  704. tintMod.blue = color 0 0 0
  705. tintMod.map1 = Bitmaptexture fileName:texArray[3]
  706. -- tintMod.map1.effectsChannel = uvChnArray[5]
  707. tintMod.map1.coords.mapChannel = uvChnArray[3]
  708. tintMod.map1Enabled = true
  709. maskMod2.mask = tintMod
  710. maskMod1.map = Bitmaptexture fileName:texArray[4]
  711. maskMod2.map = Bitmaptexture fileName:texArray[5]
  712. -- maskMod1.map.effectsChannel = uvChnArray[3]
  713. -- maskMod2.map.effectsChannel = uvChnArray[3]
  714. maskMod1.map.coords.mapChannel = uvChnArray[4]
  715. maskMod2.map.coords.mapChannel = uvChnArray[5]
  716. maskMod1.map.coords.u_tiling = matBump1
  717. maskMod1.map.coords.v_tiling = matBump1
  718. maskMod2.map.coords.u_tiling = matBump2
  719. maskMod2.map.coords.v_tiling = matBump2
  720. maskMod1.mapEnabled = true
  721. maskMod2.mapEnabled = true
  722. maskMod1.maskEnabled = true
  723. maskMod2.maskEnabled = true
  724. maskMod1.maskInverted = false
  725. maskMod2.maskInverted = false
  726. layerMod.mapList.count=2
  727. layerMod.mapEnabled[1] = on
  728. layerMod.mapEnabled[2] = on
  729. layerMod.mapList[1] = maskMod1
  730. layerMod.mapList[2] = maskMod2
  731. matMod.bump_map = layerMod
  732. matMod.map2on = true
  733. )
  734. )
  735. else
  736. (
  737. matMod.map1on = true
  738. matMod.normal_map = Bitmaptexture fileName:texArray[3]
  739. -- matMod.normal_map.effectsChannel = uvChnArray[3]
  740. matMod.normal_map.coords.mapChannel = uvChnArray[3]
  741. if texMask==true do
  742. (
  743. maskMod1 = Mask ()
  744. maskMod2 = Mask ()
  745. layerMod = CompositeTexturemap ()
  746. tintMod = RGB_Tint ()
  747. tintMod.red = color 255 255 255
  748. tintMod.green = color 0 0 0
  749. tintMod.blue = color 0 0 0
  750. tintMod.map1 = Bitmaptexture fileName:texArray[4]
  751. -- tintMod.map1.effectsChannel = uvChnArray[5]
  752. tintMod.map1.coords.mapChannel = uvChnArray[4]
  753. tintMod.map1Enabled = true
  754. maskMod1.mask = tintMod
  755. tintMod = RGB_Tint ()
  756. tintMod.red = color 0 0 0
  757. tintMod.green = color 255 255 255
  758. tintMod.blue = color 0 0 0
  759. tintMod.map1 = Bitmaptexture fileName:texArray[4]
  760. tintMod.map1.coords.mapChannel = uvChnArray[4]
  761. tintMod.map1Enabled = true
  762. maskMod2.mask = tintMod
  763. maskMod1.map = Bitmaptexture fileName:texArray[5]
  764. maskMod2.map = Bitmaptexture fileName:texArray[6]
  765. -- maskMod1.map.effectsChannel = uvChnArray[4]
  766. -- maskMod2.map.effectsChannel = uvChnArray[4]
  767. maskMod1.map.coords.mapChannel = uvChnArray[5]
  768. maskMod2.map.coords.mapChannel = uvChnArray[6]
  769. maskMod1.map.coords.u_tiling = matBump1
  770. maskMod1.map.coords.v_tiling = matBump1
  771. maskMod2.map.coords.u_tiling = matBump2
  772. maskMod2.map.coords.v_tiling = matBump2
  773. maskMod1.mapEnabled = true
  774. maskMod2.mapEnabled = true
  775. maskMod1.maskEnabled = true
  776. maskMod2.maskEnabled = true
  777. maskMod1.maskInverted = false
  778. maskMod2.maskInverted = false
  779. layerMod.mapList.count=2
  780. layerMod.mapEnabled[1] = on
  781. layerMod.mapEnabled[2] = on
  782. layerMod.mapList[1] = maskMod1
  783. layerMod.mapList[2] = maskMod2
  784. matMod.bump_map = layerMod
  785. matMod.map2on = true
  786. )
  787. )
  788. -- matMod.alphaSource = 2
  789. -- matMod.filtering = 2
  790. -- matMod.alphaSource = 2
  791. mat.bumpMap = matMod
  792. )
  793. if texReflect==true do
  794. (
  795. mat.reflectionMapEnable = on
  796. mat.reflectionMapAmount = 30
  797. if texMask==false then
  798. (
  799. mat.reflectionMap = Bitmaptexture fileName:texArray[3]
  800. -- matMod.map2.effectsChannel = texArray[3]
  801. matMod.map2.coords.mapChannel = uvChnArray[3]
  802. )
  803. else
  804. (
  805. mat.reflectionMap = Bitmaptexture fileName:texArray[6]
  806. -- matMod.map2.effectsChannel = texArray[6]
  807. matMod.map2.coords.mapChannel = uvChnArray[6]
  808. )
  809. )
  810. showTextureMap mat true
  811. )
  812. vertCount=readlong f #unsigned
  813. for x = 1 to vertCount do
  814. (
  815. vx=readfloat f*scaling
  816. vz=readfloat f*scaling
  817. vy=readfloat f*-scaling
  818. nx=readfloat f*scaling
  819. nz=readfloat f*scaling
  820. ny=readfloat f*-scaling
  821. cr=readbyte f #unsigned
  822. cg=readbyte f #unsigned
  823. cb=readbyte f #unsigned
  824. ca=readbyte f #unsigned/255
  825. for y = 1 to uvwCount do
  826. (
  827. if y==1 do append vertBuffer.texture [(readfloat f),(readfloat f*-1),0]
  828. if y==2 do append vertBuffer.texture2 [(readfloat f),(readfloat f*-1),0]
  829. if y==3 do append vertBuffer.texture3 [(readfloat f),(readfloat f*-1),0]
  830. )
  831. for y = 1 to uvwCount do
  832. (
  833. -- Skips Vertex Tangents, (3dsmax doesn't support tangents.)
  834. fseek f (4*4) #seek_cur
  835. )
  836. if boneCount!=0 do
  837. (
  838. b1 = readshort f #unsigned+1
  839. b2 = readshort f #unsigned+1
  840. b3 = readshort f #unsigned+1
  841. b4 = readshort f #unsigned+1
  842. w1 = readfloat f
  843. w2 = readfloat f
  844. w3 = readfloat f
  845. w4 = readfloat f
  846. if b1!=0 do
  847. (
  848. find=findItem boneArray b1
  849. if find==0 do( append boneArray b1)
  850. )
  851. if b2!=0 do
  852. (
  853. find=findItem boneArray b2
  854. if find==0 do( append boneArray b2)
  855. )
  856. if b3!=0 do
  857. (
  858. find=findItem boneArray b3
  859. if find==0 do( append boneArray b3)
  860. )
  861. if b4!=0 do
  862. (
  863. find=findItem boneArray b4
  864. if find==0 do( append boneArray b4)
  865. )
  866. append vertBuffer.boneids [b1,b2,b3,b4]
  867. append vertBuffer.weights [w1,w2,w3,w4]
  868. )
  869. append vertBuffer.position [vx,vy,vz]
  870. append vertBuffer.normal [nx,ny,nz]
  871. append vertBuffer.colour [cr,cg,cb,ca]
  872. )
  873. faceCount=readlong f #unsigned
  874. for x = 1 to faceCount do
  875. (
  876. fc = readlong f + faceAdder
  877. fb = readlong f + faceAdder
  878. fa = readlong f + faceAdder
  879. append faceArray[fa,fb,fc]
  880. )
  881. if meshON==true do
  882. (
  883. if mshSingle==false then
  884. (
  885. msh = mesh vertices:vertBuffer.position faces:faceArray
  886. msh.numTVerts = vertCount
  887. buildTVFaces msh
  888. msh.name = mshName
  889. msh.material=mat
  890. for j = 1 to vertCount do meshop.setVertColor msh 0 j (color vertBuffer.colour[j][1] vertBuffer.colour[j][2] vertBuffer.colour[j][3])
  891. for j = 1 to vertCount do meshop.setVertAlpha msh -2 j vertBuffer.colour[j][4]
  892. for j = 1 to vertCount do setTVert msh j vertBuffer.texture[j]
  893. -- for j = 1 to vertCount do setNormal msh j vertBuffer.normal[j] -- Normals Don't Stick, lost when modifers are added
  894. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  895. if uvwCount==2 do
  896. (
  897. meshop.setNumMaps msh 3 keep:true
  898. for j = 1 to vertCount do (meshOp.setMapVert msh 2 j vertBuffer.texture2[j])
  899. )
  900. if uvwCount==3 do
  901. (
  902. meshop.setNumMaps msh 4 keep:true
  903. for j = 1 to vertCount do (meshOp.setMapVert msh 3 j vertBuffer.texture3[j])
  904. )
  905. max modify mode
  906. if skinON==true do
  907. (
  908. clearSelection()
  909. select msh
  910. skinMod = skin ()
  911. addModifier msh skinMod
  912. for i = 1 to boneArray.count do
  913. (
  914. if 1 != boneArray.count then
  915. (
  916. skinOps.addBone skinMod BNArr[(boneArray[i])] 0
  917. )
  918. else
  919. (
  920. skinOps.addBone skinMod BNArr[(boneArray[i])] 1
  921. )
  922. )
  923. modPanel.setCurrentObject skinMod
  924. for i = 1 to vertCount do
  925. (
  926. bi = #()
  927. wv = #()
  928. for j = 1 to 4 do
  929. (
  930. boneid = vertBuffer.boneids[i][j]
  931. weight = vertBuffer.weights[i][j]
  932. if weight!=0 do
  933. (
  934. append bi (findItem boneArray boneid)
  935. append wv weight
  936. )
  937. )
  938. skinOps.ReplaceVertexWeights skinMod i bi wv
  939. )
  940. )
  941. --enable skin loop
  942. if normON==true do
  943. (
  944. clearSelection()
  945. select msh
  946. normMod = Edit_Normals()
  947. addModifier msh normMod
  948. normMod.displayLength = 1
  949. -- subobjectLevel = 1
  950. -- modPanel.setCurrentObject normMod
  951. for n = 1 to (normMod.GetNumFaces node:msh) do
  952. (
  953. -- norm=normMod.GetNormal n node:msh
  954. -- print norm
  955. vertID=getFace msh n
  956. normMod.displayLength = 0
  957. subobjectLevel = 1
  958. modPanel.setCurrentObject normMod
  959. for c = 1 to 3 do
  960. (
  961. normID=normMod.GetNormalID n c node:msh
  962. normMod.EditNormalsMod.SetSelection #{normID}
  963. normMod.EditNormalsMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
  964. normMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
  965. normMod.EditNormalsMod.MakeExplicit ()
  966. normMod.EditNormalsMod.SetSelection #{}
  967. )
  968. )
  969. subobjectLevel = 0
  970. -- update msh
  971. modPanel.setCurrentObject normMod
  972. )
  973. -- enable normals loop
  974. )
  975. else
  976. (
  977. mat.name = mshName
  978. faceAdder+=vertCount
  979. append faceDimArray faceCount
  980. )
  981. )
  982. --useless loop lol
  983. )
  984. -- ends mesh loop
  985. if mshSingle==true do
  986. (
  987. vertCount=vertBuffer.position.count
  988. msh = mesh vertices:vertBuffer.position faces:faceArray
  989. msh.numTVerts = vertCount
  990. buildTVFaces msh
  991. msh.name = fname
  992. msh.material=mm
  993. faceAdder=0
  994. for j = 1 to meshCount do (for x = 1 to faceDimArray[j] do(faceAdder+=1;setFaceMatID msh faceAdder j))
  995. for j = 1 to vertCount do meshop.setVertColor msh 0 j (color vertBuffer.colour[j][1] vertBuffer.colour[j][2] vertBuffer.colour[j][3])
  996. for j = 1 to vertCount do meshop.setVertAlpha msh -2 j vertBuffer.colour[j][4]
  997. for j = 1 to vertCount do setTVert msh j vertBuffer.texture[j]
  998. -- for j = 1 to vertCount do setNormal msh j vertBuffer.normal[j] -- Normals Don't Stick, lost when modifers are added
  999. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  1000. if uvwCount==2 do
  1001. (
  1002. meshop.setNumMaps msh 3 keep:true
  1003. for j = 1 to vertCount do (meshOp.setMapVert msh 2 j vertBuffer.texture2[j])
  1004. )
  1005. if uvwCount==3 do
  1006. (
  1007. meshop.setNumMaps msh 4 keep:true
  1008. for j = 1 to vertCount do (meshOp.setMapVert msh 3 j vertBuffer.texture3[j])
  1009. )
  1010. max modify mode
  1011. if skinON==true do
  1012. (
  1013. clearSelection()
  1014. select msh
  1015. skinMod = skin ()
  1016. addModifier msh skinMod
  1017. for i = 1 to boneArray.count do
  1018. (
  1019. if 1 != boneArray.count then
  1020. (
  1021. skinOps.addBone skinMod BNArr[(boneArray[i])] 0
  1022. )
  1023. else
  1024. (
  1025. skinOps.addBone skinMod BNArr[(boneArray[i])] 1
  1026. )
  1027. )
  1028. modPanel.setCurrentObject skinMod
  1029. for i = 1 to vertCount do
  1030. (
  1031. bi = #()
  1032. wv = #()
  1033. for j = 1 to 4 do
  1034. (
  1035. boneid = vertBuffer.boneids[i][j]
  1036. weight = vertBuffer.weights[i][j]
  1037. if weight!=0 do
  1038. (
  1039. append bi (findItem boneArray boneid)
  1040. append wv weight
  1041. )
  1042. )
  1043. skinOps.ReplaceVertexWeights skinMod i bi wv
  1044. )
  1045. )
  1046. --enable skin loop
  1047. if normON==true do
  1048. (
  1049. clearSelection()
  1050. select msh
  1051. normMod = Edit_Normals()
  1052. addModifier msh normMod
  1053. normMod.displayLength = 1
  1054. -- subobjectLevel = 1
  1055. -- modPanel.setCurrentObject normMod
  1056. for n = 1 to (normMod.GetNumFaces node:msh) do
  1057. (
  1058. -- norm=normMod.GetNormal n node:msh
  1059. -- print norm
  1060. vertID=getFace msh n
  1061. normMod.displayLength = 0
  1062. subobjectLevel = 1
  1063. modPanel.setCurrentObject normMod
  1064. for c = 1 to 3 do
  1065. (
  1066. normID=normMod.GetNormalID n c node:msh
  1067. normMod.EditNormalsMod.SetSelection #{normID}
  1068. normMod.EditNormalsMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
  1069. normMod.SetNormal normID vertBuffer.normal[(vertID[c])] node:msh
  1070. normMod.EditNormalsMod.MakeExplicit ()
  1071. normMod.EditNormalsMod.SetSelection #{}
  1072. )
  1073. )
  1074. subobjectLevel = 0
  1075. -- update msh
  1076. modPanel.setCurrentObject normMod
  1077. )
  1078. -- enable normals loop
  1079. )
  1080. if fsize!=(ftell f) then
  1081. (
  1082. Print ("Done ! @ 0x"+((bit.intAsHex(ftell f))as string))
  1083. )
  1084. else(Print "END OF FILE REACHED")
  1085. gc()
  1086. fclose f
  1087. flushLog()
  1088. closeLog()
  1089. enableSceneRedraw()
  1090. )
  1091. )
  1092. )
  1093. -- Close mesh ext Loop
  1094. if fext==".ascii" do
  1095. (
  1096. f=MemStreamMgr.openFile fsource
  1097. fext= getFilenameType fsource
  1098. fpath= getFilenamePath fsource
  1099. fname= getFilenameFile fsource
  1100. st = timestamp() --get start time in milliseconds
  1101. ts = timestamp()
  1102. clearlistener()
  1103. openLog (fpath+fname+"_log.txt") mode:"w" outputOnly:true
  1104. print (localTime+"\n"+fname+fext)
  1105. --===========================================================================
  1106. undo off
  1107. (
  1108. --===========================================================================
  1109. with redraw off
  1110. (
  1111. struct bone_data
  1112. (
  1113. bName,parent,child,position
  1114. )
  1115. boneBuffer = (bone_data bName:#() parent:#() child:#() position:#())
  1116. boneCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
  1117. for i = 1 to boneCount do
  1118. (
  1119. boneName=f.readLine()
  1120. boneParent=f.readLine()
  1121. bonePosition=f.readLine()
  1122. -- bonePosition=bonePosition as stringstream
  1123. append boneBuffer.bName boneName
  1124. -- append boneBuffer.parent ((boneParent as integer)+1)
  1125. -- append boneBuffer.position [(readDelimitedString bonePosition " " as float), \
  1126. -- (readDelimitedString bonePosition " " as float),(readDelimitedString bonePosition "" as float)]
  1127. )
  1128. renderGroups=#()
  1129. renderSettings=#()
  1130. meshCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
  1131. Print ("\nBone Count: "+(boneCount as string)+"\nMesh Count: "+(meshCount as string)+"\n")
  1132. for i = 1 to meshCount do
  1133. (
  1134. meshName=f.readLine(); Print meshName
  1135. append renderGroups ((readDelimitedString (meshName as stringstream) "_") as integer)
  1136. append renderSettings ((readDelimitedString (meshName as stringstream) "_") as float)
  1137. append renderSettings ((readDelimitedString (meshName as stringstream) "_") as float)
  1138. uvwCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
  1139. texCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
  1140. print ((texCount as string)+" Textures, "+(uvwCount as string)+" UV Layers")
  1141. for x = 1 to texCount do
  1142. (
  1143. texName=f.readLine()
  1144. uvLayer=((readDelimitedString (f.readLine() as stringstream) " ") as integer)+1
  1145. print ((filenameFromPath texName)+" ["+(uvLayer as string)+"]")
  1146. )
  1147. print ""
  1148. vertCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
  1149. for x = 1 to vertCount do
  1150. (
  1151. meshPosition=f.readLine()
  1152. meshNormal=f.readLine()
  1153. meshColour=f.readLine()
  1154. for y = 1 to uvwCount do
  1155. (
  1156. meshUVW=f.readLine()
  1157. )
  1158. if boneCount!=0 do
  1159. (
  1160. boneIndices=f.readLine()
  1161. boneWeights=f.readLine()
  1162. -- b1 = (readDelimitedString boneIndices " " as integer)+1
  1163. -- b2 = (readDelimitedString boneIndices " " as integer)+1
  1164. -- b3 = (readDelimitedString boneIndices " " as integer)+1
  1165. -- b4 = (readDelimitedString boneIndices "" as integer)+1
  1166. -- w1 = (readDelimitedString boneWeights " " as float)
  1167. -- w2 = (readDelimitedString boneWeights " " as float)
  1168. -- w3 = (readDelimitedString boneWeights " " as float)
  1169. -- w4 = (readDelimitedString boneWeights "" as float)
  1170. -- if b1!=0 do
  1171. (
  1172. find=findItem boneArray b1
  1173. -- if find==0 do( append boneArray b1)
  1174. )
  1175. -- if b2!=0 do
  1176. (
  1177. find=findItem boneArray b2
  1178. -- if find==0 do( append boneArray b2)
  1179. )
  1180. -- if b3!=0 do
  1181. (
  1182. find=findItem boneArray b3
  1183. -- if find==0 do( append boneArray b3)
  1184. )
  1185. -- if b4!=0 do
  1186. (
  1187. find=findItem boneArray b4
  1188. -- if find==0 do( append boneArray b4)
  1189. )
  1190. -- append vertBuffer.boneids [b1,b2,b3,b4]
  1191. -- append vertBuffer.weights [w1,w2,w3,w4]
  1192. )
  1193. -- vx=(readDelimitedString meshPosition " " as float)
  1194. -- vz=(readDelimitedString meshPosition " " as float)
  1195. -- vy=(readDelimitedString meshPosition "" as float)
  1196. -- nx=(readDelimitedString meshNormal " " as float)
  1197. -- nz=(readDelimitedString meshNormal " " as float)
  1198. -- ny=(readDelimitedString meshNormal "" as float)
  1199. -- cr=(readDelimitedString meshPosition " " as integer)
  1200. -- cg=(readDelimitedString meshPosition " " as integer)
  1201. -- cb=(readDelimitedString meshPosition " " as integer)
  1202. -- ca=(readDelimitedString meshPosition "" as integer)/255
  1203. -- append vertBuffer.position [vx,vy,vz]
  1204. -- append vertBuffer.normal [nx,ny,nz]
  1205. -- append vertBuffer.colour [cr,cg,cb,ca]
  1206. )
  1207. faceCount=(readDelimitedString (f.readLine() as stringstream) " ") as integer
  1208. for x = 1 to faceCount do
  1209. (
  1210. faceIndices=f.readLine()
  1211. -- fc = (readDelimitedString faceIndices " " as integer)+1
  1212. -- fb = (readDelimitedString faceIndices " " as integer)+1
  1213. -- fa = (readDelimitedString faceIndices "" as integer)+1
  1214. -- append faceArray[fa,fb,fc]
  1215. )
  1216. -- INSERT MESH IMPORT OP HERE
  1217. )
  1218. -- Mesh Loop
  1219. print "Detected Render Groups"
  1220. print renderGroups
  1221. print ""
  1222. print ""
  1223. print "Skeleton\n"
  1224. print boneBuffer.bName
  1225. gc()
  1226. fclose f
  1227. flushLog()
  1228. closeLog()
  1229. MemStreamMgr.close f
  1230. enableSceneRedraw()
  1231. Print ("\nDone! ("+((((timestamp())-st)/60)as string)+" Seconds)") --print time to finish
  1232. )
  1233. )
  1234. )
  1235. -- Close ascii ext Loop
  1236. if fext!=".ascii" AND fext!=".mesh" do MessageBox "File Extension Error"
  1237. )
  1238. else(MessageBox "Error Opening File!")
  1239. )
  1240. else (Print "Aborted.")
  1241. )
  1242. -- Close Button for IMPORT
  1243. on btn2 pressed do
  1244. (
  1245. -- EXPORT
  1246. st = timestamp() --get start time in milliseconds
  1247. -- ssource= "C:\\Users\\ACER_PREDATOR\\Desktop\\test.obj"
  1248. -- ssource= "C:\\Program Files (x86)\\XNALara\\data\\Max_Export\\goldenaxe_bikini\\generic_item.mesh.ascii"
  1249. if expFixed==false OR ssource==""do
  1250. (
  1251. ssource = getSaveFileName \
  1252. caption:"Save XnaLara ASCII Model File" \
  1253. types: "Text File (*.ASCII)|*.ascii|All files (*.*)|*.*|"
  1254. )
  1255. -- ssource=((getFilenameFile ssource)+".mesh.ascii") -- checks the name
  1256. -- ssource = getSaveFileName \
  1257. -- caption:"WaveFront OBJ Exporter" \
  1258. -- types: "OBJ(*.obj)|*.OBJ|All files (*.*)|*.*|"
  1259. if ssource!=""AND ssource!=undefined then
  1260. (
  1261. out_file = createfile ssource
  1262. fpath=(getFilenamePath ssource)
  1263. if (doesFileExist ssource)==true then
  1264. (
  1265. -- mshScale=1
  1266. mshScale=imperial_scale/rescale -- converts centimeters to inches ? my unit system is in inches ? is detection needed?
  1267. mshFlipUV=false -- not setup/wont do anything
  1268. mshRightH=true -- not setup/wont do anything
  1269. mshBySelection=chk4.checked
  1270. mshOptimise=chk6.checked-- wtf its faster with this on?
  1271. mshAddRoot=chk5.checked -- reparents all bones to a single root bone
  1272. mshBoneLimit=false -- as for now, only warns you if you've gonve over the bone limit (59 bones MAX)
  1273. fn checkname str =
  1274. (
  1275. -- removes special characters from names
  1276. local str0=""
  1277. for i = 1 to str.count do
  1278. (
  1279. if str[i]!="_" and str[i]!="#" and str[i]!=" " and str[i]!="." and str[i]!="/" and str[i]!="_" and str[i]!="\"" and str[i]!="\\"
  1280. do str0+=str[i]
  1281. )
  1282. str0
  1283. )
  1284. fn renamedup aray idx =
  1285. (
  1286. -- renames duplicated names
  1287. local namCount=1
  1288. newname= aray[idx]+"("+(namCount as string)+")"
  1289. find=findItem aray newname
  1290. if find!=0 do
  1291. (
  1292. while(findItem aray newname)!=0 do
  1293. (
  1294. namCount+=1
  1295. newname=aray[idx]+"("+(namCount as string)+")"
  1296. )
  1297. )
  1298. newname
  1299. )
  1300. fn getMaterial msh matid =
  1301. (
  1302. -- tries to sort a material into a correct render group
  1303. local matArray=#()
  1304. matArray[14]=""
  1305. -- matArray[1]-> ESTIMATED RENDER GROUP
  1306. -- matArray[2] -> texDiffuse
  1307. -- matArray[3] -> texOpacity
  1308. -- matArray[4] -> texIllum
  1309. -- matArray[5] -> texSpecMap
  1310. -- matArray[6] -> texSpec
  1311. -- matArray[7] -> texLight
  1312. -- matArray[8] -> texBump
  1313. -- matArray[9] -> texDetail1
  1314. -- matArray[10] -> texDetail2
  1315. -- matArray[11]-> matBump1
  1316. -- matArray[12]-> matBump2
  1317. -- matArray[13]-> texMask
  1318. -- matArray[14]-> texReflect
  1319. -- $.material.originalMaterial.diffuseMap
  1320. local matslot=msh.material
  1321. if classOf matslot==standardmaterial do matslot=msh.material
  1322. if classOf matslot==Shell_Material do matslot=msh.material.originalMaterial
  1323. if classOf matslot==multimaterial do matslot=msh.material[matid]
  1324. if matslot!=undefined then
  1325. (
  1326. if classOf matslot.diffuseMap==Bitmaptexture do matArray[2]=filenameFromPath matslot.diffuseMap.filename
  1327. if classOf matslot.diffuseMap==RGB_Multiply do
  1328. (
  1329. matArray[2]=filenameFromPath matslot.diffuseMap.map1.filename
  1330. matArray[7]=filenameFromPath matslot.diffuseMap.map2.filename
  1331. )
  1332. if classOf matslot.ambientMap==Bitmaptexture do matArray[7]=filenameFromPath matslot.ambientMap.filename
  1333. if classOf matslot.opacityMap==Bitmaptexture or matslot.opacity!=100 do matArray[3]="true"
  1334. if classOf matslot.specularLevelMap==Bitmaptexture do matArray[5]=filenameFromPath matslot.specularLevelMap.filename
  1335. if matslot.selfIllumAmount!=0 do matArray[4]="true";matArray[6]=(matslot.specularLevel as string)
  1336. if classOf matslot.bumpMap==Bitmaptexture do matArray[8]=filenameFromPath matslot.bumpMap.filename
  1337. if classOf matslot.reflectionMap==Bitmaptexture do matArray[14]=filenameFromPath matslot.reflectionMap.filename
  1338. if classOf matslot.bumpMap==Normal_Bump do
  1339. (
  1340. if classOf matslot.bumpMap.normal_map==Bitmaptexture do matArray[8]=filenameFromPath matslot.bumpMap.normal_map.filename
  1341. if classOf matslot.bumpMap.bump_map==Bitmaptexture do
  1342. (
  1343. matArray[9]=filenameFromPath matslot.bumpMap.bump_map.filename
  1344. matArray[11]=(matslot.bumpMap.bump_map.coords.u_tiling) as string
  1345. matArray[10]="norm_null.tga";matArray[13]="mask_null.tga"
  1346. )
  1347. if classOf matslot.bumpMap.bump_map==CompositeTexturemap do
  1348. (
  1349. if classOf matslot.bumpMap.bump_map.mapList[2]==Mask \
  1350. AND classOf matslot.bumpMap.bump_map.mapList[3]==Mask do
  1351. (
  1352. if classOf matslot.bumpMap.bump_map.mapList[2].mask==Bitmaptexture \
  1353. OR classOf matslot.bumpMap.bump_map.mapList[2].mask==RGB_Tint then
  1354. (
  1355. if classOf matslot.bumpMap.bump_map.mapList[2].mask==Bitmaptexture do matArray[13]=matslot.bumpMap.bump_map.mapList[2].mask.filename
  1356. if classOf matslot.bumpMap.bump_map.mapList[2].mask==RGB_Tint do matArray[13]=matslot.bumpMap.bump_map.mapList[2].mask.map1.filename
  1357. if classOf matslot.bumpMap.bump_map.mapList[2].map==Bitmaptexture \
  1358. AND classOf matslot.bumpMap.bump_map.mapList[3].map==Bitmaptexture then
  1359. (
  1360. matArray[9]=matslot.bumpMap.bump_map.mapList[2].map.filename
  1361. matArray[10]=matslot.bumpMap.bump_map.mapList[3].map.filename
  1362. matArray[11]=(matslot.bumpMap.bump_map.mapList[2].map.u_tiling) as string
  1363. matArray[12]=(matslot.bumpMap.bump_map.mapList[3].map.u_tiling) as string
  1364. )
  1365. else(matArray[9]="norm_null.tga";matArray[10]="norm_null.tga";matArray[11]="1";matArray[12]="1")
  1366. )
  1367. )
  1368. )
  1369. )
  1370. )
  1371. else
  1372. (
  1373. messagebox "ERROR!!\nUnable To Read Material\n>>Only Standard and Multimaterials Are Supported<<"
  1374. if matslot!=undefined then (matArray[3]=matslot.diffuse as string;matArray[6]=matslot.specularLevel as string)else(matArray[3]="diff_null.tga")
  1375. )
  1376. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1377. -- RENDERING GROUP CHART, WRITTEN AND DESIGNED BY "XNAaraL" AS SPECIFIED FOR XNALARA VERSION 9.6
  1378. -- http://www.tombraiderforums.com/showpost.php?p=5254498&postcount=1735
  1379. -- Group | Shading | Alpha | Poseable | Specular higlight | Bump1 repeater | bump2 repeater | Textures | Texture types | Since | First model / mesh part | Downloadlink
  1380. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1381. -- 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
  1382. -- 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
  1383. -- 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
  1384. -- 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
  1385. -- 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
  1386. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1387. -- 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
  1388. -- 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
  1389. -- 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
  1390. -- 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
  1391. -- 10 | No | No | Yes | No | No | No | 1 | Diffuse | 1.85 | Doppelganger /eyepupils | http://www.mediafire.com/?m0q9yctdris
  1392. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1393. -- 11 | Vertex | No | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.1 | CroftManorHall /Group1 | http://www.mediafire.com/?jlt33lalmjj
  1394. -- 12 | Vertex | Yes | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.1 | CroftManorHall /Group35 | http://www.mediafire.com/?jlt33lalmjj
  1395. -- 13 | No | No | No | No | No | No | 1 | Diffuse | 4.1 | CroftManorHall /Group91 | http://www.mediafire.com/?jlt33lalmjj
  1396. -- 14 | No | No | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.2 | CroftManorHallLQ /Group1 | http://www.mediafire.com/?zjeznnzcgaz
  1397. -- 15 | No | Yes | No | Yes | No | No | 2 | Diffuse, Bumpmap | 4.2 | CroftManorHallLQ /Group35 | http://www.mediafire.com/?zjeznnzcgaz
  1398. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1399. -- 16 | Yes | No | No | No | No | No | 1 | Diffuse | 4.7 | Yacht / part1 | http://www.mediafire.com/?mwakzzz1djy
  1400. -- 17 | Yes | No | No | No | No | No | 2 | Diffuse, Lightmap | 4.7 | Yacht / part5 | http://www.mediafire.com/?mwakzzz1djy
  1401. -- 18 | Yes | Yes | No | No | No | No | 1 | Diffuse | 4.7 | Yacht / part13 | http://www.mediafire.com/?mwakzzz1djy
  1402. -- 19 | Yes | Yes | No | No | No | No | 2 | Diffuse, Lightmap | 5.6 | ShipNatlaRoom /Mesh005 | http://www.mediafire.com/?ztjozjnninn
  1403. -- 20 | Yes | Yes | Yes | Yes | Yes | Yes | 6 | Diffuse, Lightmap, Bumpmap, Mask, Bump1, Bump2 | 7.8 | KnightThrall /Mesh001 | http://www.mediafire.com/?z4uwig2dzum
  1404. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1405. -- 21 | No | Yes | Yes | No | No | No | 1 | Diffuse | 9.1 | kerrigan /$AtlantiB$ |
  1406. -- 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
  1407. -- 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
  1408. -- 24 | Yes | No | Yes | Yes | No | No | 4 | Diffuse, Lightmap, Bumpmap, Specular | 9.42 |
  1409. -- 25 | Yes | Yes | Yes | Yes | No | No | 4 | Diffuse, Lightmap, Bumpmap, Specular | 9.42 |
  1410. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1411. -- 26 | YES/No | No | Yes | Yes intensity | No | No | 3 | Diffuse, Bumpmap, enviroment | 9.5 | MetallicExample /trousers1 | http://www.mediafire.com/?g8gah73w0mv45q7
  1412. -- 27 | YES/No | Yes | Yes | Yes intensity | No | No | 3 | Diffuse, Bumpmap, enviroment | 9.5.5 |
  1413. -- 28 | YES/No | No | Yes | Yes intensity | YES | YES | 6 | Diffuse, Bumpmap, Mask, Bump1, Bump2, enviroment | 9.6 |
  1414. -- 29 | YES/No | Yes | Yes | Yes intensity | YES | YES | 6 | Diffuse, Bumpmap, Mask, Bump1, Bump2, enviroment | 9.6 |
  1415. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1416. if matArray[3]!="diff_null.tga"do
  1417. (
  1418. if matArray[3]!="true"then
  1419. (
  1420. -- Opaque
  1421. if matArray[4]!="true"then
  1422. (
  1423. -- not illum
  1424. if matArray[13]==undefined then
  1425. (
  1426. -- no detail map / masks
  1427. -- 5 Diffuse Only.
  1428. if matArray[5]==undefined \ -- texSpecMap
  1429. and matArray[7]==undefined \ -- texLight
  1430. and matArray[8]==undefined \ -- texBump
  1431. and matArray[14]=="" do matArray[1]="5"
  1432. -- 3 Diffuse + Lightmap
  1433. if matArray[5]==undefined \ -- texSpecMap
  1434. and matArray[7]!=undefined \ -- texLight
  1435. and matArray[8]==undefined \ -- texBump
  1436. and matArray[14]=="" do matArray[1]="3"
  1437. -- 24 Diffuse + NormalMap + SpecMap + LightMap
  1438. if matArray[5]!=undefined \ -- texSpecMap
  1439. and matArray[7]!=undefined \ -- texLight
  1440. and matArray[8]!=undefined \ -- texBump
  1441. and matArray[14]=="" do matArray[1]="24"
  1442. -- 24 Diffuse + NormalMap + SpecMap + LightMap
  1443. if matArray[5]!=undefined \ -- texSpecMap
  1444. and matArray[7]==undefined \ -- texLight
  1445. and matArray[8]==undefined \ -- texBump
  1446. and matArray[14]=="" do
  1447. (
  1448. matArray[7]="dirt_null.tga"
  1449. matArray[8]="norm_null.tga"
  1450. matArray[1]="24"
  1451. )
  1452. -- 24 Diffuse + NormalMap + SpecMap + LightMap
  1453. if matArray[5]!=undefined \ -- texSpecMap
  1454. and matArray[7]==undefined \ -- texLight
  1455. and matArray[8]!=undefined \ -- texBump
  1456. and matArray[14]=="" do
  1457. (
  1458. matArray[7]="dirt_null.tga"
  1459. matArray[1]="24"
  1460. )
  1461. -- 26 Diffuse + NormalMap + EnvMap
  1462. if matArray[5]==undefined \ -- texSpecMap
  1463. and matArray[7]==undefined \ -- texLight
  1464. and matArray[8]!=undefined \ -- texBump
  1465. and matArray[14]!="" do matArray[1]="26"
  1466. -- 4 Diffuse + NormalMap + Spec
  1467. if matArray[5]==undefined \ -- texSpecMap
  1468. and matArray[7]==undefined \ -- texLight
  1469. and matArray[8]!=undefined \ -- texBump
  1470. and matArray[14]=="" do matArray[1]="4"
  1471. -- 2 Diffuse + NormalMap + Spec + LightMap
  1472. if matArray[5]==undefined \ -- texSpecMap
  1473. and matArray[7]!=undefined \ -- texLight
  1474. and matArray[8]!=undefined \ -- texBump
  1475. and matArray[14]=="" do matArray[1]="2"
  1476. )
  1477. else
  1478. (
  1479. -- detail maps / masks
  1480. -- 28 Diffuse + NormalMap + DetailMap + EnvMap
  1481. if matArray[5]==undefined \ -- texSpecMap
  1482. and matArray[7]==undefined \ -- texLight
  1483. and matArray[8]!=undefined \ -- texBump
  1484. and matArray[14]!="" do matArray[1]="28"
  1485. -- 1 Diffuse + NormalMap + DetailMap + Spec + LightMap
  1486. if matArray[5]==undefined \ -- texSpecMap
  1487. and matArray[7]!=undefined \ -- texLight
  1488. and matArray[8]!=undefined \ -- texBump
  1489. and matArray[14]!="" do matArray[1]="1"
  1490. -- 22 Diffuse + NormalMap + DetailMap + SpecMap + LightMap
  1491. if matArray[5]!=undefined \ -- texSpecMap
  1492. and matArray[7]!=undefined \ -- texLight
  1493. and matArray[8]!=undefined \ -- texBump
  1494. and matArray[14]=="" do matArray[1]="22"
  1495. )
  1496. )
  1497. else
  1498. (
  1499. -- 10 Diffuse Only, High Emssive.
  1500. if matArray[2]!=undefined \ -- texDiffuse
  1501. and matArray[5]==undefined \ -- texSpecMap
  1502. and matArray[7]==undefined \ -- texLight
  1503. and matArray[8]==undefined \ -- texBump
  1504. and matArray[9]==undefined \ -- texDetail1
  1505. and matArray[10]==undefined \ -- texDetail2
  1506. and matArray[11]==undefined \ -- matBump1
  1507. and matArray[12]==undefined \ -- matBump2
  1508. and matArray[13]==undefined \ -- texMask
  1509. and matArray[14]=="" do matArray[1]="10"
  1510. )
  1511. )
  1512. else
  1513. (
  1514. -- Opacity
  1515. if matArray[4]!="true"then
  1516. (
  1517. -- not illum
  1518. if matArray[13]==undefined then
  1519. (
  1520. -- no detail map / masks
  1521. -- 5 Diffuse Only.
  1522. if matArray[5]==undefined \ -- texSpecMap
  1523. and matArray[7]==undefined \ -- texLight
  1524. and matArray[8]==undefined \ -- texBump
  1525. and matArray[14]=="" do matArray[1]="7"
  1526. -- 3 Diffuse + Lightmap
  1527. if matArray[5]==undefined \ -- texSpecMap
  1528. and matArray[7]!=undefined \ -- texLight
  1529. and matArray[8]==undefined \ -- texBump
  1530. and matArray[14]=="" do matArray[1]="9"
  1531. -- 24 Diffuse + NormalMap + SpecMap + LightMap
  1532. if matArray[5]!=undefined \ -- texSpecMap
  1533. and matArray[7]!=undefined \ -- texLight
  1534. and matArray[8]!=undefined \ -- texBump
  1535. and matArray[14]=="" do matArray[1]="25"
  1536. -- 24 Diffuse + NormalMap + SpecMap + LightMap
  1537. if matArray[5]!=undefined \ -- texSpecMap
  1538. and matArray[7]==undefined \ -- texLight
  1539. and matArray[8]==undefined \ -- texBump
  1540. and matArray[14]=="" do
  1541. (
  1542. matArray[7]="dirt_null.tga"
  1543. matArray[8]="norm_null.tga"
  1544. matArray[1]="25"
  1545. )
  1546. -- 24 Diffuse + NormalMap + SpecMap + LightMap
  1547. if matArray[5]!=undefined \ -- texSpecMap
  1548. and matArray[7]==undefined \ -- texLight
  1549. and matArray[8]!=undefined \ -- texBump
  1550. and matArray[14]=="" do
  1551. (
  1552. matArray[7]="dirt_null.tga"
  1553. matArray[1]="25"
  1554. )
  1555. -- 26 Diffuse + NormalMap + EnvMap
  1556. if matArray[5]==undefined \ -- texSpecMap
  1557. and matArray[7]==undefined \ -- texLight
  1558. and matArray[8]!=undefined \ -- texBump
  1559. and matArray[14]!="" do matArray[1]="27"
  1560. -- 4 Diffuse + NormalMap + Spec
  1561. if matArray[5]==undefined \ -- texSpecMap
  1562. and matArray[7]==undefined \ -- texLight
  1563. and matArray[8]!=undefined \ -- texBump
  1564. and matArray[14]=="" do matArray[1]="6"
  1565. -- 2 Diffuse + NormalMap + Spec + LightMap
  1566. if matArray[5]==undefined \ -- texSpecMap
  1567. and matArray[7]!=undefined \ -- texLight
  1568. and matArray[8]!=undefined \ -- texBump
  1569. and matArray[14]=="" do matArray[1]="8"
  1570. )
  1571. else
  1572. (
  1573. -- detail maps / masks
  1574. -- 28 Diffuse + NormalMap + DetailMap + EnvMap
  1575. if matArray[5]==undefined \ -- texSpecMap
  1576. and matArray[7]==undefined \ -- texLight
  1577. and matArray[8]!=undefined \ -- texBump
  1578. and matArray[14]!="" do matArray[1]="29"
  1579. -- 1 Diffuse + NormalMap + DetailMap + Spec + LightMap
  1580. if matArray[5]==undefined \ -- texSpecMap
  1581. and matArray[7]!=undefined \ -- texLight
  1582. and matArray[8]!=undefined \ -- texBump
  1583. and matArray[14]!="" do matArray[1]="20"
  1584. -- 22 Diffuse + NormalMap + DetailMap + SpecMap + LightMap
  1585. if matArray[5]!=undefined \ -- texSpecMap
  1586. and matArray[7]!=undefined \ -- texLight
  1587. and matArray[8]!=undefined \ -- texBump
  1588. and matArray[14]=="" do matArray[1]="23"
  1589. )
  1590. )
  1591. else
  1592. (
  1593. -- 10 Diffuse Only, High Emssive.
  1594. if matArray[2]!=undefined \ -- texDiffuse
  1595. and matArray[5]==undefined \ -- texSpecMap
  1596. and matArray[7]==undefined \ -- texLight
  1597. and matArray[8]==undefined \ -- texBump
  1598. and matArray[9]==undefined \ -- texDetail1
  1599. and matArray[10]==undefined \ -- texDetail2
  1600. and matArray[11]==undefined \ -- matBump1
  1601. and matArray[12]==undefined \ -- matBump2
  1602. and matArray[13]==undefined \ -- texMask
  1603. and matArray[14]=="" do matArray[1]="21"
  1604. )
  1605. )
  1606. )
  1607. -- matArray[2] -> texDiffuse
  1608. -- matArray[3] -> texOpacity
  1609. -- matArray[4] -> texIllum
  1610. -- matArray[5] -> texSpecMap
  1611. -- matArray[6] -> texSpec
  1612. -- matArray[7] -> texLight
  1613. -- matArray[8] -> texBump
  1614. -- matArray[9] -> texDetail1
  1615. -- matArray[10] -> texDetail2
  1616. -- matArray[11]-> matBump1
  1617. -- matArray[12]-> matBump2
  1618. -- matArray[13]-> texMask
  1619. -- matArray[14]-> texReflect
  1620. -- matArray[15]-> ESTIMATED RENDER GROUP
  1621. if matArray[1]==undefined do
  1622. (
  1623. matArray[2]="diff_null.tga"
  1624. matArray[1]="5"
  1625. )
  1626. if matArray[2]==undefined do matArray[2]="diff_null.tga"
  1627. if matArray[6]==undefined do matArray[6]="100"
  1628. if (matArray[6] as float)<=0 do matArray[6]="10" -- texSpec
  1629. if matArray[3]==undefined do matArray[3]="" -- texOpacity
  1630. if matArray[4]==undefined do matArray[4]="" -- texIllum
  1631. if matArray[5]!=undefined do matArray[6]="100"
  1632. if matArray[5]==undefined do matArray[5]="" -- texSpecMap
  1633. if matArray[7]==undefined do matArray[7]="" -- texLight
  1634. if matArray[8]==undefined do matArray[8]="" -- texBump
  1635. if matArray[9]==undefined do matArray[9]="" -- texDetail1
  1636. if matArray[10]==undefined do matArray[10]="" -- texDetail2
  1637. if matArray[11]==undefined do matArray[11]="" -- matBump1
  1638. if matArray[12]==undefined do matArray[12]="" -- matBump2
  1639. if matArray[13]==undefined do matArray[13]="" -- texMask
  1640. if matArray[14]==undefined do matArray[14]="" -- texReflect
  1641. matArray
  1642. )
  1643. fn maketext s p =
  1644. (
  1645. -- makes a 8x8 tga any colour, usage: (maketext savefile pixelcolour)
  1646. if (doesFileExist s)==false do
  1647. (
  1648. createFile s
  1649. s = fopen s "ab"
  1650. a=19;b=1
  1651. nullTex=#
  1652. (
  1653. 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x20,0x00,0xFF,0xFF, \
  1654. 0xFF,0x8A,0xFF,0xFF,0xFF,0x44,0xFF,0xFF,0xFF,0x68,0xFF,0xFF,0xFF,0x89,0xFF,0xFF,0xFF,0x86,0xFF,0xFF, \
  1655. 0xFF,0xC5,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE5,0xFF,0xFF,0xFF,0xCC,0xFF,0xFF, \
  1656. 0xFF,0xDE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFC,0xFF,0xFF,0xFF,0xF9,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF, \
  1657. 0xFF,0xFE,0xFF,0xFF,0xFF,0xEF,0xFF,0xFF,0xFF,0xE6,0xFF,0xFF,0xFF,0xED,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF, \
  1658. 0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xF9,0xFF,0xFF, \
  1659. 0xFF,0xF6,0xFF,0xFF,0xFF,0xFA,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
  1660. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
  1661. 0xFF,0xFE,0xFF,0xFF,0xFF,0xBB,0xFF,0xFF,0xFF,0xA3,0xFF,0xFF,0xFF,0x8C,0xFF,0xFF,0xFF,0x93,0xFF,0xFF, \
  1662. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xAA,0xFF,0xFF, \
  1663. 0xFF,0x8E,0xFF,0xFF,0xFF,0x92,0xFF,0xFF,0xFF,0x8F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
  1664. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
  1665. 0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
  1666. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF
  1667. )
  1668. -- A small 8x8 White TGA Texture
  1669. for i = 1 to (8*8) do
  1670. (
  1671. nullTex[a]=p.blue;b+=1
  1672. nullTex[(a+1)]=p.green;b+=1
  1673. nullTex[(a+2)]=p.red;b+=1
  1674. a+=4
  1675. )
  1676. -- replaces pixels
  1677. for x=1 to nullTex.count do writebyte s nullTex[x]
  1678. fclose s
  1679. )
  1680. )
  1681. undo off
  1682. (
  1683. with redraw off
  1684. (
  1685. classesArr = #(BoneGeometry,Biped_Object,Dummy,IK_Chain_Object,Point)
  1686. getBone=for o in objects where findItem classesArr (classof o) > 0 collect o
  1687. classesArr = #(Editable_Mesh,Editable_Poly,PolyMeshObject)
  1688. if mshBySelection==false then
  1689. (
  1690. getMesh=for o in objects where findItem classesArr (classof o) > 0 collect o
  1691. if getMesh.count==0 do messagebox "FAIL!!\nNothing Valid to Export"
  1692. )
  1693. else
  1694. (
  1695. getMesh=for o in selection where findItem classesArr (classof o) > 0 collect o
  1696. if getMesh.count==0 do messagebox "FAIL!!\nNothing In Selection Valid to Export"
  1697. )
  1698. if getMesh.count!=0 do
  1699. (
  1700. struct bone_data(name,position,parent,child)
  1701. boneBuffer = (bone_data name:#() position:#() parent:#() child:#())
  1702. staticMsh=#()
  1703. skin_bone_limit=#()
  1704. skin_bone_limit[getMesh.count]=false
  1705. faceCount=0
  1706. for i = 1 to getMesh.count do
  1707. (
  1708. skinPresent=false
  1709. PhyiqArray=""
  1710. faceCount+=getMesh[i].numfaces
  1711. for x = 1 to getMesh[i].modifiers.count do
  1712. (
  1713. skinMod=getMesh[i].modifiers[x]
  1714. if classOf skinMod==Skin do
  1715. (
  1716. skinPresent=true
  1717. if (skinOps.GetNumberBones skinMod)>=boneLimit do
  1718. (
  1719. skin_bone_limit[i]=true;boneWarning+=(getMesh[i].name+"\n")
  1720. )
  1721. )
  1722. if classOf skinMod==Physique do PhyiqArray+=(" - "+getMesh[i].name+"\n")
  1723. )
  1724. if skinPresent==false do append staticMsh getMesh[i]
  1725. if PhyiqArray!="" do MessageBox ("WARNING!! Physique Not Supported\n\nFollowing Objects Have Failed to Convert:\n"+PhyiqArray)
  1726. )
  1727. if (getBone.count+staticMsh.count)!=0 do
  1728. (
  1729. boneBuffer.name[(getBone.count+staticMsh.count)]=""
  1730. boneBuffer.position[(getBone.count+staticMsh.count)]=[0,0,0]
  1731. boneBuffer.parent[(getBone.count+staticMsh.count)]=0
  1732. boneBuffer.child[(getBone.count+staticMsh.count)]=0
  1733. for i = 1 to getBone.count do
  1734. (
  1735. obj=getBone[i]
  1736. p=findItem getBone obj.parent
  1737. c=findItem getBone obj.children[1]
  1738. -- if p==0 do p=-1
  1739. p-=1 -- convert to base 0
  1740. if c==undefined do c=0
  1741. boneBuffer.name[i]=obj.name
  1742. boneBuffer.position[i]=obj.transform[4]
  1743. boneBuffer.parent[i]=p
  1744. boneBuffer.child[i]=c
  1745. )
  1746. for i = (getBone.count+1) to (getBone.count+staticMsh.count) do
  1747. (
  1748. obj=staticMsh[(i-getBone.count)]
  1749. boneBuffer.name[i]=obj.name
  1750. boneBuffer.position[i]=obj.transform[4]
  1751. boneBuffer.parent[i]=-1
  1752. boneBuffer.child[i]=0
  1753. )
  1754. )
  1755. if mshAddRoot==true do
  1756. (
  1757. -- reorder crap
  1758. find=findItem boneBuffer.name "root ground"
  1759. if find==0 then
  1760. (
  1761. -- Need to add Ground Root
  1762. insertItem "root ground" boneBuffer.name 1
  1763. insertItem [0,0,0] boneBuffer.position 1
  1764. insertItem -2 boneBuffer.parent 1
  1765. insertItem 0 boneBuffer.child 1
  1766. for i = 1 to boneBuffer.name.count do
  1767. (
  1768. boneBuffer.parent[i]+=1
  1769. )
  1770. )
  1771. else
  1772. (
  1773. -- Reorder all bones to Ground Root (Not tested? dont know if this even works)
  1774. if find!=1 then
  1775. (
  1776. -- the Root needs to be moved back to top
  1777. -- NOT WRITTEN -> would mean unlinking the root? not safe?
  1778. )
  1779. else
  1780. (
  1781. -- reparent everything else to the top
  1782. for i = 1 to boneBuffer.name.count do
  1783. (
  1784. if boneBuffer.parent[i]==-1 AND i!=find do
  1785. (
  1786. boneBuffer.parent[i]=0
  1787. )
  1788. )
  1789. )
  1790. )
  1791. )
  1792. if getMesh.count!=0 do
  1793. (
  1794. struct mesh_data(faces,vertices)
  1795. struct mesh_data(name,matname,faces,vertices,matinfo)
  1796. struct vertex_data(position,normal,tangent,colour,texture1,texture2,texture3,boneids,weights)
  1797. struct material_data(diffmap,dirtmap,specmap,normmap,bumpmap1,bumpmap2,maskmap,envmap)
  1798. meshBuffer = (mesh_data faces:#() vertices:#())
  1799. matBuffer = (material_data diffmap:#() dirtmap:#() specmap:#() normmap:#() bumpmap1:#() bumpmap2:#() maskmap:#() envmap:#())
  1800. meshBuffer = (mesh_data name:#() matname:#() faces:#() vertices:#() matinfo:#())
  1801. vertBuffer = (vertex_data position:#() normal:#() tangent:#() colour:#() texture1:#() texture2:#() texture3:#() boneids:#() weights:#())
  1802. vertBuffer.position [(faceCount*3)] = [0,0,0]
  1803. vertBuffer.normal [(faceCount*3)] = [0,0,0]
  1804. vertBuffer.tangent [(faceCount*3)] = [0,0,0]
  1805. vertBuffer.colour [(faceCount*3)] = [0,0,0]
  1806. vertBuffer.texture1 [(faceCount*3)] = [0,0,0]
  1807. vertBuffer.texture2 [(faceCount*3)] = [0,0,0]
  1808. vertBuffer.texture3 [(faceCount*3)] = [0,0,0]
  1809. vertBuffer.boneids [(faceCount*3)] = [0,0,0,0]
  1810. vertBuffer.weights [(faceCount*3)] = [0,0,0,0]
  1811. faceBuffer=#()
  1812. faceBuffer[(faceCount*3)]=0
  1813. )
  1814. vertCount=0 -- Counts used to index through my arrays
  1815. faceCount=0
  1816. for m = 1 to getMesh.count do
  1817. (
  1818. --loop meshcount
  1819. tvCount=getNumTVerts getMesh[m]
  1820. select getMesh[m]
  1821. max modify mode
  1822. modMesh = Edit_Mesh () --mkes sure mesh is triMesh
  1823. uvwMesh = Unwrap_UVW () --makes sure mesh has UVs !! fuck causes bad uv's >_<
  1824. addModifier getMesh[m] modMesh
  1825. if tvCount==0 do addModifier getMesh[m] uvwMesh
  1826. mat=getMesh[m].material
  1827. tmesh = getMesh[m]
  1828. -- tmesh = snapshotAsMesh getMesh[m] -- no material access wtf
  1829. UVLayers=1 -- should return 2, the 2nd channel is reserved for vertex colours
  1830. UVIndex=0
  1831. if (numMapsUsed tmesh)>=3 do
  1832. (
  1833. ;UVLayers=0 -- do a double check for vaild UV Channels
  1834. for i = 1 to (numMapsUsed tmesh) do
  1835. (
  1836. -- loop through each uv channel
  1837. if meshop.getMapSupport tmesh i == true do UVLayers+=1
  1838. )
  1839. )
  1840. 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")
  1841. vColors=getNumCPVVerts tmesh -- returns 0 if there are no colours stored
  1842. cvert=(color 255 255 255) --white
  1843. num_verts = tmesh.numverts
  1844. num_faces = tmesh.numfaces
  1845. weightBuffer=#();weightBuffer[tmesh.numverts]=0.0
  1846. boneIDBuffer=#();boneIDBuffer[tmesh.numverts]=0
  1847. skinPresent=false
  1848. skinMod=undefined
  1849. if tmesh.modifiers.count!=0 then
  1850. (
  1851. for i = 1 to tmesh.modifiers.count do
  1852. (
  1853. -- Get Skin Data
  1854. if classOf tmesh.modifiers[i]==Skin do
  1855. (
  1856. skinPresent=true
  1857. skinMod=tmesh.modifiers[i]
  1858. )
  1859. )
  1860. if skinPresent==true then
  1861. (
  1862. modPanel.setCurrentObject skinMod
  1863. skinOps.RemoveZeroWeights skinMod
  1864. for i = 1 to tmesh.numverts do
  1865. (
  1866. vertex_bone_count = skinOps.GetVertexWeightCount skinMod i -- #of weights per vert
  1867. if vertex_bone_count!=0 then
  1868. (
  1869. weightCollection=#();weightCollection[vertex_bone_count]=0.0
  1870. boneidCollection=#();boneidCollection[vertex_bone_count]=0
  1871. for x = 1 to vertex_bone_count do
  1872. (
  1873. bone_weight = skinops.getvertexweight skinMod i x
  1874. bone_index = findItem boneBuffer.name
  1875. (
  1876. skinOps.GetBoneName skinMod \
  1877. (skinOps.GetVertexWeightBoneID skinMod i x) 0
  1878. )
  1879. if bone_index==0 do bone_index=1
  1880. if x<=4 do
  1881. (
  1882. -- limits to four bones weights per vertex
  1883. weightCollection[x]=bone_weight
  1884. boneidCollection[x]=bone_index
  1885. )
  1886. )
  1887. )
  1888. else
  1889. (
  1890. --dead weight found, nothing fancy just append weight to bone1
  1891. weightCollection=#();weightCollection[1]=0.0
  1892. boneidCollection=#();boneidCollection[1]=0
  1893. bone_index = 1
  1894. weightCollection[1]=1.0
  1895. boneidCollection[1]=1
  1896. )
  1897. if vertex_bone_count<=4 then
  1898. (
  1899. for x = (vertex_bone_count+1) to 4 do
  1900. (
  1901. weightCollection[x]=0
  1902. boneidCollection[x]=0
  1903. )
  1904. )
  1905. else
  1906. (
  1907. w=weightCollection[1]+weightCollection[2]+weightCollection[3]+weightCollection[4]
  1908. d=1-w;weightCollection[1]=(weightCollection[1]+d)
  1909. )
  1910. b1=boneidCollection[1]-1 -- convert to base 0
  1911. b2=boneidCollection[2]-1
  1912. b3=boneidCollection[3]-1
  1913. b4=boneidCollection[4]-1
  1914. if b1<=0 do b1=0
  1915. if b2<=0 do b2=0
  1916. if b3<=0 do b3=0
  1917. if b4<=0 do b4=0
  1918. boneIDBuffer[i]=[b1,b2,b3,b4]
  1919. -- boneIDBuffer[i]=[(boneidCollection[1]),(boneidCollection[2]),(boneidCollection[3]),(boneidCollection[4])]
  1920. weightBuffer[i]=[(weightCollection[1]),(weightCollection[2]),(weightCollection[3]),(weightCollection[4])]
  1921. )
  1922. )
  1923. else
  1924. (
  1925. for x = 1 to tmesh.numverts do
  1926. (
  1927. -- static mesh, fix skin info
  1928. weightBuffer[x]=[1,0,0,0]
  1929. if tmesh.parent!=undefined
  1930. then boneid=findItem boneBuffer.name tmesh.parent.name -- weight to a possible parent
  1931. else boneid=findItem boneBuffer.name tmesh.name -- if no parent weight to scene root
  1932. boneid-=1 -- convert to base 0
  1933. if boneid<=0 do boneid=0 -- convert to base 0
  1934. boneIDBuffer[x]=[boneid,0,0,0]
  1935. )
  1936. )
  1937. )
  1938. else
  1939. (
  1940. for x = 1 to tmesh.numverts do
  1941. (
  1942. weightBuffer[x]=[1,0,0,0]
  1943. if tmesh.parent!=undefined
  1944. then boneid=findItem getBone tmesh.parent.name
  1945. else boneid=findItem getBone tmesh.name
  1946. boneid-=1 -- convert to base 0
  1947. if boneid<=0 do boneid=0 -- convert to base 0
  1948. boneIDBuffer[x]=[boneid,0,0,0]
  1949. )
  1950. )
  1951. modNorm = Edit_Normals ()
  1952. addModifier tmesh modNorm
  1953. vertCollection=#() -- arrays reset on each mesh / material ID
  1954. normCollection=#()
  1955. tvertCollection=#()
  1956. faceCollection=#()
  1957. boneCheck=#()
  1958. vertCollection[(num_faces*3)] = [0,0,0,0]
  1959. normCollection[(num_faces*3)] = [0,0,0]
  1960. tvertCollection[(num_faces*3)] = [0,0,0,0]
  1961. faceCollection[num_faces] = [0,0]
  1962. if classOf mat==Multimaterial then
  1963. (
  1964. -- If MultiMaterial, Sort Faces By IDs
  1965. for x = 1 to num_faces do
  1966. (
  1967. faceCollection[x]=[(getFaceMatId tmesh x),(tmesh.faces[x].index)]
  1968. )
  1969. fn sortFN v1 v2 =
  1970. (
  1971. local d=v1[1]-v2[1];
  1972. case of
  1973. (
  1974. (d < 0.): -1
  1975. (d > 0.): 1
  1976. default: 0
  1977. );
  1978. );
  1979. qsort faceCollection sortFN
  1980. )
  1981. else(for x = 1 to num_faces do (faceCollection[x]= [1,x]))
  1982. faceStart=faceCollection[1][1]
  1983. faceCounter=0
  1984. count=0 -- count for resetable arrays
  1985. boneLimitReached=false
  1986. for x = 1 to num_faces do
  1987. (
  1988. if boneLimitReached==true do
  1989. (
  1990. matcrap=getMaterial tmesh faceStart
  1991. append meshBuffer.matinfo [(matcrap[1] as integer),(matcrap[6] as float),(matcrap[11] as float),(matcrap[12] as float)]
  1992. append matBuffer.diffmap matcrap[2]
  1993. append matBuffer.dirtmap matcrap[7]
  1994. append matBuffer.specmap matcrap[5]
  1995. append matBuffer.normmap matcrap[8]
  1996. append matBuffer.bumpmap1 matcrap[9]
  1997. append matBuffer.bumpmap2 matcrap[10]
  1998. append matBuffer.maskmap matcrap[13]
  1999. append matBuffer.envmap matcrap[14]
  2000. if matNames==true then mshName=(checkname tmesh.name) else mshName=(checkname tmesh.name)
  2001. find=findItem meshBuffer.name mshName
  2002. if find!=0 do mshName=renamedup meshBuffer.name find
  2003. append meshBuffer.name mshName
  2004. append meshBuffer.matname mshName
  2005. vertCollection=#() -- reset arrays
  2006. normCollection=#()
  2007. tvertCollection=#()
  2008. boneCheck=#()
  2009. vertCollection[(num_faces*3)] = [0,0,0,0]
  2010. normCollection[(num_faces*3)] = [0,0,0]
  2011. tvertCollection[(num_faces*3)] = [0,0,0,0]
  2012. append meshBuffer.faces faceCounter -- save counts, and reset shit
  2013. append meshBuffer.vertices count
  2014. boneLimitReached=false
  2015. faceCounter=0
  2016. count=0
  2017. )
  2018. case of
  2019. (
  2020. (classOf mat==Multimaterial):
  2021. (
  2022. -- reading materials, also rests arrays on new matID
  2023. d=faceCollection[x][1]-faceStart -- Compares Current MatID vs the Last MatID
  2024. case of
  2025. (
  2026. (d != 0):
  2027. (
  2028. -- Means Unique ID, need to reset
  2029. matcrap=getMaterial tmesh faceStart
  2030. append meshBuffer.matinfo [(matcrap[1] as integer),(matcrap[6] as float),(matcrap[11] as float),(matcrap[12] as float)]
  2031. append matBuffer.diffmap matcrap[2]
  2032. append matBuffer.dirtmap matcrap[7]
  2033. append matBuffer.specmap matcrap[5]
  2034. append matBuffer.normmap matcrap[8]
  2035. append matBuffer.bumpmap1 matcrap[9]
  2036. append matBuffer.bumpmap2 matcrap[10]
  2037. append matBuffer.maskmap matcrap[13]
  2038. append matBuffer.envmap matcrap[14]
  2039. case of
  2040. (
  2041. (mat.material[(faceCollection[x][1])] != undefined):
  2042. (
  2043. if matNames==true then mshName=(checkname tmesh.material[faceStart].name) else mshName=(checkname tmesh.name)
  2044. find=findItem meshBuffer.name mshName
  2045. if find!=0 do mshName=renamedup meshBuffer.name find
  2046. append meshBuffer.name mshName
  2047. append meshBuffer.matname mshName
  2048. )
  2049. (mat.material[(faceCollection[x][1])] == undefined):
  2050. (
  2051. if matNames==true then mshName=("Mat_"+(x as string)+"_"+(faceCollection[x][1] as string)) else mshName=(checkname tmesh.name)
  2052. find=findItem meshBuffer.name mshName
  2053. if find!=0 do mshName=renamedup meshBuffer.name find
  2054. append meshBuffer.name mshName
  2055. append meshBuffer.matname mshName
  2056. )
  2057. )
  2058. -- suppose to ensure that the material name is correct, this is critical.. but not properly set yet. -FIX ME!!
  2059. vertCollection=#() -- reset arrays
  2060. normCollection=#()
  2061. tvertCollection=#()
  2062. boneCheck=#()
  2063. vertCollection[(num_faces*3)] = [0,0,0,0]
  2064. normCollection[(num_faces*3)] = [0,0,0]
  2065. tvertCollection[(num_faces*3)] = [0,0,0,0]
  2066. append meshBuffer.faces faceCounter -- save counts, and reset shit
  2067. append meshBuffer.vertices count
  2068. faceStart=faceCollection[x][1]
  2069. faceCounter=0
  2070. count=0
  2071. )
  2072. )
  2073. )
  2074. (classOf mat!=Multimaterial):
  2075. (
  2076. -- assume this is an invalid material, or some other special type of material
  2077. -- do something here? lol makeup fake mat info
  2078. -- FIX ME!!
  2079. )
  2080. )
  2081. findex=getFace tmesh faceCollection[x][2] -- gets face index of mesh
  2082. tindex=getTVFace tmesh faceCollection[x][2] -- gets face index of texture coordinates
  2083. if vColors!=0 do cindex=getVCFace tmesh faceCollection[x][2] -- gets face index of vertex colours
  2084. -- t2index=getTVFace tmesh faceCollection[x][2] -- gets face for second UV channel (Fixed Channel)
  2085. if mshOptimise==true then
  2086. (
  2087. for y = 1 to 3 do
  2088. (
  2089. vert=getVert tmesh findex[y]
  2090. tvert=getTVert tmesh tindex[y]
  2091. tvert2=getTVert tmesh tindex[y]
  2092. if vColors!=0 do cvert=getVertColor tmesh cindex[y]
  2093. norm=modNorm.GetNormal (modNorm.GetNormalID faceCollection[x][2] y)
  2094. vertCull=findItem vertCollection [vert.x,vert.y,vert.z,(findex[y])]
  2095. tvertCull=findItem tvertCollection [tvert.x,tvert.y,0,(tindex[y])]
  2096. normCull=findItem normCollection norm
  2097. if vertCull!=0 do (if normCollection[vertCull]!=norm do normCull=0)
  2098. if vertCull!=tvertCull OR vertCull==0 OR normCull==0 then
  2099. (
  2100. --not found
  2101. count+=1
  2102. faceCount+=1
  2103. vertCount+=1
  2104. vertCollection[count]=[vert.x,vert.y,vert.z,(findex[y])]
  2105. tvertCollection[count]=[tvert.x,tvert.y,0,(tindex[y])]
  2106. normCollection[count]=norm
  2107. vertBuffer.position[vertCount]=[vert.x,vert.y,vert.z,(findex[y])] -- Face ID is left, relates to the Skin Weight
  2108. vertBuffer.texture1[vertCount]=[tvert.x,tvert.y,0]
  2109. vertBuffer.colour[vertCount]=cvert
  2110. vertBuffer.normal[vertCount]=norm
  2111. vertBuffer.boneids[vertCount]=boneIDBuffer[(findex[y])]
  2112. vertBuffer.weights[vertCount]=weightBuffer[(findex[y])]
  2113. faceBuffer[faceCount]=count
  2114. if skin_bone_limit[m]==true do
  2115. (
  2116. -- if current object exceeds bone limit, start new mesh
  2117. boneids=boneIDBuffer[(findex[y])]
  2118. for b = 1 to 4 do(if (finditem boneCheck boneids[b])==0 do append boneCheck boneids[b])
  2119. if boneCheck.count>=boneLimit do(boneLimitReached=true)
  2120. )
  2121. -- note to self, need to copy any changes to this function to the unoptimized loop
  2122. )
  2123. else
  2124. (
  2125. faceCount+=1
  2126. faceBuffer[faceCount]=vertCull
  2127. )
  2128. )
  2129. )
  2130. else
  2131. (
  2132. for y = 1 to 3 do
  2133. (
  2134. vert=getVert tmesh findex[y]
  2135. tvert=getTVert tmesh tindex[y]
  2136. norm=modNorm.GetNormal (modNorm.GetNormalID faceCollection[x][2] y)
  2137. count+=1
  2138. faceCount+=1
  2139. vertCount+=1
  2140. vertBuffer.position[vertCount]=[vert.x,vert.y,vert.z,(findex[y])] -- Face ID is left, relates to the Skin Weight
  2141. vertBuffer.texture1[vertCount]=[tvert.x,tvert.y,0]
  2142. vertBuffer.normal[vertCount]=norm
  2143. vertBuffer.boneids[vertCount]=boneIDBuffer[(findex[y])]
  2144. vertBuffer.weights[vertCount]=weightBuffer[(findex[y])]
  2145. faceBuffer[faceCount]=count
  2146. )
  2147. )
  2148. faceCounter+=1
  2149. )
  2150. matcrap=getMaterial tmesh faceStart
  2151. append meshBuffer.matinfo [(matcrap[1] as integer),(matcrap[6] as float),(matcrap[11] as float),(matcrap[12] as float)]
  2152. append matBuffer.diffmap matcrap[2]
  2153. append matBuffer.dirtmap matcrap[7]
  2154. append matBuffer.specmap matcrap[5]
  2155. append matBuffer.normmap matcrap[8]
  2156. append matBuffer.bumpmap1 matcrap[9]
  2157. append matBuffer.bumpmap2 matcrap[10]
  2158. append matBuffer.maskmap matcrap[13]
  2159. append matBuffer.envmap matcrap[14]
  2160. append meshBuffer.vertices count --flush counts (this may be improper? replace with if statement if counts are borked)
  2161. append meshBuffer.faces faceCounter
  2162. if classOf mat==Multimaterial then
  2163. (
  2164. if matNames==true then mshName=(checkname tmesh.material[faceStart].name) else mshName=(checkname tmesh.name)
  2165. find=findItem meshBuffer.name mshName
  2166. if find!=0 do mshName=renamedup meshBuffer.name find
  2167. append meshBuffer.name mshName
  2168. append meshBuffer.matname mshName
  2169. )
  2170. else
  2171. (
  2172. if tmesh.material==undefined then
  2173. (
  2174. if matNames==true then mshName=(checkname tmesh.name) else mshName=tmesh.name
  2175. find=findItem meshBuffer.name mshName
  2176. if find!=0 do mshName=renamedup meshBuffer.name find
  2177. append meshBuffer.name mshName
  2178. append meshBuffer.matname mshName
  2179. )
  2180. else
  2181. (
  2182. if matNames==true then mshName=(checkname tmesh.material.name) else mshName=(checkname tmesh.name)
  2183. find=findItem meshBuffer.name mshName
  2184. if find!=0 do mshName=renamedup meshBuffer.name find
  2185. append meshBuffer.name mshName
  2186. append meshBuffer.matname mshName
  2187. )
  2188. )
  2189. deleteModifier tmesh modNorm
  2190. deleteModifier tmesh modMesh
  2191. if tvCount==0 do deleteModifier tmesh uvwMesh
  2192. )
  2193. print meshBuffer
  2194. if getMesh.count!=0 do
  2195. (
  2196. -- xnalara ASCII format
  2197. vertIndex=1
  2198. nextvert=0
  2199. faceIndex=1
  2200. nextface=0
  2201. faceCounter=0
  2202. format "% # bones\n" boneBuffer.name.count to:out_file
  2203. for f = 1 to boneBuffer.name.count do
  2204. (
  2205. format "%\n" boneBuffer.name[f] to:out_file
  2206. format "% # parent index\n" boneBuffer.parent[f] to:out_file
  2207. format "% % %\n" (boneBuffer.position[f][1]*mshScale) (boneBuffer.position[f][3]*mshScale) (boneBuffer.position[f][2]*-mshScale) to:out_file
  2208. )
  2209. format "% # meshes\n" meshBuffer.name.count to:out_file
  2210. for f = 1 to meshBuffer.name.count do
  2211. (
  2212. nextvert+=meshBuffer.vertices[f]
  2213. nextface+=meshBuffer.faces[f]
  2214. 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!!
  2215. format "% # uv layers\n" 1 to:out_file -- Multiple UV channels not setup yet
  2216. texCount=1
  2217. a=meshBuffer.matinfo[f][1] -- calculated render group
  2218. case of
  2219. (
  2220. (a == 1): texCount=6
  2221. (a == 2): texCount=3
  2222. (a == 3): texCount=2
  2223. (a == 4): texCount=2
  2224. (a == 5): texCount=1
  2225. (a == 6): texCount=2
  2226. (a == 7): texCount=1
  2227. (a == 8): texCount=3
  2228. (a == 9): texCount=2
  2229. (a == 10): texCount=1
  2230. (a == 11): texCount=2
  2231. (a == 12): texCount=2
  2232. (a == 13): texCount=1
  2233. (a == 14): texCount=2
  2234. (a == 15): texCount=2
  2235. (a == 16): texCount=1
  2236. (a == 17): texCount=2
  2237. (a == 18): texCount=1
  2238. (a == 19): texCount=2
  2239. (a == 20): texCount=6
  2240. (a == 21): texCount=1
  2241. (a == 22): texCount=7
  2242. (a == 23): texCount=7
  2243. (a == 24): texCount=4
  2244. (a == 25): texCount=4
  2245. (a == 26): texCount=3
  2246. (a == 27): texCount=3
  2247. (a == 28): texCount=6
  2248. (a == 29): texCount=6
  2249. default: texCount=1
  2250. )
  2251. format "% # textures\n" texCount to:out_file
  2252. case of
  2253. (
  2254. (texCount==1):
  2255. (
  2256. format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
  2257. )
  2258. (texCount==2):
  2259. (
  2260. format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
  2261. if matBuffer.dirtmap[f]!=""
  2262. then format "%\n"matBuffer.dirtmap[f] to:out_file
  2263. else format "%\n"matBuffer.normmap[f] to:out_file
  2264. format "% # uv layer index\n" 0 to:out_file -- layers not implemented yet
  2265. )
  2266. (texCount==3):
  2267. (
  2268. format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
  2269. if matBuffer.envmap[f]!=""
  2270. then format "%\n% # uv layer index\n"matBuffer.normmap[f] 0 matBuffer.envmap[f] to:out_file -- layers not implemented yet
  2271. else format "%\n% # uv layer index\n"matBuffer.dirtmap[f] matBuffer.normmap[f] to:out_file
  2272. )
  2273. (texCount==4):
  2274. (
  2275. format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
  2276. format "%\n% # uv layer index\n" matBuffer.dirtmap[f] 0 to:out_file
  2277. format "%\n% # uv layer index\n" matBuffer.normmap[f] 0 to:out_file
  2278. format "%\n% # uv layer index\n" matBuffer.specmap[f] 0 to:out_file
  2279. )
  2280. (texCount==6):
  2281. (
  2282. format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
  2283. if matBuffer.envmap[f]!=""
  2284. 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"\
  2285. 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
  2286. 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"\
  2287. 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
  2288. )
  2289. (texCount==7):
  2290. (
  2291. format "%\n% # uv layer index\n" matBuffer.diffmap[f] 0 to:out_file
  2292. format "%\n% # uv layer index\n" matBuffer.dirtmap[f] 0 to:out_file
  2293. format "%\n% # uv layer index\n" matBuffer.normmap[f] 0 to:out_file
  2294. format "%\n% # uv layer index\n" matBuffer.maskmap[f] 0 to:out_file
  2295. format "%\n% # uv layer index\n" matBuffer.bumpmap1[f] 0 to:out_file
  2296. format "%\n% # uv layer index\n" matBuffer.bumpmap2[f] 0 to:out_file
  2297. format "%\n% # uv layer index\n" matBuffer.specmap[f] 0 to:out_file
  2298. )
  2299. )
  2300. format "% # vertices\n" meshBuffer.vertices[f] to:out_file
  2301. for i = vertIndex to nextvert do
  2302. (
  2303. format "% % %\n" (vertBuffer.position[i][1]*mshScale) (vertBuffer.position[i][3]*mshScale) (vertBuffer.position[i][2]*-mshScale) to:out_file
  2304. norm=normalize [(vertBuffer.normal[i][1]*mshScale),(vertBuffer.normal[i][3]*mshScale),(vertBuffer.normal[i][2]*-mshScale)]
  2305. format "% % %\n" norm.x norm.y norm.z to:out_file
  2306. -- format "% % %\n" vertBuffer.normal[i][1] vertBuffer.normal[i][3] vertBuffer.normal[i][2] to:out_file
  2307. 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
  2308. for y = 1 to 1 do
  2309. (
  2310. -- needs UV layer count, net setup yet
  2311. if y==1 do format "% %\n" vertBuffer.texture1[i][1] (vertBuffer.texture1[i][2]*-1) to:out_file
  2312. if y==2 do format "% %\n" vertBuffer.texture2[i][1] (vertBuffer.texture2[i][2]*-1) to:out_file
  2313. if y==3 do format "% %\n" vertBuffer.texture3[i][1] (vertBuffer.texture3[i][2]*-1) to:out_file
  2314. )
  2315. -- -- Vertex Tangents would go here
  2316. 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
  2317. format "% % % %\n" vertBuffer.weights[i][1] vertBuffer.weights[i][2] \
  2318. vertBuffer.weights[i][3] vertBuffer.weights[i][4] to:out_file
  2319. )
  2320. format "% # faces\n" meshBuffer.faces[f] to:out_file
  2321. for i = faceIndex to nextface do
  2322. (
  2323. fa=faceBuffer[(faceCounter+1)]-1
  2324. fb=faceBuffer[(faceCounter+2)]-1
  2325. fc=faceBuffer[(faceCounter+3)]-1
  2326. format "% % %\n" fc fb fa to:out_file
  2327. faceCounter+=3
  2328. )
  2329. faceIndex+=meshBuffer.faces[f]
  2330. vertIndex+=meshBuffer.vertices[f]
  2331. )
  2332. -- mesh loop
  2333. for x = 1 to matBuffer.diffmap.count do
  2334. (
  2335. if matBuffer.diffmap[x]=="diff_null.tga" do maketext (fpath+"\\diff_null.tga") (color 115 115 115)
  2336. if matBuffer.dirtmap[x]=="dirt_null.tga" do maketext (fpath+"\\dirt_null.tga") (color 254 254 254)
  2337. if matBuffer.specmap[x]=="spec_null.tga" do maketext (fpath+"\\spec_null.tga") (color 50 50 50)
  2338. if matBuffer.normmap[x]=="norm_null.tga" do maketext (fpath+"\\norm_null.tga") (color 128 128 255)
  2339. if matBuffer.maskmap[x]=="mask_null.tga" do maketext (fpath+"\\mask_null.tga") (color 255 0 0)
  2340. if matBuffer.bumpmap1[x]=="bump1_null.tga" do maketext (fpath+"\\bump1_null.tga") (color 128 128 255)
  2341. if matBuffer.bumpmap2[x]=="bump2_null.tga" do maketext (fpath+"\\bump2_nul.tgal") (color 128 128 255)
  2342. )
  2343. )
  2344. -- vertIndex=1
  2345. -- nextvert=0
  2346. -- faceIndex=1
  2347. -- nextface=0
  2348. -- lastface=0
  2349. -- faceCounter=0
  2350. -- for f = 1 to meshBuffer.name.count do
  2351. (
  2352. --dumps output as a wavefront OBJ format
  2353. -- nextvert+=meshBuffer.vertices[f]
  2354. -- format "# % vertices\n" meshBuffer.vertices[f] to:out_file
  2355. -- for i = vertIndex to nextvert do
  2356. (
  2357. -- format "v % % %\n" (vertBuffer.position[i][1]*mshScale) (vertBuffer.position[i][3]*mshScale) (vertBuffer.position[i][2]*-mshScale) to:out_file
  2358. )
  2359. -- format "\n# % vertex normals\n" meshBuffer.vertices[f] to:out_file
  2360. -- for i = vertIndex to nextvert do
  2361. (
  2362. -- norm=normalize [(vertBuffer.normal[i][1]*mshScale),(vertBuffer.normal[i][3]*mshScale),(vertBuffer.normal[i][2]*-mshScale)]
  2363. -- format "vn % % %\n" norm.x norm.y norm.z to:out_file
  2364. -- -- format "vn % % %\n" (vertBuffer.normal[i][1]*mshScale) (vertBuffer.normal[i][3]*mshScale) (vertBuffer.normal[i][2]*-mshScale) to:out_file
  2365. --
  2366. )
  2367. -- format "\n# % texture coords\n" meshBuffer.vertices[f] to:out_file
  2368. -- for i = vertIndex to nextvert do
  2369. (
  2370. -- format "vt % % 0.0\n" vertBuffer.texture1[i][1] vertBuffer.texture1[i][2] to:out_file
  2371. )
  2372. -- vertIndex+=meshBuffer.vertices[f]
  2373. )
  2374. -- print ("My Face Array has "+(faceBuffer.count as string)+" Entries")
  2375. -- for f = 1 to meshBuffer.name.count do
  2376. (
  2377. -- format "\n# % faces\n" meshBuffer.faces[f] to:out_file
  2378. -- format "g %\n" meshBuffer.name[f] to:out_file
  2379. -- nextface+=meshBuffer.faces[f]
  2380. -- print ("Currently Reading Set "+(f as string)+" from index "+(faceIndex as string)+" to "+(nextface as string)+"\n")
  2381. -- for i = faceIndex to nextface do
  2382. (
  2383. -- fa=faceBuffer[(faceCounter+1)]+lastface
  2384. -- fb=faceBuffer[(faceCounter+2)]+lastface
  2385. -- fc=faceBuffer[(faceCounter+3)]+lastface
  2386. -- format "f %/%/% %/%/% %/%/%\n" fa fa fa fb fb fb fc fc fc to:out_file
  2387. -- faceCounter+=3
  2388. )
  2389. -- faceIndex+=meshBuffer.faces[f]
  2390. -- lastface+=meshBuffer.vertices[f]
  2391. --
  2392. )
  2393. close out_file
  2394. if doesFileExist (fpath+"\\MeshAsciiToBin.exe")==true do
  2395. (
  2396. DOSCommand ("MeshAsciiToBin.exe \""+ssource+"\"")
  2397. )
  2398. messagebox ("DONE!\nOperation Completed in: "+((((timestamp()-st)/1000)+10)as string)+" s")
  2399. if boneWarning!="" do messagebox ("Warning!\nThe Following Meshes Exceed The 59 Bone Limit\n\n"+boneWarning)
  2400. gc() -- this will erase and undo saves, helps? flush files
  2401. enableSceneRedraw()
  2402. )
  2403. )
  2404. )
  2405. -- undo renabled / redraw scene
  2406. )
  2407. else(MessageBox "Error Creating File!")
  2408. )
  2409. else (Print "Aborted.")
  2410. format "% ms\n" (timestamp()-st)
  2411. )
  2412. -- Close Button for EXPORT
  2413. on btn3 pressed do
  2414. (
  2415. rollout AboutBox "About..." width:300 height:200
  2416. (
  2417. label lbl3 "XNALara Converter (v1.1b) (August2011)" pos:[16,15] width:263 height:16
  2418. label lbl4 "__________________________________________________________________________" pos:[18,29] width:263 height:17
  2419. label lbl5 "- Mario_Kart64n (mario_kart64n@hotmail.com)" pos:[19,176] width:272 height:19
  2420. label lbl8 "__________________________________________________________________________" pos:[18,153] width:263 height:17
  2421. 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
  2422. )
  2423. createDialog AboutBox
  2424. )
  2425. )
  2426. createDialog appGUI
  2427. gc() -- flushes cache, also resets undo. but command needed to help release files (not required to be on)
  2428. fclose f
  2429. fclose s
  2430. clearlistener()
  2431. )
  2432. else(MessageBox "ERROR!!\nYour 3DSMAX Is Not Compatible with this Script\n-Sorry")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement