@onerjs/loaders 8.23.1

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 (280) hide show
  1. package/OBJ/index.d.ts +4 -0
  2. package/OBJ/index.js +5 -0
  3. package/OBJ/index.js.map +1 -0
  4. package/OBJ/mtlFileLoader.d.ts +41 -0
  5. package/OBJ/mtlFileLoader.js +231 -0
  6. package/OBJ/mtlFileLoader.js.map +1 -0
  7. package/OBJ/objFileLoader.d.ts +136 -0
  8. package/OBJ/objFileLoader.js +318 -0
  9. package/OBJ/objFileLoader.js.map +1 -0
  10. package/OBJ/objFileLoader.metadata.d.ts +4 -0
  11. package/OBJ/objFileLoader.metadata.js +5 -0
  12. package/OBJ/objFileLoader.metadata.js.map +1 -0
  13. package/OBJ/objLoadingOptions.d.ts +47 -0
  14. package/OBJ/objLoadingOptions.js +2 -0
  15. package/OBJ/objLoadingOptions.js.map +1 -0
  16. package/OBJ/solidParser.d.ts +174 -0
  17. package/OBJ/solidParser.js +862 -0
  18. package/OBJ/solidParser.js.map +1 -0
  19. package/SPLAT/index.d.ts +2 -0
  20. package/SPLAT/index.js +4 -0
  21. package/SPLAT/index.js.map +1 -0
  22. package/SPLAT/splatFileLoader.d.ts +88 -0
  23. package/SPLAT/splatFileLoader.js +562 -0
  24. package/SPLAT/splatFileLoader.js.map +1 -0
  25. package/SPLAT/splatFileLoader.metadata.d.ts +14 -0
  26. package/SPLAT/splatFileLoader.metadata.js +12 -0
  27. package/SPLAT/splatFileLoader.metadata.js.map +1 -0
  28. package/SPLAT/splatLoadingOptions.d.ts +13 -0
  29. package/SPLAT/splatLoadingOptions.js +2 -0
  30. package/SPLAT/splatLoadingOptions.js.map +1 -0
  31. package/STL/index.d.ts +1 -0
  32. package/STL/index.js +2 -0
  33. package/STL/index.js.map +1 -0
  34. package/STL/stlFileLoader.d.ts +78 -0
  35. package/STL/stlFileLoader.js +239 -0
  36. package/STL/stlFileLoader.js.map +1 -0
  37. package/STL/stlFileLoader.metadata.d.ts +8 -0
  38. package/STL/stlFileLoader.metadata.js +8 -0
  39. package/STL/stlFileLoader.metadata.js.map +1 -0
  40. package/bvh/bvhFileLoader.d.ts +69 -0
  41. package/bvh/bvhFileLoader.js +133 -0
  42. package/bvh/bvhFileLoader.js.map +1 -0
  43. package/bvh/bvhFileLoader.metadata.d.ts +8 -0
  44. package/bvh/bvhFileLoader.metadata.js +8 -0
  45. package/bvh/bvhFileLoader.metadata.js.map +1 -0
  46. package/bvh/bvhLoader.d.ts +14 -0
  47. package/bvh/bvhLoader.js +329 -0
  48. package/bvh/bvhLoader.js.map +1 -0
  49. package/bvh/bvhLoadingOptions.d.ts +9 -0
  50. package/bvh/bvhLoadingOptions.js +2 -0
  51. package/bvh/bvhLoadingOptions.js.map +1 -0
  52. package/bvh/index.d.ts +2 -0
  53. package/bvh/index.js +4 -0
  54. package/bvh/index.js.map +1 -0
  55. package/bvh/license.md +21 -0
  56. package/dynamic.d.ts +5 -0
  57. package/dynamic.js +57 -0
  58. package/dynamic.js.map +1 -0
  59. package/glTF/1.0/glTFBinaryExtension.d.ts +16 -0
  60. package/glTF/1.0/glTFBinaryExtension.js +65 -0
  61. package/glTF/1.0/glTFBinaryExtension.js.map +1 -0
  62. package/glTF/1.0/glTFLoader.d.ts +144 -0
  63. package/glTF/1.0/glTFLoader.js +1841 -0
  64. package/glTF/1.0/glTFLoader.js.map +1 -0
  65. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -0
  66. package/glTF/1.0/glTFLoaderInterfaces.js +96 -0
  67. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -0
  68. package/glTF/1.0/glTFLoaderUtils.d.ts +71 -0
  69. package/glTF/1.0/glTFLoaderUtils.js +255 -0
  70. package/glTF/1.0/glTFLoaderUtils.js.map +1 -0
  71. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +13 -0
  72. package/glTF/1.0/glTFMaterialsCommonExtension.js +131 -0
  73. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -0
  74. package/glTF/1.0/index.d.ts +5 -0
  75. package/glTF/1.0/index.js +6 -0
  76. package/glTF/1.0/index.js.map +1 -0
  77. package/glTF/2.0/Extensions/EXT_lights_ies.d.ts +41 -0
  78. package/glTF/2.0/Extensions/EXT_lights_ies.js +84 -0
  79. package/glTF/2.0/Extensions/EXT_lights_ies.js.map +1 -0
  80. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +48 -0
  81. package/glTF/2.0/Extensions/EXT_lights_image_based.js +116 -0
  82. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -0
  83. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.d.ts +43 -0
  84. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +69 -0
  85. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +1 -0
  86. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +39 -0
  87. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +82 -0
  88. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -0
  89. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +39 -0
  90. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +51 -0
  91. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -0
  92. package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +34 -0
  93. package/glTF/2.0/Extensions/EXT_texture_avif.js +39 -0
  94. package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -0
  95. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +33 -0
  96. package/glTF/2.0/Extensions/EXT_texture_webp.js +38 -0
  97. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -0
  98. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +48 -0
  99. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +63 -0
  100. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -0
  101. package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +47 -0
  102. package/glTF/2.0/Extensions/KHR_animation_pointer.data.d.ts +1 -0
  103. package/glTF/2.0/Extensions/KHR_animation_pointer.data.js +239 -0
  104. package/glTF/2.0/Extensions/KHR_animation_pointer.data.js.map +1 -0
  105. package/glTF/2.0/Extensions/KHR_animation_pointer.js +78 -0
  106. package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -0
  107. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +47 -0
  108. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +93 -0
  109. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
  110. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.d.ts +352 -0
  111. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js +1700 -0
  112. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js.map +1 -0
  113. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.d.ts +33 -0
  114. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.js +20 -0
  115. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.js.map +1 -0
  116. package/glTF/2.0/Extensions/KHR_interactivity/index.d.ts +3 -0
  117. package/glTF/2.0/Extensions/KHR_interactivity/index.js +4 -0
  118. package/glTF/2.0/Extensions/KHR_interactivity/index.js.map +1 -0
  119. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.d.ts +70 -0
  120. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js +450 -0
  121. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js.map +1 -0
  122. package/glTF/2.0/Extensions/KHR_interactivity.d.ts +38 -0
  123. package/glTF/2.0/Extensions/KHR_interactivity.js +151 -0
  124. package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -0
  125. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -0
  126. package/glTF/2.0/Extensions/KHR_lights_punctual.js +92 -0
  127. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -0
  128. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +42 -0
  129. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +61 -0
  130. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -0
  131. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +43 -0
  132. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -0
  133. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -0
  134. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +43 -0
  135. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +95 -0
  136. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -0
  137. package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +43 -0
  138. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +60 -0
  139. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -0
  140. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +42 -0
  141. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +52 -0
  142. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
  143. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +46 -0
  144. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -0
  145. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -0
  146. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +42 -0
  147. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +71 -0
  148. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -0
  149. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +42 -0
  150. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +81 -0
  151. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -0
  152. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +43 -0
  153. package/glTF/2.0/Extensions/KHR_materials_sheen.js +85 -0
  154. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -0
  155. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +42 -0
  156. package/glTF/2.0/Extensions/KHR_materials_specular.js +85 -0
  157. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -0
  158. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +42 -0
  159. package/glTF/2.0/Extensions/KHR_materials_transmission.js +306 -0
  160. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -0
  161. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +42 -0
  162. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -0
  163. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -0
  164. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +112 -0
  165. package/glTF/2.0/Extensions/KHR_materials_variants.js +263 -0
  166. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -0
  167. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +43 -0
  168. package/glTF/2.0/Extensions/KHR_materials_volume.js +86 -0
  169. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
  170. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +29 -0
  171. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -0
  172. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -0
  173. package/glTF/2.0/Extensions/KHR_node_hoverability.d.ts +31 -0
  174. package/glTF/2.0/Extensions/KHR_node_hoverability.js +190 -0
  175. package/glTF/2.0/Extensions/KHR_node_hoverability.js.map +1 -0
  176. package/glTF/2.0/Extensions/KHR_node_selectability.d.ts +30 -0
  177. package/glTF/2.0/Extensions/KHR_node_selectability.js +124 -0
  178. package/glTF/2.0/Extensions/KHR_node_selectability.js.map +1 -0
  179. package/glTF/2.0/Extensions/KHR_node_visibility.d.ts +30 -0
  180. package/glTF/2.0/Extensions/KHR_node_visibility.js +69 -0
  181. package/glTF/2.0/Extensions/KHR_node_visibility.js.map +1 -0
  182. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +33 -0
  183. package/glTF/2.0/Extensions/KHR_texture_basisu.js +38 -0
  184. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -0
  185. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +37 -0
  186. package/glTF/2.0/Extensions/KHR_texture_transform.js +59 -0
  187. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -0
  188. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +39 -0
  189. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +48 -0
  190. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -0
  191. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +56 -0
  192. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +227 -0
  193. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -0
  194. package/glTF/2.0/Extensions/MSFT_lod.d.ts +104 -0
  195. package/glTF/2.0/Extensions/MSFT_lod.js +338 -0
  196. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -0
  197. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +27 -0
  198. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +41 -0
  199. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -0
  200. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +27 -0
  201. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +42 -0
  202. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -0
  203. package/glTF/2.0/Extensions/dynamic.d.ts +4 -0
  204. package/glTF/2.0/Extensions/dynamic.js +156 -0
  205. package/glTF/2.0/Extensions/dynamic.js.map +1 -0
  206. package/glTF/2.0/Extensions/gltfPathToObjectConverter.d.ts +45 -0
  207. package/glTF/2.0/Extensions/gltfPathToObjectConverter.js +101 -0
  208. package/glTF/2.0/Extensions/gltfPathToObjectConverter.js.map +1 -0
  209. package/glTF/2.0/Extensions/index.d.ts +39 -0
  210. package/glTF/2.0/Extensions/index.js +41 -0
  211. package/glTF/2.0/Extensions/index.js.map +1 -0
  212. package/glTF/2.0/Extensions/objectModelMapping.d.ts +289 -0
  213. package/glTF/2.0/Extensions/objectModelMapping.js +828 -0
  214. package/glTF/2.0/Extensions/objectModelMapping.js.map +1 -0
  215. package/glTF/2.0/glTFLoader.d.ts +429 -0
  216. package/glTF/2.0/glTFLoader.js +2408 -0
  217. package/glTF/2.0/glTFLoader.js.map +1 -0
  218. package/glTF/2.0/glTFLoaderAnimation.d.ts +42 -0
  219. package/glTF/2.0/glTFLoaderAnimation.js +80 -0
  220. package/glTF/2.0/glTFLoaderAnimation.js.map +1 -0
  221. package/glTF/2.0/glTFLoaderExtension.d.ts +165 -0
  222. package/glTF/2.0/glTFLoaderExtension.js +2 -0
  223. package/glTF/2.0/glTFLoaderExtension.js.map +1 -0
  224. package/glTF/2.0/glTFLoaderExtensionRegistry.d.ts +25 -0
  225. package/glTF/2.0/glTFLoaderExtensionRegistry.js +33 -0
  226. package/glTF/2.0/glTFLoaderExtensionRegistry.js.map +1 -0
  227. package/glTF/2.0/glTFLoaderInterfaces.d.ts +257 -0
  228. package/glTF/2.0/glTFLoaderInterfaces.js +2 -0
  229. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -0
  230. package/glTF/2.0/index.d.ts +6 -0
  231. package/glTF/2.0/index.js +8 -0
  232. package/glTF/2.0/index.js.map +1 -0
  233. package/glTF/glTFFileLoader.d.ts +516 -0
  234. package/glTF/glTFFileLoader.js +968 -0
  235. package/glTF/glTFFileLoader.js.map +1 -0
  236. package/glTF/glTFFileLoader.metadata.d.ts +15 -0
  237. package/glTF/glTFFileLoader.metadata.js +18 -0
  238. package/glTF/glTFFileLoader.metadata.js.map +1 -0
  239. package/glTF/glTFValidation.d.ts +29 -0
  240. package/glTF/glTFValidation.js +126 -0
  241. package/glTF/glTFValidation.js.map +1 -0
  242. package/glTF/index.d.ts +5 -0
  243. package/glTF/index.js +7 -0
  244. package/glTF/index.js.map +1 -0
  245. package/index.d.ts +5 -0
  246. package/index.js +7 -0
  247. package/index.js.map +1 -0
  248. package/legacy/legacy-bvhFileLoader.d.ts +1 -0
  249. package/legacy/legacy-bvhFileLoader.js +16 -0
  250. package/legacy/legacy-bvhFileLoader.js.map +1 -0
  251. package/legacy/legacy-glTF.d.ts +2 -0
  252. package/legacy/legacy-glTF.js +19 -0
  253. package/legacy/legacy-glTF.js.map +1 -0
  254. package/legacy/legacy-glTF1.d.ts +2 -0
  255. package/legacy/legacy-glTF1.js +16 -0
  256. package/legacy/legacy-glTF1.js.map +1 -0
  257. package/legacy/legacy-glTF1FileLoader.d.ts +2 -0
  258. package/legacy/legacy-glTF1FileLoader.js +4 -0
  259. package/legacy/legacy-glTF1FileLoader.js.map +1 -0
  260. package/legacy/legacy-glTF2.d.ts +2 -0
  261. package/legacy/legacy-glTF2.js +35 -0
  262. package/legacy/legacy-glTF2.js.map +1 -0
  263. package/legacy/legacy-glTF2FileLoader.d.ts +2 -0
  264. package/legacy/legacy-glTF2FileLoader.js +4 -0
  265. package/legacy/legacy-glTF2FileLoader.js.map +1 -0
  266. package/legacy/legacy-glTFFileLoader.d.ts +3 -0
  267. package/legacy/legacy-glTFFileLoader.js +5 -0
  268. package/legacy/legacy-glTFFileLoader.js.map +1 -0
  269. package/legacy/legacy-objFileLoader.d.ts +1 -0
  270. package/legacy/legacy-objFileLoader.js +16 -0
  271. package/legacy/legacy-objFileLoader.js.map +1 -0
  272. package/legacy/legacy-stlFileLoader.d.ts +1 -0
  273. package/legacy/legacy-stlFileLoader.js +16 -0
  274. package/legacy/legacy-stlFileLoader.js.map +1 -0
  275. package/legacy/legacy.d.ts +7 -0
  276. package/legacy/legacy.js +10 -0
  277. package/legacy/legacy.js.map +1 -0
  278. package/license.md +71 -0
  279. package/package.json +49 -0
  280. package/readme.md +23 -0
@@ -0,0 +1,1841 @@
1
+ import { EParameterType, ETextureFilterType, ECullingType, EBlendingFunction, EShaderType } from "./glTFLoaderInterfaces.js";
2
+ import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector.js";
3
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
4
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
5
+ import { Camera } from "@babylonjs/core/Cameras/camera.js";
6
+ import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera.js";
7
+ import { Animation } from "@babylonjs/core/Animations/animation.js";
8
+ import { Bone } from "@babylonjs/core/Bones/bone.js";
9
+ import { Skeleton } from "@babylonjs/core/Bones/skeleton.js";
10
+ import { Effect } from "@babylonjs/core/Materials/effect.js";
11
+ import { Material } from "@babylonjs/core/Materials/material.js";
12
+ import { MultiMaterial } from "@babylonjs/core/Materials/multiMaterial.js";
13
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
14
+ import { ShaderMaterial } from "@babylonjs/core/Materials/shaderMaterial.js";
15
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
16
+ import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData.js";
17
+ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
18
+ import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
19
+ import { SubMesh } from "@babylonjs/core/Meshes/subMesh.js";
20
+ import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
21
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
22
+ import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight.js";
23
+ import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight.js";
24
+ import { PointLight } from "@babylonjs/core/Lights/pointLight.js";
25
+ import { SpotLight } from "@babylonjs/core/Lights/spotLight.js";
26
+ import { GLTFUtils } from "./glTFLoaderUtils.js";
27
+ import { GLTFFileLoader } from "../glTFFileLoader.js";
28
+ import { Constants } from "@babylonjs/core/Engines/constants.js";
29
+ /**
30
+ * Tokenizer. Used for shaders compatibility
31
+ * Automatically map world, view, projection, worldViewProjection, attributes and so on
32
+ */
33
+ // eslint-disable-next-line @typescript-eslint/naming-convention
34
+ var ETokenType;
35
+ (function (ETokenType) {
36
+ ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
37
+ ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
38
+ ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
39
+ })(ETokenType || (ETokenType = {}));
40
+ class Tokenizer {
41
+ constructor(toParse) {
42
+ this._pos = 0;
43
+ this.currentToken = ETokenType.UNKNOWN;
44
+ this.currentIdentifier = "";
45
+ this.currentString = "";
46
+ this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
47
+ this._toParse = toParse;
48
+ this._maxPos = toParse.length;
49
+ }
50
+ getNextToken() {
51
+ if (this.isEnd()) {
52
+ return ETokenType.END_OF_INPUT;
53
+ }
54
+ this.currentString = this.read();
55
+ this.currentToken = ETokenType.UNKNOWN;
56
+ if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
57
+ this.currentToken = ETokenType.IDENTIFIER;
58
+ this.currentIdentifier = this.currentString;
59
+ while (!this.isEnd() && (this.isLetterOrDigitPattern.test((this.currentString = this.peek())) || this.currentString === "_")) {
60
+ this.currentIdentifier += this.currentString;
61
+ this.forward();
62
+ }
63
+ }
64
+ return this.currentToken;
65
+ }
66
+ peek() {
67
+ return this._toParse[this._pos];
68
+ }
69
+ read() {
70
+ return this._toParse[this._pos++];
71
+ }
72
+ forward() {
73
+ this._pos++;
74
+ }
75
+ isEnd() {
76
+ return this._pos >= this._maxPos;
77
+ }
78
+ }
79
+ /**
80
+ * Values
81
+ */
82
+ // eslint-disable-next-line @typescript-eslint/naming-convention
83
+ const glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
84
+ const BabylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
85
+ // eslint-disable-next-line @typescript-eslint/naming-convention
86
+ const glTFAnimationPaths = ["translation", "rotation", "scale"];
87
+ const BabylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
88
+ /**
89
+ * Parse
90
+ * @param parsedBuffers
91
+ * @param gltfRuntime
92
+ */
93
+ const ParseBuffers = (parsedBuffers, gltfRuntime) => {
94
+ for (const buf in parsedBuffers) {
95
+ const parsedBuffer = parsedBuffers[buf];
96
+ gltfRuntime.buffers[buf] = parsedBuffer;
97
+ gltfRuntime.buffersCount++;
98
+ }
99
+ };
100
+ const ParseShaders = (parsedShaders, gltfRuntime) => {
101
+ for (const sha in parsedShaders) {
102
+ const parsedShader = parsedShaders[sha];
103
+ gltfRuntime.shaders[sha] = parsedShader;
104
+ gltfRuntime.shaderscount++;
105
+ }
106
+ };
107
+ const ParseObject = (parsedObjects, runtimeProperty, gltfRuntime) => {
108
+ for (const object in parsedObjects) {
109
+ const parsedObject = parsedObjects[object];
110
+ gltfRuntime[runtimeProperty][object] = parsedObject;
111
+ }
112
+ };
113
+ /**
114
+ * Utils
115
+ * @param buffer
116
+ */
117
+ const NormalizeUVs = (buffer) => {
118
+ if (!buffer) {
119
+ return;
120
+ }
121
+ for (let i = 0; i < buffer.length / 2; i++) {
122
+ buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
123
+ }
124
+ };
125
+ const GetAttribute = (attributeParameter) => {
126
+ if (attributeParameter.semantic === "NORMAL") {
127
+ return "normal";
128
+ }
129
+ else if (attributeParameter.semantic === "POSITION") {
130
+ return "position";
131
+ }
132
+ else if (attributeParameter.semantic === "JOINT") {
133
+ return "matricesIndices";
134
+ }
135
+ else if (attributeParameter.semantic === "WEIGHT") {
136
+ return "matricesWeights";
137
+ }
138
+ else if (attributeParameter.semantic === "COLOR") {
139
+ return "color";
140
+ }
141
+ else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
142
+ const channel = Number(attributeParameter.semantic.split("_")[1]);
143
+ return "uv" + (channel === 0 ? "" : channel + 1);
144
+ }
145
+ return null;
146
+ };
147
+ /**
148
+ * Loads and creates animations
149
+ * @param gltfRuntime
150
+ */
151
+ const LoadAnimations = (gltfRuntime) => {
152
+ for (const anim in gltfRuntime.animations) {
153
+ const animation = gltfRuntime.animations[anim];
154
+ if (!animation.channels || !animation.samplers) {
155
+ continue;
156
+ }
157
+ let lastAnimation = null;
158
+ for (let i = 0; i < animation.channels.length; i++) {
159
+ // Get parameters and load buffers
160
+ const channel = animation.channels[i];
161
+ const sampler = animation.samplers[channel.sampler];
162
+ if (!sampler) {
163
+ continue;
164
+ }
165
+ let inputData = null;
166
+ let outputData = null;
167
+ if (animation.parameters) {
168
+ inputData = animation.parameters[sampler.input];
169
+ outputData = animation.parameters[sampler.output];
170
+ }
171
+ else {
172
+ inputData = sampler.input;
173
+ outputData = sampler.output;
174
+ }
175
+ const bufferInput = GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
176
+ const bufferOutput = GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
177
+ const targetId = channel.target.id;
178
+ let targetNode = gltfRuntime.scene.getNodeById(targetId);
179
+ if (targetNode === null) {
180
+ targetNode = gltfRuntime.scene.getNodeByName(targetId);
181
+ }
182
+ if (targetNode === null) {
183
+ Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetId + " to attach to");
184
+ continue;
185
+ }
186
+ const isBone = targetNode instanceof Bone;
187
+ // Get target path (position, rotation or scaling)
188
+ let targetPath = channel.target.path;
189
+ const targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
190
+ if (targetPathIndex !== -1) {
191
+ targetPath = BabylonAnimationPaths[targetPathIndex];
192
+ }
193
+ // Determine animation type
194
+ let animationType = Animation.ANIMATIONTYPE_MATRIX;
195
+ if (!isBone) {
196
+ if (targetPath === "rotationQuaternion") {
197
+ animationType = Animation.ANIMATIONTYPE_QUATERNION;
198
+ targetNode.rotationQuaternion = new Quaternion();
199
+ }
200
+ else {
201
+ animationType = Animation.ANIMATIONTYPE_VECTOR3;
202
+ }
203
+ }
204
+ // Create animation and key frames
205
+ let babylonAnimation = null;
206
+ const keys = [];
207
+ let arrayOffset = 0;
208
+ let modifyKey = false;
209
+ if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
210
+ babylonAnimation = lastAnimation;
211
+ modifyKey = true;
212
+ }
213
+ if (!modifyKey) {
214
+ gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
215
+ babylonAnimation = new Animation(anim, isBone ? "_matrix" : targetPath, 1, animationType, Animation.ANIMATIONLOOPMODE_CYCLE);
216
+ gltfRuntime.scene._blockEntityCollection = false;
217
+ }
218
+ // For each frame
219
+ for (let j = 0; j < bufferInput.length; j++) {
220
+ let value = null;
221
+ if (targetPath === "rotationQuaternion") {
222
+ // VEC4
223
+ value = Quaternion.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
224
+ arrayOffset += 4;
225
+ }
226
+ else {
227
+ // Position and scaling are VEC3
228
+ value = Vector3.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
229
+ arrayOffset += 3;
230
+ }
231
+ if (isBone) {
232
+ const bone = targetNode;
233
+ let translation = Vector3.Zero();
234
+ let rotationQuaternion = new Quaternion();
235
+ let scaling = Vector3.Zero();
236
+ // Warning on decompose
237
+ let mat = bone.getBaseMatrix();
238
+ if (modifyKey && lastAnimation) {
239
+ mat = lastAnimation.getKeys()[j].value;
240
+ }
241
+ mat.decompose(scaling, rotationQuaternion, translation);
242
+ if (targetPath === "position") {
243
+ translation = value;
244
+ }
245
+ else if (targetPath === "rotationQuaternion") {
246
+ rotationQuaternion = value;
247
+ }
248
+ else {
249
+ scaling = value;
250
+ }
251
+ value = Matrix.Compose(scaling, rotationQuaternion, translation);
252
+ }
253
+ if (!modifyKey) {
254
+ keys.push({
255
+ frame: bufferInput[j],
256
+ value: value,
257
+ });
258
+ }
259
+ else if (lastAnimation) {
260
+ lastAnimation.getKeys()[j].value = value;
261
+ }
262
+ }
263
+ // Finish
264
+ if (!modifyKey && babylonAnimation) {
265
+ babylonAnimation.setKeys(keys);
266
+ targetNode.animations.push(babylonAnimation);
267
+ }
268
+ lastAnimation = babylonAnimation;
269
+ gltfRuntime.scene.stopAnimation(targetNode);
270
+ gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
271
+ }
272
+ }
273
+ };
274
+ /**
275
+ * @returns the bones transformation matrix
276
+ * @param node
277
+ */
278
+ const ConfigureBoneTransformation = (node) => {
279
+ let mat = null;
280
+ if (node.translation || node.rotation || node.scale) {
281
+ const scale = Vector3.FromArray(node.scale || [1, 1, 1]);
282
+ const rotation = Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
283
+ const position = Vector3.FromArray(node.translation || [0, 0, 0]);
284
+ mat = Matrix.Compose(scale, rotation, position);
285
+ }
286
+ else {
287
+ mat = Matrix.FromArray(node.matrix);
288
+ }
289
+ return mat;
290
+ };
291
+ /**
292
+ * Returns the parent bone
293
+ * @param gltfRuntime
294
+ * @param skins
295
+ * @param jointName
296
+ * @param newSkeleton
297
+ * @returns the parent bone
298
+ */
299
+ const GetParentBone = (gltfRuntime, skins, jointName, newSkeleton) => {
300
+ // Try to find
301
+ for (let i = 0; i < newSkeleton.bones.length; i++) {
302
+ if (newSkeleton.bones[i].name === jointName) {
303
+ return newSkeleton.bones[i];
304
+ }
305
+ }
306
+ // Not found, search in gltf nodes
307
+ const nodes = gltfRuntime.nodes;
308
+ for (const nde in nodes) {
309
+ const node = nodes[nde];
310
+ if (!node.jointName) {
311
+ continue;
312
+ }
313
+ const children = node.children;
314
+ for (let i = 0; i < children.length; i++) {
315
+ const child = gltfRuntime.nodes[children[i]];
316
+ if (!child.jointName) {
317
+ continue;
318
+ }
319
+ if (child.jointName === jointName) {
320
+ const mat = ConfigureBoneTransformation(node);
321
+ const bone = new Bone(node.name || "", newSkeleton, GetParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
322
+ bone.id = nde;
323
+ return bone;
324
+ }
325
+ }
326
+ }
327
+ return null;
328
+ };
329
+ /**
330
+ * Returns the appropriate root node
331
+ * @param nodesToRoot
332
+ * @param id
333
+ * @returns the root node
334
+ */
335
+ const GetNodeToRoot = (nodesToRoot, id) => {
336
+ for (let i = 0; i < nodesToRoot.length; i++) {
337
+ const nodeToRoot = nodesToRoot[i];
338
+ for (let j = 0; j < nodeToRoot.node.children.length; j++) {
339
+ const child = nodeToRoot.node.children[j];
340
+ if (child === id) {
341
+ return nodeToRoot.bone;
342
+ }
343
+ }
344
+ }
345
+ return null;
346
+ };
347
+ /**
348
+ * Returns the node with the joint name
349
+ * @param gltfRuntime
350
+ * @param jointName
351
+ * @returns the node with the joint name
352
+ */
353
+ const GetJointNode = (gltfRuntime, jointName) => {
354
+ const nodes = gltfRuntime.nodes;
355
+ let node = nodes[jointName];
356
+ if (node) {
357
+ return {
358
+ node: node,
359
+ id: jointName,
360
+ };
361
+ }
362
+ for (const nde in nodes) {
363
+ node = nodes[nde];
364
+ if (node.jointName === jointName) {
365
+ return {
366
+ node: node,
367
+ id: nde,
368
+ };
369
+ }
370
+ }
371
+ return null;
372
+ };
373
+ /**
374
+ * Checks if a nodes is in joints
375
+ * @param skins
376
+ * @param id
377
+ * @returns true if the node is in joints, else false
378
+ */
379
+ const NodeIsInJoints = (skins, id) => {
380
+ for (let i = 0; i < skins.jointNames.length; i++) {
381
+ if (skins.jointNames[i] === id) {
382
+ return true;
383
+ }
384
+ }
385
+ return false;
386
+ };
387
+ /**
388
+ * Fills the nodes to root for bones and builds hierarchy
389
+ * @param gltfRuntime
390
+ * @param newSkeleton
391
+ * @param skins
392
+ * @param nodesToRoot
393
+ */
394
+ const GetNodesToRoot = (gltfRuntime, newSkeleton, skins, nodesToRoot) => {
395
+ // Creates nodes for root
396
+ for (const nde in gltfRuntime.nodes) {
397
+ const node = gltfRuntime.nodes[nde];
398
+ const id = nde;
399
+ if (!node.jointName || NodeIsInJoints(skins, node.jointName)) {
400
+ continue;
401
+ }
402
+ // Create node to root bone
403
+ const mat = ConfigureBoneTransformation(node);
404
+ const bone = new Bone(node.name || "", newSkeleton, null, mat);
405
+ bone.id = id;
406
+ nodesToRoot.push({ bone: bone, node: node, id: id });
407
+ }
408
+ // Parenting
409
+ for (let i = 0; i < nodesToRoot.length; i++) {
410
+ const nodeToRoot = nodesToRoot[i];
411
+ const children = nodeToRoot.node.children;
412
+ for (let j = 0; j < children.length; j++) {
413
+ let child = null;
414
+ for (let k = 0; k < nodesToRoot.length; k++) {
415
+ if (nodesToRoot[k].id === children[j]) {
416
+ child = nodesToRoot[k];
417
+ break;
418
+ }
419
+ }
420
+ if (child) {
421
+ child.bone._parent = nodeToRoot.bone;
422
+ nodeToRoot.bone.children.push(child.bone);
423
+ }
424
+ }
425
+ }
426
+ };
427
+ /**
428
+ * Imports a skeleton
429
+ * @param gltfRuntime
430
+ * @param skins
431
+ * @param mesh
432
+ * @param newSkeleton
433
+ * @returns the bone name
434
+ */
435
+ const ImportSkeleton = (gltfRuntime, skins, mesh, newSkeleton) => {
436
+ if (!newSkeleton) {
437
+ newSkeleton = new Skeleton(skins.name || "", "", gltfRuntime.scene);
438
+ }
439
+ if (!skins.babylonSkeleton) {
440
+ return newSkeleton;
441
+ }
442
+ // Find the root bones
443
+ const nodesToRoot = [];
444
+ const nodesToRootToAdd = [];
445
+ GetNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
446
+ newSkeleton.bones = [];
447
+ // Joints
448
+ for (let i = 0; i < skins.jointNames.length; i++) {
449
+ const jointNode = GetJointNode(gltfRuntime, skins.jointNames[i]);
450
+ if (!jointNode) {
451
+ continue;
452
+ }
453
+ const node = jointNode.node;
454
+ if (!node) {
455
+ Tools.Warn("Joint named " + skins.jointNames[i] + " does not exist");
456
+ continue;
457
+ }
458
+ const id = jointNode.id;
459
+ // Optimize, if the bone already exists...
460
+ const existingBone = gltfRuntime.scene.getBoneById(id);
461
+ if (existingBone) {
462
+ newSkeleton.bones.push(existingBone);
463
+ continue;
464
+ }
465
+ // Search for parent bone
466
+ let foundBone = false;
467
+ let parentBone = null;
468
+ for (let j = 0; j < i; j++) {
469
+ const jointNode = GetJointNode(gltfRuntime, skins.jointNames[j]);
470
+ if (!jointNode) {
471
+ continue;
472
+ }
473
+ const joint = jointNode.node;
474
+ if (!joint) {
475
+ Tools.Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
476
+ continue;
477
+ }
478
+ const children = joint.children;
479
+ if (!children) {
480
+ continue;
481
+ }
482
+ foundBone = false;
483
+ for (let k = 0; k < children.length; k++) {
484
+ if (children[k] === id) {
485
+ parentBone = GetParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
486
+ foundBone = true;
487
+ break;
488
+ }
489
+ }
490
+ if (foundBone) {
491
+ break;
492
+ }
493
+ }
494
+ // Create bone
495
+ const mat = ConfigureBoneTransformation(node);
496
+ if (!parentBone && nodesToRoot.length > 0) {
497
+ parentBone = GetNodeToRoot(nodesToRoot, id);
498
+ if (parentBone) {
499
+ if (nodesToRootToAdd.indexOf(parentBone) === -1) {
500
+ nodesToRootToAdd.push(parentBone);
501
+ }
502
+ }
503
+ }
504
+ const bone = new Bone(node.jointName || "", newSkeleton, parentBone, mat);
505
+ bone.id = id;
506
+ }
507
+ // Polish
508
+ const bones = newSkeleton.bones;
509
+ newSkeleton.bones = [];
510
+ for (let i = 0; i < skins.jointNames.length; i++) {
511
+ const jointNode = GetJointNode(gltfRuntime, skins.jointNames[i]);
512
+ if (!jointNode) {
513
+ continue;
514
+ }
515
+ for (let j = 0; j < bones.length; j++) {
516
+ if (bones[j].id === jointNode.id) {
517
+ newSkeleton.bones.push(bones[j]);
518
+ break;
519
+ }
520
+ }
521
+ }
522
+ newSkeleton.prepare();
523
+ // Finish
524
+ for (let i = 0; i < nodesToRootToAdd.length; i++) {
525
+ newSkeleton.bones.push(nodesToRootToAdd[i]);
526
+ }
527
+ return newSkeleton;
528
+ };
529
+ /**
530
+ * Imports a mesh and its geometries
531
+ * @param gltfRuntime
532
+ * @param node
533
+ * @param meshes
534
+ * @param id
535
+ * @param newMesh
536
+ * @returns the new mesh
537
+ */
538
+ const ImportMesh = (gltfRuntime, node, meshes, id, newMesh) => {
539
+ if (!newMesh) {
540
+ gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
541
+ newMesh = new Mesh(node.name || "", gltfRuntime.scene);
542
+ newMesh._parentContainer = gltfRuntime.assetContainer;
543
+ gltfRuntime.scene._blockEntityCollection = false;
544
+ newMesh.id = id;
545
+ }
546
+ if (!node.babylonNode) {
547
+ return newMesh;
548
+ }
549
+ const subMaterials = [];
550
+ let vertexData = null;
551
+ const verticesStarts = [];
552
+ const verticesCounts = [];
553
+ const indexStarts = [];
554
+ const indexCounts = [];
555
+ for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
556
+ const meshId = meshes[meshIndex];
557
+ const mesh = gltfRuntime.meshes[meshId];
558
+ if (!mesh) {
559
+ continue;
560
+ }
561
+ // Positions, normals and UVs
562
+ for (let i = 0; i < mesh.primitives.length; i++) {
563
+ // Temporary vertex data
564
+ const tempVertexData = new VertexData();
565
+ const primitive = mesh.primitives[i];
566
+ if (primitive.mode !== 4) {
567
+ // continue;
568
+ }
569
+ const attributes = primitive.attributes;
570
+ let accessor = null;
571
+ let buffer = null;
572
+ // Set positions, normal and uvs
573
+ for (const semantic in attributes) {
574
+ // Link accessor and buffer view
575
+ accessor = gltfRuntime.accessors[attributes[semantic]];
576
+ buffer = GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
577
+ if (semantic === "NORMAL") {
578
+ tempVertexData.normals = new Float32Array(buffer.length);
579
+ tempVertexData.normals.set(buffer);
580
+ }
581
+ else if (semantic === "POSITION") {
582
+ if (GLTFFileLoader.HomogeneousCoordinates) {
583
+ tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
584
+ for (let j = 0; j < buffer.length; j += 4) {
585
+ tempVertexData.positions[j] = buffer[j];
586
+ tempVertexData.positions[j + 1] = buffer[j + 1];
587
+ tempVertexData.positions[j + 2] = buffer[j + 2];
588
+ }
589
+ }
590
+ else {
591
+ tempVertexData.positions = new Float32Array(buffer.length);
592
+ tempVertexData.positions.set(buffer);
593
+ }
594
+ verticesCounts.push(tempVertexData.positions.length);
595
+ }
596
+ else if (semantic.indexOf("TEXCOORD_") !== -1) {
597
+ const channel = Number(semantic.split("_")[1]);
598
+ const uvKind = VertexBuffer.UVKind + (channel === 0 ? "" : channel + 1);
599
+ const uvs = new Float32Array(buffer.length);
600
+ uvs.set(buffer);
601
+ NormalizeUVs(uvs);
602
+ tempVertexData.set(uvs, uvKind);
603
+ }
604
+ else if (semantic === "JOINT") {
605
+ tempVertexData.matricesIndices = new Float32Array(buffer.length);
606
+ tempVertexData.matricesIndices.set(buffer);
607
+ }
608
+ else if (semantic === "WEIGHT") {
609
+ tempVertexData.matricesWeights = new Float32Array(buffer.length);
610
+ tempVertexData.matricesWeights.set(buffer);
611
+ }
612
+ else if (semantic === "COLOR") {
613
+ tempVertexData.colors = new Float32Array(buffer.length);
614
+ tempVertexData.colors.set(buffer);
615
+ }
616
+ }
617
+ // Indices
618
+ accessor = gltfRuntime.accessors[primitive.indices];
619
+ if (accessor) {
620
+ buffer = GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
621
+ tempVertexData.indices = new Int32Array(buffer.length);
622
+ tempVertexData.indices.set(buffer);
623
+ indexCounts.push(tempVertexData.indices.length);
624
+ }
625
+ else {
626
+ // Set indices on the fly
627
+ const indices = [];
628
+ for (let j = 0; j < tempVertexData.positions.length / 3; j++) {
629
+ indices.push(j);
630
+ }
631
+ tempVertexData.indices = new Int32Array(indices);
632
+ indexCounts.push(tempVertexData.indices.length);
633
+ }
634
+ if (!vertexData) {
635
+ vertexData = tempVertexData;
636
+ }
637
+ else {
638
+ vertexData.merge(tempVertexData);
639
+ }
640
+ // Sub material
641
+ const material = gltfRuntime.scene.getMaterialById(primitive.material);
642
+ subMaterials.push(material === null ? GLTFUtils.GetDefaultMaterial(gltfRuntime.scene) : material);
643
+ // Update vertices start and index start
644
+ verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
645
+ indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
646
+ }
647
+ }
648
+ let material;
649
+ gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
650
+ if (subMaterials.length > 1) {
651
+ material = new MultiMaterial("multimat" + id, gltfRuntime.scene);
652
+ material.subMaterials = subMaterials;
653
+ }
654
+ else {
655
+ material = new StandardMaterial("multimat" + id, gltfRuntime.scene);
656
+ }
657
+ if (subMaterials.length === 1) {
658
+ material = subMaterials[0];
659
+ }
660
+ material._parentContainer = gltfRuntime.assetContainer;
661
+ if (!newMesh.material) {
662
+ newMesh.material = material;
663
+ }
664
+ // Apply geometry
665
+ new Geometry(id, gltfRuntime.scene, vertexData, false, newMesh);
666
+ newMesh.computeWorldMatrix(true);
667
+ gltfRuntime.scene._blockEntityCollection = false;
668
+ // Apply submeshes
669
+ newMesh.subMeshes = [];
670
+ let index = 0;
671
+ for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
672
+ const meshId = meshes[meshIndex];
673
+ const mesh = gltfRuntime.meshes[meshId];
674
+ if (!mesh) {
675
+ continue;
676
+ }
677
+ for (let i = 0; i < mesh.primitives.length; i++) {
678
+ if (mesh.primitives[i].mode !== 4) {
679
+ //continue;
680
+ }
681
+ SubMesh.AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
682
+ index++;
683
+ }
684
+ }
685
+ // Finish
686
+ return newMesh;
687
+ };
688
+ /**
689
+ * Configure node transformation from position, rotation and scaling
690
+ * @param newNode
691
+ * @param position
692
+ * @param rotation
693
+ * @param scaling
694
+ */
695
+ const ConfigureNode = (newNode, position, rotation, scaling) => {
696
+ if (newNode.position) {
697
+ newNode.position = position;
698
+ }
699
+ if (newNode.rotationQuaternion || newNode.rotation) {
700
+ newNode.rotationQuaternion = rotation;
701
+ }
702
+ if (newNode.scaling) {
703
+ newNode.scaling = scaling;
704
+ }
705
+ };
706
+ /**
707
+ * Configures node from transformation matrix
708
+ * @param newNode
709
+ * @param node
710
+ */
711
+ const ConfigureNodeFromMatrix = (newNode, node) => {
712
+ if (node.matrix) {
713
+ const position = new Vector3(0, 0, 0);
714
+ const rotation = new Quaternion();
715
+ const scaling = new Vector3(0, 0, 0);
716
+ const mat = Matrix.FromArray(node.matrix);
717
+ mat.decompose(scaling, rotation, position);
718
+ ConfigureNode(newNode, position, rotation, scaling);
719
+ }
720
+ else if (node.translation && node.rotation && node.scale) {
721
+ ConfigureNode(newNode, Vector3.FromArray(node.translation), Quaternion.FromArray(node.rotation), Vector3.FromArray(node.scale));
722
+ }
723
+ newNode.computeWorldMatrix(true);
724
+ };
725
+ /**
726
+ * Imports a node
727
+ * @param gltfRuntime
728
+ * @param node
729
+ * @param id
730
+ * @returns the newly imported node
731
+ */
732
+ const ImportNode = (gltfRuntime, node, id) => {
733
+ let lastNode = null;
734
+ if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
735
+ if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
736
+ return null;
737
+ }
738
+ }
739
+ // Meshes
740
+ if (node.skin) {
741
+ if (node.meshes) {
742
+ const skin = gltfRuntime.skins[node.skin];
743
+ const newMesh = ImportMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
744
+ newMesh.skeleton = gltfRuntime.scene.getLastSkeletonById(node.skin);
745
+ if (newMesh.skeleton === null) {
746
+ newMesh.skeleton = ImportSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton);
747
+ if (!skin.babylonSkeleton) {
748
+ skin.babylonSkeleton = newMesh.skeleton;
749
+ }
750
+ }
751
+ lastNode = newMesh;
752
+ }
753
+ }
754
+ else if (node.meshes) {
755
+ /**
756
+ * Improve meshes property
757
+ */
758
+ const newMesh = ImportMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
759
+ lastNode = newMesh;
760
+ }
761
+ // Lights
762
+ else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
763
+ const light = gltfRuntime.lights[node.light];
764
+ if (light) {
765
+ if (light.type === "ambient") {
766
+ const ambienLight = light[light.type];
767
+ const hemiLight = new HemisphericLight(node.light, Vector3.Zero(), gltfRuntime.scene);
768
+ hemiLight.name = node.name || "";
769
+ if (ambienLight.color) {
770
+ hemiLight.diffuse = Color3.FromArray(ambienLight.color);
771
+ }
772
+ lastNode = hemiLight;
773
+ }
774
+ else if (light.type === "directional") {
775
+ const directionalLight = light[light.type];
776
+ const dirLight = new DirectionalLight(node.light, Vector3.Zero(), gltfRuntime.scene);
777
+ dirLight.name = node.name || "";
778
+ if (directionalLight.color) {
779
+ dirLight.diffuse = Color3.FromArray(directionalLight.color);
780
+ }
781
+ lastNode = dirLight;
782
+ }
783
+ else if (light.type === "point") {
784
+ const pointLight = light[light.type];
785
+ const ptLight = new PointLight(node.light, Vector3.Zero(), gltfRuntime.scene);
786
+ ptLight.name = node.name || "";
787
+ if (pointLight.color) {
788
+ ptLight.diffuse = Color3.FromArray(pointLight.color);
789
+ }
790
+ lastNode = ptLight;
791
+ }
792
+ else if (light.type === "spot") {
793
+ const spotLight = light[light.type];
794
+ const spLight = new SpotLight(node.light, Vector3.Zero(), Vector3.Zero(), 0, 0, gltfRuntime.scene);
795
+ spLight.name = node.name || "";
796
+ if (spotLight.color) {
797
+ spLight.diffuse = Color3.FromArray(spotLight.color);
798
+ }
799
+ if (spotLight.fallOfAngle) {
800
+ spLight.angle = spotLight.fallOfAngle;
801
+ }
802
+ if (spotLight.fallOffExponent) {
803
+ spLight.exponent = spotLight.fallOffExponent;
804
+ }
805
+ lastNode = spLight;
806
+ }
807
+ }
808
+ }
809
+ // Cameras
810
+ else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
811
+ const camera = gltfRuntime.cameras[node.camera];
812
+ if (camera) {
813
+ gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
814
+ if (camera.type === "orthographic") {
815
+ const orthoCamera = new FreeCamera(node.camera, Vector3.Zero(), gltfRuntime.scene, false);
816
+ orthoCamera.name = node.name || "";
817
+ orthoCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
818
+ orthoCamera.attachControl();
819
+ lastNode = orthoCamera;
820
+ orthoCamera._parentContainer = gltfRuntime.assetContainer;
821
+ }
822
+ else if (camera.type === "perspective") {
823
+ const perspectiveCamera = camera[camera.type];
824
+ const persCamera = new FreeCamera(node.camera, Vector3.Zero(), gltfRuntime.scene, false);
825
+ persCamera.name = node.name || "";
826
+ persCamera.attachControl();
827
+ if (!perspectiveCamera.aspectRatio) {
828
+ perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
829
+ }
830
+ if (perspectiveCamera.znear && perspectiveCamera.zfar) {
831
+ persCamera.maxZ = perspectiveCamera.zfar;
832
+ persCamera.minZ = perspectiveCamera.znear;
833
+ }
834
+ lastNode = persCamera;
835
+ persCamera._parentContainer = gltfRuntime.assetContainer;
836
+ }
837
+ gltfRuntime.scene._blockEntityCollection = false;
838
+ }
839
+ }
840
+ // Empty node
841
+ if (!node.jointName) {
842
+ if (node.babylonNode) {
843
+ return node.babylonNode;
844
+ }
845
+ else if (lastNode === null) {
846
+ gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
847
+ const dummy = new Mesh(node.name || "", gltfRuntime.scene);
848
+ dummy._parentContainer = gltfRuntime.assetContainer;
849
+ gltfRuntime.scene._blockEntityCollection = false;
850
+ node.babylonNode = dummy;
851
+ lastNode = dummy;
852
+ }
853
+ }
854
+ if (lastNode !== null) {
855
+ if (node.matrix && lastNode instanceof Mesh) {
856
+ ConfigureNodeFromMatrix(lastNode, node);
857
+ }
858
+ else {
859
+ const translation = node.translation || [0, 0, 0];
860
+ const rotation = node.rotation || [0, 0, 0, 1];
861
+ const scale = node.scale || [1, 1, 1];
862
+ ConfigureNode(lastNode, Vector3.FromArray(translation), Quaternion.FromArray(rotation), Vector3.FromArray(scale));
863
+ }
864
+ lastNode.updateCache(true);
865
+ node.babylonNode = lastNode;
866
+ }
867
+ return lastNode;
868
+ };
869
+ /**
870
+ * Traverses nodes and creates them
871
+ * @param gltfRuntime
872
+ * @param id
873
+ * @param parent
874
+ * @param meshIncluded
875
+ */
876
+ const TraverseNodes = (gltfRuntime, id, parent, meshIncluded = false) => {
877
+ const node = gltfRuntime.nodes[id];
878
+ let newNode = null;
879
+ if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
880
+ if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
881
+ meshIncluded = true;
882
+ }
883
+ else {
884
+ meshIncluded = false;
885
+ }
886
+ }
887
+ else {
888
+ meshIncluded = true;
889
+ }
890
+ if (!node.jointName && meshIncluded) {
891
+ newNode = ImportNode(gltfRuntime, node, id);
892
+ if (newNode !== null) {
893
+ newNode.id = id;
894
+ newNode.parent = parent;
895
+ }
896
+ }
897
+ if (node.children) {
898
+ for (let i = 0; i < node.children.length; i++) {
899
+ TraverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
900
+ }
901
+ }
902
+ };
903
+ /**
904
+ * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
905
+ * @param gltfRuntime
906
+ */
907
+ const PostLoad = (gltfRuntime) => {
908
+ // Nodes
909
+ let currentScene = gltfRuntime.currentScene;
910
+ if (currentScene) {
911
+ for (let i = 0; i < currentScene.nodes.length; i++) {
912
+ TraverseNodes(gltfRuntime, currentScene.nodes[i], null);
913
+ }
914
+ }
915
+ else {
916
+ for (const thing in gltfRuntime.scenes) {
917
+ currentScene = gltfRuntime.scenes[thing];
918
+ for (let i = 0; i < currentScene.nodes.length; i++) {
919
+ TraverseNodes(gltfRuntime, currentScene.nodes[i], null);
920
+ }
921
+ }
922
+ }
923
+ // Set animations
924
+ LoadAnimations(gltfRuntime);
925
+ for (let i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
926
+ const skeleton = gltfRuntime.scene.skeletons[i];
927
+ gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
928
+ }
929
+ };
930
+ /**
931
+ * onBind shaderrs callback to set uniforms and matrices
932
+ * @param mesh
933
+ * @param gltfRuntime
934
+ * @param unTreatedUniforms
935
+ * @param shaderMaterial
936
+ * @param technique
937
+ * @param material
938
+ * @param onSuccess
939
+ */
940
+ const OnBindShaderMaterial = (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) => {
941
+ const materialValues = material.values || technique.parameters;
942
+ for (const unif in unTreatedUniforms) {
943
+ const uniform = unTreatedUniforms[unif];
944
+ const type = uniform.type;
945
+ if (type === EParameterType.FLOAT_MAT2 || type === EParameterType.FLOAT_MAT3 || type === EParameterType.FLOAT_MAT4) {
946
+ if (uniform.semantic && !uniform.source && !uniform.node) {
947
+ GLTFUtils.SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
948
+ }
949
+ else if (uniform.semantic && (uniform.source || uniform.node)) {
950
+ let source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
951
+ if (source === null) {
952
+ source = gltfRuntime.scene.getNodeById(uniform.source || uniform.node || "");
953
+ }
954
+ if (source === null) {
955
+ continue;
956
+ }
957
+ GLTFUtils.SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
958
+ }
959
+ }
960
+ else {
961
+ const value = materialValues[technique.uniforms[unif]];
962
+ if (!value) {
963
+ continue;
964
+ }
965
+ if (type === EParameterType.SAMPLER_2D) {
966
+ const texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
967
+ if (texture === null || texture === undefined) {
968
+ continue;
969
+ }
970
+ shaderMaterial.getEffect().setTexture(unif, texture);
971
+ }
972
+ else {
973
+ GLTFUtils.SetUniform(shaderMaterial.getEffect(), unif, value, type);
974
+ }
975
+ }
976
+ }
977
+ onSuccess(shaderMaterial);
978
+ };
979
+ /**
980
+ * Prepare uniforms to send the only one time
981
+ * Loads the appropriate textures
982
+ * @param gltfRuntime
983
+ * @param shaderMaterial
984
+ * @param technique
985
+ * @param material
986
+ */
987
+ const PrepareShaderMaterialUniforms = (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) => {
988
+ const materialValues = material.values || technique.parameters;
989
+ const techniqueUniforms = technique.uniforms;
990
+ /**
991
+ * Prepare values here (not matrices)
992
+ */
993
+ for (const unif in unTreatedUniforms) {
994
+ const uniform = unTreatedUniforms[unif];
995
+ const type = uniform.type;
996
+ let value = materialValues[techniqueUniforms[unif]];
997
+ if (value === undefined) {
998
+ // In case the value is the same for all materials
999
+ value = uniform.value;
1000
+ }
1001
+ if (!value) {
1002
+ continue;
1003
+ }
1004
+ const onLoadTexture = (uniformName) => {
1005
+ return (texture) => {
1006
+ if (uniform.value && uniformName) {
1007
+ // Static uniform
1008
+ shaderMaterial.setTexture(uniformName, texture);
1009
+ delete unTreatedUniforms[uniformName];
1010
+ }
1011
+ };
1012
+ };
1013
+ // Texture (sampler2D)
1014
+ if (type === EParameterType.SAMPLER_2D) {
1015
+ GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), () => onLoadTexture(null));
1016
+ }
1017
+ // Others
1018
+ else {
1019
+ if (uniform.value && GLTFUtils.SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
1020
+ // Static uniform
1021
+ delete unTreatedUniforms[unif];
1022
+ }
1023
+ }
1024
+ }
1025
+ };
1026
+ /**
1027
+ * Shader compilation failed
1028
+ * @param program
1029
+ * @param shaderMaterial
1030
+ * @param onError
1031
+ * @returns callback when shader is compiled
1032
+ */
1033
+ const OnShaderCompileError = (program, shaderMaterial, onError) => {
1034
+ return (effect, error) => {
1035
+ shaderMaterial.dispose(true);
1036
+ onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
1037
+ };
1038
+ };
1039
+ /**
1040
+ * Shader compilation success
1041
+ * @param gltfRuntime
1042
+ * @param shaderMaterial
1043
+ * @param technique
1044
+ * @param material
1045
+ * @param unTreatedUniforms
1046
+ * @param onSuccess
1047
+ * @returns callback when shader is compiled
1048
+ */
1049
+ const OnShaderCompileSuccess = (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) => {
1050
+ return (_) => {
1051
+ PrepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
1052
+ shaderMaterial.onBind = (mesh) => {
1053
+ OnBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
1054
+ };
1055
+ };
1056
+ };
1057
+ /**
1058
+ * Returns the appropriate uniform if already handled by babylon
1059
+ * @param tokenizer
1060
+ * @param technique
1061
+ * @param unTreatedUniforms
1062
+ * @returns the name of the uniform handled by babylon
1063
+ */
1064
+ const ParseShaderUniforms = (tokenizer, technique, unTreatedUniforms) => {
1065
+ for (const unif in technique.uniforms) {
1066
+ const uniform = technique.uniforms[unif];
1067
+ const uniformParameter = technique.parameters[uniform];
1068
+ if (tokenizer.currentIdentifier === unif) {
1069
+ if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
1070
+ const transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
1071
+ if (transformIndex !== -1) {
1072
+ delete unTreatedUniforms[unif];
1073
+ return BabylonTransforms[transformIndex];
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ return tokenizer.currentIdentifier;
1079
+ };
1080
+ /**
1081
+ * All shaders loaded. Create materials one by one
1082
+ * @param gltfRuntime
1083
+ */
1084
+ const ImportMaterials = (gltfRuntime) => {
1085
+ // Create materials
1086
+ for (const mat in gltfRuntime.materials) {
1087
+ GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, () => { }, () => { });
1088
+ }
1089
+ };
1090
+ /**
1091
+ * Implementation of the base glTF spec
1092
+ * @internal
1093
+ */
1094
+ export class GLTFLoaderBase {
1095
+ static CreateRuntime(parsedData, scene, rootUrl) {
1096
+ const gltfRuntime = {
1097
+ extensions: {},
1098
+ accessors: {},
1099
+ buffers: {},
1100
+ bufferViews: {},
1101
+ meshes: {},
1102
+ lights: {},
1103
+ cameras: {},
1104
+ nodes: {},
1105
+ images: {},
1106
+ textures: {},
1107
+ shaders: {},
1108
+ programs: {},
1109
+ samplers: {},
1110
+ techniques: {},
1111
+ materials: {},
1112
+ animations: {},
1113
+ skins: {},
1114
+ extensionsUsed: [],
1115
+ scenes: {},
1116
+ buffersCount: 0,
1117
+ shaderscount: 0,
1118
+ scene: scene,
1119
+ rootUrl: rootUrl,
1120
+ loadedBufferCount: 0,
1121
+ loadedBufferViews: {},
1122
+ loadedShaderCount: 0,
1123
+ importOnlyMeshes: false,
1124
+ dummyNodes: [],
1125
+ assetContainer: null,
1126
+ };
1127
+ // Parse
1128
+ if (parsedData.extensions) {
1129
+ ParseObject(parsedData.extensions, "extensions", gltfRuntime);
1130
+ }
1131
+ if (parsedData.extensionsUsed) {
1132
+ ParseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
1133
+ }
1134
+ if (parsedData.buffers) {
1135
+ ParseBuffers(parsedData.buffers, gltfRuntime);
1136
+ }
1137
+ if (parsedData.bufferViews) {
1138
+ ParseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
1139
+ }
1140
+ if (parsedData.accessors) {
1141
+ ParseObject(parsedData.accessors, "accessors", gltfRuntime);
1142
+ }
1143
+ if (parsedData.meshes) {
1144
+ ParseObject(parsedData.meshes, "meshes", gltfRuntime);
1145
+ }
1146
+ if (parsedData.lights) {
1147
+ ParseObject(parsedData.lights, "lights", gltfRuntime);
1148
+ }
1149
+ if (parsedData.cameras) {
1150
+ ParseObject(parsedData.cameras, "cameras", gltfRuntime);
1151
+ }
1152
+ if (parsedData.nodes) {
1153
+ ParseObject(parsedData.nodes, "nodes", gltfRuntime);
1154
+ }
1155
+ if (parsedData.images) {
1156
+ ParseObject(parsedData.images, "images", gltfRuntime);
1157
+ }
1158
+ if (parsedData.textures) {
1159
+ ParseObject(parsedData.textures, "textures", gltfRuntime);
1160
+ }
1161
+ if (parsedData.shaders) {
1162
+ ParseShaders(parsedData.shaders, gltfRuntime);
1163
+ }
1164
+ if (parsedData.programs) {
1165
+ ParseObject(parsedData.programs, "programs", gltfRuntime);
1166
+ }
1167
+ if (parsedData.samplers) {
1168
+ ParseObject(parsedData.samplers, "samplers", gltfRuntime);
1169
+ }
1170
+ if (parsedData.techniques) {
1171
+ ParseObject(parsedData.techniques, "techniques", gltfRuntime);
1172
+ }
1173
+ if (parsedData.materials) {
1174
+ ParseObject(parsedData.materials, "materials", gltfRuntime);
1175
+ }
1176
+ if (parsedData.animations) {
1177
+ ParseObject(parsedData.animations, "animations", gltfRuntime);
1178
+ }
1179
+ if (parsedData.skins) {
1180
+ ParseObject(parsedData.skins, "skins", gltfRuntime);
1181
+ }
1182
+ if (parsedData.scenes) {
1183
+ gltfRuntime.scenes = parsedData.scenes;
1184
+ }
1185
+ if (parsedData.scene && parsedData.scenes) {
1186
+ gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
1187
+ }
1188
+ return gltfRuntime;
1189
+ }
1190
+ // eslint-disable-next-line no-restricted-syntax
1191
+ static LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
1192
+ const buffer = gltfRuntime.buffers[id];
1193
+ if (Tools.IsBase64(buffer.uri)) {
1194
+ setTimeout(() => onSuccess(new Uint8Array(Tools.DecodeBase64(buffer.uri))));
1195
+ }
1196
+ else {
1197
+ Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri, (data) => onSuccess(new Uint8Array(data)), onProgress, undefined, true, (request) => {
1198
+ if (request) {
1199
+ onError(request.status + " " + request.statusText);
1200
+ }
1201
+ });
1202
+ }
1203
+ }
1204
+ // eslint-disable-next-line no-restricted-syntax
1205
+ static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
1206
+ const texture = gltfRuntime.textures[id];
1207
+ if (!texture || !texture.source) {
1208
+ onError("");
1209
+ return;
1210
+ }
1211
+ if (texture.babylonTexture) {
1212
+ onSuccess(null);
1213
+ return;
1214
+ }
1215
+ const source = gltfRuntime.images[texture.source];
1216
+ if (Tools.IsBase64(source.uri)) {
1217
+ setTimeout(() => onSuccess(new Uint8Array(Tools.DecodeBase64(source.uri))));
1218
+ }
1219
+ else {
1220
+ Tools.LoadFile(gltfRuntime.rootUrl + source.uri, (data) => onSuccess(new Uint8Array(data)), undefined, undefined, true, (request) => {
1221
+ if (request) {
1222
+ onError(request.status + " " + request.statusText);
1223
+ }
1224
+ });
1225
+ }
1226
+ }
1227
+ // eslint-disable-next-line no-restricted-syntax
1228
+ static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess) {
1229
+ const texture = gltfRuntime.textures[id];
1230
+ if (texture.babylonTexture) {
1231
+ onSuccess(texture.babylonTexture);
1232
+ return;
1233
+ }
1234
+ const sampler = gltfRuntime.samplers[texture.sampler];
1235
+ const createMipMaps = sampler.minFilter === ETextureFilterType.NEAREST_MIPMAP_NEAREST ||
1236
+ sampler.minFilter === ETextureFilterType.NEAREST_MIPMAP_LINEAR ||
1237
+ sampler.minFilter === ETextureFilterType.LINEAR_MIPMAP_NEAREST ||
1238
+ sampler.minFilter === ETextureFilterType.LINEAR_MIPMAP_LINEAR;
1239
+ const samplingMode = Texture.BILINEAR_SAMPLINGMODE;
1240
+ const blob = buffer == null ? new Blob() : new Blob([buffer]);
1241
+ const blobURL = URL.createObjectURL(blob);
1242
+ const revokeBlobURL = () => URL.revokeObjectURL(blobURL);
1243
+ const newTexture = new Texture(blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
1244
+ if (sampler.wrapS !== undefined) {
1245
+ newTexture.wrapU = GLTFUtils.GetWrapMode(sampler.wrapS);
1246
+ }
1247
+ if (sampler.wrapT !== undefined) {
1248
+ newTexture.wrapV = GLTFUtils.GetWrapMode(sampler.wrapT);
1249
+ }
1250
+ newTexture.name = id;
1251
+ texture.babylonTexture = newTexture;
1252
+ onSuccess(newTexture);
1253
+ }
1254
+ // eslint-disable-next-line no-restricted-syntax
1255
+ static LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
1256
+ const shader = gltfRuntime.shaders[id];
1257
+ if (Tools.IsBase64(shader.uri)) {
1258
+ const shaderString = atob(shader.uri.split(",")[1]);
1259
+ if (onSuccess) {
1260
+ onSuccess(shaderString);
1261
+ }
1262
+ }
1263
+ else {
1264
+ Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, (request) => {
1265
+ if (request && onError) {
1266
+ onError(request.status + " " + request.statusText);
1267
+ }
1268
+ });
1269
+ }
1270
+ }
1271
+ // eslint-disable-next-line no-restricted-syntax
1272
+ static LoadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
1273
+ const material = gltfRuntime.materials[id];
1274
+ if (!material.technique) {
1275
+ if (onError) {
1276
+ onError("No technique found.");
1277
+ }
1278
+ return;
1279
+ }
1280
+ const technique = gltfRuntime.techniques[material.technique];
1281
+ if (!technique) {
1282
+ gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
1283
+ const defaultMaterial = new StandardMaterial(id, gltfRuntime.scene);
1284
+ defaultMaterial._parentContainer = gltfRuntime.assetContainer;
1285
+ gltfRuntime.scene._blockEntityCollection = false;
1286
+ defaultMaterial.diffuseColor = new Color3(0.5, 0.5, 0.5);
1287
+ defaultMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
1288
+ onSuccess(defaultMaterial);
1289
+ return;
1290
+ }
1291
+ const program = gltfRuntime.programs[technique.program];
1292
+ const states = technique.states;
1293
+ const vertexShader = Effect.ShadersStore[program.vertexShader + "VertexShader"];
1294
+ const pixelShader = Effect.ShadersStore[program.fragmentShader + "PixelShader"];
1295
+ let newVertexShader = "";
1296
+ let newPixelShader = "";
1297
+ const vertexTokenizer = new Tokenizer(vertexShader);
1298
+ const pixelTokenizer = new Tokenizer(pixelShader);
1299
+ const unTreatedUniforms = {};
1300
+ const uniforms = [];
1301
+ const attributes = [];
1302
+ const samplers = [];
1303
+ // Fill uniform, sampler2D and attributes
1304
+ for (const unif in technique.uniforms) {
1305
+ const uniform = technique.uniforms[unif];
1306
+ const uniformParameter = technique.parameters[uniform];
1307
+ unTreatedUniforms[unif] = uniformParameter;
1308
+ if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
1309
+ const transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
1310
+ if (transformIndex !== -1) {
1311
+ uniforms.push(BabylonTransforms[transformIndex]);
1312
+ delete unTreatedUniforms[unif];
1313
+ }
1314
+ else {
1315
+ uniforms.push(unif);
1316
+ }
1317
+ }
1318
+ else if (uniformParameter.type === EParameterType.SAMPLER_2D) {
1319
+ samplers.push(unif);
1320
+ }
1321
+ else {
1322
+ uniforms.push(unif);
1323
+ }
1324
+ }
1325
+ for (const attr in technique.attributes) {
1326
+ const attribute = technique.attributes[attr];
1327
+ const attributeParameter = technique.parameters[attribute];
1328
+ if (attributeParameter.semantic) {
1329
+ const name = GetAttribute(attributeParameter);
1330
+ if (name) {
1331
+ attributes.push(name);
1332
+ }
1333
+ }
1334
+ }
1335
+ // Configure vertex shader
1336
+ while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
1337
+ const tokenType = vertexTokenizer.currentToken;
1338
+ if (tokenType !== ETokenType.IDENTIFIER) {
1339
+ newVertexShader += vertexTokenizer.currentString;
1340
+ continue;
1341
+ }
1342
+ let foundAttribute = false;
1343
+ for (const attr in technique.attributes) {
1344
+ const attribute = technique.attributes[attr];
1345
+ const attributeParameter = technique.parameters[attribute];
1346
+ if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
1347
+ newVertexShader += GetAttribute(attributeParameter);
1348
+ foundAttribute = true;
1349
+ break;
1350
+ }
1351
+ }
1352
+ if (foundAttribute) {
1353
+ continue;
1354
+ }
1355
+ newVertexShader += ParseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
1356
+ }
1357
+ // Configure pixel shader
1358
+ while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
1359
+ const tokenType = pixelTokenizer.currentToken;
1360
+ if (tokenType !== ETokenType.IDENTIFIER) {
1361
+ newPixelShader += pixelTokenizer.currentString;
1362
+ continue;
1363
+ }
1364
+ newPixelShader += ParseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
1365
+ }
1366
+ // Create shader material
1367
+ const shaderPath = {
1368
+ vertex: program.vertexShader + id,
1369
+ fragment: program.fragmentShader + id,
1370
+ };
1371
+ const options = {
1372
+ attributes: attributes,
1373
+ uniforms: uniforms,
1374
+ samplers: samplers,
1375
+ needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1,
1376
+ };
1377
+ Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
1378
+ Effect.ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
1379
+ const shaderMaterial = new ShaderMaterial(id, gltfRuntime.scene, shaderPath, options);
1380
+ shaderMaterial.onError = OnShaderCompileError(program, shaderMaterial, onError);
1381
+ shaderMaterial.onCompiled = OnShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
1382
+ shaderMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
1383
+ if (states && states.functions) {
1384
+ const functions = states.functions;
1385
+ if (functions.cullFace && functions.cullFace[0] !== ECullingType.BACK) {
1386
+ shaderMaterial.backFaceCulling = false;
1387
+ }
1388
+ const blendFunc = functions.blendFuncSeparate;
1389
+ if (blendFunc) {
1390
+ if (blendFunc[0] === EBlendingFunction.SRC_ALPHA &&
1391
+ blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_ALPHA &&
1392
+ blendFunc[2] === EBlendingFunction.ONE &&
1393
+ blendFunc[3] === EBlendingFunction.ONE) {
1394
+ shaderMaterial.alphaMode = Constants.ALPHA_COMBINE;
1395
+ }
1396
+ else if (blendFunc[0] === EBlendingFunction.ONE &&
1397
+ blendFunc[1] === EBlendingFunction.ONE &&
1398
+ blendFunc[2] === EBlendingFunction.ZERO &&
1399
+ blendFunc[3] === EBlendingFunction.ONE) {
1400
+ shaderMaterial.alphaMode = Constants.ALPHA_ONEONE;
1401
+ }
1402
+ else if (blendFunc[0] === EBlendingFunction.SRC_ALPHA &&
1403
+ blendFunc[1] === EBlendingFunction.ONE &&
1404
+ blendFunc[2] === EBlendingFunction.ZERO &&
1405
+ blendFunc[3] === EBlendingFunction.ONE) {
1406
+ shaderMaterial.alphaMode = Constants.ALPHA_ADD;
1407
+ }
1408
+ else if (blendFunc[0] === EBlendingFunction.ZERO &&
1409
+ blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_COLOR &&
1410
+ blendFunc[2] === EBlendingFunction.ONE &&
1411
+ blendFunc[3] === EBlendingFunction.ONE) {
1412
+ shaderMaterial.alphaMode = Constants.ALPHA_SUBTRACT;
1413
+ }
1414
+ else if (blendFunc[0] === EBlendingFunction.DST_COLOR &&
1415
+ blendFunc[1] === EBlendingFunction.ZERO &&
1416
+ blendFunc[2] === EBlendingFunction.ONE &&
1417
+ blendFunc[3] === EBlendingFunction.ONE) {
1418
+ shaderMaterial.alphaMode = Constants.ALPHA_MULTIPLY;
1419
+ }
1420
+ else if (blendFunc[0] === EBlendingFunction.SRC_ALPHA &&
1421
+ blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_COLOR &&
1422
+ blendFunc[2] === EBlendingFunction.ONE &&
1423
+ blendFunc[3] === EBlendingFunction.ONE) {
1424
+ shaderMaterial.alphaMode = Constants.ALPHA_MAXIMIZED;
1425
+ }
1426
+ }
1427
+ }
1428
+ }
1429
+ }
1430
+ /**
1431
+ * glTF V1 Loader
1432
+ * @internal
1433
+ * @deprecated
1434
+ */
1435
+ export class GLTFLoader {
1436
+ static RegisterExtension(extension) {
1437
+ if (GLTFLoader.Extensions[extension.name]) {
1438
+ Tools.Error('Tool with the same name "' + extension.name + '" already exists');
1439
+ return;
1440
+ }
1441
+ GLTFLoader.Extensions[extension.name] = extension;
1442
+ }
1443
+ dispose() {
1444
+ // do nothing
1445
+ }
1446
+ // eslint-disable-next-line no-restricted-syntax
1447
+ _importMeshAsync(meshesNames, scene, data, rootUrl, assetContainer, onSuccess, onProgress, onError) {
1448
+ scene.useRightHandedSystem = true;
1449
+ GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, (gltfRuntime) => {
1450
+ gltfRuntime.assetContainer = assetContainer;
1451
+ gltfRuntime.importOnlyMeshes = true;
1452
+ if (meshesNames === "") {
1453
+ gltfRuntime.importMeshesNames = [];
1454
+ }
1455
+ else if (typeof meshesNames === "string") {
1456
+ gltfRuntime.importMeshesNames = [meshesNames];
1457
+ }
1458
+ else if (meshesNames && !(meshesNames instanceof Array)) {
1459
+ gltfRuntime.importMeshesNames = [meshesNames];
1460
+ }
1461
+ else {
1462
+ gltfRuntime.importMeshesNames = [];
1463
+ Tools.Warn("Argument meshesNames must be of type string or string[]");
1464
+ }
1465
+ // Create nodes
1466
+ this._createNodes(gltfRuntime);
1467
+ const meshes = [];
1468
+ const skeletons = [];
1469
+ // Fill arrays of meshes and skeletons
1470
+ for (const nde in gltfRuntime.nodes) {
1471
+ const node = gltfRuntime.nodes[nde];
1472
+ if (node.babylonNode instanceof AbstractMesh) {
1473
+ meshes.push(node.babylonNode);
1474
+ }
1475
+ }
1476
+ for (const skl in gltfRuntime.skins) {
1477
+ const skin = gltfRuntime.skins[skl];
1478
+ if (skin.babylonSkeleton instanceof Skeleton) {
1479
+ skeletons.push(skin.babylonSkeleton);
1480
+ }
1481
+ }
1482
+ // Load buffers, shaders, materials, etc.
1483
+ this._loadBuffersAsync(gltfRuntime, () => {
1484
+ this._loadShadersAsync(gltfRuntime, () => {
1485
+ ImportMaterials(gltfRuntime);
1486
+ PostLoad(gltfRuntime);
1487
+ if (!GLTFFileLoader.IncrementalLoading && onSuccess) {
1488
+ onSuccess(meshes, skeletons);
1489
+ }
1490
+ });
1491
+ });
1492
+ if (GLTFFileLoader.IncrementalLoading && onSuccess) {
1493
+ onSuccess(meshes, skeletons);
1494
+ }
1495
+ }, onError);
1496
+ return true;
1497
+ }
1498
+ /**
1499
+ * Imports one or more meshes from a loaded gltf file and adds them to the scene
1500
+ * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
1501
+ * @param scene the scene the meshes should be added to
1502
+ * @param assetContainer defines the asset container to use (can be null)
1503
+ * @param data gltf data containing information of the meshes in a loaded file
1504
+ * @param rootUrl root url to load from
1505
+ * @param onProgress event that fires when loading progress has occured
1506
+ * @returns a promise containg the loaded meshes, particles, skeletons and animations
1507
+ */
1508
+ // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
1509
+ importMeshAsync(meshesNames, scene, assetContainer, data, rootUrl, onProgress) {
1510
+ return new Promise((resolve, reject) => {
1511
+ this._importMeshAsync(meshesNames, scene, data, rootUrl, assetContainer, (meshes, skeletons) => {
1512
+ resolve({
1513
+ meshes: meshes,
1514
+ particleSystems: [],
1515
+ skeletons: skeletons,
1516
+ animationGroups: [],
1517
+ lights: [],
1518
+ transformNodes: [],
1519
+ geometries: [],
1520
+ spriteManagers: [],
1521
+ });
1522
+ }, onProgress, (message) => {
1523
+ reject(new Error(message));
1524
+ });
1525
+ });
1526
+ }
1527
+ // eslint-disable-next-line no-restricted-syntax
1528
+ _loadAsync(scene, data, rootUrl, onSuccess, onProgress, onError) {
1529
+ scene.useRightHandedSystem = true;
1530
+ GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, (gltfRuntime) => {
1531
+ // Load runtime extensios
1532
+ GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, () => {
1533
+ // Create nodes
1534
+ this._createNodes(gltfRuntime);
1535
+ // Load buffers, shaders, materials, etc.
1536
+ this._loadBuffersAsync(gltfRuntime, () => {
1537
+ this._loadShadersAsync(gltfRuntime, () => {
1538
+ ImportMaterials(gltfRuntime);
1539
+ PostLoad(gltfRuntime);
1540
+ if (!GLTFFileLoader.IncrementalLoading) {
1541
+ onSuccess();
1542
+ }
1543
+ });
1544
+ });
1545
+ if (GLTFFileLoader.IncrementalLoading) {
1546
+ onSuccess();
1547
+ }
1548
+ }, onError);
1549
+ }, onError);
1550
+ }
1551
+ /**
1552
+ * Imports all objects from a loaded gltf file and adds them to the scene
1553
+ * @param scene the scene the objects should be added to
1554
+ * @param data gltf data containing information of the meshes in a loaded file
1555
+ * @param rootUrl root url to load from
1556
+ * @param onProgress event that fires when loading progress has occured
1557
+ * @returns a promise which completes when objects have been loaded to the scene
1558
+ */
1559
+ async loadAsync(scene, data, rootUrl, onProgress) {
1560
+ return await new Promise((resolve, reject) => {
1561
+ this._loadAsync(scene, data, rootUrl, () => {
1562
+ resolve();
1563
+ }, onProgress, (message) => {
1564
+ reject(new Error(message));
1565
+ });
1566
+ });
1567
+ }
1568
+ // eslint-disable-next-line no-restricted-syntax
1569
+ _loadShadersAsync(gltfRuntime, onload) {
1570
+ let hasShaders = false;
1571
+ const processShader = (sha, shader) => {
1572
+ GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, (shaderString) => {
1573
+ if (shaderString instanceof ArrayBuffer) {
1574
+ return;
1575
+ }
1576
+ gltfRuntime.loadedShaderCount++;
1577
+ if (shaderString) {
1578
+ Effect.ShadersStore[sha + (shader.type === EShaderType.VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
1579
+ }
1580
+ if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
1581
+ onload();
1582
+ }
1583
+ }, () => {
1584
+ Tools.Error("Error when loading shader program named " + sha + " located at " + shader.uri);
1585
+ });
1586
+ };
1587
+ for (const sha in gltfRuntime.shaders) {
1588
+ hasShaders = true;
1589
+ const shader = gltfRuntime.shaders[sha];
1590
+ if (shader) {
1591
+ processShader.bind(this, sha, shader)();
1592
+ }
1593
+ else {
1594
+ Tools.Error("No shader named: " + sha);
1595
+ }
1596
+ }
1597
+ if (!hasShaders) {
1598
+ onload();
1599
+ }
1600
+ }
1601
+ // eslint-disable-next-line no-restricted-syntax
1602
+ _loadBuffersAsync(gltfRuntime, onLoad) {
1603
+ let hasBuffers = false;
1604
+ const processBuffer = (buf, buffer) => {
1605
+ GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, (bufferView) => {
1606
+ gltfRuntime.loadedBufferCount++;
1607
+ if (bufferView) {
1608
+ if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
1609
+ Tools.Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
1610
+ }
1611
+ gltfRuntime.loadedBufferViews[buf] = bufferView;
1612
+ }
1613
+ if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
1614
+ onLoad();
1615
+ }
1616
+ }, () => {
1617
+ Tools.Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
1618
+ });
1619
+ };
1620
+ for (const buf in gltfRuntime.buffers) {
1621
+ hasBuffers = true;
1622
+ const buffer = gltfRuntime.buffers[buf];
1623
+ if (buffer) {
1624
+ processBuffer.bind(this, buf, buffer)();
1625
+ }
1626
+ else {
1627
+ Tools.Error("No buffer named: " + buf);
1628
+ }
1629
+ }
1630
+ if (!hasBuffers) {
1631
+ onLoad();
1632
+ }
1633
+ }
1634
+ _createNodes(gltfRuntime) {
1635
+ let currentScene = gltfRuntime.currentScene;
1636
+ if (currentScene) {
1637
+ // Only one scene even if multiple scenes are defined
1638
+ for (let i = 0; i < currentScene.nodes.length; i++) {
1639
+ TraverseNodes(gltfRuntime, currentScene.nodes[i], null);
1640
+ }
1641
+ }
1642
+ else {
1643
+ // Load all scenes
1644
+ for (const thing in gltfRuntime.scenes) {
1645
+ currentScene = gltfRuntime.scenes[thing];
1646
+ for (let i = 0; i < currentScene.nodes.length; i++) {
1647
+ TraverseNodes(gltfRuntime, currentScene.nodes[i], null);
1648
+ }
1649
+ }
1650
+ }
1651
+ }
1652
+ }
1653
+ GLTFLoader.Extensions = {};
1654
+ /** @internal */
1655
+ export class GLTFLoaderExtension {
1656
+ constructor(name) {
1657
+ this._name = name;
1658
+ }
1659
+ get name() {
1660
+ return this._name;
1661
+ }
1662
+ /**
1663
+ * Defines an override for loading the runtime
1664
+ * Return true to stop further extensions from loading the runtime
1665
+ * @param scene
1666
+ * @param data
1667
+ * @param rootUrl
1668
+ * @param onSuccess
1669
+ * @param onError
1670
+ * @returns true to stop further extensions from loading the runtime
1671
+ */
1672
+ // eslint-disable-next-line no-restricted-syntax
1673
+ loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError) {
1674
+ return false;
1675
+ }
1676
+ /**
1677
+ * Defines an onverride for creating gltf runtime
1678
+ * Return true to stop further extensions from creating the runtime
1679
+ * @param gltfRuntime
1680
+ * @param onSuccess
1681
+ * @param onError
1682
+ * @returns true to stop further extensions from creating the runtime
1683
+ */
1684
+ // eslint-disable-next-line no-restricted-syntax
1685
+ loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError) {
1686
+ return false;
1687
+ }
1688
+ /**
1689
+ * Defines an override for loading buffers
1690
+ * Return true to stop further extensions from loading this buffer
1691
+ * @param gltfRuntime
1692
+ * @param id
1693
+ * @param onSuccess
1694
+ * @param onError
1695
+ * @param onProgress
1696
+ * @returns true to stop further extensions from loading this buffer
1697
+ */
1698
+ // eslint-disable-next-line no-restricted-syntax
1699
+ // eslint-disable-next-line no-restricted-syntax
1700
+ loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
1701
+ return false;
1702
+ }
1703
+ /**
1704
+ * Defines an override for loading texture buffers
1705
+ * Return true to stop further extensions from loading this texture data
1706
+ * @param gltfRuntime
1707
+ * @param id
1708
+ * @param onSuccess
1709
+ * @param onError
1710
+ * @returns true to stop further extensions from loading this texture data
1711
+ */
1712
+ // eslint-disable-next-line no-restricted-syntax
1713
+ loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
1714
+ return false;
1715
+ }
1716
+ /**
1717
+ * Defines an override for creating textures
1718
+ * Return true to stop further extensions from loading this texture
1719
+ * @param gltfRuntime
1720
+ * @param id
1721
+ * @param buffer
1722
+ * @param onSuccess
1723
+ * @param onError
1724
+ * @returns true to stop further extensions from loading this texture
1725
+ */
1726
+ // eslint-disable-next-line no-restricted-syntax
1727
+ createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError) {
1728
+ return false;
1729
+ }
1730
+ /**
1731
+ * Defines an override for loading shader strings
1732
+ * Return true to stop further extensions from loading this shader data
1733
+ * @param gltfRuntime
1734
+ * @param id
1735
+ * @param onSuccess
1736
+ * @param onError
1737
+ * @returns true to stop further extensions from loading this shader data
1738
+ */
1739
+ // eslint-disable-next-line no-restricted-syntax
1740
+ loadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
1741
+ return false;
1742
+ }
1743
+ /**
1744
+ * Defines an override for loading materials
1745
+ * Return true to stop further extensions from loading this material
1746
+ * @param gltfRuntime
1747
+ * @param id
1748
+ * @param onSuccess
1749
+ * @param onError
1750
+ * @returns true to stop further extensions from loading this material
1751
+ */
1752
+ // eslint-disable-next-line no-restricted-syntax
1753
+ loadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
1754
+ return false;
1755
+ }
1756
+ // ---------
1757
+ // Utilities
1758
+ // ---------
1759
+ // eslint-disable-next-line no-restricted-syntax
1760
+ static LoadRuntimeAsync(scene, data, rootUrl, onSuccess, onError) {
1761
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1762
+ return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
1763
+ }, () => {
1764
+ setTimeout(() => {
1765
+ if (!onSuccess) {
1766
+ return;
1767
+ }
1768
+ onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
1769
+ });
1770
+ });
1771
+ }
1772
+ // eslint-disable-next-line no-restricted-syntax
1773
+ static LoadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError) {
1774
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1775
+ return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
1776
+ }, () => {
1777
+ setTimeout(() => {
1778
+ onSuccess();
1779
+ });
1780
+ });
1781
+ }
1782
+ // eslint-disable-next-line no-restricted-syntax
1783
+ static LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
1784
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1785
+ return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
1786
+ }, () => {
1787
+ GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
1788
+ });
1789
+ }
1790
+ // eslint-disable-next-line no-restricted-syntax
1791
+ static LoadTextureAsync(gltfRuntime, id, onSuccess, onError) {
1792
+ GLTFLoaderExtension._LoadTextureBufferAsync(gltfRuntime, id, (buffer) => {
1793
+ if (buffer) {
1794
+ GLTFLoaderExtension._CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
1795
+ }
1796
+ }, onError);
1797
+ }
1798
+ // eslint-disable-next-line no-restricted-syntax
1799
+ static LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
1800
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1801
+ return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
1802
+ }, () => {
1803
+ GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
1804
+ });
1805
+ }
1806
+ // eslint-disable-next-line no-restricted-syntax
1807
+ static LoadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
1808
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1809
+ return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
1810
+ }, () => {
1811
+ GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
1812
+ });
1813
+ }
1814
+ // eslint-disable-next-line no-restricted-syntax
1815
+ static _LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
1816
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1817
+ return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
1818
+ }, () => {
1819
+ GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
1820
+ });
1821
+ }
1822
+ // eslint-disable-next-line no-restricted-syntax
1823
+ static _CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError) {
1824
+ GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
1825
+ return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
1826
+ }, () => {
1827
+ GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess);
1828
+ });
1829
+ }
1830
+ static _ApplyExtensions(func, defaultFunc) {
1831
+ for (const extensionName in GLTFLoader.Extensions) {
1832
+ const loaderExtension = GLTFLoader.Extensions[extensionName];
1833
+ if (func(loaderExtension)) {
1834
+ return;
1835
+ }
1836
+ }
1837
+ defaultFunc();
1838
+ }
1839
+ }
1840
+ GLTFFileLoader._CreateGLTF1Loader = () => new GLTFLoader();
1841
+ //# sourceMappingURL=glTFLoader.js.map