home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 15490 / RE2_R.7z / RE2_R_UPD.ms < prev   
Encoding:
Text File  |  2019-01-15  |  15.1 KB  |  606 lines

  1. if (heapSize < 200000) then
  2.         heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
  3. fname = getOpenFileName \
  4. caption:"Open .mesh from Mesh folder" \
  5. types:"RE2 Models (*.mes;*.mesh;*.*)|*.mes;*.mesh;*.*" \
  6. historyCategory:"RE2ObjectPresets"
  7. f = fopen fname "rb"
  8.  
  9. clearlistener()
  10.  
  11. fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
  12.     
  13. fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))    
  14.     
  15. fn readBEword fstream = (
  16. short = readshort fstream #unsigned
  17. short = bit.swapBytes short 1 2
  18. return short
  19. )    
  20.  
  21. fn ReadBEHalfFloat fstream = 
  22.     (
  23.     hf=readBEword fstream
  24.     sign = bit.get hf 16
  25.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  26.     fraction = bit.and hf (bit.hexasint "03FF")
  27.     if sign==true then sign = 1 else sign = 0
  28.     exponentF = exponent + 127
  29.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  30.     (bit.shift exponentF 23)) (bit.shift sign 31)
  31.     return bit.intasfloat outputasfloat*2
  32. )    
  33.  
  34. fn ReadHalfFloat fstream = 
  35.     (
  36.     hf=readshort fstream
  37.     sign = bit.get hf 16
  38.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  39.     fraction = bit.and hf (bit.hexasint "03FF")
  40.     if sign==true then sign = 1 else sign = 0
  41.     exponentF = exponent + 127
  42.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  43.     (bit.shift exponentF 23)) (bit.shift sign 31)
  44.     return bit.intasfloat outputasfloat*2
  45. )
  46.  
  47. fn readFixedString bstream fixedLen = (
  48. local str = ""
  49. for i = 1 to fixedLen do (
  50. str += bit.intAsChar (ReadByte bstream #unsigned))
  51. str
  52. )
  53. struct weight_data
  54. (
  55.     boneids,weights
  56. )
  57. struct Bone_Info_Struct
  58. (
  59.     Bone1,Bone2,Bone3,Bone4
  60. )
  61. struct Weight_Info_Struct
  62. (
  63.     Weight1,Weight2,Weight3,Weight4
  64. )
  65. struct Mesh_Info_Struct
  66. (
  67.     DataOff,DataSize,DataCount
  68. )    
  69. struct Mesh_Info_Struct_2 
  70. (
  71.     DataOff2,DataSize2,DataCount2
  72. )    
  73. clearlistener()
  74.  
  75. BNArr=#()    
  76. BNameArray=#()
  77.  
  78. fseek f (0x0) #seek_set
  79. Magic=readlong f
  80. if Magic!=1213416781 then fclose f
  81. if Magic==1213416781 then (
  82. unk=readbyte f
  83. vertSize=readbyte f
  84. UnkCount=readbyte f
  85. MatCount=readbyte f    
  86. FileSize=readlong f
  87. readlong f    
  88. SkelMapCount=readshort f
  89. UnkMeshCount=readbyte f    
  90. MMeshCount=readbyte f+1
  91. GBBOff=readlong f
  92. Print ("Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  93. DatOffFirst=readlong f        
  94. fseek f (0x14) #seek_cur    
  95. DatOff=readlong f    
  96. fseek f (0x14) #seek_cur        
  97. BBOff=readlong f
  98. readlong f
  99. MeshStartOff=readlong f
  100. fseek f (0xC) #seek_cur        
  101. BoneEnd=readlong f
  102. readlong f    
  103. BoneMapOff=readlong f    
  104. fseek f (0xC) #seek_cur        
  105. MatNameOff=readlong f    
  106.     
  107. fseek f (0x78) #seek_set    
  108. NameOff=readlong f        
  109.         
  110. Print ("End @ 0x"+((bit.intAsHex(ftell f))as string))        
  111.  
  112. print ("Bone Related Section End "+BoneEnd as string)
  113.     
  114. print ("MeshInfo Related Section End "+DatOff as string)    
  115.  
  116. fseek f (DatOffFirst) #seek_set
  117. UCount1=readbyte f    
  118. UCount2=readbyte f    
  119. VType=readbyte f
  120. FType=readbyte f        
  121.  
  122. BMapArray=#()    
  123. if DatOff!=0 then (    
  124. fseek f (DatOff) #seek_set
  125. BCount=readlong f
  126. BMapCount=readlong f    
  127.     
  128. Print ("Bone Count @ 0x"+((bit.intAsHex(ftell f))as string))        
  129.     
  130. fseek f (8) #seek_cur    
  131.  
  132. Print ("Bone and Map Offsets @ 0x"+((bit.intAsHex(ftell f))as string))        
  133.     
  134. BParOff=readlong f    
  135. readlong f
  136. BOff=readlong f        
  137.     
  138. fseek f (20) #seek_cur    
  139.  
  140. Print ("BoneMap Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  141.     
  142. for i=1 to BMapCount do (
  143. BMap=readshort f #usigned+1
  144. append BMapArray BMap    
  145. )    
  146.     
  147. Print ("BoneMap End @ 0x"+((bit.intAsHex(ftell f))as string))    
  148.     
  149. fseek f (BParOff) #seek_set        
  150.     
  151. Print ("Bone Parent Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  152.     
  153. BParArray=#()        
  154. for i=1 to BCount do (
  155. getPos = ftell f + 16
  156. BoneId=readshort f #usigned+1
  157. BPar=readshort f #usigned    
  158. fseek f getPos #seek_set    
  159. append BParArray BPar     
  160. )    
  161.     
  162. Print ("Bone Parent End @ 0x"+((bit.intAsHex(ftell f))as string))        
  163.     
  164. print ("This is Bones Count: "+BCount as string)    
  165. print ("This is Bones Offset: "+BOff as string)    
  166.     
  167. fseek f (BOff) #seek_set    
  168.     
  169. Print ("Bone Start 1 @ 0x"+((bit.intAsHex(ftell f))as string))    
  170.  
  171. for i=1 to BCount do (    
  172. getPos = ftell f + 64
  173. fseek f getPos #seek_set                                      
  174. )        
  175.     
  176. for i=1 to BCount do (    
  177. getPos = ftell f + 64
  178. fseek f getPos #seek_set                                      
  179. )    
  180.  
  181. BonesStartMain=ftell f
  182.  
  183. for i=1 to BCount do (    
  184. getPos = ftell f + 64
  185. fseek f getPos #seek_set                                      
  186. )    
  187.  
  188. Print ("Bone/Mat Order Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  189.     
  190. fseek f 16 #seek_cur
  191.  
  192. for i=1 to BCount do (
  193. readshort f #usigned
  194. )    
  195.     
  196. fseek f NameOff #seek_set    
  197.  
  198. Print ("Bone/Mat Order End @ 0x"+((bit.intAsHex(ftell f))as string))    
  199.  
  200. for i=1 to UCount2 do (
  201. getPos = ftell f + 8
  202. fseek f getPos #seek_set        
  203. )    
  204.  
  205. Print ("Bone Name Offsets Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  206.     
  207. for i=1 to BCount do (
  208. getPos = ftell f + 8
  209. BNameOff=readlong f
  210. readlong f    
  211. BnamePos=ftell f
  212. fseek f BNameOff #seek_set    
  213. BName=readstring f
  214. fseek f BnamePos #seek_set        
  215. fseek f getPos #seek_set    
  216. append BNameArray BName    
  217. )    
  218.  
  219. Print ("Bone Name Offsets End @ 0x"+((bit.intAsHex(ftell f))as string))    
  220.  
  221. fseek f BonesStartMain #seek_set    
  222.  
  223. Print ("Bone Start Main @ 0x"+((bit.intAsHex(ftell f))as string))    
  224.  
  225. for a=1 to BCount do (    
  226. getPos = ftell f + 64
  227. c11=readfloat f;c12=readfloat f;c13=readfloat f;c14=readfloat f
  228. c21=readfloat f;c22=readfloat f;c23=readfloat f;c24=readfloat f
  229. c31=readfloat f;c32=readfloat f;c33=readfloat f;c34=readfloat f
  230. c41=readfloat f;c42=readfloat f;c43=readfloat f;c44=readfloat f    
  231. fseek f getPos #seek_set    
  232.     
  233. tfm = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] ([c41,c42,c43]*100)    
  234.     
  235. if isvalidnode (getNodeByName BNameArray[a]) != true then (
  236. newBone = bonesys.createbone    \
  237.                                       tfm.row4      \
  238.                                       (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  239.                                       (normalize tfm.row3)
  240.                             newBone.width  = 0.01
  241.                             newBone.height = 0.01
  242.                             newBone.name = BNameArray[a]                                  
  243.                             newBone.transform = inverse tfm
  244.                             newBone.setBoneEnable false 0
  245.                             newBone.wirecolor = yellow
  246.                             newbone.showlinks = true
  247.                             newBone.pos.controller      = TCB_position ()
  248.                             newBone.rotation.controller = TCB_rotation ()         
  249.                             if (BParArray[a]!= -1) then
  250.                             newBone.parent = BNArr[(BParArray[a]+1)]                     
  251. )    
  252. if isvalidnode (getNodeByName BNameArray[a]) == true then (
  253. newBone = getNodeByName BNameArray[a]
  254. )
  255. append BNArr newBone                                        
  256. )    
  257.  
  258. Print ("Bone Main End @ 0x"+((bit.intAsHex(ftell f))as string))            
  259. )
  260.  
  261. VertexCountArray=#() 
  262. FaceCountArray=#()
  263. FaceStrideArray=#()
  264. VertStrideArray=#()
  265. MeshSubCountArray=#()
  266. IdOffArray=#()
  267. BMapCountArray=#()
  268. VEnd1=#()    
  269. FEnd1=#()    
  270.  
  271. fseek f (DatOffFirst) #seek_set
  272. for i=1 to 1 do (
  273. UCount1=readbyte f    
  274. UCount2=readbyte f    
  275. VType=readbyte f
  276. FType=readbyte f    
  277. IdCheck=readlong f
  278. if i==1 then fseek f (0x38) #seek_cur    
  279. if i!=1 then fseek f (0x8) #seek_cur    
  280. OffOne=readlong f    
  281. fseek f (OffOne) #seek_set    
  282. OffTwo=readlong f    
  283. fseek f (OffTwo) #seek_set
  284. for i=1 to 1 do (
  285. MeshCountTrue=readshort f
  286. BMapCount=readBEword f
  287. UnkLong=readlong f
  288. MeshOff=readlong f
  289. readlong f
  290.  
  291. append BMapCountArray BMapCount    
  292.         
  293. print     (MeshCountTrue as string)
  294.     
  295. fseek f (MeshOff) #seek_set    
  296.     
  297. Print ("Mesh Offset @ 0x"+((bit.intAsHex(ftell f))as string))        
  298.     
  299. MeshOffArray=#()    
  300. for i=1 to MeshCountTrue do (    
  301. MeshOffStart=readlong f
  302. Null=readlong f        
  303. append MeshOffArray MeshOffStart
  304. )    
  305.     
  306. for i=1 to MeshOffArray.count do (
  307. fseek f (MeshOffArray[i]) #seek_set    
  308. Print ("Mesh Info Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  309. MeshId=readbyte f+1
  310. MeshStart=readbyte f
  311. readshort f
  312. readlong f
  313. VertexCount=readlong f
  314. FaceCount2=readlong f
  315.  
  316. print (MeshStart as string)    
  317. for a=1 to MeshStart do (    
  318. IdOff=readlong f    
  319. FaceCount=readlong f    
  320. FaceStride=readlong f    
  321. VertStride=readlong f
  322. append FaceStrideArray FaceStride
  323. append VertStrideArray VertStride    
  324. append FaceCountArray FaceCount    
  325. append IdOffArray IdOff    
  326. )
  327. append MeshSubCountArray MeshStart
  328. append VertexCountArray VertexCount 
  329. print (VertexCountArray[i] as string)
  330. print (FaceCountArray[i]  as string)
  331. print (FaceStrideArray[i]  as string)
  332. print (VertStrideArray[i]  as string)
  333. )    
  334.  
  335. Print ("Mesh Info End @ 0x"+((bit.intAsHex(ftell f))as string))
  336. )    
  337. )
  338.  
  339. fseek f (MeshStartOff) #seek_set
  340.  
  341. Print ("MeshStartOff @ 0x"+((bit.intAsHex(ftell f))as string))    
  342.     
  343. fseek f (16) #seek_cur    
  344. FaceOffset=readlong f    
  345. readlong f    
  346. TotalVBuffSize=readlong f
  347. TotalFBuffSize=readlong f    
  348. Buff1Count=readshort f
  349. Buff2Count=readshort f    
  350. fseek f (12) #seek_cur        
  351. VBuff1Id=readshort f    
  352. VBuff1Size=readshort f    
  353. VBuffOff1=readlong f        
  354. VBuff2Id=readshort f    
  355. VBuff2Size=readshort f    
  356. VBuffOff2=readlong f    
  357. VBuff3Id=readshort f    
  358. VBuff3Size=readshort f    
  359. VBuffOff3=readlong f    
  360. VBuff4Id=readshort f    
  361. VBuff4Size=readshort f        
  362. VBuffOff4=readlong f    
  363. if Buff1Count==4 then fseek f (0) #seek_cur    
  364. if Buff1Count!=4 then (
  365. VBuff5Id=readshort f
  366. VBuff5Size=readshort f    
  367. VBuffOff5=readlong f        
  368. )    
  369.  
  370. VertOffset=ftell f
  371.  
  372. print ("This is Vertex Size: "+VBuff1Size as string)
  373.  
  374. Print ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @ 0x"+((bit.intAsHex(ftell f))as string))    
  375.  
  376. Vert1=#()
  377. for i=1 to IdOffArray.count do (    
  378. Face_array_Vert=#()        
  379. fseek f (FaceOffset+(FaceStrideArray[i]*2)) #seek_set    
  380.     
  381. for x = 1 to FaceCountArray[i] do (
  382. Vert=readshort f #unsigned + 1
  383. append Face_array_Vert Vert
  384. )    
  385. sort Face_array_Vert
  386. Vertex=(Face_array_Vert[FaceCountArray[i]])
  387. append Vert1 (Vertex as integer)
  388. )    
  389.     
  390. for i=1 to IdOffArray.count do (
  391.         
  392. Vert_array=#()
  393. Face_array=#()
  394. UV_array=#()    
  395. UV_array2=#()    
  396. Weight_array=#()    
  397.     
  398. fseek f (VertOffset+(VertStrideArray[i]*VBuff1Size)) #seek_set
  399.     
  400. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  401.     
  402. if VBuff1Size==12 then     
  403. for x =1 to Vert1[i] do (
  404. getPos = ftell f + 12
  405.     
  406. vx = readFloat f
  407. vy = readFloat f
  408. vz = readFloat f    
  409.     
  410. fseek f getPos #seek_set            
  411. append Vert_array ([vx,vy,vz]*100)    
  412. )        
  413.  
  414. Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))
  415.     
  416. VertexEnd1=ftell f
  417.  
  418. fseek f ((VertOffset+VBuffOff3)+(VertStrideArray[i]*VBuff3Size)) #seek_set    
  419.     
  420. Print ("Uv's Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  421.     
  422. if VBuff3Size==4 then     
  423. for x =1 to Vert1[i] do (
  424. getPos = ftell f + 4
  425.     
  426. tu=readHalfFloat f
  427. tv=readHalfFloat f    
  428.     
  429. fseek f getPos #seek_set            
  430. append UV_array [tu,(1.0-tv),0]     
  431. )        
  432.  
  433. Print ("Uv's End @ 0x"+((bit.intAsHex(ftell f))as string))
  434.     
  435. fseek f ((VertOffset+VBuffOff4)+(VertStrideArray[i]*VBuff4Size)) #seek_set    
  436.     
  437. Print ("Second Uv's Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  438.     
  439. if VBuff4Size==4 then     
  440. for x =1 to Vert1[i] do (
  441. getPos = ftell f + 4
  442.     
  443. tu2=readHalfFloat f
  444. tv2=readHalfFloat f    
  445.     
  446. fseek f getPos #seek_set            
  447. append UV_array2 [tu2,(1.0-tv2),0]     
  448. )        
  449.  
  450. Print ("Second Uv's End @ 0x"+((bit.intAsHex(ftell f))as string))    
  451.     
  452. if Buff1Count!=4 then (    
  453. fseek f ((VertOffset+VBuffOff5)+(VertStrideArray[i]*VBuff5Size)) #seek_set    
  454.     
  455. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  456.     
  457. if VBuff5Size==16 then     
  458. for x =1 to Vert1[i] do (
  459. getPos = ftell f + 16
  460.     
  461. bone1 = readbyte f #unsigned    
  462. bone2 = readbyte f #unsigned    
  463. bone3 = readbyte f #unsigned    
  464. bone4 = readbyte f #unsigned
  465. bone5 = readbyte f #unsigned    
  466. bone6 = readbyte f #unsigned    
  467. bone7 = readbyte f #unsigned    
  468. bone8 = readbyte f #unsigned    
  469.  
  470. weight1 = readbyte f #unsigned    
  471. weight2 = readbyte f #unsigned    
  472. weight3 = readbyte f #unsigned    
  473. weight4 = readbyte f #unsigned        
  474. weight5 = readbyte f #unsigned    
  475. weight6 = readbyte f #unsigned    
  476. weight7 = readbyte f #unsigned    
  477. weight8 = readbyte f #unsigned    
  478.     
  479. w = (weight_data boneids:#() weights:#())
  480. maxweight = 0
  481. if(weight1 != 0) then
  482.    maxweight = maxweight + weight1
  483. if(weight2 != 0) then
  484.    maxweight = maxweight + weight2
  485. if(weight3 != 0) then
  486.    maxweight = maxweight + weight3
  487. if(weight4 != 0) then
  488.    maxweight = maxweight + weight4
  489. if(weight5 != 0) then
  490.    maxweight = maxweight + weight5
  491. if(weight6 != 0) then
  492.    maxweight = maxweight + weight6
  493. if(weight7 != 0) then
  494.    maxweight = maxweight + weight7
  495. if(weight8 != 0) then
  496.    maxweight = maxweight + weight8    
  497.  
  498.  
  499. if(maxweight != 0) then (
  500.       if(weight1 != 0) then (
  501.          w1 = weight1 as float
  502.          append w.boneids (bone1 + 1)
  503.          append w.weights (w1/255.0)
  504.       )
  505.       if(weight2 != 0) then (
  506.          w2 = weight2 as float
  507.          append w.boneids (bone2 + 1)
  508.          append w.weights (w2/255.0)
  509.       )
  510.       if(weight3 != 0) then (
  511.          w3 = weight3 as float
  512.          append w.boneids (bone3 + 1)
  513.          append w.weights (w3/255.0)
  514.       )
  515.       if(weight4 != 0) then (
  516.          w4 = weight4 as float
  517.          append w.boneids (bone4 + 1)
  518.         append w.weights (w4/255.0)
  519.       )   
  520.       if(weight5 != 0) then (
  521.          w5 = weight5 as float
  522.          append w.boneids (bone5 + 1)
  523.          append w.weights (w5/255.0)
  524.       )
  525.       if(weight6 != 0) then (
  526.          w6 = weight6 as float
  527.          append w.boneids (bone6 + 1)
  528.          append w.weights (w6/255.0)
  529.       )
  530.       if(weight7 != 0) then (
  531.          w7 = weight7 as float
  532.          append w.boneids (bone7 + 1)
  533.          append w.weights (w7/255.0)
  534.       )
  535.       if(weight8 != 0) then (
  536.          w8 = weight8 as float
  537.          append w.boneids (bone8 + 1)
  538.         append w.weights (w8/255.0)
  539.       )         
  540.    )        
  541. fseek f getPos #seek_set    
  542. append Weight_array w       
  543. )        
  544.  
  545. Print ("Weights End @ 0x"+((bit.intAsHex(ftell f))as string))        
  546. )    
  547. fseek f (FaceOffset+(FaceStrideArray[i]*2)) #seek_set    
  548.  
  549. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  550.     
  551. for x = 1 to FaceCountArray[i]/3 do (
  552. fa=readshort f #unsigned + 1
  553. fb=readshort f #unsigned+ 1
  554. fc=readshort f #unsigned+ 1
  555. append Face_array [fa,fb,fc]     
  556. )    
  557.  
  558. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))
  559.  
  560. FaceEnd1=ftell f    
  561.  
  562. append VEnd1 VertexEnd1    
  563. append FEnd1 FaceEnd1     
  564.  
  565. try(    
  566. msh = mesh vertices:Vert_array faces:Face_array
  567. msh.numTVerts = UV_array.count
  568. msh.name="Resident Evil 7: "+i as string
  569. buildTVFaces msh
  570. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  571. for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
  572.     
  573. max modify mode
  574. select msh
  575. skinMod = skin ()
  576. addModifier msh skinMod
  577. for i = 1 to BMapArray.count do
  578. (
  579.     maxbone = BNArr[BMapArray[i]]
  580.     if i != BMapArray.count then 
  581.         skinOps.addBone skinMod maxbone 0
  582.     else
  583.         skinOps.addBone skinMod maxbone 1
  584. )
  585. modPanel.setCurrentObject skinMod
  586. for i = 1 to vert_Array.count do (
  587.    w = Weight_array[i]
  588.    bi = #() --bone index array
  589.    wv = #() --weight value array
  590.    
  591.    for j = 1 to w.boneids.count do
  592.    (
  593.       boneid = w.boneids[j]
  594.       weight = w.weights[j]
  595.       append bi boneid
  596.       append wv weight
  597.    )   
  598.    
  599.    skinOps.ReplaceVertexWeights skinMod i bi wv
  600. )
  601. )catch(format "Wrong Skeleton!!!\n")
  602. )
  603. ------------------------------------------------------------------------------------------------------------------------------
  604. )
  605.  
  606. fclose f