@onerjs/loaders 8.53.5 → 8.53.7

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