@zephyr3d/scene 0.9.2 → 0.9.3

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 (420) hide show
  1. package/dist/animation/animationset.js +135 -135
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/ik/ik_chain_builder.js +68 -0
  4. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  5. package/dist/animation/ik/ik_pole_constraint.js +2 -7
  6. package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
  7. package/dist/animation/joint_dynamics/controller.js +146 -146
  8. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  9. package/dist/animation/joint_dynamics/math.js +16 -0
  10. package/dist/animation/joint_dynamics/math.js.map +1 -0
  11. package/dist/animation/spring/spring_particle.js +4 -4
  12. package/dist/animation/spring/spring_particle.js.map +1 -1
  13. package/dist/animation/spring/spring_system.js +75 -75
  14. package/dist/animation/spring/spring_system.js.map +1 -1
  15. package/dist/animation/spring2/constraints.js.map +1 -1
  16. package/dist/animation/spring2/controller.js +64 -64
  17. package/dist/animation/spring2/controller.js.map +1 -1
  18. package/dist/animation/spring2/math.js.map +1 -1
  19. package/dist/animation/spring2/spring_system.js +8 -8
  20. package/dist/animation/spring2/spring_system.js.map +1 -1
  21. package/dist/asset/model.js +57 -57
  22. package/dist/asset/model.js.map +1 -1
  23. package/dist/camera/camera.js +184 -184
  24. package/dist/camera/camera.js.map +1 -1
  25. package/dist/index.d.ts +2 -6
  26. package/dist/index.js +1 -1
  27. package/dist/material/material.js +288 -288
  28. package/dist/material/material.js.map +1 -1
  29. package/dist/material/shader/helper.js +281 -278
  30. package/dist/material/shader/helper.js.map +1 -1
  31. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  32. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  33. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  34. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  35. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  36. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  37. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  38. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  39. package/dist/render/cluster_light.js +3 -4
  40. package/dist/render/cluster_light.js.map +1 -1
  41. package/dist/render/rendergraph/history_resource_manager.js +93 -93
  42. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  43. package/dist/render/rendergraph/history_resources.js +3 -3
  44. package/dist/render/rendergraph/history_resources.js.map +1 -1
  45. package/dist/render/rendergraph/types.js +22 -22
  46. package/dist/render/rendergraph/types.js.map +1 -1
  47. package/dist/scene/mesh.js +80 -80
  48. package/dist/scene/mesh.js.map +1 -1
  49. package/dist/scene/scene_node.js +228 -228
  50. package/dist/scene/scene_node.js.map +1 -1
  51. package/dist/shapes/torus.js +90 -59
  52. package/dist/shapes/torus.js.map +1 -1
  53. package/dist/src/animation/animation.js +127 -0
  54. package/dist/src/animation/animation.js.map +1 -0
  55. package/dist/src/animation/animationset.js +255 -0
  56. package/dist/src/animation/animationset.js.map +1 -0
  57. package/dist/src/animation/animationtrack.js +34 -0
  58. package/dist/src/animation/animationtrack.js.map +1 -0
  59. package/dist/src/animation/eulerrotationtrack.js +52 -0
  60. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  61. package/dist/src/animation/morphtarget.js +93 -0
  62. package/dist/src/animation/morphtarget.js.map +1 -0
  63. package/dist/src/animation/morphtrack.js +70 -0
  64. package/dist/src/animation/morphtrack.js.map +1 -0
  65. package/dist/src/animation/proptrack.js +161 -0
  66. package/dist/src/animation/proptrack.js.map +1 -0
  67. package/dist/src/animation/rotationtrack.js +51 -0
  68. package/dist/src/animation/rotationtrack.js.map +1 -0
  69. package/dist/src/animation/scaletrack.js +50 -0
  70. package/dist/src/animation/scaletrack.js.map +1 -0
  71. package/dist/src/animation/skeleton.js +204 -0
  72. package/dist/src/animation/skeleton.js.map +1 -0
  73. package/dist/src/animation/translationtrack.js +50 -0
  74. package/dist/src/animation/translationtrack.js.map +1 -0
  75. package/dist/src/app/app.js +129 -0
  76. package/dist/src/app/app.js.map +1 -0
  77. package/dist/src/app/inputmgr.js +267 -0
  78. package/dist/src/app/inputmgr.js.map +1 -0
  79. package/dist/src/asset/assetmanager.js +404 -0
  80. package/dist/src/asset/assetmanager.js.map +1 -0
  81. package/dist/src/asset/builtin.js +337 -0
  82. package/dist/src/asset/builtin.js.map +1 -0
  83. package/dist/src/asset/loaders/dds/dds.js +470 -0
  84. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  85. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  86. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  87. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  88. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  89. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  90. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  91. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  92. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  93. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  94. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  95. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  96. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  97. package/dist/src/asset/loaders/loader.js +45 -0
  98. package/dist/src/asset/loaders/loader.js.map +1 -0
  99. package/dist/src/asset/model.js +414 -0
  100. package/dist/src/asset/model.js.map +1 -0
  101. package/dist/src/blitter/bilateralblur.js +221 -0
  102. package/dist/src/blitter/bilateralblur.js.map +1 -0
  103. package/dist/src/blitter/blitter.js +390 -0
  104. package/dist/src/blitter/blitter.js.map +1 -0
  105. package/dist/src/blitter/box.js +118 -0
  106. package/dist/src/blitter/box.js.map +1 -0
  107. package/dist/src/blitter/copy.js +22 -0
  108. package/dist/src/blitter/copy.js.map +1 -0
  109. package/dist/src/blitter/gaussianblur.js +228 -0
  110. package/dist/src/blitter/gaussianblur.js.map +1 -0
  111. package/dist/src/camera/base.js +92 -0
  112. package/dist/src/camera/base.js.map +1 -0
  113. package/dist/src/camera/camera.js +1005 -0
  114. package/dist/src/camera/camera.js.map +1 -0
  115. package/dist/src/camera/fps.js +238 -0
  116. package/dist/src/camera/fps.js.map +1 -0
  117. package/dist/src/camera/orbit.js +245 -0
  118. package/dist/src/camera/orbit.js.map +1 -0
  119. package/dist/src/camera/orthocamera.js +167 -0
  120. package/dist/src/camera/orthocamera.js.map +1 -0
  121. package/dist/src/camera/perspectivecamera.js +141 -0
  122. package/dist/src/camera/perspectivecamera.js.map +1 -0
  123. package/dist/src/index.js +120 -0
  124. package/dist/src/index.js.map +1 -0
  125. package/dist/src/material/blinn.js +81 -0
  126. package/dist/src/material/blinn.js.map +1 -0
  127. package/dist/src/material/grassmaterial.js +113 -0
  128. package/dist/src/material/grassmaterial.js.map +1 -0
  129. package/dist/src/material/lambert.js +92 -0
  130. package/dist/src/material/lambert.js.map +1 -0
  131. package/dist/src/material/material.js +301 -0
  132. package/dist/src/material/material.js.map +1 -0
  133. package/dist/src/material/meshmaterial.js +704 -0
  134. package/dist/src/material/meshmaterial.js.map +1 -0
  135. package/dist/src/material/mixins/albedocolor.js +76 -0
  136. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  137. package/dist/src/material/mixins/foliage.js +47 -0
  138. package/dist/src/material/mixins/foliage.js.map +1 -0
  139. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  140. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  141. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  142. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  143. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  144. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  145. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  146. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  147. package/dist/src/material/mixins/lit.js +476 -0
  148. package/dist/src/material/mixins/lit.js.map +1 -0
  149. package/dist/src/material/mixins/pbr/common.js +918 -0
  150. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  151. package/dist/src/material/mixins/texture.js +172 -0
  152. package/dist/src/material/mixins/texture.js.map +1 -0
  153. package/dist/src/material/mixins/vertexcolor.js +56 -0
  154. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  155. package/dist/src/material/particle.js +178 -0
  156. package/dist/src/material/particle.js.map +1 -0
  157. package/dist/src/material/pbrmr.js +97 -0
  158. package/dist/src/material/pbrmr.js.map +1 -0
  159. package/dist/src/material/pbrsg.js +97 -0
  160. package/dist/src/material/pbrsg.js.map +1 -0
  161. package/dist/src/material/shader/helper.js +1209 -0
  162. package/dist/src/material/shader/helper.js.map +1 -0
  163. package/dist/src/material/terrain-cm.js +606 -0
  164. package/dist/src/material/terrain-cm.js.map +1 -0
  165. package/dist/src/material/terrainmaterial.js +375 -0
  166. package/dist/src/material/terrainmaterial.js.map +1 -0
  167. package/dist/src/material/unlit.js +41 -0
  168. package/dist/src/material/unlit.js.map +1 -0
  169. package/dist/src/material/water.js +417 -0
  170. package/dist/src/material/water.js.map +1 -0
  171. package/dist/src/posteffect/bloom.js +361 -0
  172. package/dist/src/posteffect/bloom.js.map +1 -0
  173. package/dist/src/posteffect/compositor.js +226 -0
  174. package/dist/src/posteffect/compositor.js.map +1 -0
  175. package/dist/src/posteffect/fxaa.js +273 -0
  176. package/dist/src/posteffect/fxaa.js.map +1 -0
  177. package/dist/src/posteffect/grayscale.js +69 -0
  178. package/dist/src/posteffect/grayscale.js.map +1 -0
  179. package/dist/src/posteffect/motionblur.js +96 -0
  180. package/dist/src/posteffect/motionblur.js.map +1 -0
  181. package/dist/src/posteffect/posteffect.js +126 -0
  182. package/dist/src/posteffect/posteffect.js.map +1 -0
  183. package/dist/src/posteffect/sao.js +324 -0
  184. package/dist/src/posteffect/sao.js.map +1 -0
  185. package/dist/src/posteffect/ssr.js +489 -0
  186. package/dist/src/posteffect/ssr.js.map +1 -0
  187. package/dist/src/posteffect/taa.js +172 -0
  188. package/dist/src/posteffect/taa.js.map +1 -0
  189. package/dist/src/posteffect/tonemap.js +94 -0
  190. package/dist/src/posteffect/tonemap.js.map +1 -0
  191. package/dist/src/render/abuffer_oit.js +361 -0
  192. package/dist/src/render/abuffer_oit.js.map +1 -0
  193. package/dist/src/render/clipmap.js +851 -0
  194. package/dist/src/render/clipmap.js.map +1 -0
  195. package/dist/src/render/cluster_light.js +333 -0
  196. package/dist/src/render/cluster_light.js.map +1 -0
  197. package/dist/src/render/cull_visitor.js +187 -0
  198. package/dist/src/render/cull_visitor.js.map +1 -0
  199. package/dist/src/render/depthpass.js +68 -0
  200. package/dist/src/render/depthpass.js.map +1 -0
  201. package/dist/src/render/drawable_mixin.js +227 -0
  202. package/dist/src/render/drawable_mixin.js.map +1 -0
  203. package/dist/src/render/envlight.js +463 -0
  204. package/dist/src/render/envlight.js.map +1 -0
  205. package/dist/src/render/fbm_wavegenerator.js +251 -0
  206. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  207. package/dist/src/render/fft_wavegenerator.js +1006 -0
  208. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  209. package/dist/src/render/fullscreenquad.js +38 -0
  210. package/dist/src/render/fullscreenquad.js.map +1 -0
  211. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  212. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  213. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  214. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  215. package/dist/src/render/hzb.js +273 -0
  216. package/dist/src/render/hzb.js.map +1 -0
  217. package/dist/src/render/lightpass.js +172 -0
  218. package/dist/src/render/lightpass.js.map +1 -0
  219. package/dist/src/render/objectcolorpass.js +51 -0
  220. package/dist/src/render/objectcolorpass.js.map +1 -0
  221. package/dist/src/render/primitive.js +364 -0
  222. package/dist/src/render/primitive.js.map +1 -0
  223. package/dist/src/render/render_queue.js +467 -0
  224. package/dist/src/render/render_queue.js.map +1 -0
  225. package/dist/src/render/renderbundle_wrapper.js +152 -0
  226. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  227. package/dist/src/render/renderer.js +455 -0
  228. package/dist/src/render/renderer.js.map +1 -0
  229. package/dist/src/render/renderpass.js +200 -0
  230. package/dist/src/render/renderpass.js.map +1 -0
  231. package/dist/src/render/shadowmap_pass.js +56 -0
  232. package/dist/src/render/shadowmap_pass.js.map +1 -0
  233. package/dist/src/render/sky.js +1103 -0
  234. package/dist/src/render/sky.js.map +1 -0
  235. package/dist/src/render/weightedblended_oit.js +168 -0
  236. package/dist/src/render/weightedblended_oit.js.map +1 -0
  237. package/dist/src/scene/batchgroup.js +162 -0
  238. package/dist/src/scene/batchgroup.js.map +1 -0
  239. package/dist/src/scene/environment.js +209 -0
  240. package/dist/src/scene/environment.js.map +1 -0
  241. package/dist/src/scene/graph_node.js +72 -0
  242. package/dist/src/scene/graph_node.js.map +1 -0
  243. package/dist/src/scene/light.js +416 -0
  244. package/dist/src/scene/light.js.map +1 -0
  245. package/dist/src/scene/mesh.js +341 -0
  246. package/dist/src/scene/mesh.js.map +1 -0
  247. package/dist/src/scene/octree.js +649 -0
  248. package/dist/src/scene/octree.js.map +1 -0
  249. package/dist/src/scene/particlesys.js +738 -0
  250. package/dist/src/scene/particlesys.js.map +1 -0
  251. package/dist/src/scene/raycast_visitor.js +103 -0
  252. package/dist/src/scene/raycast_visitor.js.map +1 -0
  253. package/dist/src/scene/scene.js +284 -0
  254. package/dist/src/scene/scene.js.map +1 -0
  255. package/dist/src/scene/scene_node.js +732 -0
  256. package/dist/src/scene/scene_node.js.map +1 -0
  257. package/dist/src/scene/terrain/grass.js +278 -0
  258. package/dist/src/scene/terrain/grass.js.map +1 -0
  259. package/dist/src/scene/terrain/heightfield.js +475 -0
  260. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  261. package/dist/src/scene/terrain/patch.js +530 -0
  262. package/dist/src/scene/terrain/patch.js.map +1 -0
  263. package/dist/src/scene/terrain/quadtree.js +461 -0
  264. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  265. package/dist/src/scene/terrain/terrain.js +246 -0
  266. package/dist/src/scene/terrain/terrain.js.map +1 -0
  267. package/dist/src/scene/terrain-cm/grass.js +594 -0
  268. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  269. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  270. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  271. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  272. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  273. package/dist/src/scene/water.js +374 -0
  274. package/dist/src/scene/water.js.map +1 -0
  275. package/dist/src/shaders/atmosphere.js +957 -0
  276. package/dist/src/shaders/atmosphere.js.map +1 -0
  277. package/dist/src/shaders/fog.js +112 -0
  278. package/dist/src/shaders/fog.js.map +1 -0
  279. package/dist/src/shaders/misc.js +266 -0
  280. package/dist/src/shaders/misc.js.map +1 -0
  281. package/dist/src/shaders/noise.js +222 -0
  282. package/dist/src/shaders/noise.js.map +1 -0
  283. package/dist/src/shaders/pbr.js +51 -0
  284. package/dist/src/shaders/pbr.js.map +1 -0
  285. package/dist/src/shaders/shadow.js +636 -0
  286. package/dist/src/shaders/shadow.js.map +1 -0
  287. package/dist/src/shaders/ssr.js +490 -0
  288. package/dist/src/shaders/ssr.js.map +1 -0
  289. package/dist/src/shaders/temporal.js +215 -0
  290. package/dist/src/shaders/temporal.js.map +1 -0
  291. package/dist/src/shaders/water.js +756 -0
  292. package/dist/src/shaders/water.js.map +1 -0
  293. package/dist/src/shadow/esm.js +237 -0
  294. package/dist/src/shadow/esm.js.map +1 -0
  295. package/dist/src/shadow/pcf_opt.js +181 -0
  296. package/dist/src/shadow/pcf_opt.js.map +1 -0
  297. package/dist/src/shadow/pcf_pd.js +189 -0
  298. package/dist/src/shadow/pcf_pd.js.map +1 -0
  299. package/dist/src/shadow/shader.js +37 -0
  300. package/dist/src/shadow/shader.js.map +1 -0
  301. package/dist/src/shadow/shadow_impl.js +15 -0
  302. package/dist/src/shadow/shadow_impl.js.map +1 -0
  303. package/dist/src/shadow/shadowmapper.js +790 -0
  304. package/dist/src/shadow/shadowmapper.js.map +1 -0
  305. package/dist/src/shadow/ssm.js +159 -0
  306. package/dist/src/shadow/ssm.js.map +1 -0
  307. package/dist/src/shadow/vsm.js +297 -0
  308. package/dist/src/shadow/vsm.js.map +1 -0
  309. package/dist/src/shapes/box.js +386 -0
  310. package/dist/src/shapes/box.js.map +1 -0
  311. package/dist/src/shapes/cylinder.js +125 -0
  312. package/dist/src/shapes/cylinder.js.map +1 -0
  313. package/dist/src/shapes/plane.js +88 -0
  314. package/dist/src/shapes/plane.js.map +1 -0
  315. package/dist/src/shapes/shape.js +87 -0
  316. package/dist/src/shapes/shape.js.map +1 -0
  317. package/dist/src/shapes/sphere.js +114 -0
  318. package/dist/src/shapes/sphere.js.map +1 -0
  319. package/dist/src/shapes/tetrahedron.js +188 -0
  320. package/dist/src/shapes/tetrahedron.js.map +1 -0
  321. package/dist/src/shapes/torus.js +111 -0
  322. package/dist/src/shapes/torus.js.map +1 -0
  323. package/dist/src/utility/aabbtree.js +400 -0
  324. package/dist/src/utility/aabbtree.js.map +1 -0
  325. package/dist/src/utility/bounding_volume.js +29 -0
  326. package/dist/src/utility/bounding_volume.js.map +1 -0
  327. package/dist/src/utility/debug.js +28 -0
  328. package/dist/src/utility/debug.js.map +1 -0
  329. package/dist/src/utility/draco/decoder.js +116 -0
  330. package/dist/src/utility/draco/decoder.js.map +1 -0
  331. package/dist/src/utility/misc.js +105 -0
  332. package/dist/src/utility/misc.js.map +1 -0
  333. package/dist/src/utility/panorama.js +163 -0
  334. package/dist/src/utility/panorama.js.map +1 -0
  335. package/dist/src/utility/pmrem.js +354 -0
  336. package/dist/src/utility/pmrem.js.map +1 -0
  337. package/dist/src/utility/rendermipmap.js +115 -0
  338. package/dist/src/utility/rendermipmap.js.map +1 -0
  339. package/dist/src/utility/serialization/json.js +402 -0
  340. package/dist/src/utility/serialization/json.js.map +1 -0
  341. package/dist/src/utility/serialization/manager.js +623 -0
  342. package/dist/src/utility/serialization/manager.js.map +1 -0
  343. package/dist/src/utility/serialization/scene/animation.js +248 -0
  344. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  345. package/dist/src/utility/serialization/scene/batch.js +59 -0
  346. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  347. package/dist/src/utility/serialization/scene/camera.js +790 -0
  348. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  349. package/dist/src/utility/serialization/scene/common.js +222 -0
  350. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  351. package/dist/src/utility/serialization/scene/light.js +575 -0
  352. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  353. package/dist/src/utility/serialization/scene/material.js +1111 -0
  354. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  355. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  356. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  357. package/dist/src/utility/serialization/scene/misc.js +39 -0
  358. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  359. package/dist/src/utility/serialization/scene/node.js +451 -0
  360. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  361. package/dist/src/utility/serialization/scene/particle.js +425 -0
  362. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  363. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  364. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  365. package/dist/src/utility/serialization/scene/scene.js +704 -0
  366. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  367. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  368. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  369. package/dist/src/utility/serialization/scene/water.js +465 -0
  370. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  371. package/dist/src/utility/shprojector.js +297 -0
  372. package/dist/src/utility/shprojector.js.map +1 -0
  373. package/dist/src/utility/textures/ggxlut.js +213 -0
  374. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  375. package/dist/src/utility/textures/gradientnoise.js +62 -0
  376. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  377. package/dist/src/utility/textures/randomnoise.js +41 -0
  378. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  379. package/dist/src/values.js +162 -0
  380. package/dist/src/values.js.map +1 -0
  381. package/dist/utility/blueprint/material/common.js +7 -0
  382. package/dist/utility/blueprint/material/common.js.map +1 -0
  383. package/dist/utility/blueprint/material/ir.js +489 -489
  384. package/dist/utility/blueprint/material/ir.js.map +1 -1
  385. package/dist/utility/serialization/blueprint/constants.js +255 -0
  386. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  387. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  388. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  389. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  390. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  391. package/dist/utility/serialization/manager.js +271 -271
  392. package/dist/utility/serialization/manager.js.map +1 -1
  393. package/dist/utility/serialization/scene/animation.js.map +1 -1
  394. package/dist/utility/serialization/scene/camera.js.map +1 -1
  395. package/dist/utility/serialization/scene/common.js.map +1 -1
  396. package/dist/utility/serialization/scene/light.js.map +1 -1
  397. package/dist/utility/serialization/scene/material.js.map +1 -1
  398. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  399. package/dist/utility/serialization/scene/node.js.map +1 -1
  400. package/dist/utility/serialization/scene/particle.js.map +1 -1
  401. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  402. package/dist/utility/serialization/scene/scene.js.map +1 -1
  403. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  404. package/dist/utility/serialization/types.js +4 -4
  405. package/dist/utility/serialization/types.js.map +1 -1
  406. package/dist/values.js +49 -53
  407. package/dist/values.js.map +1 -1
  408. package/package.json +1 -1
  409. package/dist/animation/joint_dynamics/vrm_spring_bone.js +0 -46
  410. package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +0 -1
  411. package/dist/animation/spring/spring_bone.js +0 -240
  412. package/dist/animation/spring/spring_bone.js.map +0 -1
  413. package/dist/animation/spring/spring_bone_collider.js +0 -198
  414. package/dist/animation/spring/spring_bone_collider.js.map +0 -1
  415. package/dist/animation/spring/spring_bone_constraint.js +0 -170
  416. package/dist/animation/spring/spring_bone_constraint.js.map +0 -1
  417. package/dist/animation/spring/spring_bone_system.js +0 -328
  418. package/dist/animation/spring/spring_bone_system.js.map +0 -1
  419. package/dist/render/sky_motion_vector.js +0 -85
  420. package/dist/render/sky_motion_vector.js.map +0 -1
@@ -0,0 +1,1265 @@
1
+ import { Matrix4x4, Vector3, Quaternion, Interpolator, DRef, Vector4 } from '@zephyr3d/base';
2
+ import { SharedModel, AssetScene, AssetSkeleton } from '../../model.js';
3
+ import { BoundingBox } from '../../../utility/bounding_volume.js';
4
+ import { Primitive } from '../../../render/primitive.js';
5
+ import '../../../material/shader/helper.js';
6
+ import '../../../material/lambert.js';
7
+ import '../../../material/blinn.js';
8
+ import { UnlitMaterial } from '../../../material/unlit.js';
9
+ import '../../../material/particle.js';
10
+ import '@zephyr3d/device';
11
+ import { MORPH_TARGET_POSITION, MORPH_TARGET_NORMAL, MORPH_TARGET_TANGENT, MORPH_TARGET_TEX0, MORPH_TARGET_TEX1, MORPH_TARGET_TEX2, MORPH_TARGET_TEX3, MORPH_TARGET_COLOR } from '../../../values.js';
12
+ import { Application } from '../../../app/app.js';
13
+ import '../../../material/meshmaterial.js';
14
+ import '../../../material/grassmaterial.js';
15
+ import '../../../material/terrainmaterial.js';
16
+ import '../../../material/terrain-cm.js';
17
+ import { PBRMetallicRoughnessMaterial } from '../../../material/pbrmr.js';
18
+ import { PBRSpecularGlossinessMaterial } from '../../../material/pbrsg.js';
19
+ import { GLTFAccessor, ComponentType } from './helpers.js';
20
+ import { AbstractModelLoader } from '../loader.js';
21
+ import { DracoMeshDecoder } from '../../../utility/draco/decoder.js';
22
+
23
+ /**
24
+ * The GLTF/GLB model loader
25
+ * @internal
26
+ */ class GLTFLoader extends AbstractModelLoader {
27
+ supportMIMEType(mimeType) {
28
+ return mimeType === 'model/gltf+json' || mimeType === 'model/gltf-binary';
29
+ }
30
+ async load(assetManager, url, mimeType, data, decoderModule) {
31
+ const buffer = await data.arrayBuffer();
32
+ if (this.isGLB(buffer)) {
33
+ return this.loadBinary(assetManager, url, buffer, assetManager.vfs, decoderModule);
34
+ }
35
+ const gltf = await new Response(data).json();
36
+ gltf._manager = assetManager;
37
+ gltf._device = Application.instance.device;
38
+ gltf._vfs = assetManager.vfs;
39
+ gltf._loadedBuffers = null;
40
+ return this.loadJson(url, gltf, decoderModule);
41
+ }
42
+ async loadBinary(assetManager, url, buffer, vfs, decoderModule) {
43
+ const jsonChunkType = 0x4e4f534a;
44
+ const binaryChunkType = 0x004e4942;
45
+ let gltf = null;
46
+ const buffers = [];
47
+ const chunkInfos = this.getGLBChunkInfos(buffer);
48
+ for (const info of chunkInfos){
49
+ if (info.type === jsonChunkType && !gltf) {
50
+ const jsonSlice = new Uint8Array(buffer, 20, info.length);
51
+ const stringBuffer = new TextDecoder('utf-8').decode(jsonSlice);
52
+ gltf = JSON.parse(stringBuffer);
53
+ } else if (info.type === binaryChunkType) {
54
+ buffers.push(buffer.slice(info.start, info.start + info.length));
55
+ }
56
+ }
57
+ if (gltf) {
58
+ gltf._manager = assetManager;
59
+ gltf._device = Application.instance.device;
60
+ gltf._vfs = vfs;
61
+ gltf._loadedBuffers = buffers;
62
+ return this.loadJson(url, gltf, decoderModule);
63
+ }
64
+ return null;
65
+ }
66
+ async loadJson(url, gltf, dracoDecoderModule) {
67
+ // check extensions
68
+ if (!dracoDecoderModule && gltf.extensionsRequired && gltf.extensionsRequired.indexOf('KHR_draco_mesh_compression') >= 0) {
69
+ console.error('Draco3d is required for loading model');
70
+ return null;
71
+ }
72
+ gltf._dracoModule = dracoDecoderModule;
73
+ gltf._accessors = [];
74
+ gltf._bufferCache = {};
75
+ gltf._textureCache = {};
76
+ gltf._materialCache = {};
77
+ gltf._nodes = [];
78
+ gltf._meshes = [];
79
+ // check asset property
80
+ const asset = gltf.asset;
81
+ if (asset) {
82
+ const gltfVersion = asset.version;
83
+ if (gltfVersion !== '2.0') {
84
+ console.error(`Invalid GLTF version: ${gltfVersion}`);
85
+ return null;
86
+ }
87
+ }
88
+ gltf._baseURI = url.substring(0, url.lastIndexOf('/') + 1);
89
+ if (!gltf._loadedBuffers) {
90
+ gltf._loadedBuffers = [];
91
+ const buffers = gltf.buffers;
92
+ if (buffers) {
93
+ for (const buffer of buffers){
94
+ const uri = this._normalizeURI(gltf._baseURI, buffer.uri);
95
+ const buf = await gltf._manager.fetchBinaryData(uri, null);
96
+ if (buffer.byteLength !== buf.byteLength) {
97
+ console.error(`Invalid GLTF: buffer byte length error.`);
98
+ return null;
99
+ }
100
+ gltf._loadedBuffers.push(buf);
101
+ }
102
+ }
103
+ }
104
+ const accessors = gltf.accessors;
105
+ if (accessors) {
106
+ for (const accessor of gltf.accessors){
107
+ gltf._accessors.push(new GLTFAccessor(accessor));
108
+ }
109
+ }
110
+ const scenes = gltf.scenes;
111
+ if (scenes) {
112
+ const sharedModel = new SharedModel();
113
+ await this._loadMeshes(gltf);
114
+ this._loadNodes(gltf, sharedModel);
115
+ this._loadSkins(gltf, sharedModel);
116
+ for(let i = 0; i < gltf.nodes?.length; i++){
117
+ if (typeof gltf.nodes[i].skin === 'number' && gltf.nodes[i].skin >= 0) {
118
+ gltf._nodes[i].skeleton = sharedModel.skeletons[gltf.nodes[i].skin];
119
+ }
120
+ }
121
+ this._loadAnimations(gltf, sharedModel);
122
+ for (const scene of scenes){
123
+ const assetScene = new AssetScene(scene.name);
124
+ for (const node of scene.nodes){
125
+ assetScene.rootNodes.push(gltf._nodes[node]);
126
+ }
127
+ sharedModel.scenes.push(assetScene);
128
+ }
129
+ if (typeof gltf.scene === 'number') {
130
+ sharedModel.activeScene = gltf.scene;
131
+ }
132
+ return sharedModel;
133
+ }
134
+ return null;
135
+ }
136
+ /** @internal */ _normalizeURI(baseURI, uri) {
137
+ const s = uri.toLowerCase();
138
+ if (s.startsWith('http://') || s.startsWith('https://') || s.startsWith('blob:') || s.startsWith('data:')) {
139
+ // absolute path
140
+ return encodeURI(uri);
141
+ }
142
+ uri = uri.replace(/\.\//g, '');
143
+ uri = decodeURIComponent(uri);
144
+ if (uri[0] === '/') {
145
+ uri = uri.slice(1);
146
+ }
147
+ uri = uri.split('/').map((val)=>encodeURIComponent(val)).join('/');
148
+ return baseURI + uri;
149
+ }
150
+ /** @internal */ _loadNodes(gltf, model) {
151
+ if (gltf.nodes) {
152
+ for(let i = 0; i < gltf.nodes.length; i++){
153
+ this._loadNode(gltf, i, null, model);
154
+ }
155
+ for (const node of gltf._nodes){
156
+ if (!node.parent) {
157
+ node.computeTransforms(null);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ /** @internal */ _loadSkins(gltf, model) {
163
+ if (gltf.skins) {
164
+ for(let i = 0; i < gltf.skins.length; i++){
165
+ const skinInfo = gltf.skins[i];
166
+ const skeleton = new AssetSkeleton(skinInfo.name);
167
+ if (typeof skinInfo.skeleton === 'number') {
168
+ skeleton.pivot = gltf._nodes[skinInfo.skeleton];
169
+ }
170
+ const accessor = gltf._accessors[skinInfo.inverseBindMatrices];
171
+ if (!accessor || accessor.type !== 'MAT4' || accessor.componentType !== ComponentType.FLOAT) {
172
+ throw new Error('Invalid GLTF inverse bind matricies accessor');
173
+ }
174
+ const matrices = typeof skinInfo.inverseBindMatrices === 'number' ? accessor.getDeinterlacedView(gltf) : null;
175
+ skinInfo.joints.forEach((joint, index)=>{
176
+ const m = index * 16;
177
+ skeleton.addJoint(gltf._nodes[joint], matrices ? new Matrix4x4(matrices.subarray(m, m + 16)) : Matrix4x4.identity());
178
+ });
179
+ model.addSkeleton(skeleton);
180
+ }
181
+ }
182
+ }
183
+ /** @internal */ _loadAnimations(gltf, model) {
184
+ if (gltf.animations) {
185
+ for(let i = 0; i < gltf.animations.length; i++){
186
+ const animation = this._loadAnimation(gltf, i);
187
+ model.addAnimation(animation);
188
+ }
189
+ }
190
+ }
191
+ /** @internal */ collectNodes(gltf) {
192
+ const collect = new Map();
193
+ for (const node of gltf._nodes){
194
+ collect.set(node, {
195
+ translate: node.position || Vector3.zero(),
196
+ rotation: node.rotation || Quaternion.identity(),
197
+ scale: node.scaling || Vector3.one(),
198
+ worldTransform: null
199
+ });
200
+ }
201
+ return collect;
202
+ }
203
+ /** @internal */ getAnimationInfo(gltf, index) {
204
+ const animationInfo = gltf.animations[index];
205
+ const name = animationInfo.name || null;
206
+ const channels = animationInfo.channels;
207
+ const samplers = animationInfo.samplers;
208
+ const interpolators = [];
209
+ const interpolatorTypes = [];
210
+ const nodes = this.collectNodes(gltf);
211
+ let maxTime = 0;
212
+ for(let i = 0; i < channels.length; i++){
213
+ const channel = channels[i];
214
+ const sampler = samplers[channel.sampler];
215
+ const input = gltf._accessors[sampler.input].getNormalizedDeinterlacedView(gltf);
216
+ const output = gltf._accessors[sampler.output].getNormalizedDeinterlacedView(gltf);
217
+ if (!(input instanceof Float32Array) || !(output instanceof Float32Array)) {
218
+ console.error('Input/output channel of animation must be Float32Array');
219
+ continue;
220
+ }
221
+ const mode = sampler.interpolation === 'STEP' ? 'step' : sampler.interpolation === 'CUBICSPLINE' ? 'cubicspline' : 'linear';
222
+ if (channel.target.path === 'rotation') {
223
+ interpolators.push(new Interpolator(mode, 'quat', input, output));
224
+ interpolatorTypes.push('rotation');
225
+ } else if (channel.target.path === 'translation') {
226
+ interpolators.push(new Interpolator(mode, 'vec3', input, output));
227
+ interpolatorTypes.push('translation');
228
+ } else if (channel.target.path === 'scale') {
229
+ interpolators.push(new Interpolator(mode, 'vec3', input, output));
230
+ interpolatorTypes.push('scale');
231
+ } else if (channel.target.path === 'weights') {
232
+ interpolators.push(new Interpolator(mode, null, input, output));
233
+ interpolatorTypes.push('weights');
234
+ } else {
235
+ continue;
236
+ }
237
+ const max = input[input.length - 1];
238
+ if (max > maxTime) {
239
+ maxTime = max;
240
+ }
241
+ }
242
+ return {
243
+ name,
244
+ channels,
245
+ samplers,
246
+ interpolators,
247
+ interpolatorTypes,
248
+ maxTime,
249
+ nodes
250
+ };
251
+ }
252
+ /** @internal */ _loadAnimation(gltf, index) {
253
+ const animationInfo = this.getAnimationInfo(gltf, index);
254
+ const animationData = {
255
+ name: animationInfo.name,
256
+ tracks: [],
257
+ skeletons: [],
258
+ nodes: []
259
+ };
260
+ for(let i = 0; i < animationInfo.channels.length; i++){
261
+ const targetNode = gltf._nodes[animationInfo.channels[i].target.node];
262
+ const track = {
263
+ node: targetNode,
264
+ type: animationInfo.interpolatorTypes[i],
265
+ interpolator: animationInfo.interpolators[i]
266
+ };
267
+ if (track.type === 'weights') {
268
+ track.defaultMorphWeights = targetNode.weights;
269
+ }
270
+ animationData.tracks.push(track);
271
+ if (animationData.nodes.indexOf(targetNode) < 0) {
272
+ animationData.nodes.push(targetNode);
273
+ }
274
+ if (targetNode.skeletonAttached) {
275
+ for (const skeleton of targetNode.skeletonAttached){
276
+ if (animationData.skeletons.indexOf(skeleton) < 0) {
277
+ animationData.skeletons.push(skeleton);
278
+ }
279
+ }
280
+ }
281
+ }
282
+ return animationData;
283
+ }
284
+ /** @internal */ _loadNode(gltf, nodeIndex, parent, model) {
285
+ let node = gltf._nodes[nodeIndex];
286
+ if (node) {
287
+ if (parent) {
288
+ if (node.parent) {
289
+ throw new Error('invalid node hierarchy');
290
+ }
291
+ parent.addChild(node);
292
+ }
293
+ return node;
294
+ }
295
+ const nodeInfo = gltf.nodes?.[nodeIndex];
296
+ if (nodeInfo) {
297
+ node = model.addNode(parent, nodeIndex, nodeInfo.name);
298
+ if (typeof nodeInfo.mesh === 'number') {
299
+ node.mesh = gltf._meshes[nodeInfo.mesh];
300
+ if (node.weights) {
301
+ node.mesh.morphWeights = node.weights;
302
+ }
303
+ const instancing = nodeInfo.extensions?.['EXT_mesh_gpu_instancing'];
304
+ if (instancing) {
305
+ const attributes = instancing.attributes;
306
+ if (attributes) {
307
+ const accessorTranslation = typeof attributes.TRANSLATION === 'number' ? gltf._accessors[attributes.TRANSLATION] : null;
308
+ const accessorScale = typeof attributes.SCALE === 'number' ? gltf._accessors[attributes.SCALE] : null;
309
+ const accessorRotation = typeof attributes.ROTATION === 'number' ? gltf._accessors[attributes.ROTATION] : null;
310
+ const count = accessorTranslation?.count ?? accessorScale?.count ?? accessorRotation.count ?? 0;
311
+ const translationValues = accessorTranslation?.getNormalizedDeinterlacedView(gltf);
312
+ const scaleValues = accessorScale?.getNormalizedDeinterlacedView(gltf);
313
+ const rotationValues = accessorRotation?.getNormalizedDeinterlacedView(gltf);
314
+ for(let i = 0; i < count; i++){
315
+ const t = translationValues ? new Vector3(translationValues[i * 3], translationValues[i * 3 + 1], translationValues[i * 3 + 2]) : Vector3.zero();
316
+ const s = scaleValues ? new Vector3(scaleValues[i * 3], scaleValues[i * 3 + 1], scaleValues[i * 3 + 2]) : Vector3.one();
317
+ const r = rotationValues ? new Quaternion(rotationValues[i * 4], rotationValues[i * 4 + 1], rotationValues[i * 4 + 2], rotationValues[i * 4 + 3]) : Quaternion.identity();
318
+ node.instances.push({
319
+ t,
320
+ s,
321
+ r
322
+ });
323
+ }
324
+ }
325
+ } else {
326
+ node.instances.push({
327
+ t: Vector3.zero(),
328
+ s: Vector3.one(),
329
+ r: Quaternion.identity()
330
+ });
331
+ }
332
+ }
333
+ if (!(typeof nodeInfo.skin === 'number') || nodeInfo.skin < 0) {
334
+ // GLTF spec: Only the joint transforms are applied to the skinned mesh; the transform of the skinned mesh node MUST be ignored.
335
+ if (nodeInfo.matrix) {
336
+ const matrix = new Matrix4x4(nodeInfo.matrix);
337
+ matrix.decompose(node.scaling, node.rotation, node.position);
338
+ } else {
339
+ if (nodeInfo.rotation) {
340
+ node.rotation.set(nodeInfo.rotation);
341
+ }
342
+ if (nodeInfo.scale) {
343
+ node.scaling.set(nodeInfo.scale);
344
+ }
345
+ if (nodeInfo.translation) {
346
+ node.position.set(nodeInfo.translation);
347
+ }
348
+ }
349
+ }
350
+ gltf._nodes[nodeIndex] = node;
351
+ if (nodeInfo.children) {
352
+ for (const childIndex of nodeInfo.children){
353
+ this._loadNode(gltf, childIndex, node, model);
354
+ }
355
+ }
356
+ } else {
357
+ throw new Error(`invalid GLTF node: ${nodeIndex}`);
358
+ }
359
+ return node;
360
+ }
361
+ /** @internal */ async _loadMeshes(gltf) {
362
+ if (gltf.meshes) {
363
+ for(let i = 0; i < gltf.meshes.length; i++){
364
+ gltf._meshes[i] = await this._loadMesh(gltf, i);
365
+ }
366
+ }
367
+ }
368
+ /** @internal */ async _loadMesh(gltf, meshIndex) {
369
+ const meshInfo = gltf.meshes && gltf.meshes[meshIndex];
370
+ let mesh = null;
371
+ if (meshInfo) {
372
+ mesh = {
373
+ morphWeights: meshInfo.weights ?? null,
374
+ subMeshes: []
375
+ };
376
+ const primitives = meshInfo.primitives;
377
+ const meshName = meshInfo.name || null;
378
+ if (primitives) {
379
+ for(let i = 0; i < primitives.length; i++){
380
+ const p = primitives[i];
381
+ const subMeshData = {
382
+ name: `${meshName}-${i}`,
383
+ primitive: new DRef(),
384
+ material: new DRef(),
385
+ rawPositions: null,
386
+ rawBlendIndices: null,
387
+ rawJointWeights: null,
388
+ numTargets: 0
389
+ };
390
+ const primitive = new Primitive();
391
+ const attributes = p.attributes;
392
+ const dracoExtension = gltf._dracoModule ? p.extensions?.['KHR_draco_mesh_compression'] : null;
393
+ let dracoMeshDecoder = null;
394
+ if (dracoExtension) {
395
+ const bufferView = gltf.bufferViews && gltf.bufferViews[dracoExtension.bufferView];
396
+ if (!bufferView) {
397
+ throw new Error('Draco buffer view not set');
398
+ }
399
+ const arrayBuffer = gltf._loadedBuffers && gltf._loadedBuffers[bufferView.buffer];
400
+ if (!arrayBuffer) {
401
+ throw new Error('Draco buffer view does not point to a valid ArrayBuffer');
402
+ }
403
+ dracoMeshDecoder = new DracoMeshDecoder(new Int8Array(arrayBuffer, bufferView.byteOffset ?? 0, bufferView.byteLength), gltf._dracoModule);
404
+ }
405
+ for(const attrib in attributes){
406
+ this._loadVertexBuffer(gltf, attrib, attributes[attrib], primitive, subMeshData, dracoExtension, dracoMeshDecoder);
407
+ }
408
+ if (p.targets) {
409
+ if (Application.instance.device.type === 'webgl') {
410
+ // Emulate vertexID for WebGL1 device
411
+ if (attributes['TEXCOORD_7'] !== undefined) {
412
+ console.error(`Could not load morph target animation`);
413
+ p.targets = null;
414
+ } else {
415
+ const vertexIndices = new Float32Array(primitive.getNumVertices());
416
+ for(let i = 0; i < vertexIndices.length; i++){
417
+ vertexIndices[i] = i;
418
+ }
419
+ primitive.createAndSetVertexBuffer('tex7_f32', vertexIndices);
420
+ }
421
+ }
422
+ }
423
+ if (p.targets) {
424
+ const targets = {};
425
+ const targetBox = [];
426
+ const targetMap = {
427
+ POSITION: MORPH_TARGET_POSITION,
428
+ NORMAL: MORPH_TARGET_NORMAL,
429
+ TANGENT: MORPH_TARGET_TANGENT,
430
+ TEXCOORD_0: MORPH_TARGET_TEX0,
431
+ TEXCOORD_1: MORPH_TARGET_TEX1,
432
+ TEXCOORD_2: MORPH_TARGET_TEX2,
433
+ TEXCOORD_3: MORPH_TARGET_TEX3,
434
+ COLOR_0: MORPH_TARGET_COLOR
435
+ };
436
+ const morphAttribSet = new Set();
437
+ for (const target of p.targets){
438
+ for(const k in target){
439
+ const t = targetMap[k];
440
+ if (t !== undefined) {
441
+ targets[t] = targets[t] ?? {
442
+ numComponents: 0,
443
+ data: []
444
+ };
445
+ const accessorIndex = target[k];
446
+ const accessor = gltf._accessors[accessorIndex];
447
+ targets[t].numComponents = accessor.getComponentCount(accessor.type);
448
+ targets[t].data.push(accessor.getNormalizedDeinterlacedView(gltf));
449
+ if (k === 'POSITION') {
450
+ const min = accessor.min ? new Vector3(accessor.min[0], accessor.min[1], accessor.min[2]) : Vector3.zero();
451
+ const max = accessor.max ? new Vector3(accessor.max[0], accessor.max[1], accessor.max[2]) : Vector3.zero();
452
+ targetBox.push(new BoundingBox(min, max));
453
+ }
454
+ morphAttribSet.add(t);
455
+ }
456
+ }
457
+ }
458
+ subMeshData.numTargets = p.targets.length;
459
+ subMeshData.targets = targets;
460
+ subMeshData.targetBox = targetBox;
461
+ subMeshData.morphAttribCount = morphAttribSet.size;
462
+ }
463
+ const indices = p.indices;
464
+ if (typeof indices === 'number') {
465
+ this._loadIndexBuffer(gltf, indices, primitive, subMeshData, dracoExtension, dracoMeshDecoder);
466
+ }
467
+ let primitiveType = p.mode;
468
+ if (typeof primitiveType !== 'number') {
469
+ primitiveType = 4;
470
+ }
471
+ primitive.primitiveType = this._primitiveType(primitiveType);
472
+ const hasVertexNormal = !!primitive.getVertexBuffer('normal');
473
+ const hasVertexColor = !!primitive.getVertexBuffer('diffuse');
474
+ const hasVertexTangent = !!primitive.getVertexBuffer('tangent');
475
+ const materialHash = `${p.material}.${Number(hasVertexNormal)}.${Number(hasVertexColor)}.${Number(hasVertexTangent)}`;
476
+ let material = gltf._materialCache[materialHash];
477
+ if (!material) {
478
+ const materialInfo = p.material !== undefined ? gltf.materials[p.material] : null;
479
+ material = await this._loadMaterial(gltf, materialInfo, hasVertexColor, hasVertexNormal, hasVertexTangent);
480
+ gltf._materialCache[materialHash] = material;
481
+ }
482
+ subMeshData.primitive.set(primitive);
483
+ subMeshData.material.set(material);
484
+ mesh.subMeshes.push(subMeshData);
485
+ }
486
+ }
487
+ }
488
+ return mesh;
489
+ }
490
+ async _createMaterial(assetMaterial) {
491
+ if (assetMaterial.type === 'unlit') {
492
+ const unlitAssetMaterial = assetMaterial;
493
+ const unlitMaterial = new UnlitMaterial();
494
+ unlitMaterial.albedoColor = unlitAssetMaterial.diffuse ?? Vector4.one();
495
+ if (unlitAssetMaterial.diffuseMap) {
496
+ unlitMaterial.albedoTexture = unlitAssetMaterial.diffuseMap.texture;
497
+ unlitMaterial.albedoTextureSampler = unlitAssetMaterial.diffuseMap.sampler;
498
+ unlitMaterial.albedoTexCoordIndex = unlitAssetMaterial.diffuseMap.texCoord;
499
+ unlitMaterial.albedoTexCoordMatrix = unlitAssetMaterial.diffuseMap.transform;
500
+ }
501
+ unlitMaterial.vertexColor = unlitAssetMaterial.common.vertexColor;
502
+ if (assetMaterial.common.alphaMode === 'blend') {
503
+ unlitMaterial.blendMode = 'blend';
504
+ } else if (assetMaterial.common.alphaMode === 'mask') {
505
+ unlitMaterial.alphaCutoff = assetMaterial.common.alphaCutoff;
506
+ }
507
+ if (assetMaterial.common.doubleSided) {
508
+ unlitMaterial.cullMode = 'none';
509
+ }
510
+ return unlitMaterial;
511
+ } else if (assetMaterial.type === 'pbrSpecularGlossiness') {
512
+ const assetPBRMaterial = assetMaterial;
513
+ const pbrMaterial = new PBRSpecularGlossinessMaterial();
514
+ pbrMaterial.ior = assetPBRMaterial.ior;
515
+ pbrMaterial.albedoColor = assetPBRMaterial.diffuse;
516
+ pbrMaterial.specularFactor = new Vector3(assetPBRMaterial.specular.x, assetPBRMaterial.specular.y, assetPBRMaterial.specular.z);
517
+ pbrMaterial.glossinessFactor = assetPBRMaterial.glossness;
518
+ if (assetPBRMaterial.diffuseMap) {
519
+ pbrMaterial.albedoTexture = assetPBRMaterial.diffuseMap.texture;
520
+ pbrMaterial.albedoTextureSampler = assetPBRMaterial.diffuseMap.sampler;
521
+ pbrMaterial.albedoTexCoordIndex = assetPBRMaterial.diffuseMap.texCoord;
522
+ pbrMaterial.albedoTexCoordMatrix = assetPBRMaterial.diffuseMap.transform;
523
+ }
524
+ if (assetPBRMaterial.common.normalMap) {
525
+ pbrMaterial.normalTexture = assetPBRMaterial.common.normalMap.texture;
526
+ pbrMaterial.normalTextureSampler = assetPBRMaterial.common.normalMap.sampler;
527
+ pbrMaterial.normalTexCoordIndex = assetPBRMaterial.common.normalMap.texCoord;
528
+ pbrMaterial.normalTexCoordMatrix = assetPBRMaterial.common.normalMap.transform;
529
+ }
530
+ pbrMaterial.normalScale = assetPBRMaterial.common.bumpScale;
531
+ if (assetPBRMaterial.common.emissiveMap) {
532
+ pbrMaterial.emissiveTexture = assetPBRMaterial.common.emissiveMap.texture;
533
+ pbrMaterial.emissiveTextureSampler = assetPBRMaterial.common.emissiveMap.sampler;
534
+ pbrMaterial.emissiveTexCoordIndex = assetPBRMaterial.common.emissiveMap.texCoord;
535
+ pbrMaterial.emissiveTexCoordMatrix = assetPBRMaterial.common.emissiveMap.transform;
536
+ }
537
+ pbrMaterial.emissiveColor = assetPBRMaterial.common.emissiveColor;
538
+ pbrMaterial.emissiveStrength = assetPBRMaterial.common.emissiveStrength;
539
+ if (assetPBRMaterial.common.occlusionMap) {
540
+ pbrMaterial.occlusionTexture = assetPBRMaterial.common.occlusionMap.texture;
541
+ pbrMaterial.occlusionTextureSampler = assetPBRMaterial.common.occlusionMap.sampler;
542
+ pbrMaterial.occlusionTexCoordIndex = assetPBRMaterial.common.occlusionMap.texCoord;
543
+ pbrMaterial.occlusionTexCoordMatrix = assetPBRMaterial.common.occlusionMap.transform;
544
+ }
545
+ pbrMaterial.occlusionStrength = assetPBRMaterial.common.occlusionStrength;
546
+ if (assetPBRMaterial.specularGlossnessMap) {
547
+ pbrMaterial.specularTexture = assetPBRMaterial.specularGlossnessMap.texture;
548
+ pbrMaterial.specularTextureSampler = assetPBRMaterial.specularGlossnessMap.sampler;
549
+ pbrMaterial.specularTexCoordIndex = assetPBRMaterial.specularGlossnessMap.texCoord;
550
+ pbrMaterial.specularTexCoordMatrix = assetPBRMaterial.specularGlossnessMap.transform;
551
+ }
552
+ pbrMaterial.vertexTangent = assetPBRMaterial.common.useTangent;
553
+ pbrMaterial.vertexColor = assetPBRMaterial.common.vertexColor;
554
+ if (assetPBRMaterial.common.alphaMode === 'blend') {
555
+ pbrMaterial.blendMode = 'blend';
556
+ } else if (assetPBRMaterial.common.alphaMode === 'mask') {
557
+ pbrMaterial.alphaCutoff = assetPBRMaterial.common.alphaCutoff;
558
+ }
559
+ if (assetPBRMaterial.common.doubleSided) {
560
+ pbrMaterial.cullMode = 'none';
561
+ }
562
+ pbrMaterial.vertexNormal = !!assetMaterial.common.vertexNormal;
563
+ return pbrMaterial;
564
+ } else if (assetMaterial.type === 'pbrMetallicRoughness') {
565
+ const assetPBRMaterial = assetMaterial;
566
+ const pbrMaterial = new PBRMetallicRoughnessMaterial();
567
+ pbrMaterial.ior = assetPBRMaterial.ior;
568
+ pbrMaterial.albedoColor = assetPBRMaterial.diffuse;
569
+ pbrMaterial.metallic = assetPBRMaterial.metallic;
570
+ pbrMaterial.roughness = assetPBRMaterial.roughness;
571
+ if (assetPBRMaterial.diffuseMap) {
572
+ pbrMaterial.albedoTexture = assetPBRMaterial.diffuseMap.texture;
573
+ pbrMaterial.albedoTextureSampler = assetPBRMaterial.diffuseMap.sampler;
574
+ pbrMaterial.albedoTexCoordIndex = assetPBRMaterial.diffuseMap.texCoord;
575
+ pbrMaterial.albedoTexCoordMatrix = assetPBRMaterial.diffuseMap.transform;
576
+ }
577
+ if (assetPBRMaterial.common.normalMap) {
578
+ pbrMaterial.normalTexture = assetPBRMaterial.common.normalMap.texture;
579
+ pbrMaterial.normalTextureSampler = assetPBRMaterial.common.normalMap.sampler;
580
+ pbrMaterial.normalTexCoordIndex = assetPBRMaterial.common.normalMap.texCoord;
581
+ pbrMaterial.normalTexCoordMatrix = assetPBRMaterial.common.normalMap.transform;
582
+ }
583
+ pbrMaterial.normalScale = assetPBRMaterial.common.bumpScale;
584
+ if (assetPBRMaterial.common.emissiveMap) {
585
+ pbrMaterial.emissiveTexture = assetPBRMaterial.common.emissiveMap.texture;
586
+ pbrMaterial.emissiveTextureSampler = assetPBRMaterial.common.emissiveMap.sampler;
587
+ pbrMaterial.emissiveTexCoordIndex = assetPBRMaterial.common.emissiveMap.texCoord;
588
+ pbrMaterial.emissiveTexCoordMatrix = assetPBRMaterial.common.emissiveMap.transform;
589
+ }
590
+ pbrMaterial.emissiveColor = assetPBRMaterial.common.emissiveColor;
591
+ pbrMaterial.emissiveStrength = assetPBRMaterial.common.emissiveStrength;
592
+ if (assetPBRMaterial.common.occlusionMap) {
593
+ pbrMaterial.occlusionTexture = assetPBRMaterial.common.occlusionMap.texture;
594
+ pbrMaterial.occlusionTextureSampler = assetPBRMaterial.common.occlusionMap.sampler;
595
+ pbrMaterial.occlusionTexCoordIndex = assetPBRMaterial.common.occlusionMap.texCoord;
596
+ pbrMaterial.occlusionTexCoordMatrix = assetPBRMaterial.common.occlusionMap.transform;
597
+ pbrMaterial.occlusionStrength = assetPBRMaterial.common.occlusionStrength;
598
+ }
599
+ if (assetPBRMaterial.metallicMap) {
600
+ pbrMaterial.metallicRoughnessTexture = assetPBRMaterial.metallicMap.texture;
601
+ pbrMaterial.metallicRoughnessTextureSampler = assetPBRMaterial.metallicMap.sampler;
602
+ pbrMaterial.metallicRoughnessTexCoordIndex = assetPBRMaterial.metallicMap.texCoord;
603
+ pbrMaterial.metallicRoughnessTexCoordMatrix = assetPBRMaterial.metallicMap.transform;
604
+ }
605
+ pbrMaterial.specularFactor = assetPBRMaterial.specularFactor;
606
+ if (assetPBRMaterial.specularMap) {
607
+ pbrMaterial.specularTexture = assetPBRMaterial.specularMap.texture;
608
+ pbrMaterial.specularTextureSampler = assetPBRMaterial.specularMap.sampler;
609
+ pbrMaterial.specularTexCoordIndex = assetPBRMaterial.specularMap.texCoord;
610
+ pbrMaterial.specularTexCoordMatrix = assetPBRMaterial.specularMap.transform;
611
+ }
612
+ if (assetPBRMaterial.specularColorMap) {
613
+ pbrMaterial.specularColorTexture = assetPBRMaterial.specularColorMap.texture;
614
+ pbrMaterial.specularColorTextureSampler = assetPBRMaterial.specularColorMap.sampler;
615
+ pbrMaterial.specularColorTexCoordIndex = assetPBRMaterial.specularColorMap.texCoord;
616
+ pbrMaterial.specularColorTexCoordMatrix = assetPBRMaterial.specularColorMap.transform;
617
+ }
618
+ if (assetPBRMaterial.sheen) {
619
+ const sheen = assetPBRMaterial.sheen;
620
+ pbrMaterial.sheen = true;
621
+ pbrMaterial.sheenColorFactor = sheen.sheenColorFactor;
622
+ pbrMaterial.sheenRoughnessFactor = sheen.sheenRoughnessFactor;
623
+ if (sheen.sheenColorMap) {
624
+ pbrMaterial.sheenColorTexture = sheen.sheenColorMap.texture;
625
+ pbrMaterial.sheenColorTextureSampler = sheen.sheenColorMap.sampler;
626
+ pbrMaterial.sheenColorTexCoordIndex = sheen.sheenColorMap.texCoord;
627
+ pbrMaterial.sheenColorTexCoordMatrix = sheen.sheenColorMap.transform;
628
+ }
629
+ if (sheen.sheenRoughnessMap) {
630
+ pbrMaterial.sheenRoughnessTexture = sheen.sheenRoughnessMap.texture;
631
+ pbrMaterial.sheenRoughnessTextureSampler = sheen.sheenRoughnessMap.sampler;
632
+ pbrMaterial.sheenRoughnessTexCoordIndex = sheen.sheenRoughnessMap.texCoord;
633
+ pbrMaterial.sheenRoughnessTexCoordMatrix = sheen.sheenRoughnessMap.transform;
634
+ }
635
+ }
636
+ if (assetPBRMaterial.iridescence) {
637
+ const iridescence = assetPBRMaterial.iridescence;
638
+ pbrMaterial.iridescence = true;
639
+ pbrMaterial.iridescenceFactor = iridescence.iridescenceFactor;
640
+ pbrMaterial.iridescenceIor = iridescence.iridescenceIor;
641
+ if (iridescence.iridescenceMap) {
642
+ pbrMaterial.iridescenceTexture = iridescence.iridescenceMap.texture;
643
+ pbrMaterial.iridescenceTextureSampler = iridescence.iridescenceMap.sampler;
644
+ pbrMaterial.iridescenceTexCoordIndex = iridescence.iridescenceMap.texCoord;
645
+ pbrMaterial.iridescenceTexCoordMatrix = iridescence.iridescenceMap.transform;
646
+ }
647
+ pbrMaterial.iridescenceThicknessMin = iridescence.iridescenceThicknessMinimum;
648
+ pbrMaterial.iridescenceThicknessMax = iridescence.iridescenceThicknessMaximum;
649
+ if (iridescence.iridescenceThicknessMap) {
650
+ pbrMaterial.iridescenceThicknessTexture = iridescence.iridescenceThicknessMap.texture;
651
+ pbrMaterial.iridescenceThicknessTextureSampler = iridescence.iridescenceThicknessMap.sampler;
652
+ pbrMaterial.iridescenceThicknessTexCoordIndex = iridescence.iridescenceThicknessMap.texCoord;
653
+ pbrMaterial.iridescenceThicknessTexCoordMatrix = iridescence.iridescenceThicknessMap.transform;
654
+ }
655
+ }
656
+ if (assetPBRMaterial.transmission) {
657
+ const transmission = assetPBRMaterial.transmission;
658
+ pbrMaterial.transmission = true;
659
+ pbrMaterial.transmissionFactor = transmission.transmissionFactor;
660
+ if (transmission.transmissionMap) {
661
+ pbrMaterial.transmissionTexture = transmission.transmissionMap.texture;
662
+ pbrMaterial.transmissionTextureSampler = transmission.transmissionMap.sampler;
663
+ pbrMaterial.transmissionTexCoordIndex = transmission.transmissionMap.texCoord;
664
+ pbrMaterial.transmissionTexCoordMatrix = transmission.transmissionMap.transform;
665
+ }
666
+ pbrMaterial.thicknessFactor = transmission.thicknessFactor;
667
+ if (transmission.thicknessMap) {
668
+ pbrMaterial.thicknessTexture = transmission.thicknessMap.texture;
669
+ pbrMaterial.thicknessTextureSampler = transmission.thicknessMap.sampler;
670
+ pbrMaterial.thicknessTexCoordIndex = transmission.thicknessMap.texCoord;
671
+ pbrMaterial.thicknessTexCoordMatrix = transmission.thicknessMap.transform;
672
+ }
673
+ pbrMaterial.attenuationDistance = transmission.attenuationDistance;
674
+ pbrMaterial.attenuationColor = transmission.attenuationColor;
675
+ }
676
+ if (assetPBRMaterial.clearcoat) {
677
+ const cc = assetPBRMaterial.clearcoat;
678
+ pbrMaterial.clearcoat = true;
679
+ pbrMaterial.clearcoatIntensity = cc.clearCoatFactor;
680
+ pbrMaterial.clearcoatRoughnessFactor = cc.clearCoatRoughnessFactor;
681
+ if (cc.clearCoatIntensityMap) {
682
+ pbrMaterial.clearcoatIntensityTexture = cc.clearCoatIntensityMap.texture;
683
+ pbrMaterial.clearcoatIntensityTextureSampler = cc.clearCoatIntensityMap.sampler;
684
+ pbrMaterial.clearcoatIntensityTexCoordIndex = cc.clearCoatIntensityMap.texCoord;
685
+ pbrMaterial.clearcoatIntensityTexCoordMatrix = cc.clearCoatIntensityMap.transform;
686
+ }
687
+ if (cc.clearCoatRoughnessMap) {
688
+ pbrMaterial.clearcoatRoughnessTexture = cc.clearCoatRoughnessMap.texture;
689
+ pbrMaterial.clearcoatRoughnessTextureSampler = cc.clearCoatRoughnessMap.sampler;
690
+ pbrMaterial.clearcoatRoughnessTexCoordIndex = cc.clearCoatRoughnessMap.texCoord;
691
+ pbrMaterial.clearcoatRoughnessTexCoordMatrix = cc.clearCoatRoughnessMap.transform;
692
+ }
693
+ if (cc.clearCoatNormalMap) {
694
+ pbrMaterial.clearcoatNormalTexture = cc.clearCoatNormalMap.texture;
695
+ pbrMaterial.clearcoatNormalTextureSampler = cc.clearCoatNormalMap.sampler;
696
+ pbrMaterial.clearcoatNormalTexCoordIndex = cc.clearCoatNormalMap.texCoord;
697
+ pbrMaterial.clearcoatNormalTexCoordMatrix = cc.clearCoatNormalMap.transform;
698
+ }
699
+ }
700
+ pbrMaterial.vertexTangent = assetPBRMaterial.common.useTangent;
701
+ pbrMaterial.vertexColor = assetPBRMaterial.common.vertexColor;
702
+ if (assetPBRMaterial.common.alphaMode === 'blend') {
703
+ pbrMaterial.blendMode = 'blend';
704
+ } else if (assetPBRMaterial.common.alphaMode === 'mask') {
705
+ pbrMaterial.alphaCutoff = assetPBRMaterial.common.alphaCutoff;
706
+ }
707
+ if (assetPBRMaterial.common.doubleSided) {
708
+ pbrMaterial.cullMode = 'none';
709
+ }
710
+ pbrMaterial.vertexNormal = !!assetMaterial.common.vertexNormal;
711
+ return pbrMaterial;
712
+ }
713
+ }
714
+ /** @internal */ async _loadMaterial(gltf, materialInfo, vertexColor, vertexNormal, useTangent) {
715
+ let assetMaterial = null;
716
+ let pbrMetallicRoughness = null;
717
+ let pbrSpecularGlossness = null;
718
+ const pbrCommon = {
719
+ useTangent,
720
+ vertexColor,
721
+ vertexNormal,
722
+ bumpScale: 1,
723
+ emissiveColor: Vector3.zero(),
724
+ emissiveStrength: 1,
725
+ occlusionStrength: 1
726
+ };
727
+ switch(materialInfo?.alphaMode){
728
+ case 'BLEND':
729
+ {
730
+ pbrCommon.alphaMode = 'blend';
731
+ break;
732
+ }
733
+ case 'MASK':
734
+ {
735
+ pbrCommon.alphaMode = 'mask';
736
+ pbrCommon.alphaCutoff = materialInfo.alphaCutoff ?? 0.5;
737
+ break;
738
+ }
739
+ }
740
+ if (materialInfo?.doubleSided) {
741
+ pbrCommon.doubleSided = true;
742
+ }
743
+ if (materialInfo?.pbrMetallicRoughness || materialInfo?.extensions?.KHR_materials_pbrSpecularGlossiness) {
744
+ pbrCommon.normalMap = materialInfo.normalTexture ? await this._loadTexture(gltf, materialInfo.normalTexture, false) : null;
745
+ pbrCommon.bumpScale = materialInfo.normalTexture?.scale ?? 1;
746
+ pbrCommon.occlusionMap = materialInfo.occlusionTexture ? await this._loadTexture(gltf, materialInfo.occlusionTexture, false) : null;
747
+ pbrCommon.occlusionStrength = materialInfo.occlusionTexture?.strength ?? 1;
748
+ pbrCommon.emissiveMap = materialInfo.emissiveTexture ? await this._loadTexture(gltf, materialInfo.emissiveTexture, false) : null;
749
+ pbrCommon.emissiveStrength = materialInfo?.extensions?.KHR_materials_emissive_strength?.emissiveStrength ?? 1;
750
+ pbrCommon.emissiveColor = materialInfo.emissiveFactor ? new Vector3(materialInfo.emissiveFactor) : Vector3.zero();
751
+ }
752
+ if (materialInfo?.pbrMetallicRoughness) {
753
+ pbrMetallicRoughness = {
754
+ type: 'pbrMetallicRoughness',
755
+ ior: 1.5,
756
+ common: pbrCommon
757
+ };
758
+ pbrMetallicRoughness.diffuse = new Vector4(materialInfo.pbrMetallicRoughness.baseColorFactor ?? [
759
+ 1,
760
+ 1,
761
+ 1,
762
+ 1
763
+ ]);
764
+ pbrMetallicRoughness.metallic = materialInfo.pbrMetallicRoughness.metallicFactor ?? 1;
765
+ pbrMetallicRoughness.roughness = materialInfo.pbrMetallicRoughness.roughnessFactor ?? 1;
766
+ pbrMetallicRoughness.diffuseMap = materialInfo.pbrMetallicRoughness.baseColorTexture ? await this._loadTexture(gltf, materialInfo.pbrMetallicRoughness.baseColorTexture, true) : null;
767
+ pbrMetallicRoughness.metallicMap = materialInfo.pbrMetallicRoughness.metallicRoughnessTexture ? await this._loadTexture(gltf, materialInfo.pbrMetallicRoughness.metallicRoughnessTexture, false) : null;
768
+ pbrMetallicRoughness.metallicIndex = 2;
769
+ pbrMetallicRoughness.roughnessIndex = 1;
770
+ }
771
+ if (materialInfo?.extensions?.KHR_materials_pbrSpecularGlossiness) {
772
+ const sg = materialInfo.extensions?.KHR_materials_pbrSpecularGlossiness;
773
+ pbrSpecularGlossness = {
774
+ type: 'pbrSpecularGlossiness',
775
+ ior: 1.5,
776
+ common: pbrCommon
777
+ };
778
+ pbrSpecularGlossness.diffuse = new Vector4(sg.diffuseFactor ?? [
779
+ 1,
780
+ 1,
781
+ 1,
782
+ 1
783
+ ]);
784
+ pbrSpecularGlossness.specular = new Vector3(sg.specularFactor ?? [
785
+ 1,
786
+ 1,
787
+ 1
788
+ ]);
789
+ pbrSpecularGlossness.glossness = sg.glossnessFactor ?? 1;
790
+ pbrSpecularGlossness.diffuseMap = sg.diffuseTexture ? await this._loadTexture(gltf, sg.diffuseTexture, true) : null;
791
+ pbrSpecularGlossness.specularGlossnessMap = sg.specularGlossinessTexture ? await this._loadTexture(gltf, sg.specularGlossinessTexture, true) : null;
792
+ }
793
+ assetMaterial = pbrSpecularGlossness || pbrMetallicRoughness;
794
+ if (!assetMaterial || materialInfo?.extensions?.KHR_materials_unlit) {
795
+ if (materialInfo?.extensions?.KHR_materials_unlit) {
796
+ assetMaterial = {
797
+ type: 'unlit',
798
+ common: pbrCommon,
799
+ diffuse: pbrMetallicRoughness?.diffuse ?? Vector4.one(),
800
+ diffuseMap: pbrMetallicRoughness?.diffuseMap ?? null
801
+ };
802
+ } else {
803
+ assetMaterial = {
804
+ type: 'pbrMetallicRoughness',
805
+ common: pbrCommon,
806
+ diffuse: Vector4.one(),
807
+ metallic: 1,
808
+ roughness: 1,
809
+ diffuseMap: null,
810
+ metallicMap: null,
811
+ metallicIndex: 2,
812
+ roughnessIndex: 1
813
+ };
814
+ }
815
+ }
816
+ if (assetMaterial.type !== 'unlit' && materialInfo?.extensions?.KHR_materials_ior) {
817
+ assetMaterial.ior = materialInfo.extensions.KHR_materials_ior.ior ?? 1.5;
818
+ }
819
+ if (assetMaterial.type === 'pbrMetallicRoughness') {
820
+ pbrMetallicRoughness = assetMaterial;
821
+ // KHR_materials_specular extension
822
+ const specularColorFactor = materialInfo?.extensions?.KHR_materials_specular?.specularColorFactor ?? [
823
+ 1,
824
+ 1,
825
+ 1
826
+ ];
827
+ pbrMetallicRoughness.specularFactor = new Vector4(...specularColorFactor, materialInfo?.extensions?.KHR_materials_specular?.specularFactor ?? 1);
828
+ pbrMetallicRoughness.specularMap = materialInfo?.extensions?.KHR_materials_specular?.specularTexture ? await this._loadTexture(gltf, materialInfo.extensions.KHR_materials_specular.specularTexture, false) : null;
829
+ pbrMetallicRoughness.specularColorMap = materialInfo?.extensions?.KHR_materials_specular?.specularColorTexture ? await this._loadTexture(gltf, materialInfo.extensions.KHR_materials_specular.specularColorTexture, true) : null;
830
+ // KHR_materials_iridescence
831
+ const iridescence = materialInfo?.extensions?.KHR_materials_iridescence;
832
+ if (iridescence) {
833
+ pbrMetallicRoughness.iridescence = {
834
+ iridescenceFactor: iridescence.iridescenceFactor ?? 0,
835
+ iridescenceMap: iridescence.iridescenceTexture ? await this._loadTexture(gltf, iridescence.iridescenceTexture, false) : null,
836
+ iridescenceIor: iridescence.iridescenceIor ?? 1.3,
837
+ iridescenceThicknessMinimum: iridescence.iridescenceThicknessMinimum ?? 100,
838
+ iridescenceThicknessMaximum: iridescence.iridescenceThicknessMaximum ?? 400,
839
+ iridescenceThicknessMap: iridescence.iridescenceThicknessTexture ? await this._loadTexture(gltf, iridescence.iridescenceThicknessTexture, false) : null
840
+ };
841
+ }
842
+ // KHR_materials_transmission
843
+ const transmission = materialInfo?.extensions?.KHR_materials_transmission;
844
+ if (transmission) {
845
+ pbrMetallicRoughness.transmission = {
846
+ transmissionFactor: transmission.transmissionFactor ?? 0,
847
+ transmissionMap: transmission.transmissionTexture ? await this._loadTexture(gltf, transmission.transmissionTexture, false) : null,
848
+ thicknessFactor: 0,
849
+ thicknessMap: null,
850
+ attenuationDistance: 99999,
851
+ attenuationColor: Vector3.one()
852
+ };
853
+ const volume = materialInfo?.extensions?.KHR_materials_volume;
854
+ if (volume) {
855
+ pbrMetallicRoughness.transmission.thicknessFactor = volume.thicknessFactor ?? 0;
856
+ pbrMetallicRoughness.transmission.thicknessMap = volume.thicknessTexture ? await this._loadTexture(gltf, volume.thicknessTexture, false) : null;
857
+ pbrMetallicRoughness.transmission.attenuationDistance = volume.attenuationDistance ?? 99999;
858
+ const attenuationColor = volume.attenuationColor ?? [
859
+ 1,
860
+ 1,
861
+ 1
862
+ ];
863
+ pbrMetallicRoughness.transmission.attenuationColor = new Vector3(...attenuationColor);
864
+ }
865
+ }
866
+ // KHR_materials_sheen
867
+ const sheen = materialInfo?.extensions?.KHR_materials_sheen;
868
+ if (sheen) {
869
+ pbrMetallicRoughness.sheen = {
870
+ sheenColorFactor: new Vector3(sheen.sheenColorFactor ?? [
871
+ 0,
872
+ 0,
873
+ 0
874
+ ]),
875
+ sheenColorMap: sheen.sheenColorTexture ? await this._loadTexture(gltf, sheen.sheenColorTexture, true) : null,
876
+ sheenRoughnessFactor: sheen.sheenRoughnessFactor ?? 0,
877
+ sheenRoughnessMap: sheen.sheenRoughnessTexture ? await this._loadTexture(gltf, sheen.sheenRoughnessTexture, true) : null
878
+ };
879
+ }
880
+ // KHR_materials_clearcoat
881
+ const cc = materialInfo?.extensions?.KHR_materials_clearcoat;
882
+ if (cc) {
883
+ pbrMetallicRoughness.clearcoat = {
884
+ clearCoatFactor: cc.clearcoatFactor ?? 0,
885
+ clearCoatIntensityMap: cc.clearcoatTexture ? await this._loadTexture(gltf, cc.clearcoatTexture, false) : null,
886
+ clearCoatRoughnessFactor: cc.clearcoatRoughnessFactor ?? 0,
887
+ clearCoatRoughnessMap: cc.clearcoatRoughnessTexture ? await this._loadTexture(gltf, cc.clearcoatRoughnessTexture, false) : null,
888
+ clearCoatNormalMap: cc.clearcoatNormalTexture ? await this._loadTexture(gltf, cc.clearcoatNormalTexture, false) : null
889
+ };
890
+ }
891
+ }
892
+ return await this._createMaterial(assetMaterial);
893
+ }
894
+ /** @internal */ async _loadTexture(gltf, info, sRGB) {
895
+ const mt = {
896
+ texture: null,
897
+ sampler: null,
898
+ texCoord: info.texCoord ?? 0,
899
+ transform: null
900
+ };
901
+ const textureInfo = gltf.textures[info.index];
902
+ if (textureInfo) {
903
+ if (info.extensions?.KHR_texture_transform) {
904
+ const uvTransform = info.extensions.KHR_texture_transform;
905
+ if (uvTransform.texCoord !== undefined) {
906
+ mt.texCoord = uvTransform.texCoord;
907
+ }
908
+ const rotation = uvTransform.rotation !== undefined ? Matrix4x4.rotationZ(-uvTransform.rotation) : Matrix4x4.identity();
909
+ const scale = uvTransform.scale !== undefined ? new Vector3(uvTransform.scale[0], uvTransform.scale[1], 1) : Vector3.one();
910
+ const translation = uvTransform.offset !== undefined ? new Vector3(uvTransform.offset[0], uvTransform.offset[1], 0) : Vector3.zero();
911
+ mt.transform = Matrix4x4.scaling(scale).multiplyLeft(rotation).translateLeft(translation);
912
+ }
913
+ let wrapS = 'repeat';
914
+ let wrapT = 'repeat';
915
+ let magFilter = 'linear';
916
+ let minFilter = 'linear';
917
+ let mipFilter = 'linear';
918
+ const samplerIndex = textureInfo.sampler;
919
+ const sampler = gltf.samplers && gltf.samplers[samplerIndex];
920
+ if (sampler) {
921
+ switch(sampler.wrapS){
922
+ case 0x2901:
923
+ wrapS = 'repeat';
924
+ break;
925
+ case 0x8370:
926
+ wrapS = 'mirrored-repeat';
927
+ break;
928
+ case 0x812f:
929
+ wrapS = 'clamp';
930
+ break;
931
+ }
932
+ switch(sampler.wrapT){
933
+ case 0x2901:
934
+ wrapT = 'repeat';
935
+ break;
936
+ case 0x8370:
937
+ wrapT = 'mirrored-repeat';
938
+ break;
939
+ case 0x812f:
940
+ wrapT = 'clamp';
941
+ break;
942
+ }
943
+ switch(sampler.magFilter){
944
+ case 0x2600:
945
+ magFilter = 'nearest';
946
+ break;
947
+ case 0x2601:
948
+ magFilter = 'linear';
949
+ break;
950
+ }
951
+ switch(sampler.minFilter){
952
+ case 0x2600:
953
+ minFilter = 'nearest';
954
+ mipFilter = 'none';
955
+ break;
956
+ case 0x2601:
957
+ minFilter = 'linear';
958
+ mipFilter = 'none';
959
+ break;
960
+ case 0x2700:
961
+ minFilter = 'nearest';
962
+ mipFilter = 'nearest';
963
+ break;
964
+ case 0x2701:
965
+ minFilter = 'linear';
966
+ mipFilter = 'nearest';
967
+ break;
968
+ case 0x2702:
969
+ minFilter = 'nearest';
970
+ mipFilter = 'linear';
971
+ break;
972
+ case 0x2703:
973
+ minFilter = 'linear';
974
+ mipFilter = 'linear';
975
+ break;
976
+ }
977
+ }
978
+ const imageIndex = textureInfo.source;
979
+ const hash = `${imageIndex}:${!!sRGB}:${wrapS}:${wrapT}:${minFilter}:${magFilter}:${mipFilter}`;
980
+ mt.texture = gltf._textureCache[hash];
981
+ if (!mt.texture) {
982
+ const image = gltf.images[imageIndex];
983
+ if (image) {
984
+ if (image.uri) {
985
+ const imageUrl = this._normalizeURI(gltf._baseURI, image.uri);
986
+ mt.texture = await gltf._manager.fetchTexture(imageUrl, {
987
+ linearColorSpace: !sRGB
988
+ });
989
+ mt.texture.name = imageUrl;
990
+ } else if (typeof image.bufferView === 'number' && image.mimeType) {
991
+ const bufferView = gltf.bufferViews && gltf.bufferViews[image.bufferView];
992
+ if (bufferView) {
993
+ const arrayBuffer = gltf._loadedBuffers && gltf._loadedBuffers[bufferView.buffer];
994
+ if (arrayBuffer) {
995
+ const view = new Uint8Array(arrayBuffer, bufferView.byteOffset || 0, bufferView.byteLength);
996
+ const mimeType = image.mimeType;
997
+ mt.texture = await gltf._manager.loadTextureFromBuffer(view, mimeType, sRGB);
998
+ }
999
+ }
1000
+ }
1001
+ }
1002
+ if (mt.texture) {
1003
+ gltf._textureCache[hash] = mt.texture;
1004
+ }
1005
+ }
1006
+ if (mt.texture) {
1007
+ mt.sampler = Application.instance.device.createSampler({
1008
+ addressU: wrapS,
1009
+ addressV: wrapT,
1010
+ magFilter: magFilter,
1011
+ minFilter: minFilter,
1012
+ mipFilter: mipFilter
1013
+ });
1014
+ }
1015
+ }
1016
+ return mt;
1017
+ }
1018
+ /** @internal */ _primitiveType(type) {
1019
+ switch(type){
1020
+ case 0:
1021
+ return 'point-list';
1022
+ case 1:
1023
+ return 'line-list';
1024
+ /* FIXME:
1025
+ case 2: // GL_LINE_LOOP
1026
+ return PrimitiveType.LineLoop;
1027
+ */ case 3:
1028
+ return 'line-strip';
1029
+ case 4:
1030
+ return 'triangle-list';
1031
+ case 5:
1032
+ return 'triangle-strip';
1033
+ case 6:
1034
+ return 'triangle-fan';
1035
+ default:
1036
+ return null;
1037
+ }
1038
+ }
1039
+ /** @internal */ _loadIndexBuffer(gltf, accessorIndex, primitive, meshData, dracoExtension, dracoMeshDecoder) {
1040
+ const accessor = gltf._accessors[accessorIndex];
1041
+ if (dracoMeshDecoder) {
1042
+ const indices = dracoMeshDecoder.getIndexBuffer();
1043
+ if (!indices || indices.length !== accessor.count) {
1044
+ throw new Error(`Decode index buffer failed`);
1045
+ }
1046
+ if (indices.length !== accessor.count) {
1047
+ throw new Error(`Decode index buffer failed`);
1048
+ }
1049
+ gltf._loadedBuffers.push(indices.buffer);
1050
+ if (!gltf.bufferViews) {
1051
+ gltf.bufferViews = [];
1052
+ }
1053
+ gltf.bufferViews.push({
1054
+ buffer: gltf._loadedBuffers.length - 1,
1055
+ byteOffset: 0,
1056
+ byteLength: indices.byteLength
1057
+ });
1058
+ accessor.componentType = ComponentType.UINT;
1059
+ accessor.bufferView = gltf.bufferViews.length - 1;
1060
+ }
1061
+ this._setBuffer(gltf, accessorIndex, primitive, null, meshData);
1062
+ }
1063
+ /** @internal */ _loadVertexBuffer(gltf, attribName, accessorIndex, primitive, subMeshData, dracoExtension, dracoMeshDecoder) {
1064
+ const dracoId = dracoExtension?.attributes?.[attribName];
1065
+ if (dracoId !== undefined) {
1066
+ const accessor = gltf._accessors[accessorIndex];
1067
+ let buffer = null;
1068
+ const numElements = accessor.count * accessor.getComponentCount(accessor.type);
1069
+ switch(accessor.componentType){
1070
+ case ComponentType.FLOAT:
1071
+ buffer = new Float32Array(numElements);
1072
+ break;
1073
+ case ComponentType.BYTE:
1074
+ buffer = new Int8Array(numElements);
1075
+ break;
1076
+ case ComponentType.SHORT:
1077
+ buffer = new Int16Array(numElements);
1078
+ break;
1079
+ case ComponentType.INT:
1080
+ buffer = new Int32Array(numElements);
1081
+ break;
1082
+ case ComponentType.UBYTE:
1083
+ buffer = new Uint8Array(numElements);
1084
+ break;
1085
+ case ComponentType.USHORT:
1086
+ buffer = new Uint16Array(numElements);
1087
+ break;
1088
+ case ComponentType.UINT:
1089
+ buffer = new Uint32Array(numElements);
1090
+ break;
1091
+ default:
1092
+ throw new Error(`Invalid component type: ${accessor.componentType}`);
1093
+ }
1094
+ if (!dracoMeshDecoder.getAttributeBuffer(dracoId, buffer)) {
1095
+ throw new Error(`Decode draco mesh failed`);
1096
+ }
1097
+ gltf._loadedBuffers.push(buffer.buffer);
1098
+ if (!gltf.bufferViews) {
1099
+ gltf.bufferViews = [];
1100
+ }
1101
+ gltf.bufferViews.push({
1102
+ buffer: gltf._loadedBuffers.length - 1,
1103
+ byteOffset: 0,
1104
+ byteLength: buffer.byteLength
1105
+ });
1106
+ accessor.bufferView = gltf.bufferViews.length - 1;
1107
+ }
1108
+ let semantic = null;
1109
+ switch(attribName){
1110
+ case 'POSITION':
1111
+ semantic = 'position';
1112
+ break;
1113
+ case 'NORMAL':
1114
+ semantic = 'normal';
1115
+ break;
1116
+ case 'TANGENT':
1117
+ semantic = 'tangent';
1118
+ break;
1119
+ case 'TEXCOORD_0':
1120
+ semantic = 'texCoord0';
1121
+ break;
1122
+ case 'TEXCOORD_1':
1123
+ semantic = 'texCoord1';
1124
+ break;
1125
+ case 'TEXCOORD_2':
1126
+ semantic = 'texCoord2';
1127
+ break;
1128
+ case 'TEXCOORD_3':
1129
+ semantic = 'texCoord3';
1130
+ break;
1131
+ case 'TEXCOORD_4':
1132
+ semantic = 'texCoord4';
1133
+ break;
1134
+ case 'TEXCOORD_5':
1135
+ semantic = 'texCoord5';
1136
+ break;
1137
+ case 'TEXCOORD_6':
1138
+ semantic = 'texCoord6';
1139
+ break;
1140
+ case 'TEXCOORD_7':
1141
+ semantic = 'texCoord7';
1142
+ break;
1143
+ case 'COLOR_0':
1144
+ semantic = 'diffuse';
1145
+ break;
1146
+ case 'JOINTS_0':
1147
+ semantic = 'blendIndices';
1148
+ break;
1149
+ case 'WEIGHTS_0':
1150
+ semantic = 'blendWeights';
1151
+ break;
1152
+ default:
1153
+ return;
1154
+ }
1155
+ this._setBuffer(gltf, accessorIndex, primitive, semantic, subMeshData);
1156
+ }
1157
+ /** @internal */ _setBuffer(gltf, accessorIndex, primitive, semantic, subMeshData) {
1158
+ const device = Application.instance.device;
1159
+ const accessor = gltf._accessors[accessorIndex];
1160
+ const componentCount = accessor.getComponentCount(accessor.type);
1161
+ const normalized = !!accessor.normalized;
1162
+ const hash = `${accessorIndex}:${semantic || ''}:${Number(normalized)}`;
1163
+ let buffer = gltf._bufferCache[hash];
1164
+ if (!buffer) {
1165
+ let data = accessor.getNormalizedDeinterlacedView(gltf);
1166
+ if (semantic && !(data instanceof Float32Array)) {
1167
+ const floatData = new Float32Array(data.length);
1168
+ floatData.set(data);
1169
+ data = floatData;
1170
+ }
1171
+ if (!semantic) {
1172
+ if (!(data instanceof Uint8Array) && !(data instanceof Uint16Array) && !(data instanceof Uint32Array)) {
1173
+ console.error('Invalid index buffer component type');
1174
+ return;
1175
+ }
1176
+ if (data instanceof Uint32Array && !device.getDeviceCaps().miscCaps.support32BitIndex) {
1177
+ console.error('Device does not support 32bit vertex index');
1178
+ return;
1179
+ }
1180
+ if (data instanceof Uint8Array) {
1181
+ const uint16Data = new Uint16Array(data.length);
1182
+ uint16Data.set(data);
1183
+ data = uint16Data;
1184
+ }
1185
+ }
1186
+ if (!semantic) {
1187
+ buffer = gltf._device.createIndexBuffer(data, {
1188
+ managed: true
1189
+ });
1190
+ } else {
1191
+ const attribFormat = device.getVertexAttribFormat(semantic, 'f32', componentCount);
1192
+ buffer = gltf._device.createVertexBuffer(attribFormat, data);
1193
+ }
1194
+ gltf._bufferCache[hash] = buffer;
1195
+ }
1196
+ if (buffer) {
1197
+ if (!semantic) {
1198
+ primitive.setIndexBuffer(buffer);
1199
+ primitive.indexCount = buffer.length;
1200
+ } else {
1201
+ primitive.setVertexBuffer(buffer);
1202
+ if (semantic === 'position') {
1203
+ if (!primitive.getIndexBuffer()) {
1204
+ primitive.indexCount = Math.floor(buffer.byteLength / 12);
1205
+ }
1206
+ const data = accessor.getNormalizedDeinterlacedView(gltf);
1207
+ subMeshData.rawPositions = data;
1208
+ const min = accessor.min;
1209
+ const max = accessor.max;
1210
+ if (min && max) {
1211
+ primitive.setBoundingVolume(new BoundingBox(new Vector3(min), new Vector3(max)));
1212
+ } else {
1213
+ const bbox = new BoundingBox();
1214
+ bbox.beginExtend();
1215
+ for(let i = 0; i < data.length; i++){
1216
+ const v = new Vector3(data[i * componentCount], data[i * componentCount + 1], data[i * componentCount + 2]);
1217
+ bbox.extend(v);
1218
+ }
1219
+ if (bbox.isValid()) {
1220
+ primitive.setBoundingVolume(bbox);
1221
+ }
1222
+ }
1223
+ } else if (semantic === 'blendIndices') {
1224
+ subMeshData.rawBlendIndices = accessor.getNormalizedDeinterlacedView(gltf);
1225
+ } else if (semantic === 'blendWeights') {
1226
+ subMeshData.rawJointWeights = accessor.getNormalizedDeinterlacedView(gltf);
1227
+ }
1228
+ }
1229
+ }
1230
+ return buffer;
1231
+ }
1232
+ /** @internal */ isGLB(data) {
1233
+ if (data.byteLength > 12) {
1234
+ const p = new Uint32Array(data, 0, 3);
1235
+ if (p[0] === 0x46546c67 && p[1] === 2 && p[2] === data.byteLength) {
1236
+ return true;
1237
+ }
1238
+ }
1239
+ return false;
1240
+ }
1241
+ /** @internal */ getGLBChunkInfo(data, offset) {
1242
+ const header = new Uint32Array(data, offset, 2);
1243
+ const start = offset + 8;
1244
+ const length = header[0];
1245
+ const type = header[1];
1246
+ return {
1247
+ start,
1248
+ length,
1249
+ type
1250
+ };
1251
+ }
1252
+ /** @internal */ getGLBChunkInfos(data) {
1253
+ const infos = [];
1254
+ let offset = 12;
1255
+ while(offset < data.byteLength){
1256
+ const info = this.getGLBChunkInfo(data, offset);
1257
+ infos.push(info);
1258
+ offset += info.length + 8;
1259
+ }
1260
+ return infos;
1261
+ }
1262
+ }
1263
+
1264
+ export { GLTFLoader };
1265
+ //# sourceMappingURL=gltf_loader.js.map