types.bmx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. ' types.bmx
  2. Type aiMatrix3x3
  3. Field a1:Float, a2:Float, a3:Float
  4. Field b1:Float, b2:Float, b3:Float
  5. Field c1:Float, c2:Float, c3:Float
  6. End Type
  7. Type aiMatrix4x4
  8. Field a1:Float, a2:Float, a3:Float, a4:Float
  9. Field b1:Float, b2:Float, b3:Float, b4:Float
  10. Field c1:Float, c2:Float, c3:Float, c4:Float
  11. Field d1:Float, d2:Float, d3:Float, d4:Float
  12. Field heading:Float
  13. Field attitude:Float
  14. Field bank:Float
  15. Field Tx:Float, Ty:Float, Tz:Float
  16. Field Sx:Float, Sy:Float, Sz:Float
  17. Field Rx:Float, Ry:Float, Rz:Float
  18. Function Create:aiMatrix4x4(p:Float Ptr)
  19. Local m:aiMatrix4x4 = New aiMatrix4x4
  20. Rem
  21. DebugLog "Matrix"
  22. For Local i:Int = 0 To 15
  23. DebugLog i + " " + p[i]
  24. Next
  25. EndRem
  26. m.a1 = p[0]
  27. m.a2 = p[1]
  28. m.a3 = p[2]
  29. m.a4 = p[3]
  30. m.b1 = p[4]
  31. m.b2 = p[5]
  32. m.b3 = p[6]
  33. m.b4 = p[7]
  34. m.c1 = p[8]
  35. m.c2 = p[9]
  36. m.c3 = p[10]
  37. m.c4 = p[11]
  38. m.d1 = p[12]
  39. m.d2 = p[13]
  40. m.d3 = p[14]
  41. m.d4 = p[15]
  42. Return m
  43. End Function
  44. Method Decompose()
  45. _Decompose()
  46. rx = heading
  47. ry = attitude
  48. rz = bank
  49. End Method
  50. Method _Decompose()
  51. Tx = a4
  52. Ty = b4
  53. Tz = c4
  54. Sx = Sqr(a1*a1 + a2*a2 + a3*a3)
  55. Sy = Sqr(b1*b1 + b2*b2 + b3*b3)
  56. Sz = Sqr(c1*c1 + c2*c2 + c3*c3)
  57. Local D:Float = a1 * (b2 * c3 - c2 * b3) - b1 * (a2 * c3 - c2 * a3) + c1 * (a2 * b3 - b2 * a3)
  58. Sx:* Sgn(D)
  59. Sy:* Sgn(D)
  60. Sz:* Sgn(D)
  61. Local rm:aiMatrix3x3 = New aiMatrix3x3
  62. rm.a1 = a1 ; rm.a2 = a2 ; rm.a3 = a3
  63. rm.b1 = b1 ; rm.b2 = b2 ; rm.b3 = b3
  64. rm.c1 = c1 ; rm.c2 = c2 ; rm.c3 = c3
  65. If sx Then
  66. rm.a1:/ sx
  67. rm.a2:/ sx
  68. rm.a3:/ sx
  69. EndIf
  70. If sy Then
  71. rm.b1:/ sy
  72. rm.b2:/ sy
  73. rm.b3:/ sy
  74. EndIf
  75. If sz Then
  76. rm.c1:/ sz
  77. rm.c2:/ sz
  78. rm.c3:/ sz
  79. EndIf
  80. If (b1 > 0.998) ' singularity at north pole
  81. heading = ATan2(rm.a3, rm.c3)
  82. attitude = 90 'Pi/2
  83. bank = 0
  84. 'DebugLog "' singularity at north pole **"
  85. Return
  86. EndIf
  87. If (b1 < -0.998) ' singularity at south pole
  88. heading = ATan2(rm.a3, rm.c3)
  89. attitude = -90 '-Pi/2
  90. bank = 0
  91. 'DebugLog "' singularity at south pole **"
  92. Return
  93. EndIf
  94. heading = ATan2(-rm.c1, rm.a1)
  95. bank = ATan2(-rm.b3, rm.b2)
  96. attitude = ASin(rm.b1)
  97. End Method
  98. Method GetScaleX:Float()
  99. Return Sqr(a1*a1 + a2*a2 + a3*a3)
  100. End Method
  101. Method GetScaleY:Float()
  102. Return Sqr(b1*b1 + b2*b2 + b3*b3)
  103. End Method
  104. Method GetScaleZ:Float()
  105. Return Sqr(c1*c1 + c2*c2 + c3*c3)
  106. End Method
  107. End Type
  108. Type aiMaterial
  109. ?ptr64
  110. Field pMaterial:Long Ptr
  111. ?Not ptr64
  112. Field pMaterial:Int Ptr
  113. ?
  114. Field Properties:aiMaterialProperty[]
  115. Field NumProperties:Int
  116. Field NumAllocated:Int
  117. ' helper functions based on Assimp api
  118. Method GetMaterialName:String()
  119. Return GetMaterialString(AI_MATKEY_NAME)
  120. End Method
  121. Method IsTwoSided:Int()
  122. Local values:Int[] = GetMaterialIntegerArray(AI_MATKEY_TWOSIDED)
  123. If values.length Then Return values[0]
  124. End Method
  125. Method GetAlpha:Float()
  126. Local values:Float[] = GetMaterialFloatArray(AI_MATKEY_OPACITY)
  127. If values.length
  128. Return values[0]
  129. Else
  130. Return 1.0
  131. EndIf
  132. End Method
  133. Method GetShininess:Float()
  134. Local values:Float[] = GetMaterialFloatArray(AI_MATKEY_SHININESS)
  135. If values.length
  136. Return values[0]
  137. Else
  138. Return 1.0
  139. EndIf
  140. End Method
  141. ' diffuse
  142. Method GetDiffuseRed:Float()
  143. Local Colors:Float[] = GetMaterialColor(AI_MATKEY_COLOR_DIFFUSE)
  144. If Colors.length Then Return Colors[0]
  145. End Method
  146. Method GetDiffuseGreen:Float()
  147. Local Colors:Float[] = GetMaterialColor(AI_MATKEY_COLOR_DIFFUSE)
  148. If Colors.length Then Return Colors[1]
  149. End Method
  150. Method GetDiffuseBlue:Float()
  151. Local Colors:Float[] = GetMaterialColor(AI_MATKEY_COLOR_DIFFUSE)
  152. If Colors.length Then Return Colors[2]
  153. End Method
  154. Method GetDiffuseAlpha:Float()
  155. Local Colors:Float[] = GetMaterialColor(AI_MATKEY_COLOR_DIFFUSE)
  156. If Colors.length Then Return Colors[3]
  157. End Method
  158. ' helper functions assumes material properties loaded with scene
  159. Method GetTexture()
  160. End Method
  161. Method GetPropertyNames:String[]()
  162. Local names:String[NumProperties]
  163. For Local id:Int = 0 To NumProperties - 1
  164. names[id] = Properties[id].mKey
  165. DebugLog "Property name: " + Properties[id].mKey
  166. DebugLog "Property type: " + Properties[id].mType
  167. DebugLog "Property Index " + Properties[id].Index
  168. DebugLog "Property length " + Properties[id].DataLength
  169. DebugLog "Property Semantic: " + Properties[id].Semantic
  170. Select Properties[id].mType
  171. Case aiPTI_Float
  172. For Local i:Int = 0 Until (Properties[id].DataLength / 4)
  173. ' DebugLog "FLOAT: " + Properties[i].GetFloatValue(i)
  174. Next
  175. Case aiPTI_String
  176. ' DebugLog "String: " + Properties[i].GetStringValue()
  177. Case aiPTI_Integer
  178. Case aiPTI_Buffer
  179. End Select
  180. Next
  181. Return names
  182. End Method
  183. ' native ai functions
  184. Method GetMaterialString:String(Key:String)
  185. Local s:Byte[MAXLEN + (4 * PAD)]
  186. 'Local kp:Byte Ptr = Key.ToCstring()
  187. Local retVal:Int = aiGetMaterialString(pMaterial, Key, 0, 0, Varptr s[0])
  188. 'MemFree kp
  189. If retVal = AI_SUCCESS
  190. Return String.FromCString(Varptr s[4 * PAD])
  191. 'Else
  192. 'DebugLog "mat. aiGetMaterialString failed with code " + retVal
  193. EndIf
  194. End Method
  195. Method GetMaterialColor:Float[](Key:String)
  196. Local colors:Float[4]
  197. If aiGetMaterialColor(pMaterial, Key, 0, 0, colors) = AI_SUCCESS
  198. Return colors
  199. EndIf
  200. End Method
  201. Method GetMaterialIntegerArray:Int[](Key:String)
  202. Local size:Int = MAXLEN
  203. Local values:Int[size]
  204. If aiGetMaterialIntegerArray(pMaterial, Key, 0, 0, values, Varptr size) = AI_SUCCESS
  205. values = values[..size]
  206. Return values
  207. EndIf
  208. End Method
  209. Method GetMaterialFloatArray:Float[](Key:String)
  210. Local size:Int = MAXLEN
  211. Local values:Float[size]
  212. If aiGetMaterialFloatArray(pMaterial, Key, 0, 0, values, Varptr size) = AI_SUCCESS
  213. values = values[..size]
  214. Return values
  215. EndIf
  216. End Method
  217. Method GetMaterialTexture:String(index:Int = 0)
  218. Local s:Byte[MAXLEN + (4 * PAD)]
  219. Local retval:Int = aiGetMaterialTexture(pMaterial, aiTextureType_DIFFUSE, index, Varptr s[0])
  220. If retVal = AI_SUCCESS
  221. Return String.FromCString(Varptr s[4 * PAD])
  222. Else
  223. DebugLog "mat. GetMaterialTexture failed with code " + retVal
  224. EndIf
  225. End Method
  226. End Type
  227. ' used in aiMaterial
  228. Type aiMaterialProperty
  229. Field mKey:String
  230. Field Semantic:Int
  231. Field Index:Int
  232. Field DataLength:Int
  233. Field mType:Int
  234. Field mData:Byte Ptr
  235. Function Create:aiMaterialProperty(pProps:Byte Ptr)
  236. Local mp:aiMaterialProperty = New aiMaterialProperty
  237. mp.mKey = String.FromCString(pProps + (4 * PAD))
  238. Local pVars:Int Ptr = Int Ptr(pProps + MAXLEN + (4 * PAD))
  239. mp.Semantic = pVars[0]
  240. mp.Index = pVars[1]
  241. mp.DataLength = pVars[2]
  242. mp.mType = pVars[3]
  243. mp.mData = Byte Ptr pVars[4]
  244. 'DebugLog "mp.Semantic="+mp.Semantic
  245. 'DebugLog "mp.Index ="+mp.Index
  246. 'DebugLog "mp.DataLength ="+mp.DataLength
  247. 'DebugLog "mp.mType ="+mp.mType
  248. 'DebugLog "mp.mData ="+mp.mData
  249. Return mp
  250. End Function
  251. Method GetFloatValue:Float(index:Int)
  252. Return Float Ptr(mData)[index]
  253. End Method
  254. Method GetStringValue:String()
  255. Return String.FromCString(mData + (4 * PAD))
  256. End Method
  257. Method GetIntegerValue:Int (index:Int)
  258. Return Int Ptr(mData)[index]
  259. End Method
  260. Method GetByteValue:Byte(index:Int)
  261. Return mData[index]
  262. End Method
  263. End Type
  264. Rem
  265. bbdoc: A mesh represents a geometry or model with a single material.
  266. about: It usually consists of a number of vertices and a series of primitives/faces
  267. referencing the vertices. In addition there might be a series of bones, each
  268. of them addressing a number of vertices with a certain weight. Vertex data
  269. is presented in channels with each channel containing a single per-vertex
  270. information such as a set of texture coords or a normal vector.
  271. If a data pointer is non-null, the corresponding data stream is present.
  272. From C++ programs you can also use the comfort functions Has*() to
  273. test for the presence of various data streams.
  274. <br><br>
  275. A mesh uses only a single material which is referenced by a material ID.
  276. @note The mPositions member is usually not optional. However, vertex positions
  277. *could* be missing if the AI_SCENE_FLAGS_INCOMPLETE flag is set in aiScene::mFlags.
  278. */
  279. EndRem
  280. Type aiMesh
  281. Field PrimitiveTypes:Int
  282. Field NumVertices:Int
  283. Field NumFaces:Int
  284. Field pVertices:Float Ptr
  285. Field pNormals:Float Ptr
  286. Field pTangents:Byte Ptr
  287. Field pBitangents:Byte Ptr
  288. Field pColors:Byte Ptr[AI_MAX_NUMBER_OF_COLOR_SETS * PAD]
  289. Field pTextureCoords:Byte Ptr[AI_MAX_NUMBER_OF_TEXTURECOORDS * PAD]
  290. Field NumUVComponents:Int[AI_MAX_NUMBER_OF_TEXTURECOORDS]
  291. ?ptr64
  292. Field pFaces:Long Ptr
  293. ?Not ptr64
  294. Field pFaces:Int Ptr
  295. ?
  296. Field NumBones:Int
  297. Field pBones:Byte Ptr
  298. Field MaterialIndex:Int
  299. ' vertices
  300. Method VertexX:Float(index:Int)
  301. Return pVertices[index * 3]
  302. End Method
  303. Method VertexY:Float(index:Int)
  304. Return pVertices[(index * 3) + 1]
  305. End Method
  306. Method VertexZ:Float(index:Int)
  307. Return pVertices[(index * 3) + 2]
  308. End Method
  309. ' normals
  310. Method VertexNX:Float(index:Int)
  311. Return pNormals[index * 3]
  312. End Method
  313. Method VertexNY:Float(index:Int)
  314. Return pNormals[(index * 3) + 1]
  315. End Method
  316. Method VertexNZ:Float(index:Int)
  317. Return pNormals[(index * 3) + 2]
  318. End Method
  319. ' texcoords - funky :-)
  320. Method VertexU:Float(index:Int, coord_set:Int = 0)
  321. Return Float Ptr(pTextureCoords[coord_set])[index * 3]
  322. End Method
  323. Method VertexV:Float(index:Int, coord_set:Int = 0)
  324. Return Float Ptr(pTextureCoords[coord_set])[(index * 3) + 1]
  325. End Method
  326. Method VertexW:Float(index:Int, coord_set:Int = 0)
  327. Return Float Ptr(pTextureCoords[coord_set])[(index * 3) + 2]
  328. End Method
  329. Method VertexRed:Float(index:Int, color_set:Int = 0)
  330. Return Float Ptr(pColors[color_set])[index * 4]
  331. End Method
  332. Method VertexGreen:Float(index:Int, color_set:Int = 0)
  333. Return Float Ptr(pColors[color_set])[(index * 4) + 1]
  334. End Method
  335. Method VertexBlue:Float(index:Int, color_set:Int = 0)
  336. Return Float Ptr(pColors[color_set])[(index * 4) + 2]
  337. End Method
  338. Method VertexAlpha:Float(index:Int, color_set:Int = 0)
  339. Return Float Ptr(pColors[color_set])[(index * 4) + 3]
  340. End Method
  341. Method HasPositions:Int()
  342. If NumVertices <= 0 Then Return False
  343. If pVertices <> Null Then Return True
  344. End Method
  345. Method HasFaces:Int()
  346. If NumVertices <= 0 Then Return False
  347. If pFaces <> Null Then Return True
  348. End Method
  349. Method HasNormals:Int()
  350. If NumVertices <= 0 Then Return False
  351. If pNormals <> Null Then Return True
  352. End Method
  353. Method HasTangentsAndBitangents:Int()
  354. If NumVertices <= 0 Then Return False
  355. If pTangents = Null Then Return False
  356. If pBitangents <> Null Then Return True
  357. End Method
  358. Method HasTextureCoords:Int(coord_set:Int)
  359. If coord_set >= AI_MAX_NUMBER_OF_TEXTURECOORDS Then Return False
  360. If pTextureCoords[coord_set] <> Null Then Return True
  361. End Method
  362. Method HasVertexColors:Int(color_set:Int)
  363. If NumVertices <= 0 Then Return False
  364. If color_set >= AI_MAX_NUMBER_OF_COLOR_SETS Then Return False
  365. If pColors[color_set] <> Null Then Return True
  366. End Method
  367. Method TriangleVertex:Int(index:Int, corner:Int)
  368. Local faceIndexes:Int Ptr = Int Ptr pFaces[(index * 2) + 1]
  369. Return faceIndexes[corner]
  370. End Method
  371. Method GetTriangularFaces:Int[,]()
  372. Local faces:Int[NumFaces, 3]
  373. Local index:Int
  374. For Local count:Int = 0 To NumFaces - 1
  375. Local faceCount:Int = pFaces[index]
  376. Local faceIndexes:Int Ptr = Int Ptr pFaces[index + 1]
  377. ' TODO for nontriangular faces: faceCount could be other than 3
  378. For Local n:Int = 0 To 2
  379. faces[count, n] = faceIndexes[n]
  380. Next
  381. index:+ 2
  382. Next
  383. Return faces
  384. End Method
  385. End Type
  386. ' used in aiScene
  387. Type aiNode
  388. Field pointer:Byte Ptr
  389. Field name:String
  390. Field transformation:aiMatrix4x4
  391. Field NumChildren:Int
  392. Field Children:aiNode[]
  393. Field NumMeshes:Int
  394. Field MeshIndexes:Int[]
  395. Field Parent:aiNode
  396. Function Create:aiNode(pointer:Byte Ptr, parent:aiNode = Null)
  397. Local node:aiNode = New aiNode
  398. node.Parent = parent
  399. node.pointer = pointer
  400. node.name = String.FromCString(pointer + (4 * PAD))
  401. DebugLog "Nodename " + node.name
  402. node.transformation = aiMatrix4x4.Create(Float Ptr (Byte Ptr pointer + MAXLEN + (4 * PAD)))
  403. ?ptr64
  404. Local pBase:Long Ptr = Long Ptr(Byte Ptr pointer + MAXLEN + (4 * PAD) + (16 * 4))
  405. ?Not ptr64
  406. Local pBase:Int Ptr = Int Ptr(Byte Ptr pointer + MAXLEN + (4 * PAD) + (16 * 4))
  407. ?
  408. 'For Local i:Int = 0 To 11
  409. ' DebugLog "pBase " + i + "=" + pBase[i]
  410. 'Next
  411. 'Rem
  412. node.NumMeshes = pBase[3] ' int 3/6
  413. DebugLog "Mesh count for this node: " + node.NumMeshes
  414. ?ptr64
  415. Local pMeshIndexArray:Long Ptr = Long Ptr pBase[4] ' ptr 4/8
  416. ?Not ptr64
  417. Local pMeshIndexArray:Int Ptr = Int Ptr pBase[4] ' ptr 4/8
  418. ?
  419. node.MeshIndexes = node.MeshIndexes[..node.NumMeshes]
  420. For Local id:Int = 0 To node.NumMeshes - 1
  421. node.MeshIndexes[id] = pMeshIndexArray[id]
  422. Next
  423. 'End Rem
  424. ' get child nodes
  425. node.NumChildren = pBase[1] ' int 1/2
  426. DebugLog "node.NumChildren=" + node.NumChildren
  427. If node.NumChildren
  428. ?ptr64
  429. Local pChildArray:Long Ptr = Long Ptr pBase[2] ' ptr 2/4
  430. ?Not ptr64
  431. Local pChildArray:Int Ptr = Int Ptr pBase[2] ' ptr 2/4
  432. ?
  433. 'For Local i:Int = 0 To 11
  434. ' DebugLog "pChildArray " + i + "=" + pChildArray[i]
  435. 'Next
  436. node.Children = node.Children[..node.NumChildren]
  437. For Local id:Int = 0 To node.NumChildren - 1
  438. node.Children[id] = aiNode.Create(Byte Ptr pChildArray[id], node)
  439. Next
  440. EndIf
  441. Return node
  442. End Function
  443. End Type
  444. Type aiScene
  445. ?ptr64
  446. Field pointer:Long Ptr
  447. ?Not ptr64
  448. Field pointer:Int Ptr
  449. ?
  450. Field flags:Int
  451. Field rootNode:aiNode
  452. Field numMeshes:Int
  453. Field meshes:aiMesh[]
  454. Field NumMaterials:Int
  455. Field materials:aiMaterial[]
  456. Method ImportFile:Int Ptr(fileName:String, readflags:Int)
  457. If (Left(filename, 5) = "zip::") ' load zip mesh (ram stream by Pertubatio)
  458. Local fileStream:TStream = CreateBufferedStream(fileName)
  459. Local bufLen:Int = StreamSize(fileStream)
  460. Local buffer:Byte Ptr = MemAlloc(bufLen)
  461. Local ramStream:TRamStream = CreateRamStream(buffer, bufLen, True, True)
  462. CopyStream(fileStream, ramStream)
  463. pointer = aiImportFileFromMemory(buffer, bufLen, readFlags, Right(fileName, 3))
  464. MemFree(buffer)
  465. CloseStream(fileStream)
  466. CloseStream(ramStream)
  467. ElseIf (Left(filename, 8) = "incbin::") ' load incbin mesh by Happy Cat - Jan 2013
  468. Local binName:String = Mid(filename, 9)
  469. Local buffer:Byte Ptr = IncbinPtr(binName)
  470. Local bufLen:Int = IncbinLen(binName)
  471. If (buffer = Null Or bufLen = 0) Then Return Null
  472. pointer = aiImportFileFromMemory(buffer, bufLen, readFlags, Right(fileName, 3))
  473. Else
  474. ?win32
  475. ' TODO this is a fix for wavefront mtl not being found
  476. ' does this mess up UNC paths or something else?
  477. filename = filename.Replace("/", "\")
  478. ?
  479. pointer = aiImportFile(filename, readflags)
  480. EndIf
  481. If pointer <> Null
  482. flags = pointer[0]
  483. 'For Local n:Int = 0 To 23
  484. ' DebugLog "pointer " + n + "=" + pointer[n]
  485. 'Next
  486. rootNode = aiNode.Create(Byte Ptr pointer[1]) ' 1/2
  487. numMeshes = pointer[2] ' 2/4
  488. ?ptr64
  489. Local pMeshArray:Long Ptr = Long Ptr pointer[3] ' 3/6
  490. ?Not ptr64
  491. Local pMeshArray:Int Ptr = Int Ptr pointer[3] ' 3/6
  492. ?
  493. meshes = meshes[..numMeshes]
  494. DebugLog "flags = " + flags
  495. DebugLog "rootNode.pointer = " + rootNode.pointer
  496. DebugLog "numMeshes = " + numMeshes
  497. DebugLog "pMeshArray = " + pMeshArray
  498. For Local id:Int = 0 To numMeshes - 1
  499. Local iMesh:Int Ptr = Int Ptr pMeshArray[id]
  500. ?ptr64
  501. Local pMesh:Long Ptr = Long Ptr pMeshArray[id]
  502. ?Not ptr64
  503. Local pMesh:Int Ptr = Int Ptr pMeshArray[id]
  504. ?
  505. 'For Local n:Int = 0 To 54
  506. ' DebugLog "iMesh " + n + "=" + iMesh[n] + " pMesh = " + pMesh[n]
  507. 'Next
  508. meshes[id] = New aiMesh
  509. meshes[id].PrimitiveTypes = iMesh[0]
  510. meshes[id].NumVertices = iMesh[1]
  511. meshes[id].NumFaces = iMesh[2]
  512. meshes[id].pVertices = Float Ptr pMesh[2 + ONE32] ' 3/4 - calculate 32/64 offsets
  513. meshes[id].pNormals = Float Ptr pMesh[3 + ONE32] ' 4/6
  514. meshes[id].pTangents = Byte Ptr pMesh[4 + ONE32] ' 5/8
  515. meshes[id].pBitangents = Byte Ptr pMesh[5 + ONE32] ' 6/10 - [(5 * PAD) + ONE32]
  516. DebugLog "meshes[" + id + "].PrimitiveTypes = " + meshes[id].PrimitiveTypes
  517. DebugLog "meshes[" + id + "].NumVertices = " + meshes[id].NumVertices
  518. DebugLog "meshes[" + id + "].NumFaces = " + meshes[id].NumFaces
  519. DebugLog "meshes[" + id + "].pVertices = " + meshes[id].pVertices
  520. DebugLog "meshes[" + id + "].pNormals = " + meshes[id].pNormals
  521. 'DebugLog "meshes[" + id + "].pTangents = " + meshes[id].pTangents
  522. 'DebugLog "meshes[" + id + "].pBitangents = " + meshes[id].pBitangents
  523. Local iMeshPointerOffset:Int = (6 * PAD) + ONE32 ' 7/12
  524. Local pMeshPointerOffset:Int = 6 + ONE32 ' 7/12
  525. For Local n:Int = 0 To AI_MAX_NUMBER_OF_COLOR_SETS - 1
  526. meshes[id].pColors[n] = Byte Ptr iMesh[iMeshPointerOffset + n] ' ptr arr - twice the size in 64-bit
  527. 'DebugLog "meshes[" + id + "].pColors[n] = " + meshes[id].pColors[n]
  528. Next
  529. iMeshPointerOffset:+ (AI_MAX_NUMBER_OF_COLOR_SETS * PAD) ' 15/28
  530. pMeshPointerOffset:+ AI_MAX_NUMBER_OF_COLOR_SETS ' 15/28
  531. For Local n:Int = 0 To AI_MAX_NUMBER_OF_TEXTURECOORDS - 1
  532. meshes[id].pTextureCoords[n] = Byte Ptr pMesh[pMeshPointerOffset + n] ' ptr arr
  533. 'DebugLog "meshes[" + id + "].pTextureCoords[n] = " + meshes[id].pTextureCoords[n]
  534. Next
  535. iMeshPointerOffset:+ (AI_MAX_NUMBER_OF_TEXTURECOORDS * PAD) ' 23/44
  536. pMeshPointerOffset:+ AI_MAX_NUMBER_OF_TEXTURECOORDS ' 23/44
  537. For Local n:Int = 0 To AI_MAX_NUMBER_OF_TEXTURECOORDS - 1
  538. meshes[id].NumUVComponents[n] = iMesh[iMeshPointerOffset + n] ' int arr - same size as 32-bit
  539. 'DebugLog "meshes[" + id + "].NumUVComponents[n] = " + meshes[id].NumUVComponents[n]
  540. Next
  541. iMeshPointerOffset:+ AI_MAX_NUMBER_OF_TEXTURECOORDS ' 31/52
  542. pMeshPointerOffset:+ (AI_MAX_NUMBER_OF_TEXTURECOORDS / PAD) ' 23/44
  543. ?ptr64
  544. meshes[id].pFaces = Long Ptr pMesh[pMeshPointerOffset]
  545. ?Not ptr64
  546. meshes[id].pFaces = Int Ptr pMesh[pMeshPointerOffset]
  547. ?
  548. meshes[id].NumBones = iMesh[iMeshPointerOffset + (1 * PAD)] ' 32/54
  549. meshes[id].pBones = Byte Ptr pMesh[pMeshPointerOffset + 2] ' 33/55
  550. meshes[id].MaterialIndex = iMesh[iMeshPointerOffset + (3 * PAD)] ' 34/57
  551. 'For Local n:Int = 0 To meshes[id].NumFaces - 1
  552. ' DebugLog "meshes[id].pFaces " + n + "="+meshes[id].pFaces[n]
  553. 'Next
  554. DebugLog "meshes[" + id + "].pFaces = " + meshes[id].pFaces
  555. DebugLog "meshes[" + id + "].NumBones = " + meshes[id].NumBones
  556. DebugLog "meshes[" + id + "].pBones = " + meshes[id].pBones
  557. DebugLog "meshes[" + id + "].MaterialIndex = " + meshes[id].MaterialIndex
  558. Next
  559. NumMaterials = pointer[4] ' 4/8
  560. ?ptr64
  561. Local pMaterialArray:Long Ptr = Long Ptr pointer[5] ' 5/10
  562. ?Not ptr64
  563. Local pMaterialArray:Int Ptr = Int Ptr pointer[5] ' 5/10
  564. ?
  565. materials = materials[..NumMaterials]
  566. DebugLog "NumMaterials = " + NumMaterials
  567. DebugLog "pMaterialArray = " + pMaterialArray
  568. For Local id:Int = 0 To NumMaterials - 1
  569. DebugLog "Material found"
  570. materials[id] = New aiMaterial
  571. ?ptr64
  572. materials[id].pMaterial = Long Ptr pMaterialArray[id]
  573. ?Not ptr64
  574. materials[id].pMaterial = Int Ptr pMaterialArray[id]
  575. ?
  576. materials[id].NumProperties = materials[id].pMaterial[1]
  577. materials[id].NumAllocated = materials[id].pMaterial[2]
  578. 'Rem
  579. ' loading properties is not needed, but I do it for now to make a list of loaded properties
  580. ' redim
  581. materials[id].Properties = materials[id].Properties[..materials[id].pMaterial[1]]
  582. ?ptr64
  583. Local pMaterialPropertyArray:Long Ptr = Long Ptr materials[id].pMaterial[0]
  584. ?Not ptr64
  585. Local pMaterialPropertyArray:Int Ptr = Int Ptr materials[id].pMaterial[0]
  586. ?
  587. For Local pid:Int = 0 To materials[id].NumProperties - 1
  588. DebugLog "Materialproperty found"
  589. materials[id].Properties[pid] = aiMaterialProperty.Create(Byte Ptr pMaterialPropertyArray[pid])
  590. Next
  591. 'EndRem
  592. Next
  593. EndIf
  594. Return pointer
  595. End Method
  596. Method ReleaseImport()
  597. If pointer <> Null
  598. aiReleaseImport(pointer)
  599. EndIf
  600. pointer = Null
  601. rootNode = Null
  602. meshes = Null
  603. numMeshes = 0
  604. flags = 0
  605. End Method
  606. End Type