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