@babylonjs/loaders 9.13.0 → 9.15.0

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