Advertisement
Graf_Rav

Untitled

Jan 7th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.16 KB | None | 0 0
  1. fn ImportRip RipFilePath =
  2. (
  3. f = fopen RipFilePath "rb"
  4.  
  5. Signature = readlong f #unsigned
  6. Version = readlong f #unsigned
  7.  
  8. if Version != RipFileVersion do(
  9. printDebug "Not RIP file"
  10. ---print ( "FileSig: " + Version as String )
  11. ---print ( "Sig : " + RipFileVersion as String )
  12. return 0
  13. )
  14.  
  15. dwFacesCnt = readlong f #unsigned
  16. dwVertexesCnt = readlong f #unsigned
  17. VertexSize = readlong f #unsigned
  18. TextureFilesCnt= readlong f #unsigned
  19. ShaderFilesCnt= readlong f #unsigned
  20. VertexAttributesCnt= readlong f #unsigned
  21.  
  22.  
  23. printDebug ( "*****ImportRip() File: " + RipFilePath as String )
  24. printDebug ( "dwFacesCnt=" + dwFacesCnt as String )
  25. printDebug ( "dwVertexesCnt=" + dwVertexesCnt as String )
  26. printDebug ( "VertexAttributesCnt=" + VertexAttributesCnt as String )
  27.  
  28.  
  29.  
  30. VertexAttribTypesArray= #() ---Contain all types
  31. TextureFiles = #()
  32. ShaderFiles = #()
  33.  
  34. Face_array = #()
  35. Normal_array = #()
  36. Vert_array = #()
  37. UV_array = #()
  38.  
  39.  
  40.  
  41. TempPosIdx = 0 ---Get only first index attribute flag
  42. TempNormalIdx = 0
  43. TempTexCoordIdx = 0
  44.  
  45. ---Read vertex attributes
  46. for i = 1 to VertexAttributesCnt do (
  47. Semantic = ReadStr f
  48. SemanticIndex = readlong f #unsigned
  49. Offset = readlong f #unsigned
  50. Size = readlong f #unsigned
  51. TypeMapElements = readlong f #unsigned
  52. for j = 1 to TypeMapElements do (
  53. TypeElement = readlong f #unsigned
  54. append VertexAttribTypesArray TypeElement
  55. )
  56. printDebug "------------"
  57. printDebug( "Semantic="+ Semantic )
  58. printDebug( "SemanticIndex=" + SemanticIndex as String )
  59. printDebug( "Offset=" + Offset as String )
  60. printDebug( "Size=" + Size as String )
  61. printDebug( "TypeMapElements=" + TypeMapElements as String )
  62.  
  63. ---Recognize semantic if "AUTO" set
  64. if g_VertexFormatRecog == 0 do ( ---AUTO recognition
  65. if Semantic == "POSITION" do ( --- Get as "XYZ_"
  66. if TempPosIdx == 0 do (
  67. g_PosX_Idx = Offset / 4
  68. g_PosY_Idx = g_PosX_Idx + 1
  69. g_PosZ_Idx = g_PosX_Idx + 2
  70.  
  71. TempPosIdx = TempPosIdx + 1
  72. )
  73. )
  74.  
  75. if Semantic == "NORMAL" do (
  76. if TempNormalIdx == 0 do (
  77. g_NormX_Idx = Offset / 4
  78. g_NormY_Idx = g_NormX_Idx + 1
  79. g_NormZ_Idx = g_NormX_Idx + 2
  80.  
  81. TempNormalIdx = TempNormalIdx + 1
  82. )
  83. )
  84.  
  85. if Semantic == "TEXCOORD" do (
  86. if TempTexCoordIdx == 0 do(
  87. g_Tc0_U_Idx = Offset / 4
  88. g_Tc0_V_Idx = g_Tc0_U_Idx + 1
  89.  
  90. TempTexCoordIdx = TempTexCoordIdx + 1
  91. )
  92. )
  93. )
  94.  
  95.  
  96. )
  97. printDebug "-----------------------------"
  98.  
  99. ---Read texture files list to array ( if present )
  100. for i = 1 to TextureFilesCnt do (
  101. TexFile = ReadStr f
  102. append TextureFiles ( TexFile as String )
  103. )
  104.  
  105.  
  106. ---Read shader files list to array ( if present )
  107. for i = 1 to ShaderFilesCnt do (
  108. ShaderFile = ReadStr f
  109. append ShaderFiles ( ShaderFile as String )
  110. )
  111.  
  112.  
  113.  
  114. printDebug ( "Texture Files:" )
  115. for i = 1 to TextureFiles.count do (
  116. printDebug ( TextureFiles[ i ] as String )
  117. )
  118. printDebug ( "------------" )
  119.  
  120.  
  121.  
  122. ---Read indexes
  123. for x = 1 to dwFacesCnt do(
  124. i0 = readlong f #unsigned
  125. i1 = readlong f #unsigned
  126. i2 = readlong f #unsigned
  127. if g_flipXZAxis == 1 then (
  128. append Face_array[i2+1,i1+1,i0+1]
  129. ) else (
  130. append Face_array[i0+1,i1+1,i2+1]
  131. )
  132.  
  133. --- print( "idx0: " + i0 as String + " idx1: " + i1 as String + " idx2: " + i2 as String )
  134. )
  135.  
  136.  
  137. printDebug( "PosX idx: " + g_PosX_Idx as String )
  138. printDebug( "PosY idx: " + g_PosY_Idx as String )
  139. printDebug( "PosZ idx: " + g_PosZ_Idx as String )
  140. printDebug( "NormX idx: " + g_NormX_Idx as String )
  141. printDebug( "NormY idx: " + g_NormY_Idx as String )
  142. printDebug( "NormZ idx: " + g_NormZ_Idx as String )
  143. printDebug( "Tu0 idx: " + g_Tc0_U_Idx as String )
  144. printDebug( "Tv0 idx: " + g_Tc0_V_Idx as String )
  145.  
  146.  
  147. ---Read vertexes
  148. for k = 1 to dwVertexesCnt do(
  149.  
  150. --- print ( "VertexIdx : " + (k-1) as String )
  151.  
  152. vx = 0.0
  153. vy = 0.0
  154. vz = 0.0
  155. vw = 0.0
  156. nx = 0.0
  157. ny = 0.0
  158. nz = 0.0
  159. nw = 0.0
  160. tu = 0.0
  161. tv = 0.0
  162.  
  163. for j = 0 to VertexAttribTypesArray.count - 1 do(
  164.  
  165. --- print ( "VertAttr Idx: " + j as String )
  166. ElementType = VertexAttribTypesArray[ j + 1 ]
  167. if ElementType == 0 then ( --- EFLOAT
  168. z = readfloat f
  169. )
  170. else if ElementType == 1 then ( ---EUINT
  171. z = readlong f #unsigned
  172. )
  173. else if ElementType == 2 then ( ---ESINT
  174. z = readlong f #signed
  175. )
  176. else (
  177. z = readlong f #unsigned
  178. )
  179.  
  180. if j == g_PosX_Idx do vx = z
  181. if j == g_PosY_Idx do vy = z
  182. if j == g_PosZ_Idx do vz = z
  183. !if j == g_PosW_Idx do vw = z
  184. if j == g_NormX_Idx do nx = z
  185. if j == g_NormY_Idx do ny = z
  186. if j == g_NormZ_Idx do nz = z
  187.  
  188. if j == g_Tc0_U_Idx do tu = z
  189. if j == g_Tc0_V_Idx do tv = z
  190.  
  191.  
  192. vx = vx as Float
  193. vy = vy as Float
  194. vz = vz as Float
  195. !vw = vw as Float
  196. nx = nx as Float
  197. ny = ny as Float
  198. nz = nz as Float
  199.  
  200. tu = tu as Float
  201. tv = tv as Float
  202. )
  203. append Vert_array[(vx * g_ninjaScale),(vy * g_ninjaScale),(vz * g_ninjaScale)]
  204. !append Vert_array[((vx*vw) * g_ninjaScale),((vy*vw) * g_ninjaScale),((vz*vw) * g_ninjaScale)]
  205. append Normal_array [nz,ny,nx]
  206. append UV_array[tu,tv * g_flipUV,0]
  207.  
  208. --- print( "vx: " + vx as String + " vy: " + vy as String + " vz: " + vz as String )
  209. --- print( "tu: " + tu as String + " tv: " + tv as String )
  210. )
  211.  
  212. TexFile = TextureFiles [ 1 + g_Tex0_FileLev ]
  213. if TexFile == undefined do ( TexFile = "notexture.dds" )
  214.  
  215. TexFileName = getFilenamePath RipFilePath
  216. TexFileName = TexFileName + TexFile
  217. printDebug ( "TEXTURE FILE: " + TexFileName )
  218.  
  219. ---Material
  220. -- thenewmaterial = multimaterial numsubs:1
  221. -- thenewsubmaterial = standardmaterial name:TexFile
  222. -- thenewsubmaterial.diffusemap = bitmaptexture name:TexFile
  223. -- thenewsubmaterial.diffusemap.filename = TexFileName
  224. -- thenewmaterial.materiallist[1] = thenewsubmaterial
  225. -- showtexturemap thenewsubmaterial thenewsubmaterial.diffusemap true
  226.  
  227. thenewmaterial = standardmaterial name:TexFile
  228. thenewmaterial.diffusemap = bitmaptexture name:TexFile
  229. thenewmaterial.diffusemap.filename = TexFileName
  230. -- thenewmaterial.bumpmap = bitmaptexture name:TexFile
  231. -- thenewmaterial.bumpmap.filename = TexFileName
  232. showtexturemap thenewmaterial thenewmaterial.diffusemap true
  233.  
  234. msh = mesh vertices:Vert_array faces:Face_array
  235. setNumTVerts msh UV_array.count
  236.  
  237. for i = 1 to UV_array.count do (setTVert msh i UV_array[i])
  238. buildTVFaces msh false
  239. for i = 1 to Face_array.count do (setTVFace msh i Face_array[i])
  240. --for i = 1 to Normal_array.count do (setNormal msh j Normal_array[j])
  241.  
  242. --Aplly mesh rotation
  243. currentMatrix = msh.transform
  244. preRotate currentMatrix (eulertoquat (eulerAngles g_ninjarotX g_ninjarotY g_ninjarotZ))
  245. msh.transform = currentMatrix
  246. resetxform msh
  247. maxOps.CollapseNode msh off
  248.  
  249. msh.name = getFilenameFile RipFilePath
  250. msh.material = thenewmaterial
  251.  
  252. --Redraw screen
  253. --windows.processPostedMessages() -- This prevents 3DS Max from hanging!
  254. --completeredraw()
  255. --gw.updateScreen()
  256. )
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264. on BtnImport pressed do (
  265.  
  266. if RadioVertexFormat.state == 1 then ( ---Auto
  267. printDebug "***Auto***"
  268. g_VertexFormatRecog = 0
  269. ---Set default values
  270. g_PosX_Idx = 0
  271. g_PosY_Idx = 1
  272. g_PosZ_Idx = 2
  273. !g_PosW_Idx = 3
  274. g_ninjarotX = spnrotateX.value
  275. g_ninjarotY = spnrotateY.value
  276. g_ninjarotZ = spnrotateZ.value
  277.  
  278. meshscale = spnscale.value
  279. )
  280.  
  281. else ( ---Manual
  282. printDebug "***Manual***"
  283. g_VertexFormatRecog = 1
  284.  
  285. ---Position
  286. g_PosX_Idx = ( pos_x.value as Integer )
  287. g_PosY_Idx = ( pos_y.value as Integer )
  288. g_PosZ_Idx = ( pos_z.value as Integer )
  289.  
  290. ---Normals
  291. g_NormX_Idx = ( norm_x.value as Integer )
  292. g_NormY_Idx = ( norm_y.value as Integer )
  293. g_NormZ_Idx = ( norm_z.value as Integer )
  294.  
  295. ---Tex coords
  296. g_Tc0_U_Idx = ( tc0_u.value as Integer )
  297. g_Tc0_V_Idx = ( tc0_v.value as Integer )
  298.  
  299. g_ninjarotX = spnrotateX.value
  300. g_ninjarotY = spnrotateY.value
  301. g_ninjarotZ = spnrotateZ.value
  302.  
  303. meshscale = spnscale.value
  304. )
  305.  
  306. g_Tex0_FileLev = spnTex0Lev.value as Integer
  307.  
  308.  
  309. ---Import part
  310. if g_ImportType == 1 then ( ---Single file import
  311. if g_InputSrc.count > 0 then ( ImportRip g_InputSrc )
  312. !ImportRip2 g_InputSrc
  313. else ( messageBox "Please select a .RIP file" )
  314. )
  315. else if g_ImportType == 0 then ( ---Group import
  316.  
  317. if InputSrc.text.count > 0 then (
  318. if RipList.text.count > 0 then (
  319. RipDir = getFilenamePath InputSrc.text
  320. ---print ( "RipDir: " + RipDir as String )
  321.  
  322. tokens = filterString RipList.text ","
  323. FilteredTokens = #()
  324.  
  325. ---Remove token whitespaces
  326. for i = 1 to tokens.count do (
  327. ---print ( "Tokens: " + tokens[i] as String )
  328. local Str = StringClear tokens[i]
  329. append FilteredTokens ( Str as String )
  330. )
  331.  
  332. ---Import loop. Split tokens with "-"
  333. for i = 1 to FilteredTokens.count do (
  334. printDebug ( "Filtered Tokens: " + FilteredTokens[i] as String )
  335. RangeTokens = filterString FilteredTokens[ i ] "-"
  336. if RangeTokens.count == 1 then ( --Single element
  337. RipDir1 = RipDir
  338. ss = CreateMeshName RangeTokens[ 1 ]
  339. RipDir1 = RipDir1 + ss;
  340. printDebug ( "Single Import:" + RipDir1 as String )
  341. ImportRip RipDir1
  342. !ImportRip2
  343. )
  344. else( ---Range element
  345. r0 = RangeTokens[1] as Integer
  346. r1 = RangeTokens[2] as Integer
  347. if r0 < r1 then (
  348. t1 = r0
  349. t2 = r1
  350.  
  351. messageBox("Screen redrawing has been disabled to help boost performance.")
  352. disableSceneRedraw()
  353.  
  354. tStart = timestamp()
  355.  
  356. doProcess = true
  357. setProgressCancel = false
  358.  
  359. progressBarText = "Importing "+ (t2 as string) +" objects..."
  360. progressStart (progressBarText as string)
  361.  
  362. for j = r0 to r1 while doProcess do(
  363. if getProgressCancel() == true do (
  364. doProcess = false
  365. setProgressCancel = true
  366. )
  367. if (getProgressCancel() == false) and (setProgressCancel == false) do (
  368. RipDir1 = RipDir
  369. ss = CreateMeshName j
  370. RipDir1 = RipDir1 + ss;
  371. printDebug ( "Group Import:" + RipDir1 as String )
  372. ImportRip RipDir1
  373. !ImportRip2
  374. t1 = t1 + 1
  375. tp = (100.0*t1/t2)
  376. progressUpdate (tp)
  377. )
  378. )
  379. progressEnd()
  380. enableSceneRedraw()
  381.  
  382. tEnd = timestamp()
  383.  
  384. tTimer = ((tEnd-tStart)/1000.0)
  385. if (tTimer <= 1) do ( tTime = (((tTimer) as string)+" second"))
  386. if (tTimer >= 2) do ( tTime = (((tTimer) as string)+" seconds"))
  387. if (tTimer > 60) do ( tTime = ((((tTimer)/60) as string)+" minute"))
  388. if (tTimer > 120) do ( tTime = ((((tTimer)/60) as string)+" minutes"))
  389.  
  390. if (doProcess == true) and (setProgressCancel == false) then (
  391. messageBox("Successfully imported "+ (t1 as string) +" objects in "+((tTime) as string)+"!")
  392. ) else (
  393. messageBox("Import interrupted! "+ (t1 as string) +"/"+(t2 as string)+" objects imported.")
  394. )
  395. completeRedraw()
  396. gw.updateScreen()
  397. )
  398. else (
  399. printDebug( "Incorrect range: " + r0 as String + " to " + r1 as String )
  400. )
  401. )
  402. )
  403.  
  404. )
  405. else(
  406. printDebug "Type file list"
  407. )
  408. )
  409. else (
  410. printDebug "Select dir"
  411. )
  412. )
  413. else(
  414. printDebug "Import from list file not realized"
  415. )
  416. )
  417. on BtnImport2 pressed do (
  418.  
  419. if RadioVertexFormat.state == 1 then ( ---Auto
  420. printDebug "***Auto***"
  421. g_VertexFormatRecog = 0
  422. ---Set default values
  423. g_PosX_Idx = 0
  424. g_PosY_Idx = 1
  425. g_PosZ_Idx = 2
  426. g_PosW_Idx = 3
  427.  
  428. g_ninjarotX = spnrotateX.value
  429. g_ninjarotY = spnrotateY.value
  430. g_ninjarotZ = spnrotateZ.value
  431.  
  432. meshscale = spnscale.value
  433. )
  434.  
  435. else ( ---Manual
  436. printDebug "***Manual***"
  437. g_VertexFormatRecog = 1
  438.  
  439. ---Position
  440. g_PosX_Idx = ( pos_x.value as Integer )
  441. g_PosY_Idx = ( pos_y.value as Integer )
  442. g_PosZ_Idx = ( pos_z.value as Integer )
  443. --g_PosW_Idx = ( pos_w.value as Integer )
  444.  
  445. ---Normals
  446. g_NormX_Idx = ( norm_x.value as Integer )
  447. g_NormY_Idx = ( norm_y.value as Integer )
  448. g_NormZ_Idx = ( norm_z.value as Integer )
  449.  
  450. ---Tex coords
  451. g_Tc0_U_Idx = ( tc0_u.value as Integer )
  452. g_Tc0_V_Idx = ( tc0_v.value as Integer )
  453.  
  454. g_ninjarotX = spnrotateX.value
  455. g_ninjarotY = spnrotateY.value
  456. g_ninjarotZ = spnrotateZ.value
  457.  
  458. meshscale = spnscale.value
  459. )
  460.  
  461. g_Tex0_FileLev = spnTex0Lev.value as Integer
  462.  
  463.  
  464. ---Import part
  465. if g_ImportType == 1 then ( ---Single file import
  466. if g_InputSrc.count > 0 then ( ImportRip2 g_InputSrc )
  467. else ( messageBox "Please select a .RIP file" )
  468. )
  469. else if g_ImportType == 0 then ( ---Group import
  470.  
  471. if InputSrc.text.count > 0 then (
  472. if RipList.text.count > 0 then (
  473. RipDir = getFilenamePath InputSrc.text
  474. ---print ( "RipDir: " + RipDir as String )
  475.  
  476. tokens = filterString RipList.text ","
  477. FilteredTokens = #()
  478.  
  479. ---Remove token whitespaces
  480. for i = 1 to tokens.count do (
  481. ---print ( "Tokens: " + tokens[i] as String )
  482. local Str = StringClear tokens[i]
  483. append FilteredTokens ( Str as String )
  484. )
  485.  
  486. ---Import loop. Split tokens with "-"
  487. for i = 1 to FilteredTokens.count do (
  488. printDebug ( "Filtered Tokens: " + FilteredTokens[i] as String )
  489. RangeTokens = filterString FilteredTokens[ i ] "-"
  490. if RangeTokens.count == 1 then ( --Single element
  491. RipDir1 = RipDir
  492. ss = CreateMeshName RangeTokens[ 1 ]
  493. RipDir1 = RipDir1 + ss;
  494. printDebug ( "Single Import:" + RipDir1 as String )
  495. ImportRip2 RipDir1
  496. )
  497. else( ---Range element
  498. r0 = RangeTokens[1] as Integer
  499. r1 = RangeTokens[2] as Integer
  500. if r0 < r1 then (
  501. t1 = r0
  502. t2 = r1
  503.  
  504. messageBox("Screen redrawing has been disabled to help boost performance.")
  505. disableSceneRedraw()
  506.  
  507. tStart = timestamp()
  508.  
  509. doProcess = true
  510. setProgressCancel = false
  511.  
  512. progressBarText = "Importing "+ (t2 as string) +" objects..."
  513. progressStart (progressBarText as string)
  514.  
  515. for j = r0 to r1 while doProcess do(
  516. if getProgressCancel() == true do (
  517. doProcess = false
  518. setProgressCancel = true
  519. )
  520. if (getProgressCancel() == false) and (setProgressCancel == false) do (
  521. RipDir1 = RipDir
  522. ss = CreateMeshName j
  523. RipDir1 = RipDir1 + ss;
  524. printDebug ( "Group Import:" + RipDir1 as String )
  525. ImportRip2 RipDir1
  526.  
  527. t1 = t1 + 1
  528. tp = (100.0*t1/t2)
  529. progressUpdate (tp)
  530. )
  531. )
  532. progressEnd()
  533. enableSceneRedraw()
  534.  
  535. tEnd = timestamp()
  536.  
  537. tTimer = ((tEnd-tStart)/1000.0)
  538. if (tTimer <= 1) do ( tTime = (((tTimer) as string)+" second"))
  539. if (tTimer >= 2) do ( tTime = (((tTimer) as string)+" seconds"))
  540. if (tTimer > 60) do ( tTime = ((((tTimer)/60) as string)+" minute"))
  541. if (tTimer > 120) do ( tTime = ((((tTimer)/60) as string)+" minutes"))
  542.  
  543. if (doProcess == true) and (setProgressCancel == false) then (
  544. messageBox("Successfully imported "+ (t1 as string) +" objects in "+((tTime) as string)+"!")
  545. ) else (
  546. messageBox("Import interrupted! "+ (t1 as string) +"/"+(t2 as string)+" objects imported.")
  547. )
  548. completeRedraw()
  549. gw.updateScreen()
  550. )
  551. else (
  552. printDebug( "Incorrect range: " + r0 as String + " to " + r1 as String )
  553. )
  554. )
  555. )
  556.  
  557. )
  558. else(
  559. printDebug "Type file list"
  560. )
  561. )
  562. else (
  563. printDebug "Select dir"
  564. )
  565. )
  566. else(
  567. printDebug "Import from list file not realized"
  568. )
  569. )
  570. )
  571.  
  572. createDialog MainRollout 300 374 50 60
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement