@zephyr3d/scene 0.9.5 → 0.9.6

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