Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.00 KB | None | 0 0
  1. -- ----------------------------------------------------------------------------------- --
  2. -- --
  3. -- 3DS Max C&C W3D XML Asset Importer --
  4. -- Version 1.1.0.3 --
  5. -- --
  6. -- ----------------------------------------------------------------------------------- --
  7. -- --
  8. -- Supports: Basic Meshes, Influenced Meshes, UVW Mapping, OBBoxes, Pivots, Materials --
  9. -- Working on: wwSkin --
  10. -- --
  11. -- ----------------------------------------------------------------------------------- --
  12. -- --
  13. -- Scripted by: Asuka- & Modified by: Bibber --
  14. -- --
  15. -- ----------------------------------------------------------------------------------- --
  16.  
  17.  
  18.  
  19. utility w3d_xml_asset_importer "W3D XML Asset Importer"
  20. (
  21. -- Shader Search Paths --
  22. global shaderSearchPaths = #
  23. (
  24. "$maps\fx",
  25. "$maps\fx\ra3",
  26. "$maps\fx\cnc3"
  27. )
  28.  
  29. -- Texture Search Paths --
  30. global textureSearchPaths = #
  31. (
  32. "$maps"
  33. )
  34.  
  35.  
  36.  
  37. --------------------------------
  38. -- DO NOT EDIT ANYTHING BELOW --
  39. --------------------------------
  40.  
  41. -- Global Variables --
  42. global shaderInitPath = "$maps\fx"
  43. global textureInitPath = "$maps"
  44.  
  45. global captionShaderPath = "Select Shader Directory:"
  46. global captionTexturePath = "Select Texture Directory:"
  47.  
  48. global captionImportSKN = "Select Model (W3DContainer):"
  49. global captionImportSKL = "Select Skeleton (W3DHierarchy):"
  50. global captionImportMesh = "Select Simple Mesh (W3DMesh):"
  51. global typesImport = "W3D XML Asset (*.W3X)|*.W3X|All Files (*.*)|*.*"
  52.  
  53. global shaderPath = ""
  54. global texturePath = ""
  55.  
  56. global w3dHierarchy
  57. global w3dCollisionBoxes = #()
  58. global w3dMeshs = #()
  59. global w3dContainer
  60.  
  61. global maxPivots = #()
  62. global maxOBBoxes = #()
  63. global maxMeshes = #()
  64. global maxMaterials
  65.  
  66.  
  67.  
  68. -- User Interface --
  69. group "Optional Settings"
  70. (
  71. edittext editShaderPath "Shaders:" align:#left width:136
  72. button buttonShaderPath "Select Shader Directory" align:#left width:136
  73. edittext editTexturePath "Textures:" align:#left offset:[0, 5]
  74. button buttonTexturePath "Select Texture Directory" align:#left width:136
  75. spinner spinnerScale "Scale Pivots by:" align:#left width:126 range:[0.1, 5, 1] offset:[0, 5]
  76. spinner spinnerMaterials "Material Slots used:" align:#left width:104 type:#integer range:[1, 24, 1]
  77. )
  78.  
  79. group "Import"
  80. (
  81. button buttonImportHierarchicalModel "Import Hierarchical Model" align:#left width:136
  82. button buttonImportSkeleton "Import Skeleton" align:#left width:136
  83. button buttonImportSimpleMesh "Import Simple Mesh" align:#left width:136
  84. )
  85.  
  86. group "Advanced"
  87. (
  88. button buttonToggleLinks "Toggle Show Links" align:#left width:136
  89. )
  90.  
  91. group "Information"
  92. (
  93. listbox missingShaders "Missing Shaders:" readOnly:true height:3
  94. listbox missingTextures "Missing Textures:" readOnly:true offset:[0, 5] height:5
  95. )
  96.  
  97.  
  98.  
  99. -- Structures --
  100. struct helperPivot
  101. (
  102. position,
  103. rotation
  104. )
  105.  
  106. struct w3xPivot
  107. (
  108. name,
  109. parent,
  110. translation,
  111. rotation
  112. )
  113.  
  114. struct w3xHierarchy
  115. (
  116. id,
  117. pivots = #()
  118. )
  119.  
  120. struct w3xCollisionBox
  121. (
  122. center,
  123. extent
  124. )
  125.  
  126. struct w3xShaderValue
  127. (
  128. name,
  129. value
  130. )
  131.  
  132. struct w3xShader
  133. (
  134. shaderName,
  135. techniqueName,
  136. techniqueIndex,
  137. textures = #(),
  138. floats = #(),
  139. ints = #(),
  140. bools = #()
  141. )
  142.  
  143. struct w3xMesh
  144. (
  145. id,
  146. hidden,
  147. castShadow,
  148. geometryType,
  149. sortLevel,
  150. vertices = #(),
  151. normals = #(),
  152. tangents = #(),
  153. binormals = #(),
  154. vertexColors = #(),
  155. texCoords = #(),
  156. boneInfluences = #(),
  157. shadeIndices = #(),
  158. triangles = #(),
  159. shader
  160. )
  161.  
  162. struct w3xRenderObject
  163. (
  164. type,
  165. name,
  166. object
  167. )
  168.  
  169. struct w3xSubObject
  170. (
  171. id,
  172. boneIndex,
  173. renderObject
  174. )
  175.  
  176. struct w3xContainer
  177. (
  178. id,
  179. hierarchy,
  180. subObjects = #()
  181. )
  182.  
  183.  
  184.  
  185. -- Functions --
  186. function addListItem list item =
  187. (
  188. local newItem = true
  189.  
  190. if (list.items.count > 0) then
  191. (
  192. for i = 1 to list.items.count do
  193. (
  194. if ((list.items[i] as string) == item) then
  195. (
  196. newItem = false
  197. )
  198. )
  199. )
  200.  
  201. if (newItem) then
  202. (
  203. list.items = append list.items (item)
  204. )
  205. )
  206.  
  207. function getPivots pivotNum fileI tagEnd =
  208. (
  209. local pivotStart = filePos fileI
  210. skipToString fileI "Name"
  211. skipToString fileI "\""
  212. local name = readDelimitedString fileI "\""
  213. seek fileI pivotStart
  214. skipToString fileI "Parent"
  215. skipToString fileI "\""
  216. local parent = readDelimitedString fileI "\"" as integer
  217.  
  218. skipToString fileI "<Translation"
  219. tStart = filePos fileI
  220. skipToString fileI "X"
  221. skipToString fileI "\""
  222. local x = readDelimitedString fileI "\"" as float
  223. seek fileI tStart
  224. skipToString fileI "Y"
  225. skipToString fileI "\""
  226. local y = readDelimitedString fileI "\"" as float
  227. seek fileI tStart
  228. skipToString fileI "Z"
  229. skipToString fileI "\""
  230. local z = readDelimitedString fileI "\"" as float
  231. local translation = point3 x y z
  232.  
  233. seek fileI pivotStart
  234. skipToString fileI "<Rotation"
  235. rStart = filePos fileI
  236. skipToString fileI "X"
  237. skipToString fileI "\""
  238. x = readDelimitedString fileI "\"" as float
  239. seek fileI rStart
  240. skipToString fileI "Y"
  241. skipToString fileI "\""
  242. y = readDelimitedString fileI "\"" as float
  243. seek fileI rStart
  244. skipToString fileI "Z"
  245. skipToString fileI "\""
  246. z = readDelimitedString fileI "\"" as float
  247. seek fileI rStart
  248. skipToString fileI "W"
  249. skipToString fileI "\""
  250. local w = readDelimitedString fileI "\"" as float
  251. local rotation = quat x y z w
  252. w3dHierarchy.pivots[pivotNum] = w3xPivot name parent translation rotation
  253.  
  254. pivotNum = pivotNum + 1
  255.  
  256. if ((skipToString fileI "<Pivot" != undefined) and (filePos fileI < tagEnd)) then
  257. (
  258. getPivots pivotNum fileI tagEnd
  259. )
  260. )
  261.  
  262. function drawHierarchy p =
  263. (
  264. maxPivots[maxPivots.count + 1] = sphere name:w3dHierarchy.pivots[p].name radius:spinnerScale.value segs:4 renderable:false wirecolor:[0,128,0]
  265. wwSetExportBoneFlag maxPivots[maxPivots.count] true
  266. wwSetExportGeoFlag maxPivots[maxPivots.count] false
  267. wwSetShadowFlag maxPivots[maxPivots.count] false
  268.  
  269. if (w3dHierarchy.pivots[p].parent > 0) then
  270. (
  271. maxPivots[maxPivots.count].parent = maxPivots[w3dHierarchy.pivots[p].parent]
  272. )
  273. )
  274.  
  275. function buildHierarchy fileI =
  276. (
  277. maxPivots = #()
  278. w3dHierarchy = w3xHierarchy id:"none"
  279.  
  280. seek fileI 0
  281. skipToString fileI "<W3DHierarchy"
  282. skipToString fileI "id"
  283. skipToString fileI "\""
  284. w3dHierarchy.id = readDelimitedString fileI "\""
  285.  
  286. local fileP = filePos fileI
  287. skipToString fileI "</W3DHierarchy"
  288. local tagEnd = filePos fileI
  289. seek fileI fileP
  290.  
  291. if ((skipToString fileI "<Pivot" != undefined) and (filePos fileI < tagEnd)) then
  292. (
  293. getPivots 1 fileI tagEnd
  294. )
  295.  
  296. if (w3dHierarchy.pivots.count > 1) then
  297. (
  298. for p = 2 to w3dHierarchy.pivots.count do (drawHierarchy p)
  299. )
  300. )
  301.  
  302. function searchMaterialFile searchPath searchPaths searchFile defaultFile missingList =
  303. (
  304. local resultFile = ""
  305. local searchCheck = searchPath + "\\" + searchFile
  306.  
  307. if ((searchPath != "") and (doesFileExist searchCheck)) then
  308. (
  309. resultFile = searchCheck
  310. )
  311. else
  312. (
  313. if (searchPaths.count > 0) then
  314. (
  315. for i = 1 to searchPaths.count do
  316. (
  317. if (resultFile == "") then
  318. (
  319. searchCheck = searchPaths[i] + "\\" + searchFile
  320.  
  321. if (doesFileExist searchCheck) then
  322. (
  323. resultFile = searchCheck
  324. )
  325. )
  326. )
  327. )
  328. )
  329.  
  330. if (resultFile == "") then
  331. (
  332. if (missingList != undefined) then
  333. (
  334. addListItem missingList searchFile
  335. )
  336.  
  337. resultFile = defaultFile
  338. )
  339.  
  340. return resultFile
  341. )
  342.  
  343. function getShaderParams fileI meshEnd =
  344. (
  345. local shaderMaterial = DxMaterial technique:0
  346. local tagStart = filePos fileI
  347.  
  348. if ((skipToString fileI "<FXShader" != undefined) and (filePos fileI < meshEnd)) then
  349. (
  350. tagStart = filePos fileI
  351. skipToString fileI "</FXShader"
  352. local shaderEnd = filePos fileI
  353. seek fileI tagStart
  354.  
  355. skipToString fileI "ShaderName"
  356. skipToString fileI "\""
  357. local shaderFileName = readDelimitedString fileI "\""
  358. shaderMaterial.effectfile = searchMaterialFile shaderPath shaderSearchPaths shaderFileName "$maps\fx\default.fx" missingShaders
  359. seek fileI tagStart
  360.  
  361. if ((skipToString fileI "TechniqueIndex" != undefined) and (filePos fileI < meshEnd)) then
  362. (
  363. skipToString fileI "\""
  364. shaderMaterial.technique = readDelimitedString fileI "\"" as Integer
  365. )
  366.  
  367. seek fileI tagStart
  368.  
  369. local shaderParams = getPropNames shaderMaterial
  370. local setting
  371. local tagEnd
  372. local textureFile
  373.  
  374. while (filePos fileI < shaderEnd) do
  375. (
  376. fileP = filePos fileI
  377. setting = w3xShaderValue "none"
  378.  
  379. if (skipToString fileI "<Texture" == undefined) then
  380. (
  381. seek fileI fileP
  382. if (skipToString fileI "<Float" == undefined) then
  383. (
  384. seek fileI fileP
  385. if (skipToString fileI "<Int" == undefined) then
  386. (
  387. seek fileI fileP
  388. if (skipToString fileI "<Bool" != undefined) then
  389. (
  390. fileP = filePos fileI
  391. skipToString fileI "</Bool"
  392. tagEnd = filePos fileI
  393. seek fileI fileP
  394.  
  395. skipToString fileI "Name"
  396. skipToString fileI "\""
  397. setting.name = readDelimitedString fileI "\""
  398. skipToString fileI "<Value"
  399. skipToString fileI ">"
  400. setting.value = readDelimitedString fileI "<"
  401.  
  402. if (setting.value == "true") then
  403. (
  404. setting.value = true
  405. )
  406. else
  407. (
  408. setting.value = false
  409. )
  410.  
  411. for prop = 1 to shaderParams.count do
  412. (
  413. if ((shaderParams[prop] as string) == setting.name) then
  414. (
  415.  
  416. setProperty shaderMaterial shaderParams[prop] setting.value
  417. )
  418. )
  419.  
  420. seek fileI tagEnd
  421. )
  422. )
  423. else
  424. (
  425. fileP = filePos fileI
  426. skipToString fileI "</Int"
  427. tagEnd = filePos fileI
  428. seek fileI fileP
  429.  
  430. skipToString fileI "Name"
  431. skipToString fileI "\""
  432. setting.name = readDelimitedString fileI "\""
  433. skipToString fileI "<Value"
  434. skipToString fileI ">"
  435. setting.value = readDelimitedString fileI "<" as integer
  436.  
  437. for prop = 1 to shaderParams.count do
  438. (
  439. if ((shaderParams[prop] as string) == setting.name) then
  440. (
  441. setProperty shaderMaterial shaderParams[prop] setting.value
  442. )
  443. )
  444.  
  445. seek fileI tagEnd
  446. )
  447. )
  448. else
  449. (
  450. fileP = filePos fileI
  451. skipToString fileI "</Float"
  452. tagEnd = filePos fileI
  453. seek fileI fileP
  454.  
  455. skipToString fileI "Name"
  456. skipToString fileI "\""
  457. setting.name = readDelimitedString fileI "\""
  458.  
  459. skipToString fileI "<Value"
  460. skipToString fileI ">"
  461. setting.value = #(readDelimitedString fileI "<" as float, 0, 0, 0)
  462.  
  463. if ((skipToString fileI "<Value" == undefined) or (filePos fileI >= tagEnd)) then
  464. (
  465. for prop = 1 to shaderParams.count do
  466. (
  467. if ((shaderParams[prop] as string) == setting.name) then
  468. (
  469. setProperty shaderMaterial shaderParams[prop] setting.value[1]
  470. )
  471. )
  472. )
  473. else
  474. (
  475. skipToString fileI ">"
  476. setting.value[2] = readDelimitedString fileI "<" as float
  477.  
  478. if ((skipToString fileI "<Value" != undefined) and (filePos fileI < tagEnd)) then
  479. (
  480. skipToString fileI ">"
  481. setting.value[3] = readDelimitedString fileI "<" as float
  482.  
  483. if ((skipToString fileI "<Value" != undefined) and (filePos fileI < tagEnd)) then
  484. (
  485. skipToString fileI ">"
  486. setting.value[4] = readDelimitedString fileI "<" as float
  487. )
  488. )
  489.  
  490. for prop = 1 to shaderParams.count do
  491. (
  492. if ((shaderParams[prop] as string) == setting.name) then
  493. (
  494. setProperty shaderMaterial shaderParams[prop] (point4 setting.value[1] setting.value[2] setting.value[3] setting.value[4])
  495. )
  496. )
  497. )
  498.  
  499. seek fileI tagEnd
  500. )
  501. )
  502. else
  503. (
  504. fileP = filePos fileI
  505. skipToString fileI "</Texture"
  506. tagEnd = filePos fileI
  507. seek fileI fileP
  508.  
  509. skipToString fileI "Name"
  510. skipToString fileI "\""
  511. setting.name = readDelimitedString fileI "\""
  512. skipToString fileI "<Value"
  513. skipToString fileI ">"
  514. setting.value = readDelimitedString fileI "<"
  515. textureFile = searchMaterialFile texturePath textureSearchPaths (setting.value + ".tga") "" undefined
  516.  
  517. if (textureFile == "") then
  518. (
  519. textureFile = searchMaterialFile texturePath textureSearchPaths (setting.value + ".dds") "" missingTextures
  520. )
  521.  
  522. if (textureFile != "") then
  523. (
  524. for prop = 1 to shaderParams.count do
  525. (
  526. if ((shaderParams[prop] as string) == setting.name) then
  527. (
  528. setProperty shaderMaterial shaderParams[prop] (openBitMap textureFile)
  529. )
  530. )
  531. )
  532.  
  533. seek fileI tagEnd
  534. )
  535. )
  536.  
  537. missingShaders.items = sort missingShaders.items
  538. missingTextures.items = sort missingTextures.items
  539. )
  540.  
  541. if (maxMaterials <= 24) then
  542. (
  543. setMeditMaterial maxMaterials shaderMaterial
  544. maxMaterials = maxMaterials + 1
  545. )
  546. )
  547.  
  548. function getVertices fileI meshEnd =
  549. (
  550. local verts = #()
  551. local tagStart = filePos fileI
  552.  
  553. if ((skipToString fileI "<Vertices" != undefined) and (filePos fileI < meshEnd)) then
  554. (
  555. local x, y, z
  556. tagStart = filePos fileI
  557. skipToString fileI "</Vertices"
  558. local tagEnd = filePos fileI
  559. seek fileI tagStart
  560. local vStart
  561.  
  562. while (((skipToString fileI "<V") != undefined) and (filePos fileI < tagEnd)) do
  563. (
  564. vStart = filePos fileI
  565. skipToString fileI "X"
  566. skipToString fileI "\""
  567. x = readDelimitedString fileI "\"" as float
  568. seek fileI vStart
  569. skipToString fileI "Y"
  570. skipToString fileI "\""
  571. y = readDelimitedString fileI "\"" as float
  572. seek fileI vStart
  573. skipToString fileI "Z"
  574. skipToString fileI "\""
  575. z = readDelimitedString fileI "\"" as float
  576. verts[verts.count + 1] = point3 x y z
  577. )
  578. )
  579.  
  580. return verts
  581. )
  582.  
  583. function getTexCoords fileI meshEnd =
  584. (
  585. local tverts = #()
  586. local tagStart = filePos fileI
  587.  
  588. if ((skipToString fileI "<TexCoords" != undefined) and (filePos fileI < meshEnd)) then
  589. (
  590. local x, y
  591. tagStart = filePos fileI
  592. skipToString fileI "</TexCoords"
  593. local tagEnd = filePos fileI
  594. seek fileI tagStart
  595. local tStart
  596.  
  597. while (((skipToString fileI "<T") != undefined) and (filePos fileI < tagEnd)) do
  598. (
  599. tStart = filePos fileI
  600. skipToString fileI "X"
  601. skipToString fileI "\""
  602. x = readDelimitedString fileI "\"" as float
  603. seek fileI tStart
  604. skipToString fileI "Y"
  605. skipToString fileI "\""
  606. y = readDelimitedString fileI "\"" as float
  607. tverts[tverts.count + 1] = point3 x y 0
  608. )
  609. )
  610.  
  611. return tverts
  612. )
  613.  
  614. function getBoneInfluences fileI meshEnd =
  615. (
  616. local binfluences = #()
  617. local tagStart = filePos fileI
  618.  
  619. if ((skipToString fileI "<BoneInfluences" != undefined) and (filePos fileI < meshEnd)) then
  620. (
  621. local x, y
  622. tagStart = filePos fileI
  623. skipToString fileI "</BoneInfluences"
  624. local tagEnd = filePos fileI
  625. seek fileI tagStart
  626. local iStart
  627.  
  628. while (((skipToString fileI "<I") != undefined) and (filePos fileI < tagEnd)) do
  629. (
  630. iStart = filePos fileI
  631. skipToString fileI "Bone"
  632. skipToString fileI "\""
  633. x = readDelimitedString fileI "\"" as float
  634. seek fileI iStart
  635. skipToString fileI "Weight"
  636. skipToString fileI "\""
  637. y = readDelimitedString fileI "\"" as float
  638. binfluences[binfluences.count + 1] = point2 x y
  639. )
  640. )
  641.  
  642. return binfluences
  643. )
  644.  
  645. function getFaces fileI meshEnd =
  646. (
  647. local faces = #()
  648. local tagStart = filePos fileI
  649.  
  650. if ((skipToString fileI "<Triangles" != undefined) and (filePos fileI < meshEnd)) then
  651. (
  652. local x, y, z
  653. tagStart = filePos fileI
  654. skipToString fileI "</Triangles"
  655. local tagEnd = filePos fileI
  656. seek fileI tagStart
  657.  
  658. while ((skipToString fileI "<T" != undefined) and (filePos fileI < tagEnd)) do
  659. (
  660. skipToString fileI "<V"
  661. skipToString fileI ">"
  662. x = readDelimitedString fileI "<" as integer
  663. skipToString fileI "<V"
  664. skipToString fileI ">"
  665. y = readDelimitedString fileI "<" as integer
  666. skipToString fileI "<V"
  667. skipToString fileI ">"
  668. z = readDelimitedString fileI "<" as integer
  669. faces[faces.count + 1] = point3 (1 + x) (1 + y) (1 + z)
  670. )
  671. )
  672.  
  673. return faces
  674. )
  675.  
  676. function buildMesh fileI meshName meshId =
  677. (
  678. seek fileI 0
  679. local processMesh = true
  680.  
  681. if (meshName == "") then
  682. (
  683. skipToString fileI "<W3DMesh"
  684. skipToString fileI "id"
  685. skipToString fileI "\""
  686. meshName = readDelimitedString fileI "\""
  687. )
  688. else
  689. (
  690. do
  691. (
  692. if (skipToString fileI "<W3DMesh" == undefined) then
  693. (
  694. processMesh = false
  695. )
  696. else
  697. (
  698. skipToString fileI "id"
  699. skipToString fileI "\""
  700. )
  701. )
  702. while ((readDelimitedString fileI "\"" != meshName) and (processMesh))
  703. )
  704.  
  705. if (processMesh) then
  706. (
  707. local tagStart = filePos fileI
  708. skipToString fileI "</W3DMesh"
  709. local tagEnd = filePos fileI
  710.  
  711. seek fileI tagStart
  712. local castShadow = "false"
  713.  
  714. if ((skipToString fileI "CastShadow" != undefined) and (filePos fileI < tagEnd)) then
  715. (
  716. skipToString fileI "\""
  717. castShadow = readDelimitedString fileI "\""
  718. )
  719.  
  720. seek fileI tagStart
  721. local v = getVertices fileI tagEnd
  722. seek fileI tagStart
  723. local t = getTexCoords fileI tagEnd
  724. seek fileI tagStart
  725. local inf = getBoneInfluences fileI tagEnd
  726. seek fileI tagStart
  727. local f = getFaces fileI tagEnd
  728.  
  729. if (inf.count > 0) then
  730. (
  731. local boneInfluence
  732.  
  733. for i = 1 to inf.count do
  734. (
  735. boneInfluence = bone pos:[0, 0, 0]
  736.  
  737. if ((inf[i].x > 0) and (isValidNode maxPivots[inf[i].x])) then
  738. (
  739. boneInfluence.parent = maxPivots[inf[i].x]
  740. )
  741.  
  742. in coordsys parent boneInfluence.pos = v[i]
  743. v[i] = boneInfluence.pos
  744. delete boneInfluence
  745. )
  746. )
  747.  
  748. if (meshId != "") then
  749. (
  750. meshName = meshId
  751. )
  752.  
  753. maxMeshes[maxMeshes.count + 1] = mesh name:meshName vertices:v tverts:t faces:f
  754. wwSetExportBoneFlag maxMeshes[maxMeshes.count] false
  755. wwSetExportGeoFlag maxMeshes[maxMeshes.count] true
  756.  
  757. if (castShadow == "true") then
  758. (
  759. wwSetShadowFlag maxMeshes[maxMeshes.count] true
  760. )
  761. else
  762. (
  763. wwSetShadowFlag maxMeshes[maxMeshes.count] false
  764. )
  765.  
  766. update maxMeshes[maxMeshes.count]
  767.  
  768. if (t.count > 0) then
  769. (
  770. buildTVFaces maxMeshes[maxMeshes.count]
  771. for i = 1 to maxMeshes[maxMeshes.count].numfaces do (setTVFace maxMeshes[maxMeshes.count] i (getFace maxMeshes[maxMeshes.count] i))
  772. )
  773.  
  774. seek fileI tagStart
  775. getShaderParams fileI tagEnd
  776. maxMeshes[maxMeshes.count].material = getMeditMaterial (maxMaterials - 1)
  777. )
  778. )
  779.  
  780. function getRenderObject objectNum fileI =
  781. (
  782. if (w3dContainer.subObjects[objectNum].renderObject.type == "CollisionBox") then
  783. (
  784. seek fileI 0
  785. local processOBBox = true
  786.  
  787. do
  788. (
  789. if (skipToString fileI "<W3DCollisionBox" == undefined) then
  790. (
  791. processOBBox = false
  792. )
  793. else
  794. (
  795. skipToString fileI "id"
  796. skipToString fileI "\""
  797. )
  798. )
  799. while ((readDelimitedString fileI "\"" != w3dContainer.subObjects[objectNum].renderObject.name) and (processOBBox))
  800.  
  801. if (processOBBox) then
  802. (
  803. local tagStart = filePos fileI
  804. skipToString fileI "<Center"
  805. local cStart = filePos fileI
  806. skipToString fileI "X"
  807. skipToString fileI "\""
  808. local x = readDelimitedString fileI "\"" as float
  809. seek fileI cStart
  810. skipToString fileI "Y"
  811. skipToString fileI "\""
  812. local y = readDelimitedString fileI "\"" as float
  813. seek fileI cStart
  814. skipToString fileI "Z"
  815. skipToString fileI "\""
  816. local z = readDelimitedString fileI "\"" as float
  817. local center = point3 x y z
  818.  
  819. seek fileI tagStart
  820. skipToString fileI "<Extent"
  821. local eStart = filePos fileI
  822. skipToString fileI "X"
  823. skipToString fileI "\""
  824. x = readDelimitedString fileI "\"" as float
  825. seek fileI eStart
  826. skipToString fileI "Y"
  827. skipToString fileI "\""
  828. y = readDelimitedString fileI "\"" as float
  829. seek fileI eStart
  830. skipToString fileI "Z"
  831. skipToString fileI "\""
  832. z = readDelimitedString fileI "\"" as float
  833. local extent = point3 x y z
  834.  
  835. center.z = center.z - extent.z
  836. w3dContainer.subObjects[objectNum].renderObject.object = w3xCollisionBox center extent
  837. maxOBBoxes[maxOBBoxes.count + 1] = box name:w3dContainer.subObjects[objectNum].id pos:w3dContainer.subObjects[objectNum].renderObject.object.center xray:true wirecolor:[0,255,255]
  838. maxOBBoxes[maxOBBoxes.count].width = 2 * abs(w3dContainer.subObjects[objectNum].renderObject.object.extent.x)
  839. maxOBBoxes[maxOBBoxes.count].length = 2 * abs(w3dContainer.subObjects[objectNum].renderObject.object.extent.y)
  840. maxOBBoxes[maxOBBoxes.count].height = 2 * abs(w3dContainer.subObjects[objectNum].renderObject.object.extent.z)
  841. wwSetExportBoneFlag maxOBBoxes[maxOBBoxes.count] false
  842. wwSetExportGeoFlag maxOBBoxes[maxOBBoxes.count] true
  843. wwSetShadowFlag maxOBBoxes[maxOBBoxes.count] false
  844.  
  845. if (w3dContainer.subObjects[objectNum].boneIndex > 0) then
  846. (
  847. in coordsys world maxOBBoxes[maxOBBoxes.count].pos = maxOBBoxes[maxOBBoxes.count].pos + maxPivots[w3dContainer.subObjects[objectNum].boneIndex].pos
  848.  
  849. if (maxOBBoxes[maxOBBoxes.count].name == maxPivots[w3dContainer.subObjects[objectNum].boneIndex].name) then
  850. (
  851. maxOBBoxes[maxOBBoxes.count].parent = maxPivots[w3dContainer.subObjects[objectNum].boneIndex].parent
  852. wwSetExportBoneFlag maxOBBoxes[maxOBBoxes.count] true
  853.  
  854. for i = 1 to maxPivots.count do
  855. (
  856. if (maxPivots[i].parent == maxPivots[w3dContainer.subObjects[objectNum].boneIndex]) then
  857. (
  858. maxPivots[i].parent = maxOBBoxes[maxOBBoxes.count]
  859. )
  860. )
  861.  
  862. delete maxPivots[w3dContainer.subObjects[objectNum].boneIndex]
  863. maxPivots[w3dContainer.subObjects[objectNum].boneIndex] = maxOBBoxes[maxOBBoxes.count]
  864. )
  865. else
  866. (
  867. maxOBBoxes[maxOBBoxes.count].parent = maxPivots[w3dContainer.subObjects[objectNum].boneIndex]
  868. )
  869. )
  870. )
  871. )
  872. if (w3dContainer.subObjects[objectNum].renderObject.type == "Mesh") then
  873. (
  874. buildMesh fileI w3dContainer.subObjects[objectNum].renderObject.name w3dContainer.subObjects[objectNum].id
  875.  
  876. if (w3dContainer.subObjects[objectNum].boneIndex > 0) then
  877. (
  878. in coordsys world maxMeshes[maxMeshes.count].pos = maxMeshes[maxMeshes.count].pos + maxPivots[w3dContainer.subObjects[objectNum].boneIndex].pos
  879.  
  880. if (maxMeshes[maxMeshes.count].name == maxPivots[w3dContainer.subObjects[objectNum].boneIndex].name) then
  881. (
  882. maxMeshes[maxMeshes.count].parent = maxPivots[w3dContainer.subObjects[objectNum].boneIndex].parent
  883. wwSetExportBoneFlag maxMeshes[maxMeshes.count] true
  884.  
  885. for i = 1 to maxPivots.count do
  886. (
  887. if (maxPivots[i].parent == maxPivots[w3dContainer.subObjects[objectNum].boneIndex]) then
  888. (
  889. maxPivots[i].parent = maxMeshes[maxMeshes.count]
  890. )
  891. )
  892.  
  893. delete maxPivots[w3dContainer.subObjects[objectNum].boneIndex]
  894. maxPivots[w3dContainer.subObjects[objectNum].boneIndex] = maxMeshes[maxMeshes.count]
  895. )
  896. else
  897. (
  898. maxMeshes[maxMeshes.count].parent = maxPivots[w3dContainer.subObjects[objectNum].boneIndex]
  899. )
  900. )
  901. )
  902. )
  903.  
  904. function getSubObjects objectNum fileI tagEnd =
  905. (
  906. local subStart = filePos fileI
  907. skipToString fileI "SubObjectID"
  908. skipToString fileI "\""
  909. local id = readDelimitedString fileI "\""
  910. seek fileI subStart
  911. skipToString fileI "BoneIndex"
  912. skipToString fileI "\""
  913. local boneIndex = readDelimitedString fileI "\"" as integer
  914.  
  915. local renderObject = w3xRenderObject type:"none" name:"none"
  916. skipToString fileI "<RenderObject"
  917. skipToString fileI "<"
  918. renderObject.type = readDelimitedString fileI ">"
  919. renderObject.name = readDelimitedString fileI "<"
  920. w3dContainer.subObjects[objectNum] = w3xSubObject id boneIndex renderObject
  921.  
  922. getRenderObject objectNum fileI
  923. seek fileI subStart
  924.  
  925. objectNum = objectNum + 1
  926. if ((skipToString fileI "<SubObject" != undefined) and (filePos fileI < tagEnd)) then
  927. (
  928. getSubObjects objectNum fileI tagEnd
  929. )
  930. )
  931.  
  932. function buildContainer fileI =
  933. (
  934. maxOBBoxes = #()
  935. maxMeshes = #()
  936. w3dContainer = w3xContainer id:"none" hierarchy:w3dHierarchy
  937.  
  938. seek fileI 0
  939. skipToString fileI "<W3DContainer"
  940. skipToString fileI "id"
  941. skipToString fileI "\""
  942. w3dContainer.id = readDelimitedString fileI "\""
  943.  
  944. local fileP = filePos fileI
  945. skipToString fileI "</W3DContainer"
  946. local tagEnd = filePos fileI
  947. seek fileI fileP
  948.  
  949. if ((skipToString fileI "<SubObject" != undefined) and (filePos fileI < tagEnd)) then
  950. (
  951. getSubObjects 1 fileI tagEnd
  952. )
  953. )
  954.  
  955. function evaluateHierarchy test =
  956. (
  957. local i = maxPivots.count
  958.  
  959. while (i > 0) do
  960. (
  961. move maxPivots[i] w3dHierarchy.pivots[i + 1].translation
  962. rotate maxPivots[i] w3dHierarchy.pivots[i + 1].rotation
  963. i = i - 1
  964. )
  965. )
  966.  
  967. function getPaths fileSKNName =
  968. (
  969. if (editTexturePath.text == "") then
  970. (
  971. textureSearchPaths[textureSearchPaths.count + 1] = getFilenamePath fileSKNName
  972. )
  973. else
  974. (
  975. texturePath = editTexturePath.text
  976. )
  977.  
  978. if (editShaderPath.text != "") then
  979. (
  980. shaderPath = editShaderPath.text
  981. )
  982. )
  983.  
  984.  
  985.  
  986. -- Button Pressed Events --
  987. on buttonImportSkeleton pressed do
  988. (
  989. local fileSKL = getOpenFileName caption:captionImportSKL types:typesImport
  990.  
  991. if fileSKL != undefined then
  992. (
  993. fileSKLInput = openFile fileSKL
  994. buildHierarchy fileSKLInput
  995. close fileSKLInput
  996. evaluateHierarchy true
  997. max views redraw
  998. )
  999. )
  1000.  
  1001. on buttonImportHierarchicalModel pressed do
  1002. (
  1003. local fileSKL = getOpenFileName caption:captionImportSKL types:typesImport
  1004.  
  1005. if (fileSKL != undefined) then
  1006. (
  1007. local fileSKN = getOpenFileName caption:captionImportSKN types:typesImport
  1008.  
  1009. if (fileSKN != undefined) then
  1010. (
  1011. missingShaders.items = #()
  1012. missingTextures.items = #()
  1013. maxMaterials = spinnerMaterials.value
  1014.  
  1015. fileSKLInput = openFile fileSKL
  1016.  
  1017. buildHierarchy fileSKLInput
  1018. close fileSKLInput
  1019. evaluateHierarchy true
  1020.  
  1021. fileSKNInput = openFile fileSKN
  1022. getPaths fileSKN
  1023.  
  1024. buildContainer fileSKNInput
  1025. close fileSKNInput
  1026. max views redraw
  1027. spinnerMaterials.value = maxMaterials
  1028. )
  1029. )
  1030. )
  1031.  
  1032. on buttonImportSimpleMesh pressed do
  1033. (
  1034. local fileSKN = getOpenFileName caption:captionImportMesh types:typesImport
  1035.  
  1036. if (fileSKN != undefined) then
  1037. (
  1038. maxMeshes = #()
  1039. missingShaders.items = #()
  1040. missingTextures.items = #()
  1041. maxMaterials = spinnerMaterials.value
  1042.  
  1043. fileSKNInput = openFile fileSKN
  1044. getPaths fileSKN
  1045.  
  1046. buildMesh fileSKNInput "" ""
  1047. close fileSKNInput
  1048. max views redraw
  1049. spinnerMaterials.value = maxMaterials
  1050. )
  1051. )
  1052.  
  1053. on buttonTexturePath pressed do
  1054. (
  1055. local InitDir = textureInitPath
  1056.  
  1057. if (editTexturePath.text != "") then
  1058. (
  1059. InitDir = editTexturePath.text
  1060. )
  1061.  
  1062. local CheckDir = getSavePath caption:captionTexturePath initialDir:InitDir
  1063.  
  1064. if (CheckDir != undefined) then
  1065. (
  1066. editTexturePath.text = CheckDir
  1067. )
  1068. )
  1069.  
  1070. on buttonShaderPath pressed do
  1071. (
  1072. local InitDir = shaderInitPath
  1073.  
  1074. if (editShaderPath.text != "") then
  1075. (
  1076. InitDir = editShaderPath.text
  1077. )
  1078.  
  1079. local CheckDir = getSavePath caption:captionShaderPath initialDir:InitDir
  1080.  
  1081. if (CheckDir != undefined) then
  1082. (
  1083. editShaderPath.text = CheckDir
  1084. )
  1085. )
  1086.  
  1087. on buttonToggleLinks pressed do
  1088. (
  1089. if (maxPivots.count > 0) then
  1090. (
  1091. for i = 1 to maxPivots.count do
  1092. (
  1093. if (isValidNode maxPivots[i]) then
  1094. (
  1095. maxPivots[i].showLinks = not maxPivots[i].showLinks
  1096. )
  1097. )
  1098. )
  1099. )
  1100. )
  1101.  
  1102.  
  1103.  
  1104. -- ----------------------------------------------------------------------------------- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement