@onerjs/loaders 8.53.5 → 8.53.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (517) hide show
  1. package/BVH/bvhFileLoader.d.ts +4 -67
  2. package/BVH/bvhFileLoader.js +6 -130
  3. package/BVH/bvhFileLoader.js.map +1 -1
  4. package/BVH/bvhFileLoader.pure.d.ts +75 -0
  5. package/BVH/bvhFileLoader.pure.js +154 -0
  6. package/BVH/bvhFileLoader.pure.js.map +1 -0
  7. package/BVH/bvhFileLoader.types.d.ts +11 -0
  8. package/BVH/bvhFileLoader.types.js +2 -0
  9. package/BVH/bvhFileLoader.types.js.map +1 -0
  10. package/BVH/pure.d.ts +3 -0
  11. package/BVH/pure.js +5 -0
  12. package/BVH/pure.js.map +1 -0
  13. package/FBX/fbxFileLoader.d.ts +4 -192
  14. package/FBX/fbxFileLoader.js +6 -2437
  15. package/FBX/fbxFileLoader.js.map +1 -1
  16. package/FBX/fbxFileLoader.pure.d.ts +190 -0
  17. package/FBX/fbxFileLoader.pure.js +2451 -0
  18. package/FBX/fbxFileLoader.pure.js.map +1 -0
  19. package/FBX/fbxFileLoader.types.d.ts +11 -0
  20. package/FBX/fbxFileLoader.types.js +2 -0
  21. package/FBX/fbxFileLoader.types.js.map +1 -0
  22. package/FBX/pure.d.ts +3 -0
  23. package/FBX/pure.js +4 -0
  24. package/FBX/pure.js.map +1 -0
  25. package/OBJ/objFileLoader.d.ts +4 -134
  26. package/OBJ/objFileLoader.js +6 -315
  27. package/OBJ/objFileLoader.js.map +1 -1
  28. package/OBJ/objFileLoader.pure.d.ts +132 -0
  29. package/OBJ/objFileLoader.pure.js +329 -0
  30. package/OBJ/objFileLoader.pure.js.map +1 -0
  31. package/OBJ/objFileLoader.types.d.ts +11 -0
  32. package/OBJ/objFileLoader.types.js +2 -0
  33. package/OBJ/objFileLoader.types.js.map +1 -0
  34. package/OBJ/pure.d.ts +5 -0
  35. package/OBJ/pure.js +6 -0
  36. package/OBJ/pure.js.map +1 -0
  37. package/OBJ/solidParser.js +4 -3
  38. package/OBJ/solidParser.js.map +1 -1
  39. package/SPLAT/gaussianSplattingBlockAllocator.d.ts +137 -0
  40. package/SPLAT/gaussianSplattingBlockAllocator.js +555 -0
  41. package/SPLAT/gaussianSplattingBlockAllocator.js.map +1 -0
  42. package/SPLAT/gaussianSplattingDownloadManager.d.ts +109 -0
  43. package/SPLAT/gaussianSplattingDownloadManager.js +241 -0
  44. package/SPLAT/gaussianSplattingDownloadManager.js.map +1 -0
  45. package/SPLAT/gaussianSplattingResidencyController.d.ts +133 -0
  46. package/SPLAT/gaussianSplattingResidencyController.js +222 -0
  47. package/SPLAT/gaussianSplattingResidencyController.js.map +1 -0
  48. package/SPLAT/gaussianSplattingStream.d.ts +522 -0
  49. package/SPLAT/gaussianSplattingStream.js +1530 -0
  50. package/SPLAT/gaussianSplattingStream.js.map +1 -0
  51. package/SPLAT/gaussianSplattingWorkBuffer.d.ts +107 -0
  52. package/SPLAT/gaussianSplattingWorkBuffer.js +361 -0
  53. package/SPLAT/gaussianSplattingWorkBuffer.js.map +1 -0
  54. package/SPLAT/gaussianSplattingWorkBufferShaders.d.ts +40 -0
  55. package/SPLAT/gaussianSplattingWorkBufferShaders.js +337 -0
  56. package/SPLAT/gaussianSplattingWorkBufferShaders.js.map +1 -0
  57. package/SPLAT/index.d.ts +1 -0
  58. package/SPLAT/index.js +1 -0
  59. package/SPLAT/index.js.map +1 -1
  60. package/SPLAT/pure.d.ts +5 -0
  61. package/SPLAT/pure.js +7 -0
  62. package/SPLAT/pure.js.map +1 -0
  63. package/SPLAT/sog.d.ts +2 -93
  64. package/SPLAT/sog.js +4 -418
  65. package/SPLAT/sog.js.map +1 -1
  66. package/SPLAT/sog.pure.d.ts +102 -0
  67. package/SPLAT/sog.pure.js +514 -0
  68. package/SPLAT/sog.pure.js.map +1 -0
  69. package/SPLAT/splatFileLoader.d.ts +5 -98
  70. package/SPLAT/splatFileLoader.js +9 -587
  71. package/SPLAT/splatFileLoader.js.map +1 -1
  72. package/SPLAT/splatFileLoader.pure.d.ts +104 -0
  73. package/SPLAT/splatFileLoader.pure.js +650 -0
  74. package/SPLAT/splatFileLoader.pure.js.map +1 -0
  75. package/SPLAT/splatFileLoader.types.d.ts +11 -0
  76. package/SPLAT/splatFileLoader.types.js +2 -0
  77. package/SPLAT/splatFileLoader.types.js.map +1 -0
  78. package/STL/pure.d.ts +2 -0
  79. package/STL/pure.js +3 -0
  80. package/STL/pure.js.map +1 -0
  81. package/STL/stlFileLoader.d.ts +5 -76
  82. package/STL/stlFileLoader.js +7 -236
  83. package/STL/stlFileLoader.js.map +1 -1
  84. package/STL/stlFileLoader.pure.d.ts +73 -0
  85. package/STL/stlFileLoader.pure.js +249 -0
  86. package/STL/stlFileLoader.pure.js.map +1 -0
  87. package/STL/stlFileLoader.types.d.ts +10 -0
  88. package/STL/stlFileLoader.types.js +2 -0
  89. package/STL/stlFileLoader.types.js.map +1 -0
  90. package/glTF/1.0/pure.d.ts +3 -0
  91. package/glTF/1.0/pure.js +4 -0
  92. package/glTF/1.0/pure.js.map +1 -0
  93. package/glTF/2.0/Extensions/EXT_lights_area.d.ts +4 -39
  94. package/glTF/2.0/Extensions/EXT_lights_area.js +6 -91
  95. package/glTF/2.0/Extensions/EXT_lights_area.js.map +1 -1
  96. package/glTF/2.0/Extensions/EXT_lights_area.pure.d.ts +38 -0
  97. package/glTF/2.0/Extensions/EXT_lights_area.pure.js +106 -0
  98. package/glTF/2.0/Extensions/EXT_lights_area.pure.js.map +1 -0
  99. package/glTF/2.0/Extensions/EXT_lights_area.types.d.ts +9 -0
  100. package/glTF/2.0/Extensions/EXT_lights_area.types.js +2 -0
  101. package/glTF/2.0/Extensions/EXT_lights_area.types.js.map +1 -0
  102. package/glTF/2.0/Extensions/EXT_lights_ies.d.ts +4 -39
  103. package/glTF/2.0/Extensions/EXT_lights_ies.js +6 -81
  104. package/glTF/2.0/Extensions/EXT_lights_ies.js.map +1 -1
  105. package/glTF/2.0/Extensions/EXT_lights_ies.pure.d.ts +38 -0
  106. package/glTF/2.0/Extensions/EXT_lights_ies.pure.js +96 -0
  107. package/glTF/2.0/Extensions/EXT_lights_ies.pure.js.map +1 -0
  108. package/glTF/2.0/Extensions/EXT_lights_ies.types.d.ts +9 -0
  109. package/glTF/2.0/Extensions/EXT_lights_ies.types.js +2 -0
  110. package/glTF/2.0/Extensions/EXT_lights_ies.types.js.map +1 -0
  111. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +4 -46
  112. package/glTF/2.0/Extensions/EXT_lights_image_based.js +6 -113
  113. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  114. package/glTF/2.0/Extensions/EXT_lights_image_based.pure.d.ts +37 -0
  115. package/glTF/2.0/Extensions/EXT_lights_image_based.pure.js +128 -0
  116. package/glTF/2.0/Extensions/EXT_lights_image_based.pure.js.map +1 -0
  117. package/glTF/2.0/Extensions/EXT_lights_image_based.types.d.ts +17 -0
  118. package/glTF/2.0/Extensions/EXT_lights_image_based.types.js +2 -0
  119. package/glTF/2.0/Extensions/EXT_lights_image_based.types.js.map +1 -0
  120. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +5 -37
  121. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +7 -92
  122. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  123. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.d.ts +35 -0
  124. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js +106 -0
  125. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js.map +1 -0
  126. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.types.d.ts +9 -0
  127. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.types.js +2 -0
  128. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.types.js.map +1 -0
  129. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +4 -37
  130. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +6 -48
  131. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  132. package/glTF/2.0/Extensions/EXT_meshopt_compression.pure.d.ts +36 -0
  133. package/glTF/2.0/Extensions/EXT_meshopt_compression.pure.js +63 -0
  134. package/glTF/2.0/Extensions/EXT_meshopt_compression.pure.js.map +1 -0
  135. package/glTF/2.0/Extensions/EXT_meshopt_compression.types.d.ts +9 -0
  136. package/glTF/2.0/Extensions/EXT_meshopt_compression.types.js +2 -0
  137. package/glTF/2.0/Extensions/EXT_meshopt_compression.types.js.map +1 -0
  138. package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +4 -32
  139. package/glTF/2.0/Extensions/EXT_texture_avif.js +6 -36
  140. package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -1
  141. package/glTF/2.0/Extensions/EXT_texture_avif.pure.d.ts +31 -0
  142. package/glTF/2.0/Extensions/EXT_texture_avif.pure.js +51 -0
  143. package/glTF/2.0/Extensions/EXT_texture_avif.pure.js.map +1 -0
  144. package/glTF/2.0/Extensions/EXT_texture_avif.types.d.ts +9 -0
  145. package/glTF/2.0/Extensions/EXT_texture_avif.types.js +2 -0
  146. package/glTF/2.0/Extensions/EXT_texture_avif.types.js.map +1 -0
  147. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +4 -31
  148. package/glTF/2.0/Extensions/EXT_texture_webp.js +6 -35
  149. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  150. package/glTF/2.0/Extensions/EXT_texture_webp.pure.d.ts +30 -0
  151. package/glTF/2.0/Extensions/EXT_texture_webp.pure.js +50 -0
  152. package/glTF/2.0/Extensions/EXT_texture_webp.pure.js.map +1 -0
  153. package/glTF/2.0/Extensions/EXT_texture_webp.types.d.ts +9 -0
  154. package/glTF/2.0/Extensions/EXT_texture_webp.types.js +2 -0
  155. package/glTF/2.0/Extensions/EXT_texture_webp.types.js.map +1 -0
  156. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +4 -51
  157. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +6 -71
  158. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  159. package/glTF/2.0/Extensions/ExtrasAsMetadata.pure.d.ts +50 -0
  160. package/glTF/2.0/Extensions/ExtrasAsMetadata.pure.js +85 -0
  161. package/glTF/2.0/Extensions/ExtrasAsMetadata.pure.js.map +1 -0
  162. package/glTF/2.0/Extensions/ExtrasAsMetadata.types.d.ts +9 -0
  163. package/glTF/2.0/Extensions/ExtrasAsMetadata.types.js +2 -0
  164. package/glTF/2.0/Extensions/ExtrasAsMetadata.types.js.map +1 -0
  165. package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +5 -45
  166. package/glTF/2.0/Extensions/KHR_animation_pointer.js +7 -75
  167. package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
  168. package/glTF/2.0/Extensions/KHR_animation_pointer.pure.d.ts +43 -0
  169. package/glTF/2.0/Extensions/KHR_animation_pointer.pure.js +89 -0
  170. package/glTF/2.0/Extensions/KHR_animation_pointer.pure.js.map +1 -0
  171. package/glTF/2.0/Extensions/KHR_animation_pointer.types.d.ts +9 -0
  172. package/glTF/2.0/Extensions/KHR_animation_pointer.types.js +2 -0
  173. package/glTF/2.0/Extensions/KHR_animation_pointer.types.js.map +1 -0
  174. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +4 -45
  175. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +6 -90
  176. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  177. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.d.ts +44 -0
  178. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js +105 -0
  179. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js.map +1 -0
  180. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.types.d.ts +9 -0
  181. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.types.js +2 -0
  182. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.types.js.map +1 -0
  183. package/glTF/2.0/Extensions/KHR_gaussian_splatting.d.ts +6 -0
  184. package/glTF/2.0/Extensions/KHR_gaussian_splatting.js +9 -0
  185. package/glTF/2.0/Extensions/KHR_gaussian_splatting.js.map +1 -0
  186. package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.d.ts +35 -0
  187. package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.js +195 -0
  188. package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.js.map +1 -0
  189. package/glTF/2.0/Extensions/KHR_gaussian_splatting.types.d.ts +9 -0
  190. package/glTF/2.0/Extensions/KHR_gaussian_splatting.types.js +2 -0
  191. package/glTF/2.0/Extensions/KHR_gaussian_splatting.types.js.map +1 -0
  192. package/glTF/2.0/Extensions/KHR_interactivity/pure.d.ts +4 -0
  193. package/glTF/2.0/Extensions/KHR_interactivity/pure.js +5 -0
  194. package/glTF/2.0/Extensions/KHR_interactivity/pure.js.map +1 -0
  195. package/glTF/2.0/Extensions/KHR_interactivity.d.ts +4 -36
  196. package/glTF/2.0/Extensions/KHR_interactivity.js +6 -148
  197. package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -1
  198. package/glTF/2.0/Extensions/KHR_interactivity.pure.d.ts +35 -0
  199. package/glTF/2.0/Extensions/KHR_interactivity.pure.js +163 -0
  200. package/glTF/2.0/Extensions/KHR_interactivity.pure.js.map +1 -0
  201. package/glTF/2.0/Extensions/KHR_interactivity.types.d.ts +9 -0
  202. package/glTF/2.0/Extensions/KHR_interactivity.types.js +2 -0
  203. package/glTF/2.0/Extensions/KHR_interactivity.types.js.map +1 -0
  204. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +4 -39
  205. package/glTF/2.0/Extensions/KHR_lights_punctual.js +6 -89
  206. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  207. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.d.ts +38 -0
  208. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js +104 -0
  209. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js.map +1 -0
  210. package/glTF/2.0/Extensions/KHR_lights_punctual.types.d.ts +9 -0
  211. package/glTF/2.0/Extensions/KHR_lights_punctual.types.js +2 -0
  212. package/glTF/2.0/Extensions/KHR_lights_punctual.types.js.map +1 -0
  213. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +4 -40
  214. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +6 -63
  215. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  216. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.d.ts +39 -0
  217. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js +78 -0
  218. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js.map +1 -0
  219. package/glTF/2.0/Extensions/KHR_materials_anisotropy.types.d.ts +9 -0
  220. package/glTF/2.0/Extensions/KHR_materials_anisotropy.types.js +2 -0
  221. package/glTF/2.0/Extensions/KHR_materials_anisotropy.types.js.map +1 -0
  222. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +4 -41
  223. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +6 -77
  224. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  225. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.d.ts +40 -0
  226. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js +92 -0
  227. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js.map +1 -0
  228. package/glTF/2.0/Extensions/KHR_materials_clearcoat.types.d.ts +9 -0
  229. package/glTF/2.0/Extensions/KHR_materials_clearcoat.types.js +2 -0
  230. package/glTF/2.0/Extensions/KHR_materials_clearcoat.types.js.map +1 -0
  231. package/glTF/2.0/Extensions/KHR_materials_coat.d.ts +4 -47
  232. package/glTF/2.0/Extensions/KHR_materials_coat.js +6 -117
  233. package/glTF/2.0/Extensions/KHR_materials_coat.js.map +1 -1
  234. package/glTF/2.0/Extensions/KHR_materials_coat.pure.d.ts +46 -0
  235. package/glTF/2.0/Extensions/KHR_materials_coat.pure.js +132 -0
  236. package/glTF/2.0/Extensions/KHR_materials_coat.pure.js.map +1 -0
  237. package/glTF/2.0/Extensions/KHR_materials_coat.types.d.ts +9 -0
  238. package/glTF/2.0/Extensions/KHR_materials_coat.types.js +2 -0
  239. package/glTF/2.0/Extensions/KHR_materials_coat.types.js.map +1 -0
  240. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.d.ts +4 -41
  241. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js +6 -56
  242. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +1 -1
  243. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.d.ts +40 -0
  244. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js +71 -0
  245. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js.map +1 -0
  246. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.types.d.ts +9 -0
  247. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.types.js +2 -0
  248. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.types.js.map +1 -0
  249. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +4 -41
  250. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +6 -71
  251. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  252. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.d.ts +40 -0
  253. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js +86 -0
  254. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js.map +1 -0
  255. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.types.d.ts +9 -0
  256. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.types.js +2 -0
  257. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.types.js.map +1 -0
  258. package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +4 -41
  259. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +6 -54
  260. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
  261. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.d.ts +40 -0
  262. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js +69 -0
  263. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js.map +1 -0
  264. package/glTF/2.0/Extensions/KHR_materials_dispersion.types.d.ts +9 -0
  265. package/glTF/2.0/Extensions/KHR_materials_dispersion.types.js +2 -0
  266. package/glTF/2.0/Extensions/KHR_materials_dispersion.types.js.map +1 -0
  267. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +4 -40
  268. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +6 -45
  269. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  270. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.d.ts +39 -0
  271. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js +60 -0
  272. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js.map +1 -0
  273. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.types.d.ts +9 -0
  274. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.types.js +2 -0
  275. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.types.js.map +1 -0
  276. package/glTF/2.0/Extensions/KHR_materials_fuzz.d.ts +4 -41
  277. package/glTF/2.0/Extensions/KHR_materials_fuzz.js +6 -75
  278. package/glTF/2.0/Extensions/KHR_materials_fuzz.js.map +1 -1
  279. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.d.ts +40 -0
  280. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js +90 -0
  281. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js.map +1 -0
  282. package/glTF/2.0/Extensions/KHR_materials_fuzz.types.d.ts +9 -0
  283. package/glTF/2.0/Extensions/KHR_materials_fuzz.types.js +2 -0
  284. package/glTF/2.0/Extensions/KHR_materials_fuzz.types.js.map +1 -0
  285. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +4 -44
  286. package/glTF/2.0/Extensions/KHR_materials_ior.js +6 -52
  287. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  288. package/glTF/2.0/Extensions/KHR_materials_ior.pure.d.ts +43 -0
  289. package/glTF/2.0/Extensions/KHR_materials_ior.pure.js +67 -0
  290. package/glTF/2.0/Extensions/KHR_materials_ior.pure.js.map +1 -0
  291. package/glTF/2.0/Extensions/KHR_materials_ior.types.d.ts +9 -0
  292. package/glTF/2.0/Extensions/KHR_materials_ior.types.js +2 -0
  293. package/glTF/2.0/Extensions/KHR_materials_ior.types.js.map +1 -0
  294. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +4 -40
  295. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +6 -66
  296. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  297. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.d.ts +39 -0
  298. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js +81 -0
  299. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js.map +1 -0
  300. package/glTF/2.0/Extensions/KHR_materials_iridescence.types.d.ts +9 -0
  301. package/glTF/2.0/Extensions/KHR_materials_iridescence.types.js +2 -0
  302. package/glTF/2.0/Extensions/KHR_materials_iridescence.types.js.map +1 -0
  303. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +4 -40
  304. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +6 -72
  305. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  306. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.pure.d.ts +39 -0
  307. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.pure.js +87 -0
  308. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.pure.js.map +1 -0
  309. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.types.d.ts +9 -0
  310. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.types.js +2 -0
  311. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.types.js.map +1 -0
  312. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +4 -41
  313. package/glTF/2.0/Extensions/KHR_materials_sheen.js +6 -71
  314. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  315. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.d.ts +40 -0
  316. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js +86 -0
  317. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js.map +1 -0
  318. package/glTF/2.0/Extensions/KHR_materials_sheen.types.d.ts +9 -0
  319. package/glTF/2.0/Extensions/KHR_materials_sheen.types.js +2 -0
  320. package/glTF/2.0/Extensions/KHR_materials_sheen.types.js.map +1 -0
  321. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +4 -40
  322. package/glTF/2.0/Extensions/KHR_materials_specular.js +6 -74
  323. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  324. package/glTF/2.0/Extensions/KHR_materials_specular.pure.d.ts +39 -0
  325. package/glTF/2.0/Extensions/KHR_materials_specular.pure.js +89 -0
  326. package/glTF/2.0/Extensions/KHR_materials_specular.pure.js.map +1 -0
  327. package/glTF/2.0/Extensions/KHR_materials_specular.types.d.ts +9 -0
  328. package/glTF/2.0/Extensions/KHR_materials_specular.types.js +2 -0
  329. package/glTF/2.0/Extensions/KHR_materials_specular.types.js.map +1 -0
  330. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +4 -40
  331. package/glTF/2.0/Extensions/KHR_materials_transmission.js +6 -70
  332. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  333. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.d.ts +39 -0
  334. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js +85 -0
  335. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js.map +1 -0
  336. package/glTF/2.0/Extensions/KHR_materials_transmission.types.d.ts +9 -0
  337. package/glTF/2.0/Extensions/KHR_materials_transmission.types.js +2 -0
  338. package/glTF/2.0/Extensions/KHR_materials_transmission.types.js.map +1 -0
  339. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +4 -40
  340. package/glTF/2.0/Extensions/KHR_materials_unlit.js +6 -64
  341. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  342. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.d.ts +39 -0
  343. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js +79 -0
  344. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js.map +1 -0
  345. package/glTF/2.0/Extensions/KHR_materials_unlit.types.d.ts +9 -0
  346. package/glTF/2.0/Extensions/KHR_materials_unlit.types.js +2 -0
  347. package/glTF/2.0/Extensions/KHR_materials_unlit.types.js.map +1 -0
  348. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +4 -110
  349. package/glTF/2.0/Extensions/KHR_materials_variants.js +6 -260
  350. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  351. package/glTF/2.0/Extensions/KHR_materials_variants.pure.d.ts +97 -0
  352. package/glTF/2.0/Extensions/KHR_materials_variants.pure.js +275 -0
  353. package/glTF/2.0/Extensions/KHR_materials_variants.pure.js.map +1 -0
  354. package/glTF/2.0/Extensions/KHR_materials_variants.types.d.ts +29 -0
  355. package/glTF/2.0/Extensions/KHR_materials_variants.types.js +2 -0
  356. package/glTF/2.0/Extensions/KHR_materials_variants.types.js.map +1 -0
  357. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +4 -41
  358. package/glTF/2.0/Extensions/KHR_materials_volume.js +6 -77
  359. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  360. package/glTF/2.0/Extensions/KHR_materials_volume.pure.d.ts +40 -0
  361. package/glTF/2.0/Extensions/KHR_materials_volume.pure.js +92 -0
  362. package/glTF/2.0/Extensions/KHR_materials_volume.pure.js.map +1 -0
  363. package/glTF/2.0/Extensions/KHR_materials_volume.types.d.ts +9 -0
  364. package/glTF/2.0/Extensions/KHR_materials_volume.types.js +2 -0
  365. package/glTF/2.0/Extensions/KHR_materials_volume.types.js.map +1 -0
  366. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.d.ts +4 -43
  367. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js +6 -113
  368. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js.map +1 -1
  369. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.d.ts +42 -0
  370. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js +128 -0
  371. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js.map +1 -0
  372. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.types.d.ts +9 -0
  373. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.types.js +2 -0
  374. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.types.js.map +1 -0
  375. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +4 -27
  376. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +6 -20
  377. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  378. package/glTF/2.0/Extensions/KHR_mesh_quantization.pure.d.ts +26 -0
  379. package/glTF/2.0/Extensions/KHR_mesh_quantization.pure.js +35 -0
  380. package/glTF/2.0/Extensions/KHR_mesh_quantization.pure.js.map +1 -0
  381. package/glTF/2.0/Extensions/KHR_mesh_quantization.types.d.ts +9 -0
  382. package/glTF/2.0/Extensions/KHR_mesh_quantization.types.js +2 -0
  383. package/glTF/2.0/Extensions/KHR_mesh_quantization.types.js.map +1 -0
  384. package/glTF/2.0/Extensions/KHR_node_hoverability.d.ts +4 -29
  385. package/glTF/2.0/Extensions/KHR_node_hoverability.js +6 -187
  386. package/glTF/2.0/Extensions/KHR_node_hoverability.js.map +1 -1
  387. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.d.ts +28 -0
  388. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js +202 -0
  389. package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js.map +1 -0
  390. package/glTF/2.0/Extensions/KHR_node_hoverability.types.d.ts +9 -0
  391. package/glTF/2.0/Extensions/KHR_node_hoverability.types.js +2 -0
  392. package/glTF/2.0/Extensions/KHR_node_hoverability.types.js.map +1 -0
  393. package/glTF/2.0/Extensions/KHR_node_selectability.d.ts +4 -28
  394. package/glTF/2.0/Extensions/KHR_node_selectability.js +6 -121
  395. package/glTF/2.0/Extensions/KHR_node_selectability.js.map +1 -1
  396. package/glTF/2.0/Extensions/KHR_node_selectability.pure.d.ts +27 -0
  397. package/glTF/2.0/Extensions/KHR_node_selectability.pure.js +136 -0
  398. package/glTF/2.0/Extensions/KHR_node_selectability.pure.js.map +1 -0
  399. package/glTF/2.0/Extensions/KHR_node_selectability.types.d.ts +9 -0
  400. package/glTF/2.0/Extensions/KHR_node_selectability.types.js +2 -0
  401. package/glTF/2.0/Extensions/KHR_node_selectability.types.js.map +1 -0
  402. package/glTF/2.0/Extensions/KHR_node_visibility.d.ts +4 -28
  403. package/glTF/2.0/Extensions/KHR_node_visibility.js +6 -64
  404. package/glTF/2.0/Extensions/KHR_node_visibility.js.map +1 -1
  405. package/glTF/2.0/Extensions/KHR_node_visibility.pure.d.ts +27 -0
  406. package/glTF/2.0/Extensions/KHR_node_visibility.pure.js +79 -0
  407. package/glTF/2.0/Extensions/KHR_node_visibility.pure.js.map +1 -0
  408. package/glTF/2.0/Extensions/KHR_node_visibility.types.d.ts +9 -0
  409. package/glTF/2.0/Extensions/KHR_node_visibility.types.js +2 -0
  410. package/glTF/2.0/Extensions/KHR_node_visibility.types.js.map +1 -0
  411. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +4 -31
  412. package/glTF/2.0/Extensions/KHR_texture_basisu.js +6 -35
  413. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  414. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.d.ts +30 -0
  415. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js +50 -0
  416. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js.map +1 -0
  417. package/glTF/2.0/Extensions/KHR_texture_basisu.types.d.ts +9 -0
  418. package/glTF/2.0/Extensions/KHR_texture_basisu.types.js +2 -0
  419. package/glTF/2.0/Extensions/KHR_texture_basisu.types.js.map +1 -0
  420. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +4 -35
  421. package/glTF/2.0/Extensions/KHR_texture_transform.js +6 -56
  422. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  423. package/glTF/2.0/Extensions/KHR_texture_transform.pure.d.ts +34 -0
  424. package/glTF/2.0/Extensions/KHR_texture_transform.pure.js +71 -0
  425. package/glTF/2.0/Extensions/KHR_texture_transform.pure.js.map +1 -0
  426. package/glTF/2.0/Extensions/KHR_texture_transform.types.d.ts +9 -0
  427. package/glTF/2.0/Extensions/KHR_texture_transform.types.js +2 -0
  428. package/glTF/2.0/Extensions/KHR_texture_transform.types.js.map +1 -0
  429. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +4 -37
  430. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +6 -45
  431. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  432. package/glTF/2.0/Extensions/KHR_xmp_json_ld.pure.d.ts +36 -0
  433. package/glTF/2.0/Extensions/KHR_xmp_json_ld.pure.js +60 -0
  434. package/glTF/2.0/Extensions/KHR_xmp_json_ld.pure.js.map +1 -0
  435. package/glTF/2.0/Extensions/KHR_xmp_json_ld.types.d.ts +9 -0
  436. package/glTF/2.0/Extensions/KHR_xmp_json_ld.types.js +2 -0
  437. package/glTF/2.0/Extensions/KHR_xmp_json_ld.types.js.map +1 -0
  438. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +5 -54
  439. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +7 -226
  440. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  441. package/glTF/2.0/Extensions/MSFT_audio_emitter.pure.d.ts +52 -0
  442. package/glTF/2.0/Extensions/MSFT_audio_emitter.pure.js +240 -0
  443. package/glTF/2.0/Extensions/MSFT_audio_emitter.pure.js.map +1 -0
  444. package/glTF/2.0/Extensions/MSFT_audio_emitter.types.d.ts +9 -0
  445. package/glTF/2.0/Extensions/MSFT_audio_emitter.types.js +2 -0
  446. package/glTF/2.0/Extensions/MSFT_audio_emitter.types.js.map +1 -0
  447. package/glTF/2.0/Extensions/MSFT_lod.d.ts +4 -102
  448. package/glTF/2.0/Extensions/MSFT_lod.js +6 -335
  449. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  450. package/glTF/2.0/Extensions/MSFT_lod.pure.d.ts +96 -0
  451. package/glTF/2.0/Extensions/MSFT_lod.pure.js +350 -0
  452. package/glTF/2.0/Extensions/MSFT_lod.pure.js.map +1 -0
  453. package/glTF/2.0/Extensions/MSFT_lod.types.d.ts +14 -0
  454. package/glTF/2.0/Extensions/MSFT_lod.types.js +2 -0
  455. package/glTF/2.0/Extensions/MSFT_lod.types.js.map +1 -0
  456. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +6 -27
  457. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +8 -40
  458. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  459. package/glTF/2.0/Extensions/MSFT_minecraftMesh.pure.d.ts +24 -0
  460. package/glTF/2.0/Extensions/MSFT_minecraftMesh.pure.js +53 -0
  461. package/glTF/2.0/Extensions/MSFT_minecraftMesh.pure.js.map +1 -0
  462. package/glTF/2.0/Extensions/MSFT_minecraftMesh.types.d.ts +9 -0
  463. package/glTF/2.0/Extensions/MSFT_minecraftMesh.types.js +2 -0
  464. package/glTF/2.0/Extensions/MSFT_minecraftMesh.types.js.map +1 -0
  465. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +6 -27
  466. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +8 -38
  467. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  468. package/glTF/2.0/Extensions/MSFT_sRGBFactors.pure.d.ts +24 -0
  469. package/glTF/2.0/Extensions/MSFT_sRGBFactors.pure.js +51 -0
  470. package/glTF/2.0/Extensions/MSFT_sRGBFactors.pure.js.map +1 -0
  471. package/glTF/2.0/Extensions/MSFT_sRGBFactors.types.d.ts +9 -0
  472. package/glTF/2.0/Extensions/MSFT_sRGBFactors.types.js +2 -0
  473. package/glTF/2.0/Extensions/MSFT_sRGBFactors.types.js.map +1 -0
  474. package/glTF/2.0/Extensions/dynamic.js +5 -0
  475. package/glTF/2.0/Extensions/dynamic.js.map +1 -1
  476. package/glTF/2.0/Extensions/index.d.ts +1 -0
  477. package/glTF/2.0/Extensions/index.js +1 -0
  478. package/glTF/2.0/Extensions/index.js.map +1 -1
  479. package/glTF/2.0/Extensions/objectModelMapping.d.ts +31 -2
  480. package/glTF/2.0/Extensions/objectModelMapping.js +3 -3
  481. package/glTF/2.0/Extensions/objectModelMapping.js.map +1 -1
  482. package/glTF/2.0/Extensions/pure.d.ts +46 -0
  483. package/glTF/2.0/Extensions/pure.js +48 -0
  484. package/glTF/2.0/Extensions/pure.js.map +1 -0
  485. package/glTF/2.0/glTFLoader.d.ts +1 -471
  486. package/glTF/2.0/glTFLoader.js +9 -2570
  487. package/glTF/2.0/glTFLoader.js.map +1 -1
  488. package/glTF/2.0/glTFLoader.pure.d.ts +476 -0
  489. package/glTF/2.0/glTFLoader.pure.js +2606 -0
  490. package/glTF/2.0/glTFLoader.pure.js.map +1 -0
  491. package/glTF/2.0/glTFLoaderAnimation.d.ts +2 -2
  492. package/glTF/2.0/glTFLoaderAnimation.js +2 -2
  493. package/glTF/2.0/glTFLoaderAnimation.js.map +1 -1
  494. package/glTF/2.0/pbrMaterialLoadingAdapter.d.ts +1 -1
  495. package/glTF/2.0/pbrMaterialLoadingAdapter.js +2 -2
  496. package/glTF/2.0/pbrMaterialLoadingAdapter.js.map +1 -1
  497. package/glTF/2.0/pure.d.ts +8 -0
  498. package/glTF/2.0/pure.js +10 -0
  499. package/glTF/2.0/pure.js.map +1 -0
  500. package/glTF/glTFFileLoader.d.ts +5 -571
  501. package/glTF/glTFFileLoader.js +6 -1016
  502. package/glTF/glTFFileLoader.js.map +1 -1
  503. package/glTF/glTFFileLoader.pure.d.ts +582 -0
  504. package/glTF/glTFFileLoader.pure.js +1044 -0
  505. package/glTF/glTFFileLoader.pure.js.map +1 -0
  506. package/glTF/glTFFileLoader.types.d.ts +11 -0
  507. package/glTF/glTFFileLoader.types.js +2 -0
  508. package/glTF/glTFFileLoader.types.js.map +1 -0
  509. package/glTF/glTFValidation.js +1 -1
  510. package/glTF/glTFValidation.js.map +1 -1
  511. package/glTF/pure.d.ts +6 -0
  512. package/glTF/pure.js +8 -0
  513. package/glTF/pure.js.map +1 -0
  514. package/package.json +3 -3
  515. package/pure.d.ts +8 -0
  516. package/pure.js +10 -0
  517. package/pure.js.map +1 -0
@@ -1,2571 +1,10 @@
1
- import { Deferred } from "@onerjs/core/Misc/deferred.js";
2
- import { Quaternion, Vector3, Matrix, TmpVectors } from "@onerjs/core/Maths/math.vector.js";
3
- import { Color3 } from "@onerjs/core/Maths/math.color.js";
4
- import { Tools } from "@onerjs/core/Misc/tools.js";
5
- import { Camera } from "@onerjs/core/Cameras/camera.js";
6
- import { FreeCamera } from "@onerjs/core/Cameras/freeCamera.js";
7
- import { Animation } from "@onerjs/core/Animations/animation.js";
8
- import { Bone } from "@onerjs/core/Bones/bone.js";
9
- import { Skeleton } from "@onerjs/core/Bones/skeleton.js";
10
- import { Material } from "@onerjs/core/Materials/material.js";
11
- import { Texture } from "@onerjs/core/Materials/Textures/texture.js";
12
- import { TransformNode } from "@onerjs/core/Meshes/transformNode.js";
13
- import { Buffer, VertexBuffer } from "@onerjs/core/Buffers/buffer.js";
14
- import { VertexBufferForEach, VertexBufferGetTypeByteLength } from "@onerjs/core/Buffers/buffer.pure.js";
15
- import { Geometry } from "@onerjs/core/Meshes/geometry.js";
16
- import { AbstractMesh } from "@onerjs/core/Meshes/abstractMesh.js";
17
- import { Mesh } from "@onerjs/core/Meshes/mesh.js";
18
- import { MorphTarget } from "@onerjs/core/Morph/morphTarget.js";
19
- import { MorphTargetManager } from "@onerjs/core/Morph/morphTargetManager.js";
20
- import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader.js";
21
- import { DecodeBase64UrlToBinary, GetMimeType, IsBase64DataUrl, LoadFileError } from "@onerjs/core/Misc/fileTools.js";
22
- import { Logger } from "@onerjs/core/Misc/logger.js";
23
- import { BoundingInfo } from "@onerjs/core/Culling/boundingInfo.js";
24
- import { registeredGLTFExtensions, registerGLTFExtension, unregisterGLTFExtension } from "./glTFLoaderExtensionRegistry.js";
25
- import { GetMappingForKey } from "./Extensions/objectModelMapping.js";
26
- import { deepMerge } from "@onerjs/core/Misc/deepMerger.js";
27
- import { GetTypedArrayConstructor } from "@onerjs/core/Buffers/bufferUtils.js";
28
- import { Lazy } from "@onerjs/core/Misc/lazy.js";
29
- // Caching these dynamic imports gives a surprising perf boost (compared to importing them directly each time).
30
- const LazyAnimationGroupModulePromise = new Lazy(() => import("@onerjs/core/Animations/animationGroup.js"));
31
- const LazyLoaderAnimationModulePromise = new Lazy(() => import("./glTFLoaderAnimation.js"));
32
- export { GLTFFileLoader };
33
- /**
34
- * Helper class for working with arrays when loading the glTF asset
35
- */
36
- export class ArrayItem {
37
- /**
38
- * Gets an item from the given array.
39
- * @param context The context when loading the asset
40
- * @param array The array to get the item from
41
- * @param index The index to the array
42
- * @returns The array item
43
- */
44
- static Get(context, array, index) {
45
- if (!array || index == undefined || !array[index]) {
46
- throw new Error(`${context}: Failed to find index (${index})`);
47
- }
48
- return array[index];
49
- }
50
- /**
51
- * Gets an item from the given array or returns null if not available.
52
- * @param array The array to get the item from
53
- * @param index The index to the array
54
- * @returns The array item or null
55
- */
56
- static TryGet(array, index) {
57
- if (!array || index == undefined || !array[index]) {
58
- return null;
59
- }
60
- return array[index];
61
- }
62
- /**
63
- * Assign an `index` field to each item of the given array.
64
- * @param array The array of items
65
- */
66
- static Assign(array) {
67
- if (array) {
68
- for (let index = 0; index < array.length; index++) {
69
- array[index].index = index;
70
- }
71
- }
72
- }
73
- }
74
- /** @internal */
75
- export function LoadBoundingInfoFromPositionAccessor(accessor) {
76
- if (accessor.min && accessor.max) {
77
- const minArray = accessor.min;
78
- const maxArray = accessor.max;
79
- const minVector = TmpVectors.Vector3[0].copyFromFloats(minArray[0], minArray[1], minArray[2]);
80
- const maxVector = TmpVectors.Vector3[1].copyFromFloats(maxArray[0], maxArray[1], maxArray[2]);
81
- if (accessor.normalized && accessor.componentType !== 5126 /* AccessorComponentType.FLOAT */) {
82
- let divider = 1;
83
- switch (accessor.componentType) {
84
- case 5120 /* AccessorComponentType.BYTE */:
85
- divider = 127.0;
86
- break;
87
- case 5121 /* AccessorComponentType.UNSIGNED_BYTE */:
88
- divider = 255.0;
89
- break;
90
- case 5122 /* AccessorComponentType.SHORT */:
91
- divider = 32767.0;
92
- break;
93
- case 5123 /* AccessorComponentType.UNSIGNED_SHORT */:
94
- divider = 65535.0;
95
- break;
96
- }
97
- const oneOverDivider = 1 / divider;
98
- minVector.scaleInPlace(oneOverDivider);
99
- maxVector.scaleInPlace(oneOverDivider);
100
- }
101
- return new BoundingInfo(minVector, maxVector);
102
- }
103
- return null;
104
- }
105
- /**
106
- * The glTF 2.0 loader
107
- */
108
- export class GLTFLoader {
109
- /**
110
- * Test if the given material is an instance of any PBR material type known to this loader.
111
- * @param material The material to test
112
- * @returns true if the material matches one of the loaded PBR implementations
113
- */
114
- isMatchingMaterialType(material) {
115
- if (!material) {
116
- return false;
117
- }
118
- const materialImpls = Array.from(this._pbrMaterialImpls.values());
119
- for (const impl of materialImpls) {
120
- if (material instanceof impl.materialClass) {
121
- return true;
122
- }
123
- }
124
- return false;
125
- }
126
- /**
127
- * Registers a loader extension.
128
- * @param name The name of the loader extension.
129
- * @param factory The factory function that creates the loader extension.
130
- * @deprecated Please use registerGLTFExtension instead.
131
- */
132
- static RegisterExtension(name, factory) {
133
- registerGLTFExtension(name, false, factory);
134
- }
135
- /**
136
- * Unregisters a loader extension.
137
- * @param name The name of the loader extension.
138
- * @returns A boolean indicating whether the extension has been unregistered
139
- * @deprecated Please use unregisterGLTFExtension instead.
140
- */
141
- static UnregisterExtension(name) {
142
- return unregisterGLTFExtension(name);
143
- }
144
- /**
145
- * The object that represents the glTF JSON.
146
- */
147
- get gltf() {
148
- if (!this._gltf) {
149
- throw new Error("glTF JSON is not available");
150
- }
151
- return this._gltf;
152
- }
153
- /**
154
- * The BIN chunk of a binary glTF.
155
- */
156
- get bin() {
157
- return this._bin;
158
- }
159
- /**
160
- * The parent file loader.
161
- */
162
- get parent() {
163
- return this._parent;
164
- }
165
- /**
166
- * The Babylon scene when loading the asset.
167
- */
168
- get babylonScene() {
169
- if (!this._babylonScene) {
170
- throw new Error("Scene is not available");
171
- }
172
- return this._babylonScene;
173
- }
174
- /**
175
- * The root Babylon node when loading the asset.
176
- */
177
- get rootBabylonMesh() {
178
- return this._rootBabylonMesh;
179
- }
180
- /**
181
- * The root url when loading the asset.
182
- */
183
- get rootUrl() {
184
- return this._rootUrl;
185
- }
186
- /**
187
- * @internal
188
- */
189
- constructor(parent) {
190
- /** @internal */
191
- this._completePromises = new Array();
192
- /** @internal */
193
- this._assetContainer = null;
194
- /** Storage */
195
- this._babylonLights = [];
196
- /** @internal */
197
- this._disableInstancedMesh = 0;
198
- /** @internal */
199
- this._allMaterialsDirtyRequired = false;
200
- /** @internal */
201
- this._skipStartAnimationStep = false;
202
- this._extensions = new Array();
203
- /** @internal */
204
- this._disposed = false;
205
- this._rootUrl = null;
206
- this._fileName = null;
207
- this._uniqueRootUrl = null;
208
- this._bin = null;
209
- this._rootBabylonMesh = null;
210
- this._defaultBabylonMaterialData = {};
211
- this._postSceneLoadActions = new Array();
212
- this._materialAdapterCache = new WeakMap();
213
- this._materialAdapters = new Set();
214
- /**
215
- * Loaded PBR material implementations, keyed by their identifier (e.g. "pbr", "openpbr").
216
- * Only populated after the load has started and only for the types actually needed by the asset.
217
- * Empty when PBR materials are disabled (skipMaterials).
218
- * @internal
219
- */
220
- this._pbrMaterialImpls = new Map();
221
- this._parent = parent;
222
- }
223
- /**
224
- * Creates or gets a cached material loading adapter with dynamic imports
225
- * @param material The material to adapt
226
- * @returns Promise that resolves to the appropriate adapter
227
- * @internal
228
- */
229
- _getOrCreateMaterialAdapter(material) {
230
- let adapter = this._materialAdapterCache.get(material);
231
- if (!adapter) {
232
- const materialImpls = Array.from(this._pbrMaterialImpls.values());
233
- for (const impl of materialImpls) {
234
- if (material instanceof impl.materialClass) {
235
- adapter = new impl.adapterClass(material);
236
- break;
237
- }
238
- }
239
- if (!adapter) {
240
- throw new Error(`Appropriate material adapter class not found`);
241
- }
242
- const createdAdapter = adapter;
243
- this._materialAdapterCache.set(material, createdAdapter);
244
- this._materialAdapters.add(createdAdapter);
245
- }
246
- return adapter;
247
- }
248
- /** @internal */
249
- dispose() {
250
- if (this._disposed) {
251
- return;
252
- }
253
- this._disposed = true;
254
- this._completePromises.length = 0;
255
- this._extensions.forEach((extension) => extension.dispose && extension.dispose());
256
- this._extensions.length = 0;
257
- this._materialAdapters.clear();
258
- this._gltf = null; // TODO
259
- this._bin = null;
260
- this._babylonScene = null; // TODO
261
- this._rootBabylonMesh = null;
262
- this._defaultBabylonMaterialData = {};
263
- this._postSceneLoadActions.length = 0;
264
- this._parent.dispose();
265
- }
266
- /**
267
- * @internal
268
- */
269
- async importMeshAsync(meshesNames, scene, container, data, rootUrl, onProgress, fileName = "") {
270
- return await Promise.resolve().then(async () => {
271
- this._babylonScene = scene;
272
- this._assetContainer = container;
273
- this._loadData(data);
274
- let nodes = null;
275
- if (meshesNames) {
276
- const nodeMap = {};
277
- if (this._gltf.nodes) {
278
- for (const node of this._gltf.nodes) {
279
- if (node.name) {
280
- nodeMap[node.name] = node.index;
281
- }
282
- }
283
- }
284
- const names = meshesNames instanceof Array ? meshesNames : [meshesNames];
285
- nodes = names.map((name) => {
286
- const node = nodeMap[name];
287
- if (node === undefined) {
288
- throw new Error(`Failed to find node '${name}'`);
289
- }
290
- return node;
291
- });
292
- }
293
- return await this._loadAsync(rootUrl, fileName, nodes, () => {
294
- return {
295
- meshes: this._getMeshes(),
296
- particleSystems: [],
297
- skeletons: this._getSkeletons(),
298
- animationGroups: this._getAnimationGroups(),
299
- lights: this._babylonLights,
300
- transformNodes: this._getTransformNodes(),
301
- geometries: this._getGeometries(),
302
- spriteManagers: [],
303
- };
304
- });
305
- });
306
- }
307
- /**
308
- * @internal
309
- */
310
- async loadAsync(scene, data, rootUrl, onProgress, fileName = "") {
311
- this._babylonScene = scene;
312
- this._loadData(data);
313
- return await this._loadAsync(rootUrl, fileName, null, () => undefined);
314
- }
315
- async _loadAsync(rootUrl, fileName, nodes, resultFunc) {
316
- return await Promise.resolve()
317
- .then(async () => {
318
- this._rootUrl = rootUrl;
319
- this._uniqueRootUrl = !rootUrl.startsWith("file:") && fileName ? rootUrl : `${rootUrl}${Date.now()}/`;
320
- this._fileName = fileName;
321
- this._allMaterialsDirtyRequired = false;
322
- await this._loadExtensionsAsync();
323
- if (!this.parent.skipMaterials) {
324
- const needsOpenPBR = this.parent.useOpenPBR || this.isExtensionUsed("KHR_materials_openpbr");
325
- let needsPBR = false;
326
- if (!this.parent.useOpenPBR) {
327
- // PBR is needed when useOpenPBR is turned off.
328
- needsPBR = true;
329
- }
330
- else if (this._gltf.materials?.length && this._gltf.materials.some((m) => !m.extensions?.["KHR_materials_openpbr"])) {
331
- // PBR is needed if there is at least one material that does not use the KHR_materials_openpbr extension (i.e. relies on the default PBR implementation).
332
- needsPBR = true;
333
- }
334
- const implPromises = [];
335
- if (needsOpenPBR && !this._pbrMaterialImpls.has("openpbr")) {
336
- implPromises.push(Promise.all([import("@onerjs/core/Materials/PBR/openpbrMaterial.js"), import("./openpbrMaterialLoadingAdapter.js")]).then(([{ OpenPBRMaterial: openPBRMaterialClass }, { OpenPBRMaterialLoadingAdapter: openPBRAdapterClass }]) => {
337
- this._pbrMaterialImpls.set("openpbr", {
338
- materialClass: openPBRMaterialClass,
339
- adapterClass: openPBRAdapterClass,
340
- });
341
- }));
342
- }
343
- if (needsPBR && !this._pbrMaterialImpls.has("pbr")) {
344
- implPromises.push(Promise.all([import("@onerjs/core/Materials/PBR/pbrMaterial.js"), import("./pbrMaterialLoadingAdapter.js")]).then(([{ PBRMaterial: pbrMaterialClass }, { PBRMaterialLoadingAdapter: pbrAdapterClass }]) => {
345
- this._pbrMaterialImpls.set("pbr", {
346
- materialClass: pbrMaterialClass,
347
- adapterClass: pbrAdapterClass,
348
- });
349
- }));
350
- }
351
- await Promise.all(implPromises);
352
- }
353
- const loadingToReadyCounterName = `${GLTFLoaderState[GLTFLoaderState.LOADING]} => ${GLTFLoaderState[GLTFLoaderState.READY]}`;
354
- const loadingToCompleteCounterName = `${GLTFLoaderState[GLTFLoaderState.LOADING]} => ${GLTFLoaderState[GLTFLoaderState.COMPLETE]}`;
355
- this._parent._startPerformanceCounter(loadingToReadyCounterName);
356
- this._parent._startPerformanceCounter(loadingToCompleteCounterName);
357
- this._parent._setState(GLTFLoaderState.LOADING);
358
- this._extensionsOnLoading();
359
- const promises = new Array();
360
- // Block the marking of materials dirty until the scene is loaded.
361
- const oldBlockMaterialDirtyMechanism = this._babylonScene.blockMaterialDirtyMechanism;
362
- this._babylonScene.blockMaterialDirtyMechanism = true;
363
- if (!this.parent.loadOnlyMaterials) {
364
- if (nodes) {
365
- promises.push(this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
366
- }
367
- else if (this._gltf.scene != undefined || (this._gltf.scenes && this._gltf.scenes[0])) {
368
- const scene = ArrayItem.Get(`/scene`, this._gltf.scenes, this._gltf.scene || 0);
369
- promises.push(this.loadSceneAsync(`/scenes/${scene.index}`, scene));
370
- }
371
- }
372
- if (!this.parent.skipMaterials && this.parent.loadAllMaterials && this._gltf.materials) {
373
- for (let m = 0; m < this._gltf.materials.length; ++m) {
374
- const material = this._gltf.materials[m];
375
- const context = "/materials/" + m;
376
- const babylonDrawMode = Material.TriangleFillMode;
377
- if (!this.parent.shouldSkipMaterial?.(material)) {
378
- promises.push(this._loadMaterialAsync(context, material, null, babylonDrawMode, () => { }));
379
- }
380
- }
381
- }
382
- // Restore the blocking of material dirty.
383
- if (this._allMaterialsDirtyRequired) {
384
- // This can happen if we add a light for instance as it will impact the whole scene.
385
- // This automatically resets everything if needed.
386
- this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
387
- }
388
- else {
389
- // By default a newly created material is dirty so there is no need to flag the full scene as dirty.
390
- // For perf reasons, we then bypass blockMaterialDirtyMechanism as this would "dirty" the entire scene.
391
- this._babylonScene._forceBlockMaterialDirtyMechanism(oldBlockMaterialDirtyMechanism);
392
- }
393
- if (this._parent.compileMaterials) {
394
- promises.push(this._compileMaterialsAsync());
395
- }
396
- if (this._parent.compileShadowGenerators) {
397
- promises.push(this._compileShadowGeneratorsAsync());
398
- }
399
- const resultPromise = Promise.all(promises).then(() => {
400
- if (this._rootBabylonMesh && this._rootBabylonMesh !== this._parent.customRootNode) {
401
- this._rootBabylonMesh.setEnabled(true);
402
- }
403
- // Making sure we enable enough lights to have all lights together
404
- for (const material of this._babylonScene.materials) {
405
- const mat = material;
406
- if (mat.maxSimultaneousLights !== undefined) {
407
- mat.maxSimultaneousLights = Math.max(mat.maxSimultaneousLights, this._babylonScene.lights.length);
408
- }
409
- }
410
- // Finalize all material adapters. finalizeAsync() may return a Promise for async
411
- // work (e.g. GPU texture processing); any returned Promise is pushed into
412
- // _completePromises so it is awaited before the COMPLETE state is reached.
413
- for (const adapter of Array.from(this._materialAdapters)) {
414
- this._completePromises.push(adapter.finalizeAsync(this));
415
- }
416
- this._extensionsOnReady();
417
- this._parent._setState(GLTFLoaderState.READY);
418
- if (!this._skipStartAnimationStep) {
419
- this._startAnimations();
420
- }
421
- return resultFunc();
422
- });
423
- return await resultPromise.then((result) => {
424
- this._parent._endPerformanceCounter(loadingToReadyCounterName);
425
- Tools.SetImmediate(() => {
426
- if (!this._disposed) {
427
- Promise.all(this._completePromises).then(() => {
428
- this._parent._endPerformanceCounter(loadingToCompleteCounterName);
429
- this._parent._setState(GLTFLoaderState.COMPLETE);
430
- this._parent.onCompleteObservable.notifyObservers(undefined);
431
- this._parent.onCompleteObservable.clear();
432
- this.dispose();
433
- }, (error) => {
434
- this._parent.onErrorObservable.notifyObservers(error);
435
- this._parent.onErrorObservable.clear();
436
- this.dispose();
437
- });
438
- }
439
- });
440
- return result;
441
- });
442
- })
443
- .catch((error) => {
444
- if (!this._disposed) {
445
- this._parent.onErrorObservable.notifyObservers(error);
446
- this._parent.onErrorObservable.clear();
447
- this.dispose();
448
- }
449
- throw error;
450
- });
451
- }
452
- _loadData(data) {
453
- this._gltf = data.json;
454
- this._setupData();
455
- if (data.bin) {
456
- const buffers = this._gltf.buffers;
457
- if (buffers && buffers[0] && !buffers[0].uri) {
458
- const binaryBuffer = buffers[0];
459
- if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
460
- Logger.Warn(`Binary buffer length (${binaryBuffer.byteLength}) from JSON does not match chunk length (${data.bin.byteLength})`);
461
- }
462
- this._bin = data.bin;
463
- }
464
- else {
465
- Logger.Warn("Unexpected BIN chunk");
466
- }
467
- }
468
- }
469
- _setupData() {
470
- ArrayItem.Assign(this._gltf.accessors);
471
- ArrayItem.Assign(this._gltf.animations);
472
- ArrayItem.Assign(this._gltf.buffers);
473
- ArrayItem.Assign(this._gltf.bufferViews);
474
- ArrayItem.Assign(this._gltf.cameras);
475
- ArrayItem.Assign(this._gltf.images);
476
- ArrayItem.Assign(this._gltf.materials);
477
- ArrayItem.Assign(this._gltf.meshes);
478
- ArrayItem.Assign(this._gltf.nodes);
479
- ArrayItem.Assign(this._gltf.samplers);
480
- ArrayItem.Assign(this._gltf.scenes);
481
- ArrayItem.Assign(this._gltf.skins);
482
- ArrayItem.Assign(this._gltf.textures);
483
- if (this._gltf.nodes) {
484
- const nodeParents = {};
485
- for (const node of this._gltf.nodes) {
486
- if (node.children) {
487
- for (const index of node.children) {
488
- nodeParents[index] = node.index;
489
- }
490
- }
491
- }
492
- const rootNode = this._createRootNode();
493
- for (const node of this._gltf.nodes) {
494
- const parentIndex = nodeParents[node.index];
495
- node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
496
- }
497
- }
498
- }
499
- async _loadExtensionsAsync() {
500
- const extensionPromises = [];
501
- registeredGLTFExtensions.forEach((registeredExtension, name) => {
502
- // Don't load explicitly disabled extensions.
503
- if (this.parent.extensionOptions[name]?.enabled === false) {
504
- // But warn if the disabled extension is used by the model.
505
- if (registeredExtension.isGLTFExtension && this.isExtensionUsed(name)) {
506
- Logger.Warn(`Extension ${name} is used but has been explicitly disabled.`);
507
- }
508
- }
509
- // Load loader extensions that are not a glTF extension, as well as extensions that are glTF extensions and are used by the model.
510
- else if (!registeredExtension.isGLTFExtension || this.isExtensionUsed(name)) {
511
- extensionPromises.push((async () => {
512
- const extension = await registeredExtension.factory(this);
513
- if (extension.name !== name) {
514
- Logger.Warn(`The name of the glTF loader extension instance does not match the registered name: ${extension.name} !== ${name}`);
515
- }
516
- this._parent.onExtensionLoadedObservable.notifyObservers(extension);
517
- return extension;
518
- })());
519
- }
520
- });
521
- this._extensions.push(...(await Promise.all(extensionPromises)));
522
- this._extensions.sort((a, b) => (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE));
523
- this._parent.onExtensionLoadedObservable.clear();
524
- if (this._gltf.extensionsRequired) {
525
- for (const name of this._gltf.extensionsRequired) {
526
- const available = this._extensions.some((extension) => extension.name === name && extension.enabled);
527
- if (!available) {
528
- if (this.parent.extensionOptions[name]?.enabled === false) {
529
- throw new Error(`Required extension ${name} is disabled`);
530
- }
531
- throw new Error(`Required extension ${name} is not available`);
532
- }
533
- }
534
- }
535
- }
536
- _createRootNode() {
537
- if (this._parent.customRootNode !== undefined) {
538
- this._rootBabylonMesh = this._parent.customRootNode;
539
- return {
540
- _babylonTransformNode: this._rootBabylonMesh === null ? undefined : this._rootBabylonMesh,
541
- index: -1,
542
- };
543
- }
544
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
545
- const rootMesh = new Mesh("__root__", this._babylonScene);
546
- this._rootBabylonMesh = rootMesh;
547
- this._rootBabylonMesh._parentContainer = this._assetContainer;
548
- this._babylonScene._blockEntityCollection = false;
549
- this._rootBabylonMesh.setEnabled(false);
550
- const rootNode = {
551
- _babylonTransformNode: this._rootBabylonMesh,
552
- index: -1,
553
- };
554
- switch (this._parent.coordinateSystemMode) {
555
- case GLTFLoaderCoordinateSystemMode.AUTO: {
556
- if (!this._babylonScene.useRightHandedSystem) {
557
- if (this._parent.autoConvertRootNodeCoordinateSystem ?? true) {
558
- rootNode.rotation = [0, 1, 0, 0];
559
- rootNode.scale = [-1, 1, 1];
560
- }
561
- else {
562
- rootNode.rotation = [0, 0, 0, 0];
563
- rootNode.scale = [1, 1, 1];
564
- }
565
- GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
566
- }
567
- break;
568
- }
569
- case GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED: {
570
- this._babylonScene.useRightHandedSystem = true;
571
- break;
572
- }
573
- default: {
574
- throw new Error(`Invalid coordinate system mode (${this._parent.coordinateSystemMode})`);
575
- }
576
- }
577
- this._parent.onMeshLoadedObservable.notifyObservers(rootMesh);
578
- return rootNode;
579
- }
580
- /**
581
- * Loads a glTF scene.
582
- * @param context The context when loading the asset
583
- * @param scene The glTF scene property
584
- * @returns A promise that resolves when the load is complete
585
- */
586
- loadSceneAsync(context, scene) {
587
- const extensionPromise = this._extensionsLoadSceneAsync(context, scene);
588
- if (extensionPromise) {
589
- return extensionPromise;
590
- }
591
- const promises = new Array();
592
- this.logOpen(`${context} ${scene.name || ""}`);
593
- if (scene.nodes) {
594
- for (const index of scene.nodes) {
595
- const node = ArrayItem.Get(`${context}/nodes/${index}`, this._gltf.nodes, index);
596
- promises.push(this.loadNodeAsync(`/nodes/${node.index}`, node, (babylonMesh) => {
597
- babylonMesh.parent = this._rootBabylonMesh;
598
- }));
599
- }
600
- }
601
- for (const action of this._postSceneLoadActions) {
602
- action();
603
- }
604
- promises.push(this._loadAnimationsAsync());
605
- this.logClose();
606
- return Promise.all(promises).then(() => { });
607
- }
608
- _forEachPrimitive(node, callback) {
609
- if (node._primitiveBabylonMeshes) {
610
- for (const babylonMesh of node._primitiveBabylonMeshes) {
611
- callback(babylonMesh);
612
- }
613
- }
614
- }
615
- _getGeometries() {
616
- const geometries = [];
617
- const nodes = this._gltf.nodes;
618
- if (nodes) {
619
- for (const node of nodes) {
620
- this._forEachPrimitive(node, (babylonMesh) => {
621
- const geometry = babylonMesh.geometry;
622
- if (geometry && geometries.indexOf(geometry) === -1) {
623
- geometries.push(geometry);
624
- }
625
- });
626
- }
627
- }
628
- return geometries;
629
- }
630
- _getMeshes() {
631
- const meshes = [];
632
- // Root mesh is always first, if available.
633
- if (this._rootBabylonMesh instanceof AbstractMesh) {
634
- meshes.push(this._rootBabylonMesh);
635
- }
636
- const nodes = this._gltf.nodes;
637
- if (nodes) {
638
- for (const node of nodes) {
639
- this._forEachPrimitive(node, (babylonMesh) => {
640
- meshes.push(babylonMesh);
641
- });
642
- }
643
- }
644
- return meshes;
645
- }
646
- _getTransformNodes() {
647
- const transformNodes = [];
648
- const nodes = this._gltf.nodes;
649
- if (nodes) {
650
- for (const node of nodes) {
651
- if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
652
- transformNodes.push(node._babylonTransformNode);
653
- }
654
- if (node._babylonTransformNodeForSkin) {
655
- transformNodes.push(node._babylonTransformNodeForSkin);
656
- }
657
- }
658
- }
659
- return transformNodes;
660
- }
661
- _getSkeletons() {
662
- const skeletons = [];
663
- const skins = this._gltf.skins;
664
- if (skins) {
665
- for (const skin of skins) {
666
- if (skin._data) {
667
- skeletons.push(skin._data.babylonSkeleton);
668
- }
669
- }
670
- }
671
- return skeletons;
672
- }
673
- _getAnimationGroups() {
674
- const animationGroups = [];
675
- const animations = this._gltf.animations;
676
- if (animations) {
677
- for (const animation of animations) {
678
- if (animation._babylonAnimationGroup) {
679
- animationGroups.push(animation._babylonAnimationGroup);
680
- }
681
- }
682
- }
683
- return animationGroups;
684
- }
685
- _startAnimations() {
686
- switch (this._parent.animationStartMode) {
687
- case GLTFLoaderAnimationStartMode.NONE: {
688
- // do nothing
689
- break;
690
- }
691
- case GLTFLoaderAnimationStartMode.FIRST: {
692
- const babylonAnimationGroups = this._getAnimationGroups();
693
- if (babylonAnimationGroups.length !== 0) {
694
- babylonAnimationGroups[0].start(true);
695
- }
696
- break;
697
- }
698
- case GLTFLoaderAnimationStartMode.ALL: {
699
- const babylonAnimationGroups = this._getAnimationGroups();
700
- for (const babylonAnimationGroup of babylonAnimationGroups) {
701
- babylonAnimationGroup.start(true);
702
- }
703
- break;
704
- }
705
- default: {
706
- Logger.Error(`Invalid animation start mode (${this._parent.animationStartMode})`);
707
- return;
708
- }
709
- }
710
- }
711
- /**
712
- * Loads a glTF node.
713
- * @param context The context when loading the asset
714
- * @param node The glTF node property
715
- * @param assign A function called synchronously after parsing the glTF properties
716
- * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
717
- */
718
- loadNodeAsync(context, node, assign = () => { }) {
719
- const extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
720
- if (extensionPromise) {
721
- return extensionPromise;
722
- }
723
- if (node._babylonTransformNode) {
724
- throw new Error(`${context}: Invalid recursive node hierarchy`);
725
- }
726
- const promises = new Array();
727
- this.logOpen(`${context} ${node.name || ""}`);
728
- const loadNode = (babylonTransformNode) => {
729
- GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
730
- GLTFLoader._LoadTransform(node, babylonTransformNode);
731
- if (node.camera != undefined) {
732
- const camera = ArrayItem.Get(`${context}/camera`, this._gltf.cameras, node.camera);
733
- promises.push(this.loadCameraAsync(`/cameras/${camera.index}`, camera, (babylonCamera) => {
734
- babylonCamera.parent = babylonTransformNode;
735
- if (!this._babylonScene.useRightHandedSystem) {
736
- babylonTransformNode.scaling.x = -1; // Cancelling root node scaling for handedness so the view matrix does not end up flipped.
737
- }
738
- }));
739
- }
740
- if (node.children) {
741
- for (const index of node.children) {
742
- const childNode = ArrayItem.Get(`${context}/children/${index}`, this._gltf.nodes, index);
743
- promises.push(this.loadNodeAsync(`/nodes/${childNode.index}`, childNode, (childBabylonMesh) => {
744
- childBabylonMesh.parent = babylonTransformNode;
745
- }));
746
- }
747
- }
748
- assign(babylonTransformNode);
749
- };
750
- const hasMesh = node.mesh != undefined;
751
- const hasSkin = this._parent.loadSkins && node.skin != undefined;
752
- if (!hasMesh || hasSkin) {
753
- const nodeName = node.name || `node${node.index}`;
754
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
755
- const transformNode = this.parent.createEmptyNodeHandle ? this.parent.createEmptyNodeHandle(node, this._babylonScene) : new TransformNode(nodeName, this._babylonScene);
756
- transformNode._parentContainer = this._assetContainer;
757
- this._babylonScene._blockEntityCollection = false;
758
- if (!hasMesh) {
759
- node._babylonTransformNode = transformNode;
760
- }
761
- else {
762
- node._babylonTransformNodeForSkin = transformNode;
763
- }
764
- loadNode(transformNode);
765
- }
766
- if (hasMesh) {
767
- if (hasSkin) {
768
- // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
769
- // This code path will place the skinned mesh as a sibling of the skeleton root node without loading the
770
- // transform, which effectively ignores the transform of the skinned mesh, as per spec.
771
- const mesh = ArrayItem.Get(`${context}/mesh`, this._gltf.meshes, node.mesh);
772
- promises.push(this._loadMeshAsync(`/meshes/${mesh.index}`, node, mesh, (babylonTransformNode) => {
773
- const babylonTransformNodeForSkin = node._babylonTransformNodeForSkin;
774
- // Merge the metadata from the skin node to the skinned mesh in case a loader extension added metadata.
775
- babylonTransformNode.metadata = deepMerge(babylonTransformNodeForSkin.metadata, babylonTransformNode.metadata || {});
776
- const skin = ArrayItem.Get(`${context}/skin`, this._gltf.skins, node.skin);
777
- promises.push(this._loadSkinAsync(`/skins/${skin.index}`, node, skin, (babylonSkeleton) => {
778
- this._forEachPrimitive(node, (babylonMesh) => {
779
- babylonMesh.skeleton = babylonSkeleton;
780
- });
781
- // Wait until all the nodes are parented before parenting the skinned mesh.
782
- this._postSceneLoadActions.push(() => {
783
- if (skin.skeleton != undefined) {
784
- // Place the skinned mesh node as a sibling of the skeleton root node.
785
- // Handle special case when the parent of the skeleton root is the skinned mesh.
786
- const parentNode = ArrayItem.Get(`/skins/${skin.index}/skeleton`, this._gltf.nodes, skin.skeleton).parent;
787
- if (node.index === parentNode.index) {
788
- babylonTransformNode.parent = babylonTransformNodeForSkin.parent;
789
- }
790
- else {
791
- babylonTransformNode.parent = parentNode._babylonTransformNode;
792
- }
793
- }
794
- else {
795
- babylonTransformNode.parent = this._rootBabylonMesh;
796
- }
797
- this._parent.onSkinLoadedObservable.notifyObservers({ node: babylonTransformNodeForSkin, skinnedNode: babylonTransformNode });
798
- });
799
- }));
800
- }));
801
- }
802
- else {
803
- const mesh = ArrayItem.Get(`${context}/mesh`, this._gltf.meshes, node.mesh);
804
- promises.push(this._loadMeshAsync(`/meshes/${mesh.index}`, node, mesh, loadNode));
805
- }
806
- }
807
- this.logClose();
808
- return Promise.all(promises).then(() => {
809
- this._forEachPrimitive(node, (babylonMesh) => {
810
- const asMesh = babylonMesh;
811
- if (!asMesh.isAnInstance && asMesh.geometry && asMesh.geometry.useBoundingInfoFromGeometry) {
812
- // simply apply the world matrices to the bounding info - the extends are already ok
813
- babylonMesh._updateBoundingInfo();
814
- }
815
- else {
816
- babylonMesh.refreshBoundingInfo(true, true);
817
- }
818
- });
819
- if (node._babylonTransformNode) {
820
- if (node.animations) {
821
- node.animations.forEach((animation) => {
822
- if (!node._babylonTransformNode.animations.some((anim) => anim.name === animation.name)) {
823
- node._babylonTransformNode.animations.push(Animation.Parse(animation));
824
- }
825
- });
826
- }
827
- }
828
- return node._babylonTransformNode;
829
- });
830
- }
831
- _loadMeshAsync(context, node, mesh, assign) {
832
- const primitives = mesh.primitives;
833
- if (!primitives || !primitives.length) {
834
- throw new Error(`${context}: Primitives are missing`);
835
- }
836
- if (primitives[0].index == undefined) {
837
- ArrayItem.Assign(primitives);
838
- }
839
- const promises = new Array();
840
- this.logOpen(`${context} ${mesh.name || ""}`);
841
- const name = node.name || `node${node.index}`;
842
- if (primitives.length === 1) {
843
- const primitive = mesh.primitives[0];
844
- promises.push(this._loadMeshPrimitiveAsync(`${context}/primitives/${primitive.index}`, name, node, mesh, primitive, (babylonMesh) => {
845
- node._babylonTransformNode = babylonMesh;
846
- node._primitiveBabylonMeshes = [babylonMesh];
847
- }));
848
- }
849
- else {
850
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
851
- node._babylonTransformNode = new TransformNode(name, this._babylonScene);
852
- node._babylonTransformNode._parentContainer = this._assetContainer;
853
- this._babylonScene._blockEntityCollection = false;
854
- node._primitiveBabylonMeshes = [];
855
- for (const primitive of primitives) {
856
- promises.push(this._loadMeshPrimitiveAsync(`${context}/primitives/${primitive.index}`, `${name}_primitive${primitive.index}`, node, mesh, primitive, (babylonMesh) => {
857
- babylonMesh.parent = node._babylonTransformNode;
858
- node._primitiveBabylonMeshes.push(babylonMesh);
859
- }));
860
- }
861
- }
862
- assign(node._babylonTransformNode);
863
- this.logClose();
864
- return Promise.all(promises).then(() => {
865
- return node._babylonTransformNode;
866
- });
867
- }
868
- /**
869
- * @internal Define this method to modify the default behavior when loading data for mesh primitives.
870
- * @param context The context when loading the asset
871
- * @param name The mesh name when loading the asset
872
- * @param node The glTF node when loading the asset
873
- * @param mesh The glTF mesh when loading the asset
874
- * @param primitive The glTF mesh primitive property
875
- * @param assign A function called synchronously after parsing the glTF properties
876
- * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
877
- */
878
- _loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign) {
879
- const extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
880
- if (extensionPromise) {
881
- return extensionPromise;
882
- }
883
- this.logOpen(`${context}`);
884
- const shouldInstance = this._disableInstancedMesh === 0 && this._parent.createInstances && node.skin == undefined && !mesh.primitives[0].targets;
885
- let babylonAbstractMesh;
886
- let promise;
887
- if (shouldInstance && primitive._instanceData) {
888
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
889
- babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
890
- babylonAbstractMesh._parentContainer = this._assetContainer;
891
- this._babylonScene._blockEntityCollection = false;
892
- promise = primitive._instanceData.promise;
893
- }
894
- else {
895
- const promises = new Array();
896
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
897
- const babylonMesh = new Mesh(name, this._babylonScene);
898
- babylonMesh._parentContainer = this._assetContainer;
899
- this._babylonScene._blockEntityCollection = false;
900
- if (this.parent.useMeshSideOrientation && typeof mesh.sideOrientation === "number") {
901
- babylonMesh.sideOrientation = mesh.sideOrientation;
902
- }
903
- else {
904
- babylonMesh.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
905
- }
906
- this._createMorphTargets(context, node, mesh, primitive, babylonMesh);
907
- promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh).then(async (babylonGeometry) => {
908
- return await this._loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry).then(() => {
909
- if (this._disposed) {
910
- return;
911
- }
912
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
913
- babylonGeometry.applyToMesh(babylonMesh);
914
- babylonGeometry._parentContainer = this._assetContainer;
915
- this._babylonScene._blockEntityCollection = false;
916
- });
917
- }));
918
- if (!this.parent.skipMaterials) {
919
- const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
920
- if (primitive.material == undefined) {
921
- let babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
922
- if (!babylonMaterial) {
923
- babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode, this._getDefaultImpl());
924
- this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
925
- this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
926
- }
927
- babylonMesh.material = babylonMaterial;
928
- }
929
- else {
930
- const material = ArrayItem.Get(`${context}/material`, this._gltf.materials, primitive.material);
931
- if (!this.parent.shouldSkipMaterial?.(material)) {
932
- promises.push(this._loadMaterialAsync(`/materials/${material.index}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {
933
- babylonMesh.material = babylonMaterial;
934
- }));
935
- }
936
- }
937
- }
938
- promise = Promise.all(promises);
939
- if (shouldInstance) {
940
- primitive._instanceData = {
941
- babylonSourceMesh: babylonMesh,
942
- promise: promise,
943
- };
944
- }
945
- babylonAbstractMesh = babylonMesh;
946
- }
947
- GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
948
- this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
949
- assign(babylonAbstractMesh);
950
- this.logClose();
951
- return promise.then(() => {
952
- return babylonAbstractMesh;
953
- });
954
- }
955
- _loadVertexDataAsync(context, primitive, babylonMesh) {
956
- const extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
957
- if (extensionPromise) {
958
- return extensionPromise;
959
- }
960
- const attributes = primitive.attributes;
961
- if (!attributes) {
962
- throw new Error(`${context}: Attributes are missing`);
963
- }
964
- const promises = new Array();
965
- const babylonGeometry = new Geometry(babylonMesh.name, this._babylonScene);
966
- if (primitive.indices == undefined) {
967
- babylonMesh.isUnIndexed = true;
968
- }
969
- else {
970
- const accessor = ArrayItem.Get(`${context}/indices`, this._gltf.accessors, primitive.indices);
971
- promises.push(this._loadIndicesAccessorAsync(`/accessors/${accessor.index}`, accessor).then((data) => {
972
- babylonGeometry.setIndices(data);
973
- }));
974
- }
975
- const loadAttribute = (name, kind, callback) => {
976
- if (attributes[name] == undefined) {
977
- return;
978
- }
979
- babylonMesh._delayInfo = babylonMesh._delayInfo || [];
980
- if (babylonMesh._delayInfo.indexOf(kind) === -1) {
981
- babylonMesh._delayInfo.push(kind);
982
- }
983
- const accessor = ArrayItem.Get(`${context}/attributes/${name}`, this._gltf.accessors, attributes[name]);
984
- promises.push(this._loadVertexAccessorAsync(`/accessors/${accessor.index}`, accessor, kind).then((babylonVertexBuffer) => {
985
- if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
986
- const babylonBoundingInfo = LoadBoundingInfoFromPositionAccessor(accessor);
987
- if (babylonBoundingInfo) {
988
- babylonGeometry._boundingInfo = babylonBoundingInfo;
989
- babylonGeometry.useBoundingInfoFromGeometry = true;
990
- }
991
- }
992
- babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
993
- }));
994
- if (kind == VertexBuffer.MatricesIndicesExtraKind) {
995
- babylonMesh.numBoneInfluencers = 8;
996
- }
997
- if (callback) {
998
- callback(accessor);
999
- }
1000
- };
1001
- loadAttribute("POSITION", VertexBuffer.PositionKind);
1002
- loadAttribute("NORMAL", VertexBuffer.NormalKind);
1003
- loadAttribute("TANGENT", VertexBuffer.TangentKind);
1004
- loadAttribute("TEXCOORD_0", VertexBuffer.UVKind);
1005
- loadAttribute("TEXCOORD_1", VertexBuffer.UV2Kind);
1006
- loadAttribute("TEXCOORD_2", VertexBuffer.UV3Kind);
1007
- loadAttribute("TEXCOORD_3", VertexBuffer.UV4Kind);
1008
- loadAttribute("TEXCOORD_4", VertexBuffer.UV5Kind);
1009
- loadAttribute("TEXCOORD_5", VertexBuffer.UV6Kind);
1010
- loadAttribute("JOINTS_0", VertexBuffer.MatricesIndicesKind);
1011
- loadAttribute("WEIGHTS_0", VertexBuffer.MatricesWeightsKind);
1012
- loadAttribute("JOINTS_1", VertexBuffer.MatricesIndicesExtraKind);
1013
- loadAttribute("WEIGHTS_1", VertexBuffer.MatricesWeightsExtraKind);
1014
- loadAttribute("COLOR_0", VertexBuffer.ColorKind, (accessor) => {
1015
- if (accessor.type === "VEC4" /* AccessorType.VEC4 */) {
1016
- babylonMesh.hasVertexAlpha = true;
1017
- }
1018
- });
1019
- return Promise.all(promises).then(() => {
1020
- return babylonGeometry;
1021
- });
1022
- }
1023
- _createMorphTargets(context, node, mesh, primitive, babylonMesh) {
1024
- if (!primitive.targets || !this._parent.loadMorphTargets) {
1025
- return;
1026
- }
1027
- if (node._numMorphTargets == undefined) {
1028
- node._numMorphTargets = primitive.targets.length;
1029
- }
1030
- else if (primitive.targets.length !== node._numMorphTargets) {
1031
- throw new Error(`${context}: Primitives do not have the same number of targets`);
1032
- }
1033
- const targetNames = mesh.extras ? mesh.extras.targetNames : null;
1034
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1035
- babylonMesh.morphTargetManager = new MorphTargetManager(this._babylonScene);
1036
- babylonMesh.morphTargetManager._parentContainer = this._assetContainer;
1037
- this._babylonScene._blockEntityCollection = false;
1038
- babylonMesh.morphTargetManager.areUpdatesFrozen = true;
1039
- for (let index = 0; index < primitive.targets.length; index++) {
1040
- const weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
1041
- const name = targetNames ? targetNames[index] : `morphTarget${index}`;
1042
- babylonMesh.morphTargetManager.addTarget(new MorphTarget(name, weight, babylonMesh.getScene()));
1043
- // TODO: tell the target whether it has positions, normals, tangents
1044
- }
1045
- }
1046
- _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry) {
1047
- if (!primitive.targets || !this._parent.loadMorphTargets) {
1048
- return Promise.resolve();
1049
- }
1050
- const promises = new Array();
1051
- const morphTargetManager = babylonMesh.morphTargetManager;
1052
- for (let index = 0; index < morphTargetManager.numTargets; index++) {
1053
- const babylonMorphTarget = morphTargetManager.getTarget(index);
1054
- promises.push(this._loadMorphTargetVertexDataAsync(`${context}/targets/${index}`, babylonGeometry, primitive.targets[index], babylonMorphTarget));
1055
- }
1056
- return Promise.all(promises).then(() => {
1057
- morphTargetManager.areUpdatesFrozen = false;
1058
- });
1059
- }
1060
- async _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget) {
1061
- const promises = new Array();
1062
- const loadAttribute = (attribute, kind, setData) => {
1063
- if (attributes[attribute] == undefined) {
1064
- return;
1065
- }
1066
- const babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
1067
- if (!babylonVertexBuffer) {
1068
- return;
1069
- }
1070
- const accessor = ArrayItem.Get(`${context}/${attribute}`, this._gltf.accessors, attributes[attribute]);
1071
- promises.push(this._loadFloatAccessorAsync(`/accessors/${accessor.index}`, accessor).then((data) => {
1072
- setData(babylonVertexBuffer, data);
1073
- }));
1074
- };
1075
- loadAttribute("POSITION", VertexBuffer.PositionKind, (babylonVertexBuffer, data) => {
1076
- const positions = new Float32Array(data.length);
1077
- babylonVertexBuffer.forEach(data.length, (value, index) => {
1078
- positions[index] = data[index] + value;
1079
- });
1080
- babylonMorphTarget.setPositions(positions);
1081
- });
1082
- loadAttribute("NORMAL", VertexBuffer.NormalKind, (babylonVertexBuffer, data) => {
1083
- const normals = new Float32Array(data.length);
1084
- babylonVertexBuffer.forEach(normals.length, (value, index) => {
1085
- normals[index] = data[index] + value;
1086
- });
1087
- babylonMorphTarget.setNormals(normals);
1088
- });
1089
- loadAttribute("TANGENT", VertexBuffer.TangentKind, (babylonVertexBuffer, data) => {
1090
- const tangents = new Float32Array((data.length / 3) * 4);
1091
- let dataIndex = 0;
1092
- babylonVertexBuffer.forEach((data.length / 3) * 4, (value, index) => {
1093
- // Tangent data for morph targets is stored as xyz delta.
1094
- // The vertexData.tangent is stored as xyzw.
1095
- // So we need to skip every fourth vertexData.tangent.
1096
- if ((index + 1) % 4 !== 0) {
1097
- tangents[dataIndex] = data[dataIndex] + value;
1098
- dataIndex++;
1099
- }
1100
- });
1101
- babylonMorphTarget.setTangents(tangents);
1102
- });
1103
- loadAttribute("TEXCOORD_0", VertexBuffer.UVKind, (babylonVertexBuffer, data) => {
1104
- const uvs = new Float32Array(data.length);
1105
- babylonVertexBuffer.forEach(data.length, (value, index) => {
1106
- uvs[index] = data[index] + value;
1107
- });
1108
- babylonMorphTarget.setUVs(uvs);
1109
- });
1110
- loadAttribute("TEXCOORD_1", VertexBuffer.UV2Kind, (babylonVertexBuffer, data) => {
1111
- const uvs = new Float32Array(data.length);
1112
- babylonVertexBuffer.forEach(data.length, (value, index) => {
1113
- uvs[index] = data[index] + value;
1114
- });
1115
- babylonMorphTarget.setUV2s(uvs);
1116
- });
1117
- loadAttribute("COLOR_0", VertexBuffer.ColorKind, (babylonVertexBuffer, data) => {
1118
- let colors = null;
1119
- const componentSize = babylonVertexBuffer.getSize();
1120
- if (componentSize === 3) {
1121
- colors = new Float32Array((data.length / 3) * 4);
1122
- babylonVertexBuffer.forEach(data.length, (value, index) => {
1123
- const pixid = Math.floor(index / 3);
1124
- const channel = index % 3;
1125
- colors[4 * pixid + channel] = data[3 * pixid + channel] + value;
1126
- });
1127
- for (let i = 0; i < data.length / 3; ++i) {
1128
- colors[4 * i + 3] = 1;
1129
- }
1130
- }
1131
- else if (componentSize === 4) {
1132
- colors = new Float32Array(data.length);
1133
- babylonVertexBuffer.forEach(data.length, (value, index) => {
1134
- colors[index] = data[index] + value;
1135
- });
1136
- }
1137
- else {
1138
- throw new Error(`${context}: Invalid number of components (${componentSize}) for COLOR_0 attribute`);
1139
- }
1140
- babylonMorphTarget.setColors(colors);
1141
- });
1142
- return await Promise.all(promises).then(() => { });
1143
- }
1144
- static _LoadTransform(node, babylonNode) {
1145
- // Ignore the TRS of skinned nodes.
1146
- // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
1147
- if (node.skin != undefined) {
1148
- return;
1149
- }
1150
- let position = Vector3.Zero();
1151
- let rotation = Quaternion.Identity();
1152
- let scaling = Vector3.One();
1153
- if (node.matrix) {
1154
- const matrix = Matrix.FromArray(node.matrix);
1155
- matrix.decompose(scaling, rotation, position);
1156
- }
1157
- else {
1158
- if (node.translation) {
1159
- position = Vector3.FromArray(node.translation);
1160
- }
1161
- if (node.rotation) {
1162
- rotation = Quaternion.FromArray(node.rotation);
1163
- }
1164
- if (node.scale) {
1165
- scaling = Vector3.FromArray(node.scale);
1166
- }
1167
- }
1168
- babylonNode.position = position;
1169
- babylonNode.rotationQuaternion = rotation;
1170
- babylonNode.scaling = scaling;
1171
- if (node.pivotPoint) {
1172
- babylonNode.setPivotPoint(Vector3.FromArray(node.pivotPoint));
1173
- }
1174
- }
1175
- _loadSkinAsync(context, node, skin, assign) {
1176
- if (!this._parent.loadSkins) {
1177
- return Promise.resolve();
1178
- }
1179
- const extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
1180
- if (extensionPromise) {
1181
- return extensionPromise;
1182
- }
1183
- if (skin._data) {
1184
- assign(skin._data.babylonSkeleton);
1185
- return skin._data.promise;
1186
- }
1187
- const skeletonId = `skeleton${skin.index}`;
1188
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1189
- const babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
1190
- babylonSkeleton._parentContainer = this._assetContainer;
1191
- this._babylonScene._blockEntityCollection = false;
1192
- this._loadBones(context, skin, babylonSkeleton);
1193
- const promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then((inverseBindMatricesData) => {
1194
- this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
1195
- });
1196
- skin._data = {
1197
- babylonSkeleton: babylonSkeleton,
1198
- promise: promise,
1199
- };
1200
- assign(babylonSkeleton);
1201
- return promise;
1202
- }
1203
- _loadBones(context, skin, babylonSkeleton) {
1204
- if (skin.skeleton == undefined || this._parent.alwaysComputeSkeletonRootNode) {
1205
- const rootNode = this._findSkeletonRootNode(`${context}/joints`, skin.joints);
1206
- if (rootNode) {
1207
- if (skin.skeleton === undefined) {
1208
- skin.skeleton = rootNode.index;
1209
- }
1210
- else {
1211
- const isParent = (a, b) => {
1212
- for (; b.parent; b = b.parent) {
1213
- if (b.parent === a) {
1214
- return true;
1215
- }
1216
- }
1217
- return false;
1218
- };
1219
- const skeletonNode = ArrayItem.Get(`${context}/skeleton`, this._gltf.nodes, skin.skeleton);
1220
- if (skeletonNode !== rootNode && !isParent(skeletonNode, rootNode)) {
1221
- Logger.Warn(`${context}/skeleton: Overriding with nearest common ancestor as skeleton node is not a common root`);
1222
- skin.skeleton = rootNode.index;
1223
- }
1224
- }
1225
- }
1226
- else {
1227
- Logger.Warn(`${context}: Failed to find common root`);
1228
- }
1229
- }
1230
- const babylonBones = {};
1231
- for (const index of skin.joints) {
1232
- const node = ArrayItem.Get(`${context}/joints/${index}`, this._gltf.nodes, index);
1233
- this._loadBone(node, skin, babylonSkeleton, babylonBones);
1234
- }
1235
- }
1236
- _findSkeletonRootNode(context, joints) {
1237
- if (joints.length === 0) {
1238
- return null;
1239
- }
1240
- const paths = {};
1241
- for (const index of joints) {
1242
- const path = [];
1243
- let node = ArrayItem.Get(`${context}/${index}`, this._gltf.nodes, index);
1244
- while (node.index !== -1) {
1245
- path.unshift(node);
1246
- node = node.parent;
1247
- }
1248
- paths[index] = path;
1249
- }
1250
- let rootNode = null;
1251
- for (let i = 0;; ++i) {
1252
- let path = paths[joints[0]];
1253
- if (i >= path.length) {
1254
- return rootNode;
1255
- }
1256
- const node = path[i];
1257
- for (let j = 1; j < joints.length; ++j) {
1258
- path = paths[joints[j]];
1259
- if (i >= path.length || node !== path[i]) {
1260
- return rootNode;
1261
- }
1262
- }
1263
- rootNode = node;
1264
- }
1265
- }
1266
- _loadBone(node, skin, babylonSkeleton, babylonBones) {
1267
- node._isJoint = true;
1268
- let babylonBone = babylonBones[node.index];
1269
- if (babylonBone) {
1270
- return babylonBone;
1271
- }
1272
- let parentBabylonBone = null;
1273
- if (node.index !== skin.skeleton) {
1274
- if (node.parent && node.parent.index !== -1) {
1275
- parentBabylonBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
1276
- }
1277
- else if (skin.skeleton !== undefined) {
1278
- Logger.Warn(`/skins/${skin.index}/skeleton: Skeleton node is not a common root`);
1279
- }
1280
- }
1281
- const boneIndex = skin.joints.indexOf(node.index);
1282
- babylonBone = new Bone(node.name || `joint${node.index}`, babylonSkeleton, parentBabylonBone, this._getNodeMatrix(node), null, null, boneIndex);
1283
- babylonBones[node.index] = babylonBone;
1284
- // Wait until the scene is loaded to ensure the transform nodes are loaded.
1285
- this._postSceneLoadActions.push(() => {
1286
- // Link the Babylon bone with the corresponding Babylon transform node.
1287
- // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
1288
- babylonBone.linkTransformNode(node._babylonTransformNode);
1289
- });
1290
- return babylonBone;
1291
- }
1292
- _loadSkinInverseBindMatricesDataAsync(context, skin) {
1293
- if (skin.inverseBindMatrices == undefined) {
1294
- return Promise.resolve(null);
1295
- }
1296
- const accessor = ArrayItem.Get(`${context}/inverseBindMatrices`, this._gltf.accessors, skin.inverseBindMatrices);
1297
- return this._loadFloatAccessorAsync(`/accessors/${accessor.index}`, accessor);
1298
- }
1299
- _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData) {
1300
- for (const babylonBone of babylonSkeleton.bones) {
1301
- const baseMatrix = Matrix.Identity();
1302
- const boneIndex = babylonBone._index;
1303
- if (inverseBindMatricesData && boneIndex !== -1) {
1304
- Matrix.FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
1305
- baseMatrix.invertToRef(baseMatrix);
1306
- }
1307
- const babylonParentBone = babylonBone.getParent();
1308
- if (babylonParentBone) {
1309
- baseMatrix.multiplyToRef(babylonParentBone.getAbsoluteInverseBindMatrix(), baseMatrix);
1310
- }
1311
- babylonBone.updateMatrix(baseMatrix, false, false);
1312
- babylonBone._updateAbsoluteBindMatrices(undefined, false);
1313
- }
1314
- }
1315
- _getNodeMatrix(node) {
1316
- return node.matrix
1317
- ? Matrix.FromArray(node.matrix)
1318
- : Matrix.Compose(node.scale ? Vector3.FromArray(node.scale) : Vector3.One(), node.rotation ? Quaternion.FromArray(node.rotation) : Quaternion.Identity(), node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
1319
- }
1320
- /**
1321
- * Loads a glTF camera.
1322
- * @param context The context when loading the asset
1323
- * @param camera The glTF camera property
1324
- * @param assign A function called synchronously after parsing the glTF properties
1325
- * @returns A promise that resolves with the loaded Babylon camera when the load is complete
1326
- */
1327
- loadCameraAsync(context, camera, assign = () => { }) {
1328
- const extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
1329
- if (extensionPromise) {
1330
- return extensionPromise;
1331
- }
1332
- const promises = new Array();
1333
- this.logOpen(`${context} ${camera.name || ""}`);
1334
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1335
- const babylonCamera = new FreeCamera(camera.name || `camera${camera.index}`, Vector3.Zero(), this._babylonScene, false);
1336
- babylonCamera._parentContainer = this._assetContainer;
1337
- this._babylonScene._blockEntityCollection = false;
1338
- camera._babylonCamera = babylonCamera;
1339
- // glTF cameras look towards the local -Z axis.
1340
- babylonCamera.setTarget(new Vector3(0, 0, -1));
1341
- switch (camera.type) {
1342
- case "perspective" /* CameraType.PERSPECTIVE */: {
1343
- const perspective = camera.perspective;
1344
- if (!perspective) {
1345
- throw new Error(`${context}: Camera perspective properties are missing`);
1346
- }
1347
- babylonCamera.fov = perspective.yfov;
1348
- babylonCamera.minZ = perspective.znear;
1349
- babylonCamera.maxZ = perspective.zfar || 0;
1350
- break;
1351
- }
1352
- case "orthographic" /* CameraType.ORTHOGRAPHIC */: {
1353
- if (!camera.orthographic) {
1354
- throw new Error(`${context}: Camera orthographic properties are missing`);
1355
- }
1356
- babylonCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
1357
- babylonCamera.orthoLeft = -camera.orthographic.xmag;
1358
- babylonCamera.orthoRight = camera.orthographic.xmag;
1359
- babylonCamera.orthoBottom = -camera.orthographic.ymag;
1360
- babylonCamera.orthoTop = camera.orthographic.ymag;
1361
- babylonCamera.minZ = camera.orthographic.znear;
1362
- babylonCamera.maxZ = camera.orthographic.zfar;
1363
- break;
1364
- }
1365
- default: {
1366
- throw new Error(`${context}: Invalid camera type (${camera.type})`);
1367
- }
1368
- }
1369
- GLTFLoader.AddPointerMetadata(babylonCamera, context);
1370
- this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
1371
- assign(babylonCamera);
1372
- this.logClose();
1373
- return Promise.all(promises).then(() => {
1374
- return babylonCamera;
1375
- });
1376
- }
1377
- _loadAnimationsAsync() {
1378
- this._parent._startPerformanceCounter("Load animations");
1379
- const animations = this._gltf.animations;
1380
- if (!animations) {
1381
- return Promise.resolve();
1382
- }
1383
- const promises = new Array();
1384
- for (let index = 0; index < animations.length; index++) {
1385
- const animation = animations[index];
1386
- promises.push(this.loadAnimationAsync(`/animations/${animation.index}`, animation).then((animationGroup) => {
1387
- // Delete the animation group if it ended up not having any animations in it.
1388
- if (animationGroup.targetedAnimations.length === 0) {
1389
- animationGroup.dispose();
1390
- }
1391
- }));
1392
- }
1393
- return Promise.all(promises).then(() => {
1394
- this._parent._endPerformanceCounter("Load animations");
1395
- });
1396
- }
1397
- /**
1398
- * Loads a glTF animation.
1399
- * @param context The context when loading the asset
1400
- * @param animation The glTF animation property
1401
- * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
1402
- */
1403
- loadAnimationAsync(context, animation) {
1404
- this._parent._startPerformanceCounter("Load animation");
1405
- const promise = this._extensionsLoadAnimationAsync(context, animation);
1406
- if (promise) {
1407
- return promise;
1408
- }
1409
- // eslint-disable-next-line @typescript-eslint/naming-convention
1410
- return LazyAnimationGroupModulePromise.value.then(({ AnimationGroup }) => {
1411
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1412
- const babylonAnimationGroup = new AnimationGroup(animation.name || `animation${animation.index}`, this._babylonScene);
1413
- babylonAnimationGroup._parentContainer = this._assetContainer;
1414
- this._babylonScene._blockEntityCollection = false;
1415
- animation._babylonAnimationGroup = babylonAnimationGroup;
1416
- if (animation.extras) {
1417
- babylonAnimationGroup.metadata = animation.extras;
1418
- }
1419
- const promises = new Array();
1420
- ArrayItem.Assign(animation.channels);
1421
- ArrayItem.Assign(animation.samplers);
1422
- for (const channel of animation.channels) {
1423
- promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel, (babylonTarget, babylonAnimation) => {
1424
- babylonTarget.animations = babylonTarget.animations || [];
1425
- babylonTarget.animations.push(babylonAnimation);
1426
- babylonAnimationGroup.addTargetedAnimation(babylonAnimation, babylonTarget);
1427
- }));
1428
- }
1429
- this._parent._endPerformanceCounter("Load animation");
1430
- return Promise.all(promises).then(() => {
1431
- babylonAnimationGroup.normalize(0);
1432
- return babylonAnimationGroup;
1433
- });
1434
- });
1435
- }
1436
- /**
1437
- * @hidden
1438
- * Loads a glTF animation channel.
1439
- * @param context The context when loading the asset
1440
- * @param animationContext The context of the animation when loading the asset
1441
- * @param animation The glTF animation property
1442
- * @param channel The glTF animation channel property
1443
- * @param onLoad Called for each animation loaded
1444
- * @returns A void promise that resolves when the load is complete
1445
- */
1446
- _loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
1447
- const promise = this._extensionsLoadAnimationChannelAsync(context, animationContext, animation, channel, onLoad);
1448
- if (promise) {
1449
- return promise;
1450
- }
1451
- if (channel.target.node == undefined) {
1452
- return Promise.resolve();
1453
- }
1454
- const targetNode = ArrayItem.Get(`${context}/target/node`, this._gltf.nodes, channel.target.node);
1455
- const channelTargetPath = channel.target.path;
1456
- const pathIsWeights = channelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */;
1457
- // Ignore animations that have no animation targets.
1458
- if ((pathIsWeights && !targetNode._numMorphTargets) || (!pathIsWeights && !targetNode._babylonTransformNode)) {
1459
- return Promise.resolve();
1460
- }
1461
- // Don't load node animations if disabled.
1462
- if (!this._parent.loadNodeAnimations && !pathIsWeights && !targetNode._isJoint) {
1463
- return Promise.resolve();
1464
- }
1465
- // async-load the animation sampler to provide the interpolation of the channelTargetPath
1466
- return LazyLoaderAnimationModulePromise.value.then(() => {
1467
- let properties;
1468
- switch (channelTargetPath) {
1469
- case "translation" /* AnimationChannelTargetPath.TRANSLATION */: {
1470
- properties = GetMappingForKey("/nodes/{}/translation")?.interpolation;
1471
- break;
1472
- }
1473
- case "rotation" /* AnimationChannelTargetPath.ROTATION */: {
1474
- properties = GetMappingForKey("/nodes/{}/rotation")?.interpolation;
1475
- break;
1476
- }
1477
- case "scale" /* AnimationChannelTargetPath.SCALE */: {
1478
- properties = GetMappingForKey("/nodes/{}/scale")?.interpolation;
1479
- break;
1480
- }
1481
- case "weights" /* AnimationChannelTargetPath.WEIGHTS */: {
1482
- properties = GetMappingForKey("/nodes/{}/weights")?.interpolation;
1483
- break;
1484
- }
1485
- default: {
1486
- throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);
1487
- }
1488
- }
1489
- // stay safe
1490
- if (!properties) {
1491
- throw new Error(`${context}/target/path: Could not find interpolation properties for target path (${channel.target.path})`);
1492
- }
1493
- const targetInfo = {
1494
- object: targetNode,
1495
- info: properties,
1496
- };
1497
- return this._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
1498
- });
1499
- }
1500
- /**
1501
- * @hidden
1502
- * Loads a glTF animation channel.
1503
- * @param context The context when loading the asset
1504
- * @param animationContext The context of the animation when loading the asset
1505
- * @param animation The glTF animation property
1506
- * @param channel The glTF animation channel property
1507
- * @param targetInfo The glTF target and properties
1508
- * @param onLoad Called for each animation loaded
1509
- * @returns A void promise that resolves when the load is complete
1510
- */
1511
- _loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad) {
1512
- const fps = this.parent.targetFps;
1513
- const invfps = 1 / fps;
1514
- const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);
1515
- return this._loadAnimationSamplerAsync(`${animationContext}/samplers/${channel.sampler}`, sampler).then((data) => {
1516
- let numAnimations = 0;
1517
- const target = targetInfo.object;
1518
- const propertyInfos = targetInfo.info;
1519
- // Extract the corresponding values from the read value.
1520
- // GLTF values may be dispatched to several Babylon properties.
1521
- // For example, baseColorFactor [`r`, `g`, `b`, `a`] is dispatched to
1522
- // - albedoColor as Color3(`r`, `g`, `b`)
1523
- // - alpha as `a`
1524
- for (const propertyInfo of propertyInfos) {
1525
- const stride = propertyInfo.getStride(target);
1526
- const input = data.input;
1527
- const output = data.output;
1528
- const keys = new Array(input.length);
1529
- let outputOffset = 0;
1530
- switch (data.interpolation) {
1531
- case "STEP" /* AnimationSamplerInterpolation.STEP */: {
1532
- for (let index = 0; index < input.length; index++) {
1533
- const value = propertyInfo.getValue(target, output, outputOffset, 1);
1534
- outputOffset += stride;
1535
- keys[index] = {
1536
- frame: input[index] * fps,
1537
- value: value,
1538
- interpolation: 1 /* AnimationKeyInterpolation.STEP */,
1539
- };
1540
- }
1541
- break;
1542
- }
1543
- case "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */: {
1544
- for (let index = 0; index < input.length; index++) {
1545
- const inTangent = propertyInfo.getValue(target, output, outputOffset, invfps);
1546
- outputOffset += stride;
1547
- const value = propertyInfo.getValue(target, output, outputOffset, 1);
1548
- outputOffset += stride;
1549
- const outTangent = propertyInfo.getValue(target, output, outputOffset, invfps);
1550
- outputOffset += stride;
1551
- keys[index] = {
1552
- frame: input[index] * fps,
1553
- inTangent: inTangent,
1554
- value: value,
1555
- outTangent: outTangent,
1556
- };
1557
- }
1558
- break;
1559
- }
1560
- case "LINEAR" /* AnimationSamplerInterpolation.LINEAR */: {
1561
- for (let index = 0; index < input.length; index++) {
1562
- const value = propertyInfo.getValue(target, output, outputOffset, 1);
1563
- outputOffset += stride;
1564
- keys[index] = {
1565
- frame: input[index] * fps,
1566
- value: value,
1567
- };
1568
- }
1569
- break;
1570
- }
1571
- }
1572
- if (outputOffset > 0) {
1573
- const name = `${animation.name || `animation${animation.index}`}_channel${channel.index}_${numAnimations}`;
1574
- const babylonAnimations = propertyInfo.buildAnimations(target, name, fps, keys);
1575
- for (const babylonAnimation of babylonAnimations) {
1576
- numAnimations++;
1577
- babylonAnimation.babylonAnimation.metadata = channel.extras;
1578
- onLoad(babylonAnimation.babylonAnimatable, babylonAnimation.babylonAnimation);
1579
- }
1580
- }
1581
- }
1582
- });
1583
- }
1584
- _loadAnimationSamplerAsync(context, sampler) {
1585
- if (sampler._data) {
1586
- return sampler._data;
1587
- }
1588
- const interpolation = sampler.interpolation || "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
1589
- switch (interpolation) {
1590
- case "STEP" /* AnimationSamplerInterpolation.STEP */:
1591
- case "LINEAR" /* AnimationSamplerInterpolation.LINEAR */:
1592
- case "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */: {
1593
- break;
1594
- }
1595
- default: {
1596
- throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);
1597
- }
1598
- }
1599
- const inputAccessor = ArrayItem.Get(`${context}/input`, this._gltf.accessors, sampler.input);
1600
- const outputAccessor = ArrayItem.Get(`${context}/output`, this._gltf.accessors, sampler.output);
1601
- sampler._data = Promise.all([
1602
- this._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),
1603
- this._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),
1604
- ]).then(([inputData, outputData]) => {
1605
- return {
1606
- input: inputData,
1607
- interpolation: interpolation,
1608
- output: outputData,
1609
- };
1610
- });
1611
- return sampler._data;
1612
- }
1613
- /**
1614
- * Loads a glTF buffer.
1615
- * @param context The context when loading the asset
1616
- * @param buffer The glTF buffer property
1617
- * @param byteOffset The byte offset to use
1618
- * @param byteLength The byte length to use
1619
- * @returns A promise that resolves with the loaded data when the load is complete
1620
- */
1621
- loadBufferAsync(context, buffer, byteOffset, byteLength) {
1622
- const extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
1623
- if (extensionPromise) {
1624
- return extensionPromise;
1625
- }
1626
- if (!buffer._data) {
1627
- if (buffer.uri) {
1628
- buffer._data = this.loadUriAsync(`${context}/uri`, buffer, buffer.uri);
1629
- }
1630
- else {
1631
- if (!this._bin) {
1632
- throw new Error(`${context}: Uri is missing or the binary glTF is missing its binary chunk`);
1633
- }
1634
- buffer._data = this._bin.readAsync(0, buffer.byteLength);
1635
- }
1636
- }
1637
- return buffer._data.then((data) => {
1638
- try {
1639
- return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
1640
- }
1641
- catch (e) {
1642
- throw new Error(`${context}: ${e.message}`, { cause: e });
1643
- }
1644
- });
1645
- }
1646
- /**
1647
- * Loads a glTF buffer view.
1648
- * @param context The context when loading the asset
1649
- * @param bufferView The glTF buffer view property
1650
- * @returns A promise that resolves with the loaded data when the load is complete
1651
- */
1652
- loadBufferViewAsync(context, bufferView) {
1653
- const extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
1654
- if (extensionPromise) {
1655
- return extensionPromise;
1656
- }
1657
- if (bufferView._data) {
1658
- return bufferView._data;
1659
- }
1660
- const buffer = ArrayItem.Get(`${context}/buffer`, this._gltf.buffers, bufferView.buffer);
1661
- bufferView._data = this.loadBufferAsync(`/buffers/${buffer.index}`, buffer, bufferView.byteOffset || 0, bufferView.byteLength);
1662
- return bufferView._data;
1663
- }
1664
- _loadAccessorAsync(context, accessor, constructor) {
1665
- if (accessor._data) {
1666
- return accessor._data;
1667
- }
1668
- const numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
1669
- const byteStride = numComponents * VertexBufferGetTypeByteLength(accessor.componentType);
1670
- const length = numComponents * accessor.count;
1671
- if (accessor.bufferView == undefined) {
1672
- accessor._data = Promise.resolve(new constructor(length));
1673
- }
1674
- else {
1675
- const bufferView = ArrayItem.Get(`${context}/bufferView`, this._gltf.bufferViews, accessor.bufferView);
1676
- accessor._data = this.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {
1677
- if (accessor.componentType === 5126 /* AccessorComponentType.FLOAT */ && !accessor.normalized && (!bufferView.byteStride || bufferView.byteStride === byteStride)) {
1678
- return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
1679
- }
1680
- else {
1681
- const typedArray = new constructor(length);
1682
- VertexBufferForEach(data, accessor.byteOffset || 0, bufferView.byteStride || byteStride, numComponents, accessor.componentType, typedArray.length, accessor.normalized || false, (value, index) => {
1683
- typedArray[index] = value;
1684
- });
1685
- return typedArray;
1686
- }
1687
- });
1688
- }
1689
- if (accessor.sparse) {
1690
- const sparse = accessor.sparse;
1691
- accessor._data = accessor._data.then((data) => {
1692
- const typedArray = data;
1693
- const indicesBufferView = ArrayItem.Get(`${context}/sparse/indices/bufferView`, this._gltf.bufferViews, sparse.indices.bufferView);
1694
- const valuesBufferView = ArrayItem.Get(`${context}/sparse/values/bufferView`, this._gltf.bufferViews, sparse.values.bufferView);
1695
- return Promise.all([
1696
- this.loadBufferViewAsync(`/bufferViews/${indicesBufferView.index}`, indicesBufferView),
1697
- this.loadBufferViewAsync(`/bufferViews/${valuesBufferView.index}`, valuesBufferView),
1698
- ]).then(([indicesData, valuesData]) => {
1699
- const indices = GLTFLoader._GetTypedArray(`${context}/sparse/indices`, sparse.indices.componentType, indicesData, sparse.indices.byteOffset, sparse.count);
1700
- const sparseLength = numComponents * sparse.count;
1701
- let values;
1702
- if (accessor.componentType === 5126 /* AccessorComponentType.FLOAT */ && !accessor.normalized) {
1703
- values = GLTFLoader._GetTypedArray(`${context}/sparse/values`, accessor.componentType, valuesData, sparse.values.byteOffset, sparseLength);
1704
- }
1705
- else {
1706
- const sparseData = GLTFLoader._GetTypedArray(`${context}/sparse/values`, accessor.componentType, valuesData, sparse.values.byteOffset, sparseLength);
1707
- values = new constructor(sparseLength);
1708
- VertexBufferForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, (value, index) => {
1709
- values[index] = value;
1710
- });
1711
- }
1712
- let valuesIndex = 0;
1713
- for (let indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
1714
- let dataIndex = indices[indicesIndex] * numComponents;
1715
- for (let componentIndex = 0; componentIndex < numComponents; componentIndex++) {
1716
- typedArray[dataIndex++] = values[valuesIndex++];
1717
- }
1718
- }
1719
- return typedArray;
1720
- });
1721
- });
1722
- }
1723
- return accessor._data;
1724
- }
1725
- /**
1726
- * @internal
1727
- */
1728
- _loadFloatAccessorAsync(context, accessor) {
1729
- return this._loadAccessorAsync(context, accessor, Float32Array);
1730
- }
1731
- /**
1732
- * @internal
1733
- */
1734
- _loadIndicesAccessorAsync(context, accessor) {
1735
- if (accessor.type !== "SCALAR" /* AccessorType.SCALAR */) {
1736
- throw new Error(`${context}/type: Invalid value ${accessor.type}`);
1737
- }
1738
- if (accessor.componentType !== 5121 /* AccessorComponentType.UNSIGNED_BYTE */ &&
1739
- accessor.componentType !== 5123 /* AccessorComponentType.UNSIGNED_SHORT */ &&
1740
- accessor.componentType !== 5125 /* AccessorComponentType.UNSIGNED_INT */) {
1741
- throw new Error(`${context}/componentType: Invalid value ${accessor.componentType}`);
1742
- }
1743
- if (accessor._data) {
1744
- return accessor._data;
1745
- }
1746
- if (accessor.sparse) {
1747
- const constructor = GLTFLoader._GetTypedArrayConstructor(`${context}/componentType`, accessor.componentType);
1748
- accessor._data = this._loadAccessorAsync(context, accessor, constructor);
1749
- }
1750
- else {
1751
- const bufferView = ArrayItem.Get(`${context}/bufferView`, this._gltf.bufferViews, accessor.bufferView);
1752
- accessor._data = this.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {
1753
- return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
1754
- });
1755
- }
1756
- return accessor._data;
1757
- }
1758
- /**
1759
- * @internal
1760
- */
1761
- _loadVertexBufferViewAsync(bufferView) {
1762
- if (bufferView._babylonBuffer) {
1763
- return bufferView._babylonBuffer;
1764
- }
1765
- const engine = this._babylonScene.getEngine();
1766
- bufferView._babylonBuffer = this.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {
1767
- return new Buffer(engine, data, false);
1768
- });
1769
- return bufferView._babylonBuffer;
1770
- }
1771
- /**
1772
- * @internal
1773
- */
1774
- _loadVertexAccessorAsync(context, accessor, kind) {
1775
- if (accessor._babylonVertexBuffer?.[kind]) {
1776
- return accessor._babylonVertexBuffer[kind];
1777
- }
1778
- if (!accessor._babylonVertexBuffer) {
1779
- accessor._babylonVertexBuffer = {};
1780
- }
1781
- const engine = this._babylonScene.getEngine();
1782
- if (accessor.sparse || accessor.bufferView == undefined) {
1783
- accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then((data) => {
1784
- return new VertexBuffer(engine, data, kind, false);
1785
- });
1786
- }
1787
- else {
1788
- const bufferView = ArrayItem.Get(`${context}/bufferView`, this._gltf.bufferViews, accessor.bufferView);
1789
- accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView).then((babylonBuffer) => {
1790
- const numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
1791
- return new VertexBuffer(engine, babylonBuffer, kind, false, undefined, bufferView.byteStride, undefined, accessor.byteOffset, numComponents, accessor.componentType, accessor.normalized, true, undefined, true);
1792
- });
1793
- }
1794
- return accessor._babylonVertexBuffer[kind];
1795
- }
1796
- _loadMaterialMetallicRoughnessPropertiesAsync(context, properties, babylonMaterial) {
1797
- const promises = new Array();
1798
- const adapter = this._getOrCreateMaterialAdapter(babylonMaterial);
1799
- if (properties) {
1800
- // Set base color and alpha using adapter
1801
- if (properties.baseColorFactor) {
1802
- adapter.baseColor = Color3.FromArray(properties.baseColorFactor);
1803
- adapter.geometryOpacity = properties.baseColorFactor[3];
1804
- }
1805
- else {
1806
- adapter.baseColor = Color3.White();
1807
- }
1808
- // Set metallic and roughness using adapter
1809
- adapter.baseMetalness = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
1810
- adapter.specularRoughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
1811
- if (properties.baseColorTexture) {
1812
- promises.push(this.loadTextureInfoAsync(`${context}/baseColorTexture`, properties.baseColorTexture, (texture) => {
1813
- texture.name = `${babylonMaterial.name} (Base Color)`;
1814
- adapter.baseColorTexture = texture;
1815
- }));
1816
- }
1817
- if (properties.metallicRoughnessTexture) {
1818
- properties.metallicRoughnessTexture.nonColorData = true;
1819
- promises.push(this.loadTextureInfoAsync(`${context}/metallicRoughnessTexture`, properties.metallicRoughnessTexture, (texture) => {
1820
- texture.name = `${babylonMaterial.name} (Metallic Roughness)`;
1821
- adapter.baseMetalnessTexture = texture;
1822
- adapter.specularRoughnessTexture = texture;
1823
- }));
1824
- // Configure texture channel usage using adapter
1825
- adapter.useRoughnessFromMetallicTextureGreen = true;
1826
- adapter.useMetallicFromMetallicTextureBlue = true;
1827
- }
1828
- }
1829
- return Promise.all(promises).then(() => { });
1830
- }
1831
- /**
1832
- * @internal
1833
- */
1834
- async _loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign = () => { }) {
1835
- const extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
1836
- if (extensionPromise) {
1837
- return await extensionPromise;
1838
- }
1839
- material._data = material._data || {};
1840
- let babylonData = material._data[babylonDrawMode];
1841
- if (!babylonData) {
1842
- this.logOpen(`${context} ${material.name || ""}`);
1843
- const babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
1844
- babylonData = {
1845
- babylonMaterial: babylonMaterial,
1846
- babylonMeshes: [],
1847
- promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial),
1848
- };
1849
- material._data[babylonDrawMode] = babylonData;
1850
- GLTFLoader.AddPointerMetadata(babylonMaterial, context);
1851
- this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
1852
- this.logClose();
1853
- }
1854
- if (babylonMesh) {
1855
- babylonData.babylonMeshes.push(babylonMesh);
1856
- babylonMesh.onDisposeObservable.addOnce(() => {
1857
- const index = babylonData.babylonMeshes.indexOf(babylonMesh);
1858
- if (index !== -1) {
1859
- babylonData.babylonMeshes.splice(index, 1);
1860
- }
1861
- });
1862
- }
1863
- assign(babylonData.babylonMaterial);
1864
- await babylonData.promise;
1865
- return babylonData.babylonMaterial;
1866
- }
1867
- /**
1868
- * Selects the appropriate PBR material implementation for a given glTF material.
1869
- * Uses OpenPBR when the material carries a "KHR_materials_openpbr" extension or when
1870
- * the loader-level `useOpenPBR` flag is set; falls back to standard PBR otherwise.
1871
- * @param material The glTF material
1872
- * @returns The matching loaded implementation
1873
- */
1874
- _selectImplForGltfMaterial(material) {
1875
- if (this.parent.useOpenPBR || material.extensions?.["KHR_materials_openpbr"]) {
1876
- const impl = this._pbrMaterialImpls.get("openpbr");
1877
- if (impl) {
1878
- return impl;
1879
- }
1880
- }
1881
- const impl = this._pbrMaterialImpls.get("pbr");
1882
- if (impl) {
1883
- return impl;
1884
- }
1885
- throw new Error("No PBR material implementation loaded");
1886
- }
1887
- /**
1888
- * Returns the default PBR material implementation used when there is no per-material
1889
- * selection context (e.g. when creating the built-in default material for primitives
1890
- * that have no glTF material assigned). Prefers OpenPBR when `useOpenPBR` is set.
1891
- * @returns The default loaded implementation
1892
- */
1893
- _getDefaultImpl() {
1894
- if (this.parent.useOpenPBR) {
1895
- const impl = this._pbrMaterialImpls.get("openpbr");
1896
- if (impl) {
1897
- return impl;
1898
- }
1899
- }
1900
- const impl = this._pbrMaterialImpls.get("pbr") ?? this._pbrMaterialImpls.values().next().value;
1901
- if (impl) {
1902
- return impl;
1903
- }
1904
- throw new Error("No PBR material implementation loaded");
1905
- }
1906
- _createDefaultMaterial(name, babylonDrawMode, impl) {
1907
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1908
- const babylonMaterial = new impl.materialClass(name, this._babylonScene);
1909
- babylonMaterial._parentContainer = this._assetContainer;
1910
- this._babylonScene._blockEntityCollection = false;
1911
- babylonMaterial.fillMode = babylonDrawMode;
1912
- babylonMaterial.transparencyMode = impl.materialClass.MATERIAL_OPAQUE;
1913
- // Create the material adapter and set some default properties.
1914
- // We don't need to wait for the promise to resolve here.
1915
- const adapter = this._getOrCreateMaterialAdapter(babylonMaterial);
1916
- adapter.transparencyAsAlphaCoverage = this._parent.transparencyAsCoverage;
1917
- // Set default metallic and roughness values
1918
- adapter.baseMetalness = 1.0;
1919
- adapter.specularRoughness = 1.0;
1920
- return babylonMaterial;
1921
- }
1922
- /**
1923
- * Creates a Babylon material from a glTF material.
1924
- * @param context The context when loading the asset
1925
- * @param material The glTF material property
1926
- * @param babylonDrawMode The draw mode for the Babylon material
1927
- * @returns The Babylon material
1928
- */
1929
- createMaterial(context, material, babylonDrawMode) {
1930
- const extensionMaterial = this._extensionsCreateMaterial(context, material, babylonDrawMode);
1931
- if (extensionMaterial) {
1932
- return extensionMaterial;
1933
- }
1934
- const name = material.name || `material${material.index}`;
1935
- const babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode, this._selectImplForGltfMaterial(material));
1936
- return babylonMaterial;
1937
- }
1938
- /**
1939
- * Loads properties from a glTF material into a Babylon material.
1940
- * @param context The context when loading the asset
1941
- * @param material The glTF material property
1942
- * @param babylonMaterial The Babylon material
1943
- * @returns A promise that resolves when the load is complete
1944
- */
1945
- loadMaterialPropertiesAsync(context, material, babylonMaterial) {
1946
- const extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
1947
- if (extensionPromise) {
1948
- return extensionPromise;
1949
- }
1950
- const promises = new Array();
1951
- promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
1952
- if (material.pbrMetallicRoughness) {
1953
- promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(`${context}/pbrMetallicRoughness`, material.pbrMetallicRoughness, babylonMaterial));
1954
- }
1955
- this.loadMaterialAlphaProperties(context, material, babylonMaterial);
1956
- return Promise.all(promises).then(() => { });
1957
- }
1958
- /**
1959
- * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
1960
- * @param context The context when loading the asset
1961
- * @param material The glTF material property
1962
- * @param babylonMaterial The Babylon material
1963
- * @returns A promise that resolves when the load is complete
1964
- */
1965
- loadMaterialBasePropertiesAsync(context, material, babylonMaterial) {
1966
- const promises = new Array();
1967
- const adapter = this._getOrCreateMaterialAdapter(babylonMaterial);
1968
- // Set emission color using adapter
1969
- adapter.emissionColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
1970
- // Set double-sided properties using adapter
1971
- if (material.doubleSided) {
1972
- adapter.backFaceCulling = false;
1973
- adapter.twoSidedLighting = true;
1974
- }
1975
- if (material.normalTexture) {
1976
- material.normalTexture.nonColorData = true;
1977
- promises.push(this.loadTextureInfoAsync(`${context}/normalTexture`, material.normalTexture, (texture) => {
1978
- texture.name = `${babylonMaterial.name} (Normal)`;
1979
- adapter.geometryNormalTexture = texture;
1980
- if (material.normalTexture?.scale != undefined) {
1981
- texture.level = material.normalTexture.scale;
1982
- }
1983
- }));
1984
- // Set normal map inversions using adapter
1985
- adapter.setNormalMapInversions(!this._babylonScene.useRightHandedSystem, this._babylonScene.useRightHandedSystem);
1986
- }
1987
- let aoTexture;
1988
- let aoStrength = 1.0;
1989
- let emissionTexture;
1990
- if (material.occlusionTexture) {
1991
- material.occlusionTexture.nonColorData = true;
1992
- promises.push(this.loadTextureInfoAsync(`${context}/occlusionTexture`, material.occlusionTexture, (texture) => {
1993
- texture.name = `${babylonMaterial.name} (Occlusion)`;
1994
- aoTexture = texture;
1995
- }));
1996
- if (material.occlusionTexture.strength != undefined) {
1997
- aoStrength = material.occlusionTexture.strength;
1998
- }
1999
- }
2000
- if (material.emissiveTexture) {
2001
- promises.push(this.loadTextureInfoAsync(`${context}/emissiveTexture`, material.emissiveTexture, (texture) => {
2002
- texture.name = `${babylonMaterial.name} (Emissive)`;
2003
- emissionTexture = texture;
2004
- }));
2005
- }
2006
- return Promise.all(promises).then(() => {
2007
- // Set ambient occlusion and emissive textures using adapter
2008
- if (aoTexture) {
2009
- adapter.ambientOcclusionTexture = aoTexture;
2010
- adapter.ambientOcclusionTextureStrength = aoStrength;
2011
- }
2012
- if (emissionTexture) {
2013
- adapter.emissionColorTexture = emissionTexture;
2014
- }
2015
- });
2016
- }
2017
- /**
2018
- * Loads the alpha properties from a glTF material into a Babylon material.
2019
- * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
2020
- * @param context The context when loading the asset
2021
- * @param material The glTF material property
2022
- * @param babylonMaterial The Babylon material
2023
- */
2024
- loadMaterialAlphaProperties(context, material, babylonMaterial) {
2025
- if (this._pbrMaterialImpls.size === 0) {
2026
- throw new Error(`${context}: Material type not supported`);
2027
- }
2028
- const adapter = this._getOrCreateMaterialAdapter(babylonMaterial);
2029
- const baseColorTexture = adapter.baseColorTexture;
2030
- const alphaMode = material.alphaMode || "OPAQUE" /* MaterialAlphaMode.OPAQUE */;
2031
- switch (alphaMode) {
2032
- case "OPAQUE" /* MaterialAlphaMode.OPAQUE */: {
2033
- babylonMaterial.transparencyMode = Material.MATERIAL_OPAQUE;
2034
- babylonMaterial.alpha = 1.0; // Force alpha to 1.0 for opaque mode.
2035
- break;
2036
- }
2037
- case "MASK" /* MaterialAlphaMode.MASK */: {
2038
- babylonMaterial.transparencyMode = Material.MATERIAL_ALPHATEST;
2039
- adapter.alphaCutOff = material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff;
2040
- if (baseColorTexture) {
2041
- baseColorTexture.hasAlpha = true;
2042
- adapter.useAlphaFromBaseColorTexture = true;
2043
- }
2044
- break;
2045
- }
2046
- case "BLEND" /* MaterialAlphaMode.BLEND */: {
2047
- babylonMaterial.transparencyMode = Material.MATERIAL_ALPHABLEND;
2048
- if (baseColorTexture) {
2049
- baseColorTexture.hasAlpha = true;
2050
- adapter.useAlphaFromBaseColorTexture = true;
2051
- }
2052
- break;
2053
- }
2054
- default: {
2055
- throw new Error(`${context}/alphaMode: Invalid value (${material.alphaMode})`);
2056
- }
2057
- }
2058
- }
2059
- /**
2060
- * Loads a glTF texture info.
2061
- * @param context The context when loading the asset
2062
- * @param textureInfo The glTF texture info property
2063
- * @param assign A function called synchronously after parsing the glTF properties
2064
- * @returns A promise that resolves with the loaded Babylon texture when the load is complete
2065
- */
2066
- loadTextureInfoAsync(context, textureInfo, assign = () => { }) {
2067
- const extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
2068
- if (extensionPromise) {
2069
- return extensionPromise;
2070
- }
2071
- this.logOpen(`${context}`);
2072
- if (textureInfo.texCoord >= 6) {
2073
- throw new Error(`${context}/texCoord: Invalid value (${textureInfo.texCoord})`);
2074
- }
2075
- const texture = ArrayItem.Get(`${context}/index`, this._gltf.textures, textureInfo.index);
2076
- texture._textureInfo = textureInfo;
2077
- const promise = this._loadTextureAsync(`/textures/${textureInfo.index}`, texture, (babylonTexture) => {
2078
- babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
2079
- GLTFLoader.AddPointerMetadata(babylonTexture, context);
2080
- this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
2081
- assign(babylonTexture);
2082
- });
2083
- this.logClose();
2084
- return promise;
2085
- }
2086
- /**
2087
- * @internal
2088
- */
2089
- _loadTextureAsync(context, texture, assign = () => { }) {
2090
- const extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
2091
- if (extensionPromise) {
2092
- return extensionPromise;
2093
- }
2094
- this.logOpen(`${context} ${texture.name || ""}`);
2095
- const sampler = texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(`${context}/sampler`, this._gltf.samplers, texture.sampler);
2096
- const image = ArrayItem.Get(`${context}/source`, this._gltf.images, texture.source);
2097
- const promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
2098
- this.logClose();
2099
- return promise;
2100
- }
2101
- /**
2102
- * @internal
2103
- */
2104
- _createTextureAsync(context, sampler, image, assign = () => { }, textureLoaderOptions, useSRGBBuffer) {
2105
- const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
2106
- const promises = new Array();
2107
- const deferred = new Deferred();
2108
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
2109
- const textureCreationOptions = {
2110
- noMipmap: samplerData.noMipMaps,
2111
- invertY: false,
2112
- samplingMode: samplerData.samplingMode,
2113
- onLoad: () => {
2114
- if (!this._disposed) {
2115
- deferred.resolve();
2116
- }
2117
- },
2118
- onError: (message, exception) => {
2119
- if (!this._disposed) {
2120
- deferred.reject(new Error(`${context}: ${exception && exception.message ? exception.message : message || "Failed to load texture"}`));
2121
- }
2122
- },
2123
- mimeType: image.mimeType ?? GetMimeType(image.uri ?? ""),
2124
- loaderOptions: textureLoaderOptions,
2125
- useSRGBBuffer: !!useSRGBBuffer && this._parent.useSRGBBuffers,
2126
- };
2127
- const babylonTexture = new Texture(null, this._babylonScene, textureCreationOptions);
2128
- babylonTexture._parentContainer = this._assetContainer;
2129
- this._babylonScene._blockEntityCollection = false;
2130
- promises.push(deferred.promise);
2131
- const nonBase64Uri = image.uri && !IsBase64DataUrl(image.uri) ? image.uri : undefined;
2132
- const imageId = nonBase64Uri ?? `${this._fileName}#image${image.index}`;
2133
- promises.push(this.loadImageAsync(`/images/${image.index}`, image).then((data) => {
2134
- const dataUrl = `data:${this._uniqueRootUrl}${imageId}`;
2135
- babylonTexture.updateURL(dataUrl, data);
2136
- // Set the internal texture label.
2137
- const internalTexture = babylonTexture.getInternalTexture();
2138
- if (internalTexture) {
2139
- internalTexture.label = image.name;
2140
- }
2141
- }));
2142
- babylonTexture.wrapU = samplerData.wrapU;
2143
- babylonTexture.wrapV = samplerData.wrapV;
2144
- assign(babylonTexture);
2145
- if (this._parent.useGltfTextureNames) {
2146
- const textureName = image.name || nonBase64Uri || `image${image.index}`;
2147
- babylonTexture.name = textureName;
2148
- }
2149
- return Promise.all(promises).then(() => {
2150
- return babylonTexture;
2151
- });
2152
- }
2153
- _loadSampler(context, sampler) {
2154
- if (!sampler._data) {
2155
- sampler._data = {
2156
- noMipMaps: sampler.minFilter === 9728 /* TextureMinFilter.NEAREST */ || sampler.minFilter === 9729 /* TextureMinFilter.LINEAR */,
2157
- samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
2158
- wrapU: GLTFLoader._GetTextureWrapMode(`${context}/wrapS`, sampler.wrapS),
2159
- wrapV: GLTFLoader._GetTextureWrapMode(`${context}/wrapT`, sampler.wrapT),
2160
- };
2161
- }
2162
- return sampler._data;
2163
- }
2164
- /**
2165
- * Loads a glTF image.
2166
- * @param context The context when loading the asset
2167
- * @param image The glTF image property
2168
- * @returns A promise that resolves with the loaded data when the load is complete
2169
- */
2170
- loadImageAsync(context, image) {
2171
- if (!image._data) {
2172
- this.logOpen(`${context} ${image.name || ""}`);
2173
- if (image.uri) {
2174
- image._data = this.loadUriAsync(`${context}/uri`, image, image.uri);
2175
- }
2176
- else {
2177
- const bufferView = ArrayItem.Get(`${context}/bufferView`, this._gltf.bufferViews, image.bufferView);
2178
- image._data = this.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);
2179
- }
2180
- this.logClose();
2181
- }
2182
- return image._data;
2183
- }
2184
- /**
2185
- * Loads a glTF uri.
2186
- * @param context The context when loading the asset
2187
- * @param property The glTF property associated with the uri
2188
- * @param uri The base64 or relative uri
2189
- * @returns A promise that resolves with the loaded data when the load is complete
2190
- */
2191
- loadUriAsync(context, property, uri) {
2192
- const extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
2193
- if (extensionPromise) {
2194
- return extensionPromise;
2195
- }
2196
- if (!GLTFLoader._ValidateUri(uri)) {
2197
- throw new Error(`${context}: '${uri}' is invalid`);
2198
- }
2199
- if (IsBase64DataUrl(uri)) {
2200
- const data = new Uint8Array(DecodeBase64UrlToBinary(uri));
2201
- this.log(`${context}: Decoded ${uri.substring(0, 64)}... (${data.length} bytes)`);
2202
- return Promise.resolve(data);
2203
- }
2204
- this.log(`${context}: Loading ${uri}`);
2205
- return this._parent.preprocessUrlAsync(this._rootUrl + uri).then((url) => {
2206
- return new Promise((resolve, reject) => {
2207
- this._parent._loadFile(this._babylonScene, url, (data) => {
2208
- if (!this._disposed) {
2209
- this.log(`${context}: Loaded ${uri} (${data.byteLength} bytes)`);
2210
- resolve(new Uint8Array(data));
2211
- }
2212
- }, true, (request) => {
2213
- reject(new LoadFileError(`${context}: Failed to load '${uri}'${request ? ": " + request.status + " " + request.statusText : ""}`, request));
2214
- });
2215
- });
2216
- });
2217
- }
2218
- /**
2219
- * Adds a JSON pointer to the _internalMetadata of the Babylon object at `<object>._internalMetadata.gltf.pointers`.
2220
- * @param babylonObject the Babylon object with _internalMetadata
2221
- * @param pointer the JSON pointer
2222
- */
2223
- static AddPointerMetadata(babylonObject, pointer) {
2224
- babylonObject.metadata = babylonObject.metadata || {};
2225
- const metadata = (babylonObject._internalMetadata = babylonObject._internalMetadata || {});
2226
- const gltf = (metadata.gltf = metadata.gltf || {});
2227
- const pointers = (gltf.pointers = gltf.pointers || []);
2228
- pointers.push(pointer);
2229
- }
2230
- static _GetTextureWrapMode(context, mode) {
2231
- // Set defaults if undefined
2232
- mode = mode == undefined ? 10497 /* TextureWrapMode.REPEAT */ : mode;
2233
- switch (mode) {
2234
- case 33071 /* TextureWrapMode.CLAMP_TO_EDGE */:
2235
- return Texture.CLAMP_ADDRESSMODE;
2236
- case 33648 /* TextureWrapMode.MIRRORED_REPEAT */:
2237
- return Texture.MIRROR_ADDRESSMODE;
2238
- case 10497 /* TextureWrapMode.REPEAT */:
2239
- return Texture.WRAP_ADDRESSMODE;
2240
- default:
2241
- Logger.Warn(`${context}: Invalid value (${mode})`);
2242
- return Texture.WRAP_ADDRESSMODE;
2243
- }
2244
- }
2245
- static _GetTextureSamplingMode(context, sampler) {
2246
- // Set defaults if undefined
2247
- const magFilter = sampler.magFilter == undefined ? 9729 /* TextureMagFilter.LINEAR */ : sampler.magFilter;
2248
- const minFilter = sampler.minFilter == undefined ? 9987 /* TextureMinFilter.LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
2249
- if (magFilter === 9729 /* TextureMagFilter.LINEAR */) {
2250
- switch (minFilter) {
2251
- case 9728 /* TextureMinFilter.NEAREST */:
2252
- return Texture.LINEAR_NEAREST;
2253
- case 9729 /* TextureMinFilter.LINEAR */:
2254
- return Texture.LINEAR_LINEAR;
2255
- case 9984 /* TextureMinFilter.NEAREST_MIPMAP_NEAREST */:
2256
- return Texture.LINEAR_NEAREST_MIPNEAREST;
2257
- case 9985 /* TextureMinFilter.LINEAR_MIPMAP_NEAREST */:
2258
- return Texture.LINEAR_LINEAR_MIPNEAREST;
2259
- case 9986 /* TextureMinFilter.NEAREST_MIPMAP_LINEAR */:
2260
- return Texture.LINEAR_NEAREST_MIPLINEAR;
2261
- case 9987 /* TextureMinFilter.LINEAR_MIPMAP_LINEAR */:
2262
- return Texture.LINEAR_LINEAR_MIPLINEAR;
2263
- default:
2264
- Logger.Warn(`${context}/minFilter: Invalid value (${minFilter})`);
2265
- return Texture.LINEAR_LINEAR_MIPLINEAR;
2266
- }
2267
- }
2268
- else {
2269
- if (magFilter !== 9728 /* TextureMagFilter.NEAREST */) {
2270
- Logger.Warn(`${context}/magFilter: Invalid value (${magFilter})`);
2271
- }
2272
- switch (minFilter) {
2273
- case 9728 /* TextureMinFilter.NEAREST */:
2274
- return Texture.NEAREST_NEAREST;
2275
- case 9729 /* TextureMinFilter.LINEAR */:
2276
- return Texture.NEAREST_LINEAR;
2277
- case 9984 /* TextureMinFilter.NEAREST_MIPMAP_NEAREST */:
2278
- return Texture.NEAREST_NEAREST_MIPNEAREST;
2279
- case 9985 /* TextureMinFilter.LINEAR_MIPMAP_NEAREST */:
2280
- return Texture.NEAREST_LINEAR_MIPNEAREST;
2281
- case 9986 /* TextureMinFilter.NEAREST_MIPMAP_LINEAR */:
2282
- return Texture.NEAREST_NEAREST_MIPLINEAR;
2283
- case 9987 /* TextureMinFilter.LINEAR_MIPMAP_LINEAR */:
2284
- return Texture.NEAREST_LINEAR_MIPLINEAR;
2285
- default:
2286
- Logger.Warn(`${context}/minFilter: Invalid value (${minFilter})`);
2287
- return Texture.NEAREST_NEAREST_MIPNEAREST;
2288
- }
2289
- }
2290
- }
2291
- static _GetTypedArrayConstructor(context, componentType) {
2292
- try {
2293
- return GetTypedArrayConstructor(componentType);
2294
- }
2295
- catch (e) {
2296
- throw new Error(`${context}: ${e.message}`, { cause: e });
2297
- }
2298
- }
2299
- static _GetTypedArray(context, componentType, bufferView, byteOffset, length) {
2300
- const buffer = bufferView.buffer;
2301
- byteOffset = bufferView.byteOffset + (byteOffset || 0);
2302
- const constructor = GLTFLoader._GetTypedArrayConstructor(`${context}/componentType`, componentType);
2303
- const componentTypeLength = VertexBufferGetTypeByteLength(componentType);
2304
- if (byteOffset % componentTypeLength !== 0) {
2305
- // HACK: Copy the buffer if byte offset is not a multiple of component type byte length.
2306
- Logger.Warn(`${context}: Copying buffer as byte offset (${byteOffset}) is not a multiple of component type byte length (${componentTypeLength})`);
2307
- return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
2308
- }
2309
- return new constructor(buffer, byteOffset, length);
2310
- }
2311
- static _GetNumComponents(context, type) {
2312
- switch (type) {
2313
- case "SCALAR":
2314
- return 1;
2315
- case "VEC2":
2316
- return 2;
2317
- case "VEC3":
2318
- return 3;
2319
- case "VEC4":
2320
- return 4;
2321
- case "MAT2":
2322
- return 4;
2323
- case "MAT3":
2324
- return 9;
2325
- case "MAT4":
2326
- return 16;
2327
- }
2328
- throw new Error(`${context}: Invalid type (${type})`);
2329
- }
2330
- static _ValidateUri(uri) {
2331
- return Tools.IsBase64(uri) || uri.indexOf("..") === -1;
2332
- }
2333
- /**
2334
- * @internal
2335
- */
2336
- static _GetDrawMode(context, mode) {
2337
- if (mode == undefined) {
2338
- mode = 4 /* MeshPrimitiveMode.TRIANGLES */;
2339
- }
2340
- switch (mode) {
2341
- case 0 /* MeshPrimitiveMode.POINTS */:
2342
- return Material.PointListDrawMode;
2343
- case 1 /* MeshPrimitiveMode.LINES */:
2344
- return Material.LineListDrawMode;
2345
- case 2 /* MeshPrimitiveMode.LINE_LOOP */:
2346
- return Material.LineLoopDrawMode;
2347
- case 3 /* MeshPrimitiveMode.LINE_STRIP */:
2348
- return Material.LineStripDrawMode;
2349
- case 4 /* MeshPrimitiveMode.TRIANGLES */:
2350
- return Material.TriangleFillMode;
2351
- case 5 /* MeshPrimitiveMode.TRIANGLE_STRIP */:
2352
- return Material.TriangleStripDrawMode;
2353
- case 6 /* MeshPrimitiveMode.TRIANGLE_FAN */:
2354
- return Material.TriangleFanDrawMode;
2355
- }
2356
- throw new Error(`${context}: Invalid mesh primitive mode (${mode})`);
2357
- }
2358
- _compileMaterialsAsync() {
2359
- this._parent._startPerformanceCounter("Compile materials");
2360
- const promises = new Array();
2361
- if (this._gltf.materials) {
2362
- for (const material of this._gltf.materials) {
2363
- if (material._data) {
2364
- for (const babylonDrawMode in material._data) {
2365
- const babylonData = material._data[babylonDrawMode];
2366
- for (const babylonMesh of babylonData.babylonMeshes) {
2367
- // Ensure nonUniformScaling is set if necessary.
2368
- babylonMesh.computeWorldMatrix(true);
2369
- const babylonMaterial = babylonData.babylonMaterial;
2370
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
2371
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
2372
- if (this._parent.useClipPlane) {
2373
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
2374
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
2375
- }
2376
- }
2377
- }
2378
- }
2379
- }
2380
- }
2381
- return Promise.all(promises).then(() => {
2382
- this._parent._endPerformanceCounter("Compile materials");
2383
- });
2384
- }
2385
- _compileShadowGeneratorsAsync() {
2386
- this._parent._startPerformanceCounter("Compile shadow generators");
2387
- const promises = new Array();
2388
- const lights = this._babylonScene.lights;
2389
- for (const light of lights) {
2390
- const generator = light.getShadowGenerator();
2391
- if (generator) {
2392
- promises.push(generator.forceCompilationAsync());
2393
- }
2394
- }
2395
- return Promise.all(promises).then(() => {
2396
- this._parent._endPerformanceCounter("Compile shadow generators");
2397
- });
2398
- }
2399
- _forEachExtensions(action) {
2400
- for (const extension of this._extensions) {
2401
- if (extension.enabled) {
2402
- action(extension);
2403
- }
2404
- }
2405
- }
2406
- _applyExtensions(property, functionName, actionAsync) {
2407
- for (const extension of this._extensions) {
2408
- if (extension.enabled) {
2409
- const id = `${extension.name}.${functionName}`;
2410
- const loaderProperty = property;
2411
- loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
2412
- const activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
2413
- if (!activeLoaderExtensionFunctions[id]) {
2414
- activeLoaderExtensionFunctions[id] = true;
2415
- try {
2416
- const result = actionAsync(extension);
2417
- if (result) {
2418
- return result;
2419
- }
2420
- }
2421
- finally {
2422
- delete activeLoaderExtensionFunctions[id];
2423
- }
2424
- }
2425
- }
2426
- }
2427
- return null;
2428
- }
2429
- _extensionsOnLoading() {
2430
- this._forEachExtensions((extension) => extension.onLoading && extension.onLoading());
2431
- }
2432
- _extensionsOnReady() {
2433
- this._forEachExtensions((extension) => extension.onReady && extension.onReady());
2434
- }
2435
- _extensionsLoadSceneAsync(context, scene) {
2436
- return this._applyExtensions(scene, "loadScene", (extension) => extension.loadSceneAsync && extension.loadSceneAsync(context, scene));
2437
- }
2438
- _extensionsLoadNodeAsync(context, node, assign) {
2439
- return this._applyExtensions(node, "loadNode", (extension) => extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign));
2440
- }
2441
- _extensionsLoadCameraAsync(context, camera, assign) {
2442
- return this._applyExtensions(camera, "loadCamera", (extension) => extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign));
2443
- }
2444
- _extensionsLoadVertexDataAsync(context, primitive, babylonMesh) {
2445
- return this._applyExtensions(primitive, "loadVertexData", (extension) => extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh));
2446
- }
2447
- _extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign) {
2448
- return this._applyExtensions(primitive, "loadMeshPrimitive", (extension) => extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign));
2449
- }
2450
- _extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign) {
2451
- return this._applyExtensions(material, "loadMaterial", (extension) => extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign));
2452
- }
2453
- _extensionsCreateMaterial(context, material, babylonDrawMode) {
2454
- return this._applyExtensions(material, "createMaterial", (extension) => extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode));
2455
- }
2456
- _extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial) {
2457
- return this._applyExtensions(material, "loadMaterialProperties", (extension) => extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial));
2458
- }
2459
- _extensionsLoadTextureInfoAsync(context, textureInfo, assign) {
2460
- return this._applyExtensions(textureInfo, "loadTextureInfo", (extension) => extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign));
2461
- }
2462
- _extensionsLoadTextureAsync(context, texture, assign) {
2463
- return this._applyExtensions(texture, "loadTexture", (extension) => extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign));
2464
- }
2465
- _extensionsLoadAnimationAsync(context, animation) {
2466
- return this._applyExtensions(animation, "loadAnimation", (extension) => extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation));
2467
- }
2468
- _extensionsLoadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
2469
- return this._applyExtensions(animation, "loadAnimationChannel", (extension) => extension._loadAnimationChannelAsync && extension._loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad));
2470
- }
2471
- _extensionsLoadSkinAsync(context, node, skin) {
2472
- return this._applyExtensions(skin, "loadSkin", (extension) => extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin));
2473
- }
2474
- _extensionsLoadUriAsync(context, property, uri) {
2475
- return this._applyExtensions(property, "loadUri", (extension) => extension._loadUriAsync && extension._loadUriAsync(context, property, uri));
2476
- }
2477
- _extensionsLoadBufferViewAsync(context, bufferView) {
2478
- return this._applyExtensions(bufferView, "loadBufferView", (extension) => extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView));
2479
- }
2480
- _extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength) {
2481
- return this._applyExtensions(buffer, "loadBuffer", (extension) => extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength));
2482
- }
2483
- /**
2484
- * Helper method called by a loader extension to load an glTF extension.
2485
- * @param context The context when loading the asset
2486
- * @param property The glTF property to load the extension from
2487
- * @param extensionName The name of the extension to load
2488
- * @param actionAsync The action to run
2489
- * @returns The promise returned by actionAsync or null if the extension does not exist
2490
- */
2491
- // eslint-disable-next-line @typescript-eslint/naming-convention
2492
- static LoadExtensionAsync(context, property, extensionName, actionAsync) {
2493
- if (!property.extensions) {
2494
- return null;
2495
- }
2496
- const extensions = property.extensions;
2497
- const extension = extensions[extensionName];
2498
- if (!extension) {
2499
- return null;
2500
- }
2501
- return actionAsync(`${context}/extensions/${extensionName}`, extension);
2502
- }
2503
- /**
2504
- * Helper method called by a loader extension to load a glTF extra.
2505
- * @param context The context when loading the asset
2506
- * @param property The glTF property to load the extra from
2507
- * @param extensionName The name of the extension to load
2508
- * @param actionAsync The action to run
2509
- * @returns The promise returned by actionAsync or null if the extra does not exist
2510
- */
2511
- // eslint-disable-next-line @typescript-eslint/naming-convention
2512
- static LoadExtraAsync(context, property, extensionName, actionAsync) {
2513
- if (!property.extras) {
2514
- return null;
2515
- }
2516
- const extras = property.extras;
2517
- const extra = extras[extensionName];
2518
- if (!extra) {
2519
- return null;
2520
- }
2521
- return actionAsync(`${context}/extras/${extensionName}`, extra);
2522
- }
2523
- /**
2524
- * Checks for presence of an extension.
2525
- * @param name The name of the extension to check
2526
- * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
2527
- */
2528
- isExtensionUsed(name) {
2529
- return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
2530
- }
2531
- /**
2532
- * Increments the indentation level and logs a message.
2533
- * @param message The message to log
2534
- */
2535
- logOpen(message) {
2536
- this._parent._logOpen(message);
2537
- }
2538
- /**
2539
- * Decrements the indentation level.
2540
- */
2541
- logClose() {
2542
- this._parent._logClose();
2543
- }
2544
- /**
2545
- * Logs a message
2546
- * @param message The message to log
2547
- */
2548
- log(message) {
2549
- this._parent._log(message);
2550
- }
2551
- /**
2552
- * Starts a performance counter.
2553
- * @param counterName The name of the performance counter
2554
- */
2555
- startPerformanceCounter(counterName) {
2556
- this._parent._startPerformanceCounter(counterName);
2557
- }
2558
- /**
2559
- * Ends a performance counter.
2560
- * @param counterName The name of the performance counter
2561
- */
2562
- endPerformanceCounter(counterName) {
2563
- this._parent._endPerformanceCounter(counterName);
2564
- }
2565
- }
2566
- /**
2567
- * The default glTF sampler.
2568
- */
2569
- GLTFLoader.DefaultSampler = { index: -1 };
2570
- GLTFFileLoader._CreateGLTF2Loader = (parent) => new GLTFLoader(parent);
1
+ export * from "./glTFLoader.pure.js";
2
+ import { RegisterGLTF2Loader } from "./glTFLoader.pure.js";
3
+ import { RegisterGLTFFileLoader } from "../glTFFileLoader.pure.js";
4
+ RegisterGLTF2Loader();
5
+ // Auto-register the .gltf/.glb SceneLoader plugin so that importing
6
+ // "@babylonjs/loaders/glTF/2.0" restores the pre-9.15 behavior of making
7
+ // SceneLoader able to load glTF 2.0 assets. This registers the version-aware
8
+ // GLTFFileLoader plugin only; it does not pull in the legacy glTF 1.0 loader.
9
+ RegisterGLTFFileLoader();
2571
10
  //# sourceMappingURL=glTFLoader.js.map