chorama 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/.github/workflows/publish.yml +24 -0
  2. package/.github/workflows/static.yml +22 -53
  3. package/README.md +3 -1
  4. package/assets/models/glb/AlphaBlendModeTest.glb +0 -0
  5. package/assets/models/glb/IridescenceLamp.glb +0 -0
  6. package/assets/models/glb/teapot.glb +0 -0
  7. package/astro.config.mjs +9 -21
  8. package/content/guide/render-targets-and-views.md +3 -4
  9. package/content/guide/textures-and-assets.md +5 -2
  10. package/dist/index.module.js +23336 -0
  11. package/dist/index.module.js.map +1 -0
  12. package/dist/index.umd.js +23610 -0
  13. package/dist/index.umd.js.map +1 -0
  14. package/dist/website/_astro/DocLayout.BsV7p0dY.css +1 -0
  15. package/dist/website/examples/camera/orthographic/example.html +172 -0
  16. package/dist/website/examples/camera/orthographic/index.html +124 -0
  17. package/dist/website/examples/camera/perspective/example.html +190 -0
  18. package/dist/website/examples/camera/perspective/index.html +142 -0
  19. package/dist/website/examples/camera/tone_mapping/example.html +238 -0
  20. package/dist/website/examples/camera/tone_mapping/index.html +190 -0
  21. package/dist/website/examples/index.html +2 -0
  22. package/dist/website/examples/lights/directional/example.html +447 -0
  23. package/dist/website/examples/lights/directional/index.html +399 -0
  24. package/dist/website/examples/lights/multiple_spot_lights/example.html +356 -0
  25. package/dist/website/examples/lights/multiple_spot_lights/index.html +308 -0
  26. package/dist/website/examples/lights/point/example.html +387 -0
  27. package/dist/website/examples/lights/point/index.html +339 -0
  28. package/dist/website/examples/lights/spot/example.html +416 -0
  29. package/dist/website/examples/lights/spot/index.html +368 -0
  30. package/dist/website/examples/loader/gltf/basic/example.html +129 -0
  31. package/dist/website/examples/loader/gltf/basic/index.html +81 -0
  32. package/dist/website/examples/loader/gltf/material/alpha-blend-mode/example.html +131 -0
  33. package/dist/website/examples/loader/gltf/material/alpha-blend-mode/index.html +83 -0
  34. package/dist/website/examples/loader/gltf/material/flight_helmet/example.html +162 -0
  35. package/dist/website/examples/loader/gltf/material/flight_helmet/index.html +114 -0
  36. package/dist/website/examples/loader/gltf/material/iridescence_lamp/example.html +169 -0
  37. package/dist/website/examples/loader/gltf/material/iridescence_lamp/index.html +121 -0
  38. package/dist/website/examples/loader/objloader/example.html +144 -0
  39. package/dist/website/examples/loader/objloader/index.html +96 -0
  40. package/dist/website/examples/material/cullface/example.html +163 -0
  41. package/dist/website/examples/material/cullface/index.html +115 -0
  42. package/dist/website/examples/material/materials/example.html +175 -0
  43. package/dist/website/examples/material/materials/index.html +127 -0
  44. package/dist/website/examples/material/standard/basic/example.html +212 -0
  45. package/dist/website/examples/material/standard/basic/index.html +164 -0
  46. package/dist/website/examples/material/standard/reflection_refraction/example.html +241 -0
  47. package/dist/website/examples/material/standard/reflection_refraction/index.html +193 -0
  48. package/dist/website/examples/mesh/capsule/example.html +173 -0
  49. package/dist/website/examples/mesh/capsule/index.html +125 -0
  50. package/dist/website/examples/mesh/circle/example.html +173 -0
  51. package/dist/website/examples/mesh/circle/index.html +125 -0
  52. package/dist/website/examples/mesh/cone/example.html +180 -0
  53. package/dist/website/examples/mesh/cone/index.html +132 -0
  54. package/dist/website/examples/mesh/cuboid/example.html +207 -0
  55. package/dist/website/examples/mesh/cuboid/index.html +159 -0
  56. package/dist/website/examples/mesh/cylinder/example.html +195 -0
  57. package/dist/website/examples/mesh/cylinder/index.html +147 -0
  58. package/dist/website/examples/mesh/dodecahedron/example.html +158 -0
  59. package/dist/website/examples/mesh/dodecahedron/index.html +110 -0
  60. package/dist/website/examples/mesh/ellipsoid/example.html +179 -0
  61. package/dist/website/examples/mesh/ellipsoid/index.html +131 -0
  62. package/dist/website/examples/mesh/extrude/example.html +169 -0
  63. package/dist/website/examples/mesh/extrude/index.html +121 -0
  64. package/dist/website/examples/mesh/frustum/example.html +185 -0
  65. package/dist/website/examples/mesh/frustum/index.html +137 -0
  66. package/dist/website/examples/mesh/helix/example.html +184 -0
  67. package/dist/website/examples/mesh/helix/index.html +136 -0
  68. package/dist/website/examples/mesh/icosahedron/example.html +158 -0
  69. package/dist/website/examples/mesh/icosahedron/index.html +110 -0
  70. package/dist/website/examples/mesh/icosphere/example.html +163 -0
  71. package/dist/website/examples/mesh/icosphere/index.html +115 -0
  72. package/dist/website/examples/mesh/lathe/example.html +175 -0
  73. package/dist/website/examples/mesh/lathe/index.html +127 -0
  74. package/dist/website/examples/mesh/meshTopology/example.html +210 -0
  75. package/dist/website/examples/mesh/meshTopology/index.html +162 -0
  76. package/dist/website/examples/mesh/octahedron/example.html +158 -0
  77. package/dist/website/examples/mesh/octahedron/index.html +110 -0
  78. package/dist/website/examples/mesh/plane/example.html +173 -0
  79. package/dist/website/examples/mesh/plane/index.html +125 -0
  80. package/dist/website/examples/mesh/prism/example.html +173 -0
  81. package/dist/website/examples/mesh/prism/index.html +125 -0
  82. package/dist/website/examples/mesh/pyramid/example.html +172 -0
  83. package/dist/website/examples/mesh/pyramid/index.html +124 -0
  84. package/dist/website/examples/mesh/ring/example.html +173 -0
  85. package/dist/website/examples/mesh/ring/index.html +125 -0
  86. package/dist/website/examples/mesh/skinning/example.html +187 -0
  87. package/dist/website/examples/mesh/skinning/index.html +139 -0
  88. package/dist/website/examples/mesh/terrain/example.html +214 -0
  89. package/dist/website/examples/mesh/terrain/index.html +166 -0
  90. package/dist/website/examples/mesh/tetrahedron/example.html +158 -0
  91. package/dist/website/examples/mesh/tetrahedron/index.html +110 -0
  92. package/dist/website/examples/mesh/torus/example.html +173 -0
  93. package/dist/website/examples/mesh/torus/index.html +125 -0
  94. package/dist/website/examples/mesh/torus-knot/example.html +188 -0
  95. package/dist/website/examples/mesh/torus-knot/index.html +140 -0
  96. package/dist/website/examples/mesh/tube/example.html +180 -0
  97. package/dist/website/examples/mesh/tube/index.html +132 -0
  98. package/dist/website/examples/mesh/uvsphere/example.html +169 -0
  99. package/dist/website/examples/mesh/uvsphere/index.html +121 -0
  100. package/dist/website/examples/mesh/wedge/example.html +168 -0
  101. package/dist/website/examples/mesh/wedge/index.html +120 -0
  102. package/dist/website/examples/other/rotatingCube/example.html +142 -0
  103. package/dist/website/examples/other/rotatingCube/index.html +94 -0
  104. package/dist/website/examples/other/rotatingSphere/example.html +144 -0
  105. package/dist/website/examples/other/rotatingSphere/index.html +96 -0
  106. package/dist/website/examples/rendertarget/basic_canvas/example.html +178 -0
  107. package/dist/website/examples/rendertarget/basic_canvas/index.html +130 -0
  108. package/dist/website/examples/rendertarget/depth_texture/example.html +188 -0
  109. package/dist/website/examples/rendertarget/depth_texture/index.html +140 -0
  110. package/dist/website/examples/rendertarget/image_target/example.html +196 -0
  111. package/dist/website/examples/rendertarget/image_target/index.html +148 -0
  112. package/dist/website/examples/rendertarget/multiple_views/example.html +204 -0
  113. package/dist/website/examples/rendertarget/multiple_views/index.html +156 -0
  114. package/dist/website/examples/rendertarget/render_masks/example.html +222 -0
  115. package/dist/website/examples/rendertarget/render_masks/index.html +174 -0
  116. package/dist/website/examples/rendertarget/split_screen/example.html +178 -0
  117. package/dist/website/examples/rendertarget/split_screen/index.html +130 -0
  118. package/dist/website/examples/rendertarget/split_view/example.html +191 -0
  119. package/dist/website/examples/rendertarget/split_view/index.html +143 -0
  120. package/dist/website/examples/skybox/skybox/example.html +162 -0
  121. package/dist/website/examples/skybox/skybox/index.html +114 -0
  122. package/dist/website/examples/texture/arrays/example.html +204 -0
  123. package/dist/website/examples/texture/arrays/index.html +156 -0
  124. package/dist/website/examples/texture/textureWrap/example.html +169 -0
  125. package/dist/website/examples/texture/textureWrap/index.html +121 -0
  126. package/dist/website/examples/transform/propagation/example.html +141 -0
  127. package/dist/website/examples/transform/propagation/index.html +93 -0
  128. package/dist/website/guide/api-map/index.html +82 -0
  129. package/dist/website/guide/camera-and-controls/index.html +62 -0
  130. package/dist/website/guide/first-scene/index.html +119 -0
  131. package/dist/website/guide/index.html +58 -0
  132. package/dist/website/guide/installation/index.html +133 -0
  133. package/dist/website/guide/materials-and-lighting/index.html +90 -0
  134. package/dist/website/guide/plugins-and-render-pipeline/index.html +89 -0
  135. package/dist/website/guide/render-targets-and-views/index.html +95 -0
  136. package/dist/website/guide/scene-graph-and-transforms/index.html +69 -0
  137. package/dist/website/guide/textures-and-assets/index.html +85 -0
  138. package/dist/website/guide/troubleshooting/index.html +39 -0
  139. package/dist/website/images/disappointed.jpg +0 -0
  140. package/dist/website/images/skybox/grimmnight_back.png +0 -0
  141. package/dist/website/images/skybox/grimmnight_bottom.png +0 -0
  142. package/dist/website/images/skybox/grimmnight_front.png +0 -0
  143. package/dist/website/images/skybox/grimmnight_left.png +0 -0
  144. package/dist/website/images/skybox/grimmnight_right.png +0 -0
  145. package/dist/website/images/skybox/grimmnight_top.png +0 -0
  146. package/dist/website/images/skybox/miramar_back.png +0 -0
  147. package/dist/website/images/skybox/miramar_bottom.png +0 -0
  148. package/dist/website/images/skybox/miramar_front.png +0 -0
  149. package/dist/website/images/skybox/miramar_left.png +0 -0
  150. package/dist/website/images/skybox/miramar_right.png +0 -0
  151. package/dist/website/images/skybox/miramar_top.png +0 -0
  152. package/dist/website/images/uv.jpg +0 -0
  153. package/dist/website/index.html +157 -0
  154. package/dist/website/models/glb/AlphaBlendModeTest.glb +0 -0
  155. package/dist/website/models/glb/IridescenceLamp.glb +0 -0
  156. package/dist/website/models/glb/teapot.glb +0 -0
  157. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
  158. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
  159. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
  160. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
  161. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
  162. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
  163. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
  164. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
  165. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
  166. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
  167. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
  168. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
  169. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
  170. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
  171. package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
  172. package/dist/website/models/gltf/flight_helmet/index.bin +0 -0
  173. package/dist/website/models/gltf/flight_helmet/index.gltf +705 -0
  174. package/dist/website/models/gltf/object.gltf +23 -0
  175. package/dist/website/models/gltf/pirate_girl/index.bin +0 -0
  176. package/dist/website/models/gltf/pirate_girl/index.gltf +2082 -0
  177. package/dist/website/models/obj/pirate_girl/pirate_girl.obj +18459 -0
  178. package/dist/website/models/obj/pirate_girl/pirate_girl.png +0 -0
  179. package/env.d.ts +0 -14
  180. package/examples/camera/orthographic.js +2 -1
  181. package/examples/camera/perspective.js +2 -1
  182. package/examples/camera/tone_mapping.js +187 -0
  183. package/examples/lights/directional.js +2 -3
  184. package/examples/lights/multiple_spot_lights.js +2 -1
  185. package/examples/lights/point.js +2 -3
  186. package/examples/lights/spot.js +2 -3
  187. package/examples/loader/{gltfloader.js → gltf/basic.js} +8 -8
  188. package/examples/loader/gltf/material/alpha-blend-mode.js +80 -0
  189. package/examples/loader/{gltf_material.js → gltf/material/flight_helmet.js} +8 -8
  190. package/examples/loader/gltf/material/iridescence_lamp.js +118 -0
  191. package/examples/loader/objloader.js +9 -11
  192. package/examples/material/cullface.js +8 -7
  193. package/examples/material/materials.js +9 -11
  194. package/examples/material/standard/basic.js +3 -6
  195. package/examples/material/standard/reflection_refraction.js +190 -0
  196. package/examples/mesh/capsule.js +122 -0
  197. package/examples/mesh/circle.js +11 -6
  198. package/examples/mesh/cone.js +129 -0
  199. package/examples/mesh/cuboid.js +11 -6
  200. package/examples/mesh/cylinder.js +11 -6
  201. package/examples/mesh/dodecahedron.js +107 -0
  202. package/examples/mesh/ellipsoid.js +128 -0
  203. package/examples/mesh/extrude.js +118 -0
  204. package/examples/mesh/frustum.js +134 -0
  205. package/examples/mesh/helix.js +133 -0
  206. package/examples/mesh/icosahedron.js +107 -0
  207. package/examples/mesh/icosphere.js +112 -0
  208. package/examples/mesh/lathe.js +124 -0
  209. package/examples/mesh/meshTopology.js +64 -8
  210. package/examples/mesh/octahedron.js +107 -0
  211. package/examples/mesh/plane.js +11 -6
  212. package/examples/mesh/prism.js +122 -0
  213. package/examples/mesh/pyramid.js +121 -0
  214. package/examples/mesh/ring.js +122 -0
  215. package/examples/mesh/skinning.js +8 -8
  216. package/examples/mesh/terrain.js +163 -0
  217. package/examples/mesh/tetrahedron.js +107 -0
  218. package/examples/mesh/torus-knot.js +137 -0
  219. package/examples/mesh/torus.js +122 -0
  220. package/examples/mesh/tube.js +129 -0
  221. package/examples/mesh/uvsphere.js +11 -6
  222. package/examples/mesh/wedge.js +117 -0
  223. package/examples/other/rotatingCube.js +9 -11
  224. package/examples/other/rotatingSphere.js +9 -12
  225. package/examples/rendertarget/basic_canvas.js +5 -8
  226. package/examples/rendertarget/depth_texture.js +18 -11
  227. package/examples/rendertarget/image_target.js +19 -14
  228. package/examples/rendertarget/multiple_views.js +11 -16
  229. package/examples/rendertarget/render_masks.js +3 -5
  230. package/examples/rendertarget/split_screen.js +18 -14
  231. package/examples/rendertarget/split_view.js +12 -9
  232. package/examples/skybox/skybox.js +8 -8
  233. package/examples/texture/arrays.js +9 -12
  234. package/examples/texture/textureWrap.js +8 -8
  235. package/examples/transform/propagation.js +9 -11
  236. package/package.json +18 -12
  237. package/src/caches/cache.js +121 -182
  238. package/src/caches/uniformbuffers.js +42 -53
  239. package/src/constants/texture.js +1 -1
  240. package/src/content.config.js +1 -0
  241. package/src/core/layouts/bindgroup.js +167 -0
  242. package/src/core/layouts/index.js +3 -1
  243. package/src/core/layouts/pipeline.js +165 -0
  244. package/src/core/layouts/uniformbuffer.js +11 -3
  245. package/src/core/resources/gpubuffer.js +23 -2
  246. package/src/core/resources/gpumesh.js +37 -4
  247. package/src/core/resources/gpusampler.js +43 -0
  248. package/src/core/resources/gputexture.js +31 -2
  249. package/src/core/resources/index.js +4 -2
  250. package/src/core/resources/newuniformbuffer.js +58 -0
  251. package/src/core/resources/webglshadermodule.js +58 -0
  252. package/src/core/shader.js +24 -11
  253. package/src/core/webgl/bindgroup.js +200 -42
  254. package/src/core/webgl/descriptors.js +87 -25
  255. package/src/core/webgl/gpuqueue.js +63 -0
  256. package/src/core/webgl/index.js +3 -0
  257. package/src/core/webgl/renderpassencoder.js +703 -16
  258. package/src/core/webgl/renderpipeline.js +38 -1
  259. package/src/core/webgl/utils.js +207 -57
  260. package/src/core/webgl/webglrenderdevice.js +77 -53
  261. package/src/loader/gltf.js +716 -166
  262. package/src/loader/texture.js +69 -16
  263. package/src/loader/utils.js +44 -0
  264. package/src/material/alphablend.js +21 -0
  265. package/src/material/basic.js +15 -1
  266. package/src/material/depth.js +15 -1
  267. package/src/material/index.js +1 -0
  268. package/src/material/lambert.js +15 -1
  269. package/src/material/material.js +49 -7
  270. package/src/material/normal.js +14 -0
  271. package/src/material/phong.js +16 -2
  272. package/src/material/raw.js +21 -2
  273. package/src/material/standard.js +90 -2
  274. package/src/mesh/attribute/attribute.js +2 -2
  275. package/src/mesh/attributedata/separate.js +2 -2
  276. package/src/mesh/builders/capsule.js +47 -0
  277. package/src/mesh/builders/cone.js +29 -0
  278. package/src/mesh/builders/dodecahedron.js +130 -0
  279. package/src/mesh/builders/ellipsoid.js +65 -0
  280. package/src/mesh/builders/extrude.js +136 -0
  281. package/src/mesh/builders/frustum.js +26 -0
  282. package/src/mesh/builders/geometry.js +121 -0
  283. package/src/mesh/builders/helix.js +35 -0
  284. package/src/mesh/builders/icosahedron.js +61 -0
  285. package/src/mesh/builders/icosphere.js +141 -0
  286. package/src/mesh/builders/index.js +22 -1
  287. package/src/mesh/builders/lathe.js +85 -0
  288. package/src/mesh/builders/octahedron.js +43 -0
  289. package/src/mesh/builders/polyhedron.js +121 -0
  290. package/src/mesh/builders/prism.js +19 -0
  291. package/src/mesh/builders/pyramid.js +90 -0
  292. package/src/mesh/builders/ring.js +109 -0
  293. package/src/mesh/builders/surfaces.js +69 -0
  294. package/src/mesh/builders/terrain.js +80 -0
  295. package/src/mesh/builders/tetrahedron.js +37 -0
  296. package/src/mesh/builders/torusknot.js +36 -0
  297. package/src/mesh/builders/tube.js +209 -0
  298. package/src/mesh/builders/utils.js +130 -2
  299. package/src/mesh/builders/wedge.js +22 -0
  300. package/src/mesh/mesh.js +12 -4
  301. package/src/objects/camera/camera.js +104 -1
  302. package/src/objects/light/ambient.js +22 -1
  303. package/src/objects/light/directional.js +23 -1
  304. package/src/objects/light/point.js +25 -1
  305. package/src/objects/light/spot.js +27 -1
  306. package/src/objects/mesh.js +1 -53
  307. package/src/plugins/camera/RenderTarget2DPool.js +94 -0
  308. package/src/plugins/camera/camera.js +14 -6
  309. package/src/plugins/camera/index.js +2 -0
  310. package/src/plugins/camera/nodes/canvasblit.js +153 -0
  311. package/src/plugins/camera/nodes/index.js +4 -1
  312. package/src/plugins/camera/nodes/opaquepass.js +48 -33
  313. package/src/plugins/camera/nodes/tonemapping.js +217 -0
  314. package/src/plugins/camera/nodes/transparentpass.js +87 -0
  315. package/src/plugins/camera/nodes/{cameraview.js → view.js} +27 -1
  316. package/src/plugins/camera/resources/cameracolortargets.js +66 -0
  317. package/src/plugins/camera/resources/canvasblitpipeline.js +6 -0
  318. package/src/plugins/camera/resources/index.js +3 -0
  319. package/src/plugins/camera/resources/tonemappingpipeline.js +6 -0
  320. package/src/plugins/light/light.js +0 -4
  321. package/src/plugins/meshmaterial/meshmaterial.js +433 -170
  322. package/src/plugins/meshmaterial/nodes/meshmaterial.js +39 -6
  323. package/src/plugins/meshmaterial/resources/bonetexture.js +176 -0
  324. package/src/plugins/meshmaterial/resources/environmentmap.js +44 -0
  325. package/src/plugins/meshmaterial/resources/index.js +4 -0
  326. package/src/plugins/meshmaterial/resources/materialuniformbuffers.js +94 -0
  327. package/src/plugins/meshmaterial/resources/meshmaterialbindgroups.js +40 -0
  328. package/src/plugins/shadow/nodes/index.js +3 -3
  329. package/src/plugins/shadow/nodes/{shadowOccluder.js → occluder.js} +13 -19
  330. package/src/plugins/shadow/nodes/opaquePass.js +110 -0
  331. package/src/plugins/shadow/shadow.js +0 -5
  332. package/src/plugins/skeletonhelper/skeletonhelper.js +111 -69
  333. package/src/plugins/skybox/nodes/skybox.js +230 -38
  334. package/src/plugins/skybox/resources/skyboxpipeline.js +10 -0
  335. package/src/plugins/skybox/skybox.js +0 -119
  336. package/src/renderer/core/index.js +135 -21
  337. package/src/renderer/plugin.js +0 -20
  338. package/src/renderer/renderer.js +28 -12
  339. package/src/rendertarget/canvastarget.js +8 -5
  340. package/src/rendertarget/image.js +3 -3
  341. package/src/shader/basicFragment.glsl +12 -4
  342. package/src/shader/basicVertex.glsl +26 -15
  343. package/src/shader/blitFragment.glsl +9 -0
  344. package/src/shader/common/common.glsl +35 -6
  345. package/src/shader/common/index.js +1 -0
  346. package/src/shader/common/tonemap.glsl +118 -0
  347. package/src/shader/debug/skeletonFragment.glsl +0 -2
  348. package/src/shader/debug/skeletonVertex.glsl +1 -3
  349. package/src/shader/depthFragment.glsl +0 -3
  350. package/src/shader/fullscreenVertex.glsl +26 -0
  351. package/src/shader/index.js +3 -0
  352. package/src/shader/lambertFragment.glsl +12 -4
  353. package/src/shader/normalFragment.glsl +0 -3
  354. package/src/shader/phongFragment.glsl +12 -4
  355. package/src/shader/skyboxFragment.glsl +5 -5
  356. package/src/shader/skyboxVertex.glsl +5 -4
  357. package/src/shader/standardFragment.glsl +74 -17
  358. package/src/shader/tonemappingFragment.glsl +37 -0
  359. package/src/texture/sampler.js +101 -21
  360. package/src/texture/texture.js +252 -48
  361. package/src/utils/index.js +15 -1
  362. package/{examples/addons → src/utils}/rendergraph_gui.js +5 -2
  363. package/examples/mesh/geometries.js +0 -108
  364. package/scripts/stage-chorama.mjs +0 -29
  365. package/src/core/resources/framebuffer.js +0 -127
  366. package/src/plugins/shadow/nodes/shadowOpaquePass.js +0 -73
  367. package/website/config/index.ts +0 -1
  368. package/website/config/navigation.ts +0 -53
  369. package/website/content.config.ts +0 -92
  370. package/website/layouts/DocLayout.astro +0 -501
  371. package/website/layouts/Example.astro +0 -91
  372. package/website/pages/examples/[...slug].astro +0 -77
  373. package/website/pages/examples/index.astro +0 -98
  374. package/website/pages/examples/samples/[...slug].astro +0 -17
  375. package/website/pages/guide/[slug].astro +0 -30
  376. package/website/pages/guide/index.astro +0 -21
  377. package/website/pages/index.astro +0 -9
  378. package/website/plugins/remark-link-base.js +0 -23
  379. package/website/utils/url.ts +0 -30
  380. /package/src/plugins/shadow/nodes/{shadow.js → view.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  /**@import { LoadSettings } from './loader.js' */
2
2
  import { Attribute, Mesh } from '../mesh/index.js';
3
- import { StandardMaterial } from '../material/index.js';
4
- import { MeshMaterial3D, Object3D, Skin } from '../objects/index.js';
3
+ import { StandardMaterial, AlphaMaskMode, OpaqueMode, TransparentMode } from '../material/index.js';
4
+ import { DirectionalLight, MeshMaterial3D, Object3D, PointLight, Skin, SpotLight } from '../objects/index.js';
5
5
  import { Loader } from './loader.js';
6
6
  import { arrayBufferToJSON } from './utils.js';
7
7
  import { Bone3D } from '../objects/bone.js';
@@ -10,9 +10,15 @@ import { SeparateAttributeData } from '../mesh/attributedata/separate.js';
10
10
  import { TextureLoader } from './texture.js';
11
11
  import { Texture, Sampler } from '../texture/index.js';
12
12
  import { assert } from '../utils/index.js';
13
- import { GlDataType, TextureFilter, TextureWrap, VertexFormat } from '../constants/index.js';
13
+ import { CullFace, TextureFilter, TextureType, TextureWrap } from '../constants/index.js';
14
14
 
15
15
  const defaultMaterial = new StandardMaterial()
16
+ const GLB_MAGIC = 0x46546C67
17
+ const GLB_CHUNK_TYPE_JSON = 0x4E4F534A
18
+ const GLB_CHUNK_TYPE_BIN = 0x004E4942
19
+ const GLTF_LIGHTS_PUNCTUAL_EXTENSION = "KHR_lights_punctual"
20
+ // Keep the fallback finite so attenuation and shadow math remain stable.
21
+ const DEFAULT_GLTF_LIGHT_RANGE = 1000
16
22
  /**
17
23
  * @extends {Loader<Object3D, GLTFLoadSettings>}
18
24
  */
@@ -37,6 +43,8 @@ export class GLTFLoader extends Loader {
37
43
 
38
44
  /**@type {Map<number, Object3D>} */
39
45
  const entityMap = new Map()
46
+ /** @type {Map<number, DirectionalLight | PointLight | SpotLight>} */
47
+ const lightCache = new Map()
40
48
  const baseUrl = new URL(path, location.href).href
41
49
  const gltf = await loadGLTF(buffer, baseUrl)
42
50
  const scene = gltf.scenes[gltf.scene]
@@ -52,47 +60,32 @@ export class GLTFLoader extends Loader {
52
60
  })
53
61
  }
54
62
 
63
+ if (typeof gltfTexture.bufferView === "number") {
64
+ const bufferView = gltf.bufferViews[gltfTexture.bufferView]
65
+ assert(bufferView, "GLTF image does not have a valid buffer view")
66
+
67
+ const imageBuffer = gltf.buffers[bufferView.buffer]
68
+ assert(imageBuffer, "GLTF image buffer view does not have a valid buffer")
69
+
70
+ const texture = new Texture({
71
+ type: TextureType.Texture2D
72
+ })
73
+ const slice = imageBuffer.slice(
74
+ bufferView.offset,
75
+ bufferView.offset + bufferView.length
76
+ )
77
+ await this.textureLoader.parse([slice], texture, {
78
+ mimeType: gltfTexture.mimeType
79
+ })
80
+ return texture
81
+ }
82
+
55
83
  throw "Unsupported gltf image setting"
56
84
  }))
57
- const samplers = gltf.samplers.map((gltfSampler) => {
58
- const sampler = new Sampler()
59
- sampler.magnificationFilter = gltfSampler.magFilter || TextureFilter.Nearest
60
- sampler.wrapS = gltfSampler.wrapS || TextureWrap.Clamp
61
- sampler.wrapT = gltfSampler.wrapT || TextureWrap.Clamp
62
-
63
- switch (gltfSampler.minFilter) {
64
- case WebGL2RenderingContext.NEAREST:
65
- sampler.minificationFilter = TextureFilter.Nearest
66
- sampler.mipmapFilter = undefined
67
- break;
68
- case WebGL2RenderingContext.LINEAR:
69
- sampler.minificationFilter = TextureFilter.Linear
70
- sampler.mipmapFilter = undefined
71
- break;
72
- case WebGL2RenderingContext.NEAREST_MIPMAP_NEAREST:
73
- sampler.minificationFilter = TextureFilter.Nearest
74
- sampler.mipmapFilter = TextureFilter.Nearest
75
- break;
76
- case WebGL2RenderingContext.NEAREST_MIPMAP_LINEAR:
77
- sampler.minificationFilter = TextureFilter.Nearest
78
- sampler.mipmapFilter = TextureFilter.Linear
79
- break;
80
- case WebGL2RenderingContext.LINEAR_MIPMAP_NEAREST:
81
- sampler.minificationFilter = TextureFilter.Linear
82
- sampler.mipmapFilter = TextureFilter.Nearest
83
- break;
84
- case WebGL2RenderingContext.LINEAR_MIPMAP_LINEAR:
85
- sampler.minificationFilter = TextureFilter.Linear
86
- sampler.mipmapFilter = TextureFilter.Linear
87
- break;
88
- default:
89
- throw 'GLTF: Invalid minification sampler';
90
- }
91
- return sampler
92
- })
85
+ const samplers = gltf.samplers.map((gltfSampler) => createGLTFSampler(gltfSampler))
93
86
 
94
87
  /**
95
- * @type {[Texture, Sampler | undefined][]}
88
+ * @type {[Texture, Sampler][]}
96
89
  */
97
90
  const textures = gltf.textures.map((gltfTextures) => {
98
91
  const image = images[gltfTextures.source]
@@ -100,17 +93,16 @@ export class GLTFLoader extends Loader {
100
93
 
101
94
  if (gltfTextures.sampler !== undefined) {
102
95
  const sampler = samplers[gltfTextures.sampler]
103
- if (sampler?.mipmapFilter !== undefined) {
104
- image.generateMipmaps = true
105
- }
96
+ assert(sampler, "GLTF texture does not have a valid sampler")
106
97
  return [image, sampler]
107
98
  }
108
- return [image, undefined]
99
+ return [image, createDefaultGLTFSampler()]
109
100
  })
110
101
  const materials = gltf.materials.map((gltfMaterial) => {
111
102
  const {
112
103
  emissiveFactor,
113
104
  emissiveTexture,
105
+ extensions = {},
114
106
  normalTexture,
115
107
  occlusionTexture,
116
108
  pbrMetallicRoughness
@@ -196,6 +188,57 @@ export class GLTFLoader extends Loader {
196
188
  }
197
189
  }
198
190
 
191
+ const transmissionExtension = extensions["KHR_materials_transmission"]
192
+ if (transmissionExtension) {
193
+ material.transmission = transmissionExtension.transmissionFactor ?? material.transmission
194
+
195
+ const transmissionTexture = transmissionExtension.transmissionTexture
196
+ if (transmissionTexture) {
197
+ const texture = textures[transmissionTexture.index]
198
+
199
+ if (texture) {
200
+ material.transmissionTexture = texture[0]
201
+ material.transmissionSampler = texture[1]
202
+ } else {
203
+ console.warn("gltf: invalid transmission texture on material");
204
+ }
205
+ }
206
+ }
207
+
208
+ const volumeExtension = extensions["KHR_materials_volume"]
209
+ if (volumeExtension) {
210
+ material.thickness = volumeExtension.thicknessFactor ?? material.thickness
211
+
212
+ const thicknessTexture = volumeExtension.thicknessTexture
213
+ if (thicknessTexture) {
214
+ const texture = textures[thicknessTexture.index]
215
+
216
+ if (texture) {
217
+ material.thicknessTexture = texture[0]
218
+ material.thicknessSampler = texture[1]
219
+ } else {
220
+ console.warn("gltf: invalid thickness texture on material");
221
+ }
222
+ }
223
+ }
224
+
225
+ const iorExtension = extensions["KHR_materials_ior"]
226
+ if (iorExtension) {
227
+ material.ior = iorExtension.ior ?? material.ior
228
+ }
229
+
230
+ if (gltfMaterial.alphaMode === GLFTAlphaMode.Mask) {
231
+ material.alphaBlend = new AlphaMaskMode(gltfMaterial.alphaCutoff)
232
+ } else if (gltfMaterial.alphaMode === GLFTAlphaMode.Blend) {
233
+ material.alphaBlend = new TransparentMode()
234
+ } else {
235
+ material.alphaBlend = new OpaqueMode()
236
+ }
237
+
238
+ if (gltfMaterial.doubleSided) {
239
+ material.cullFace = CullFace.None
240
+ }
241
+
199
242
  return material
200
243
  })
201
244
  const geometries = gltf.meshes.map((data) => {
@@ -203,7 +246,7 @@ export class GLTFLoader extends Loader {
203
246
  })
204
247
 
205
248
  gltf.nodes.forEach((node, index) => {
206
- const object = parseObject(index, node, gltf, geometries, materials)
249
+ const object = parseObject(index, node, gltf, geometries, materials, lightCache)
207
250
 
208
251
  if (object) {
209
252
  entityMap.set(index, object)
@@ -274,9 +317,10 @@ export class GLTFLoader extends Loader {
274
317
  * @param {string} baseUrl
275
318
  */
276
319
  async function loadGLTF(data, baseUrl) {
277
- const json = arrayBufferToJSON(data)
278
- const { buffers: urlBuffers } = json
279
- const buffers = urlBuffers instanceof Array ? await loadBuffers(baseUrl, urlBuffers) : []
320
+ const { json, buffers: embeddedBuffers } = parseGLTFAsset(data)
321
+ const buffers = json.buffers instanceof Array
322
+ ? await loadBuffers(baseUrl, json.buffers, embeddedBuffers)
323
+ : embeddedBuffers
280
324
  const gltf = GLTF.deserialize(json)
281
325
  gltf.buffers = buffers
282
326
 
@@ -285,12 +329,30 @@ async function loadGLTF(data, baseUrl) {
285
329
 
286
330
  /**
287
331
  * @param {string} base
288
- * @param {{uri: string;}[]} uris
332
+ * @param {{uri?: string; byteLength?: number;}[]} uris
333
+ * @param {ArrayBuffer[]} [embeddedBuffers]
289
334
  */
290
- async function loadBuffers(base, uris) {
335
+ async function loadBuffers(base, uris, embeddedBuffers = []) {
336
+ if (uris.length === 0) {
337
+ return embeddedBuffers.slice()
338
+ }
291
339
 
292
340
  return Promise.all(
293
- uris.map(async (buffer) => {
341
+ uris.map(async (buffer, index) => {
342
+ if (typeof buffer.uri !== "string") {
343
+ const embeddedBuffer = embeddedBuffers[index]
344
+ if (embeddedBuffer !== undefined) {
345
+ if (
346
+ typeof buffer.byteLength === "number" &&
347
+ embeddedBuffer.byteLength < buffer.byteLength
348
+ ) {
349
+ throw new Error(`Embedded buffer ${index} is shorter than declared byteLength`)
350
+ }
351
+ return embeddedBuffer
352
+ }
353
+ throw new Error(`Missing URI for buffer ${index}`)
354
+ }
355
+
294
356
  const url = buffer.uri.startsWith('data') ?
295
357
  buffer.uri :
296
358
  new URL(buffer.uri, base).href
@@ -300,6 +362,205 @@ async function loadBuffers(base, uris) {
300
362
  })
301
363
  )
302
364
  }
365
+
366
+ /**
367
+ * @param {number} filter
368
+ * @returns {TextureFilter}
369
+ */
370
+ function mapGLTFMagnificationFilter(filter) {
371
+ switch (filter) {
372
+ case TextureFilter.Nearest:
373
+ return TextureFilter.Nearest
374
+ case TextureFilter.Linear:
375
+ return TextureFilter.Linear
376
+ default:
377
+ throw "GLTF: Invalid magnification sampler"
378
+ }
379
+ }
380
+
381
+ /**
382
+ * @param {number} filter
383
+ * @returns {[TextureFilter, TextureFilter | undefined]}
384
+ */
385
+ function mapGLTFMinificationFilter(filter) {
386
+ switch (filter) {
387
+ case TextureFilter.Nearest:
388
+ return [TextureFilter.Nearest, undefined]
389
+ case TextureFilter.Linear:
390
+ return [TextureFilter.Linear, undefined]
391
+ case 0x2700:
392
+ return [TextureFilter.Nearest, TextureFilter.Nearest]
393
+ case 0x2701:
394
+ return [TextureFilter.Nearest, TextureFilter.Linear]
395
+ case 0x2702:
396
+ return [TextureFilter.Linear, TextureFilter.Nearest]
397
+ case 0x2703:
398
+ return [TextureFilter.Linear, TextureFilter.Linear]
399
+ default:
400
+ throw "GLTF: Invalid minification sampler"
401
+ }
402
+ }
403
+
404
+ /**
405
+ * @param {number} wrap
406
+ * @returns {TextureWrap}
407
+ */
408
+ function mapGLTFTextureWrap(wrap) {
409
+ switch (wrap) {
410
+ case TextureWrap.Clamp:
411
+ return TextureWrap.Clamp
412
+ case TextureWrap.MirrorRepeat:
413
+ return TextureWrap.MirrorRepeat
414
+ case TextureWrap.Repeat:
415
+ return TextureWrap.Repeat
416
+ default:
417
+ throw "GLTF: Invalid texture wrap"
418
+ }
419
+ }
420
+
421
+ /**
422
+ * @param {GLFTSampler} [gltfSampler]
423
+ * @returns {Sampler}
424
+ */
425
+ function createGLTFSampler(gltfSampler) {
426
+ const sampler = createDefaultGLTFSampler()
427
+
428
+ if (gltfSampler?.magFilter !== undefined) {
429
+ sampler.magnificationFilter = mapGLTFMagnificationFilter(gltfSampler.magFilter)
430
+ }
431
+
432
+ if (gltfSampler?.minFilter !== undefined) {
433
+ const [minificationFilter, mipmapFilter] = mapGLTFMinificationFilter(gltfSampler.minFilter)
434
+ sampler.minificationFilter = minificationFilter
435
+ sampler.mipmapFilter = mipmapFilter
436
+ }
437
+
438
+ if (gltfSampler?.wrapS !== undefined) {
439
+ sampler.wrapS = mapGLTFTextureWrap(gltfSampler.wrapS)
440
+ }
441
+
442
+ if (gltfSampler?.wrapT !== undefined) {
443
+ sampler.wrapT = mapGLTFTextureWrap(gltfSampler.wrapT)
444
+ }
445
+
446
+ return sampler
447
+ }
448
+
449
+ /**
450
+ * @returns {Sampler}
451
+ */
452
+ function createDefaultGLTFSampler() {
453
+ return new Sampler({
454
+ magnificationFilter: TextureFilter.Linear,
455
+ minificationFilter: TextureFilter.Linear,
456
+ mipmapFilter: undefined,
457
+ wrapS: TextureWrap.Repeat,
458
+ wrapT: TextureWrap.Repeat,
459
+ wrapR: TextureWrap.Repeat
460
+ })
461
+ }
462
+
463
+ /**
464
+ * @param {ArrayBuffer} data
465
+ * @returns {{ json: any, buffers: ArrayBuffer[] }}
466
+ */
467
+ function parseGLTFAsset(data) {
468
+ if (isGLB(data)) {
469
+ return parseGLB(data)
470
+ }
471
+
472
+ return {
473
+ json: arrayBufferToJSON(data),
474
+ buffers: []
475
+ }
476
+ }
477
+
478
+ /**
479
+ * @param {ArrayBuffer} data
480
+ * @returns {boolean}
481
+ */
482
+ function isGLB(data) {
483
+ if (data.byteLength < 12) {
484
+ return false
485
+ }
486
+
487
+ const view = new DataView(data)
488
+ return view.getUint32(0, true) === GLB_MAGIC
489
+ }
490
+
491
+ /**
492
+ * @param {ArrayBuffer} data
493
+ * @returns {{ json: any, buffers: ArrayBuffer[] }}
494
+ */
495
+ function parseGLB(data) {
496
+ const view = new DataView(data)
497
+ if (view.byteLength < 12) {
498
+ throw new Error("Invalid GLB file")
499
+ }
500
+
501
+ const magic = view.getUint32(0, true)
502
+ const version = view.getUint32(4, true)
503
+ const length = view.getUint32(8, true)
504
+
505
+ if (magic !== GLB_MAGIC) {
506
+ throw new Error("Invalid GLB magic")
507
+ }
508
+
509
+ if (version !== 2) {
510
+ throw new Error(`Unsupported GLB version: ${version}`)
511
+ }
512
+
513
+ if (length !== data.byteLength) {
514
+ throw new Error("GLB length does not match file size")
515
+ }
516
+
517
+ const decoder = new TextDecoder("utf-8")
518
+ let offset = 12
519
+ let json = undefined
520
+ /** @type {ArrayBuffer | undefined} */
521
+ let binBuffer
522
+ let sawJsonChunk = false
523
+
524
+ while (offset + 8 <= data.byteLength) {
525
+ const chunkStart = offset
526
+ const chunkLength = view.getUint32(chunkStart, true)
527
+ const chunkType = view.getUint32(chunkStart + 4, true)
528
+ offset = chunkStart + 8
529
+
530
+ if (offset + chunkLength > data.byteLength) {
531
+ throw new Error("Invalid GLB chunk length")
532
+ }
533
+
534
+ const chunk = data.slice(offset, offset + chunkLength)
535
+ offset += chunkLength
536
+
537
+ if (chunkType === GLB_CHUNK_TYPE_JSON) {
538
+ if (sawJsonChunk) {
539
+ throw new Error("GLB file contains multiple JSON chunks")
540
+ }
541
+ if (chunkStart !== 12) {
542
+ throw new Error("GLB JSON chunk must be the first chunk")
543
+ }
544
+ sawJsonChunk = true
545
+ json = JSON.parse(decoder.decode(chunk))
546
+ } else if (chunkType === GLB_CHUNK_TYPE_BIN) {
547
+ binBuffer = chunk
548
+ }
549
+ }
550
+
551
+ if (offset !== data.byteLength) {
552
+ throw new Error("GLB file has trailing or truncated chunk data")
553
+ }
554
+
555
+ if (json === undefined) {
556
+ throw new Error("GLB file is missing a JSON chunk")
557
+ }
558
+
559
+ return {
560
+ json,
561
+ buffers: binBuffer !== undefined ? [binBuffer] : []
562
+ }
563
+ }
303
564
  /**
304
565
  * @typedef {LoadSettings} GLTFLoadSettings
305
566
  */
@@ -357,6 +618,18 @@ class GLTF {
357
618
  * @type {GLTFMetaData}
358
619
  */
359
620
  metaData
621
+ /**
622
+ * @type {Record<string, any>}
623
+ */
624
+ extensions = {}
625
+ /**
626
+ * @type {string[]}
627
+ */
628
+ extensionsUsed = []
629
+ /**
630
+ * @type {string[]}
631
+ */
632
+ extensionsRequired = []
360
633
 
361
634
  /**
362
635
  * @param {GLTFMetaData} meta
@@ -380,7 +653,10 @@ class GLTF {
380
653
  bufferViews,
381
654
  accessors,
382
655
  asset,
383
- skins
656
+ skins,
657
+ extensions,
658
+ extensionsUsed,
659
+ extensionsRequired
384
660
  } = data
385
661
 
386
662
  if (
@@ -428,6 +704,24 @@ class GLTF {
428
704
  } else {
429
705
  gltf.skins = []
430
706
  }
707
+
708
+ if (extensions instanceof Object) {
709
+ gltf.extensions = extensions
710
+ } else {
711
+ gltf.extensions = {}
712
+ }
713
+
714
+ if (extensionsUsed instanceof Array) {
715
+ gltf.extensionsUsed = extensionsUsed.filter((value) => typeof value === "string")
716
+ } else {
717
+ gltf.extensionsUsed = []
718
+ }
719
+
720
+ if (extensionsRequired instanceof Array) {
721
+ gltf.extensionsRequired = extensionsRequired.filter((value) => typeof value === "string")
722
+ } else {
723
+ gltf.extensionsRequired = []
724
+ }
431
725
  return gltf
432
726
  }
433
727
  }
@@ -698,7 +992,7 @@ class GLTFMaterial {
698
992
  /**
699
993
  * @type {boolean}
700
994
  */
701
- doubleSide = false
995
+ doubleSided = false
702
996
 
703
997
  /**
704
998
  * @param {GLTFPBRetallicRoughness} metallicRoughness
@@ -718,7 +1012,7 @@ class GLTFMaterial {
718
1012
  emissiveFactor,
719
1013
  alphaMode,
720
1014
  alphaCutoff,
721
- doubleSide,
1015
+ doubleSided,
722
1016
  name,
723
1017
  extensions,
724
1018
  extras
@@ -750,8 +1044,8 @@ class GLTFMaterial {
750
1044
  result.alphaMode = alphaMode
751
1045
  }
752
1046
 
753
- if (typeof doubleSide === 'boolean') {
754
- result.doubleSide = doubleSide
1047
+ if (typeof doubleSided === 'boolean') {
1048
+ result.doubleSided = doubleSided
755
1049
  }
756
1050
 
757
1051
  if (typeof name === "string") {
@@ -979,7 +1273,7 @@ class GLFTTexture {
979
1273
 
980
1274
  class GLTFSkin {
981
1275
  /**
982
- * @type {number}
1276
+ * @type {number | undefined}
983
1277
  */
984
1278
  inverseBindMatrices
985
1279
 
@@ -1008,8 +1302,11 @@ class GLTFSkin {
1008
1302
  static deserialize(data) {
1009
1303
  const { joints, inverseBindMatrices, skeleton } = data
1010
1304
 
1305
+ if (!(joints instanceof Array)) {
1306
+ throw 'Invalid skin'
1307
+ }
1011
1308
  if (
1012
- !(joints instanceof Array) ||
1309
+ inverseBindMatrices !== undefined &&
1013
1310
  typeof inverseBindMatrices !== 'number'
1014
1311
  ) {
1015
1312
  throw 'Invalid skin'
@@ -1692,12 +1989,12 @@ class TRSTransform {
1692
1989
 
1693
1990
  class MatrixTransform {
1694
1991
  /**
1695
- * @type {MatrixArray}
1992
+ * @type {Affine3}
1696
1993
  */
1697
1994
  value
1698
1995
 
1699
1996
  /**
1700
- * @param {MatrixArray} value
1997
+ * @param {Affine3} value
1701
1998
  */
1702
1999
  constructor(value) {
1703
2000
  this.value = value
@@ -1717,7 +2014,11 @@ class MatrixTransform {
1717
2014
  if (t.length !== 16) {
1718
2015
  throw "invalid matrix transform"
1719
2016
  }
1720
- const transform = new MatrixTransform(/**@type {MatrixArray}*/(t))
2017
+ const transform = new MatrixTransform(new Affine3(
2018
+ t[0], t[4], t[8], t[12],
2019
+ t[1], t[5], t[9], t[13],
2020
+ t[2], t[6], t[10], t[14]
2021
+ ))
1721
2022
 
1722
2023
  return transform
1723
2024
  }
@@ -1742,10 +2043,37 @@ function getAccessorData(index, gltf) {
1742
2043
 
1743
2044
  if (!buffer) throw "Invalid access to buffer"
1744
2045
 
1745
- const byteLength = accessor.count * getComponentSize(accessor.componentType) * getElementSize(accessor.type)
2046
+ const componentSize = getComponentSize(accessor.componentType)
2047
+ const elementSize = getElementSize(accessor.type)
2048
+ const elementByteLength = componentSize * elementSize
2049
+ const stride = view.stride || elementByteLength
2050
+
2051
+ if (stride < elementByteLength) {
2052
+ throw "Invalid accessor stride"
2053
+ }
2054
+
2055
+ if (stride === elementByteLength) {
2056
+ const byteLength = accessor.count * elementByteLength
2057
+ return [
2058
+ new DataView(buffer, view.offset + accessor.offset, byteLength),
2059
+ accessor
2060
+ ]
2061
+ }
2062
+
2063
+ const packedBuffer = new ArrayBuffer(accessor.count * elementByteLength)
2064
+ const destination = new Uint8Array(packedBuffer)
2065
+ const sourceOffset = view.offset + accessor.offset
2066
+
2067
+ for (let i = 0; i < accessor.count; i++) {
2068
+ const sourceStart = sourceOffset + i * stride
2069
+ destination.set(
2070
+ new Uint8Array(buffer, sourceStart, elementByteLength),
2071
+ i * elementByteLength
2072
+ )
2073
+ }
1746
2074
 
1747
2075
  return [
1748
- new DataView(buffer, view.offset + accessor.offset, byteLength),
2076
+ new DataView(packedBuffer),
1749
2077
  accessor
1750
2078
  ]
1751
2079
  }
@@ -1755,6 +2083,10 @@ function getAccessorData(index, gltf) {
1755
2083
  * @param {DataView} view
1756
2084
  */
1757
2085
  function mapToIndices(accessor, view) {
2086
+ if (accessor.type !== GLTFAccessorType.Scalar) {
2087
+ throw "Indices provided on a mesh is not valid"
2088
+ }
2089
+
1758
2090
  switch (accessor.componentType) {
1759
2091
  case GLTFComponentType.UnsignedByte:
1760
2092
  return new Uint8Array(
@@ -1779,6 +2111,163 @@ function mapToIndices(accessor, view) {
1779
2111
  }
1780
2112
  }
1781
2113
 
2114
+ /**
2115
+ * @param {GLTFComponentType} componentType
2116
+ */
2117
+ function isFloatComponentType(componentType) {
2118
+ return componentType === GLTFComponentType.Float
2119
+ }
2120
+
2121
+ /**
2122
+ * @param {GLTFComponentType} componentType
2123
+ */
2124
+ function isNormalizedIntegerComponentType(componentType) {
2125
+ switch (componentType) {
2126
+ case GLTFComponentType.Byte:
2127
+ case GLTFComponentType.UnsignedByte:
2128
+ case GLTFComponentType.Short:
2129
+ case GLTFComponentType.UnsignedShort:
2130
+ return true
2131
+ default:
2132
+ return false
2133
+ }
2134
+ }
2135
+
2136
+ /**
2137
+ * @param {GLTFComponentType} componentType
2138
+ */
2139
+ function isJointComponentType(componentType) {
2140
+ switch (componentType) {
2141
+ case GLTFComponentType.UnsignedByte:
2142
+ case GLTFComponentType.UnsignedShort:
2143
+ return true
2144
+ default:
2145
+ return false
2146
+ }
2147
+ }
2148
+
2149
+ /**
2150
+ * @param {DataView} view
2151
+ * @param {number} offset
2152
+ * @param {GLTFComponentType} componentType
2153
+ * @param {boolean} normalized
2154
+ * @returns {number}
2155
+ */
2156
+ function readAccessorComponent(view, offset, componentType, normalized) {
2157
+ switch (componentType) {
2158
+ case GLTFComponentType.Byte: {
2159
+ const value = view.getInt8(offset)
2160
+ if (!normalized) return value
2161
+ return Math.max(value / 127, -1)
2162
+ }
2163
+ case GLTFComponentType.UnsignedByte: {
2164
+ const value = view.getUint8(offset)
2165
+ if (!normalized) return value
2166
+ return value / 255
2167
+ }
2168
+ case GLTFComponentType.Short: {
2169
+ const value = view.getInt16(offset, true)
2170
+ if (!normalized) return value
2171
+ return Math.max(value / 32767, -1)
2172
+ }
2173
+ case GLTFComponentType.UnsignedShort: {
2174
+ const value = view.getUint16(offset, true)
2175
+ if (!normalized) return value
2176
+ return value / 65535
2177
+ }
2178
+ case GLTFComponentType.Int: {
2179
+ const value = view.getInt32(offset, true)
2180
+ if (!normalized) return value
2181
+ return Math.max(value / 2147483647, -1)
2182
+ }
2183
+ case GLTFComponentType.UnsignedInt: {
2184
+ const value = view.getUint32(offset, true)
2185
+ if (!normalized) return value
2186
+ return value / 4294967295
2187
+ }
2188
+ case GLTFComponentType.Float:
2189
+ return view.getFloat32(offset, true)
2190
+ default:
2191
+ throw "Unsupported accessor component type"
2192
+ }
2193
+ }
2194
+
2195
+ /**
2196
+ * @param {GLTFAccessor} accessor
2197
+ * @param {DataView} buffer
2198
+ * @param {number} componentCount
2199
+ * @param {boolean} [allowVec3Padding=false]
2200
+ * @returns {DataView}
2201
+ */
2202
+ function convertAccessorToFloat32(accessor, buffer, componentCount, allowVec3Padding = false) {
2203
+ const sourceComponents = getElementSize(accessor.type)
2204
+ if (sourceComponents !== componentCount) {
2205
+ if (!(allowVec3Padding && componentCount === 4 && sourceComponents === 3)) {
2206
+ throw "Attribute types do not match"
2207
+ }
2208
+ }
2209
+
2210
+ const componentSize = getComponentSize(accessor.componentType)
2211
+ const normalized = accessor.normalized
2212
+ const result = new Float32Array(accessor.count * componentCount)
2213
+
2214
+ for (let i = 0; i < accessor.count; i++) {
2215
+ const sourceOffset = i * sourceComponents * componentSize
2216
+ const resultOffset = i * componentCount
2217
+
2218
+ for (let component = 0; component < sourceComponents; component++) {
2219
+ result[resultOffset + component] = readAccessorComponent(
2220
+ buffer,
2221
+ sourceOffset + component * componentSize,
2222
+ accessor.componentType,
2223
+ normalized
2224
+ )
2225
+ }
2226
+
2227
+ if (allowVec3Padding && componentCount === 4 && sourceComponents === 3) {
2228
+ result[resultOffset + 3] = 1.0
2229
+ }
2230
+ }
2231
+
2232
+ return new DataView(result.buffer)
2233
+ }
2234
+
2235
+ /**
2236
+ * @param {GLTFAccessor} accessor
2237
+ * @param {DataView} buffer
2238
+ * @returns {DataView}
2239
+ */
2240
+ function convertAccessorToUint16(accessor, buffer) {
2241
+ const sourceComponents = getElementSize(accessor.type)
2242
+ if (sourceComponents !== 4) {
2243
+ throw "Attribute types do not match"
2244
+ }
2245
+
2246
+ const componentType = accessor.componentType
2247
+ if (!isJointComponentType(componentType) || accessor.normalized) {
2248
+ throw "Attribute types do not match"
2249
+ }
2250
+
2251
+ const componentSize = getComponentSize(componentType)
2252
+ const result = new Uint16Array(accessor.count * sourceComponents)
2253
+
2254
+ for (let i = 0; i < accessor.count; i++) {
2255
+ const sourceOffset = i * sourceComponents * componentSize
2256
+ const resultOffset = i * sourceComponents
2257
+
2258
+ for (let component = 0; component < sourceComponents; component++) {
2259
+ result[resultOffset + component] = readAccessorComponent(
2260
+ buffer,
2261
+ sourceOffset + component * componentSize,
2262
+ componentType,
2263
+ false
2264
+ )
2265
+ }
2266
+ }
2267
+
2268
+ return new DataView(result.buffer)
2269
+ }
2270
+
1782
2271
  /**
1783
2272
  * @param {string} name
1784
2273
  * @param {GLTFAccessor} accessor
@@ -1786,48 +2275,56 @@ function mapToIndices(accessor, view) {
1786
2275
  * @returns {[string, DataView] | undefined}
1787
2276
  */
1788
2277
  function mapAccessorTypeToAttribute(name, accessor, buffer) {
1789
- const { componentType: type } = accessor
1790
2278
  switch (name) {
1791
2279
  case GLTFAttributeName.Position:
1792
- if (type !== mapToGLTFComponentType(Attribute.Position.format))
2280
+ if (accessor.type !== GLTFAccessorType.Vec3 || accessor.componentType !== GLTFComponentType.Float || accessor.normalized)
1793
2281
  throw "Attribute types do not match"
1794
- return [Attribute.Position.name, buffer]
2282
+ return [Attribute.Position.name, convertAccessorToFloat32(accessor, buffer, 3)]
1795
2283
  case GLTFAttributeName.TexCoord0:
1796
- if (type !== mapToGLTFComponentType(Attribute.UV.format))
2284
+ if (
2285
+ accessor.type !== GLTFAccessorType.Vec2 ||
2286
+ (!isFloatComponentType(accessor.componentType) && !isNormalizedIntegerComponentType(accessor.componentType)) ||
2287
+ (accessor.componentType === GLTFComponentType.Float ? accessor.normalized : !accessor.normalized)
2288
+ )
1797
2289
  throw "Attribute types do not match"
1798
- return [Attribute.UV.name, buffer]
2290
+ return [Attribute.UV.name, convertAccessorToFloat32(accessor, buffer, 2)]
1799
2291
  case GLTFAttributeName.TexCoord1:
1800
- if (type !== mapToGLTFComponentType(Attribute.UVB.format))
2292
+ if (
2293
+ accessor.type !== GLTFAccessorType.Vec2 ||
2294
+ (!isFloatComponentType(accessor.componentType) && !isNormalizedIntegerComponentType(accessor.componentType)) ||
2295
+ (accessor.componentType === GLTFComponentType.Float ? accessor.normalized : !accessor.normalized)
2296
+ )
1801
2297
  throw "Attribute types do not match"
1802
- return [Attribute.UVB.name, buffer]
2298
+ return [Attribute.UVB.name, convertAccessorToFloat32(accessor, buffer, 2)]
1803
2299
  case GLTFAttributeName.Normal:
1804
- if (type !== mapToGLTFComponentType(Attribute.Normal.format))
2300
+ if (accessor.type !== GLTFAccessorType.Vec3 || accessor.componentType !== GLTFComponentType.Float || accessor.normalized)
1805
2301
  throw "Attribute types do not match"
1806
- return [Attribute.Normal.name, buffer]
2302
+ return [Attribute.Normal.name, convertAccessorToFloat32(accessor, buffer, 3)]
1807
2303
  case GLTFAttributeName.Tangent:
1808
- if (type !== mapToGLTFComponentType(Attribute.Tangent.format))
2304
+ if (accessor.type !== GLTFAccessorType.Vec4 || accessor.componentType !== GLTFComponentType.Float || accessor.normalized)
1809
2305
  throw "Attribute types do not match"
1810
- return [Attribute.Tangent.name, buffer]
2306
+ return [Attribute.Tangent.name, convertAccessorToFloat32(accessor, buffer, 4)]
1811
2307
  case GLTFAttributeName.Color0:
1812
- if (type !== mapToGLTFComponentType(Attribute.Color.format))
2308
+ if (
2309
+ (accessor.type !== GLTFAccessorType.Vec3 && accessor.type !== GLTFAccessorType.Vec4) ||
2310
+ (!isFloatComponentType(accessor.componentType) && !isNormalizedIntegerComponentType(accessor.componentType)) ||
2311
+ (accessor.componentType === GLTFComponentType.Float ? accessor.normalized : !accessor.normalized)
2312
+ )
1813
2313
  throw "Attribute types do not match"
1814
- return [Attribute.Color.name, buffer]
2314
+ return [Attribute.Color.name, convertAccessorToFloat32(accessor, buffer, 4, accessor.type === GLTFAccessorType.Vec3)]
1815
2315
  case GLTFAttributeName.Weights0:
1816
- if (type !== mapToGLTFComponentType(Attribute.JointWeight.format))
2316
+ if (
2317
+ accessor.type !== GLTFAccessorType.Vec4 ||
2318
+ (!isFloatComponentType(accessor.componentType) && !isNormalizedIntegerComponentType(accessor.componentType)) ||
2319
+ (accessor.componentType === GLTFComponentType.Float ? accessor.normalized : !accessor.normalized)
2320
+ )
1817
2321
  throw "Attribute types do not match"
1818
- return [Attribute.JointWeight.name, buffer]
2322
+ return [Attribute.JointWeight.name, convertAccessorToFloat32(accessor, buffer, 4)]
1819
2323
  case GLTFAttributeName.Joints0:
1820
- if (type === mapToGLTFComponentType(Attribute.JointIndex.format)) {
1821
- return [Attribute.JointIndex.name, buffer]
1822
- } else if (type === GlDataType.UnsignedByte) {
1823
- const newBuffer = widenTypedArray(
1824
- new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength),
1825
- Uint16Array
1826
- )
1827
- return [Attribute.JointIndex.name, new DataView(newBuffer.buffer)]
1828
- } else {
2324
+ if (accessor.type !== GLTFAccessorType.Vec4 || accessor.normalized || !isJointComponentType(accessor.componentType)) {
1829
2325
  throw "Attribute types do not match"
1830
2326
  }
2327
+ return [Attribute.JointIndex.name, convertAccessorToUint16(accessor, buffer)]
1831
2328
  default:
1832
2329
  return undefined;
1833
2330
  }
@@ -1926,6 +2423,7 @@ function parseGeometry(gltfMesh, gltf) {
1926
2423
  const primitive = /**@type {GLTFPrimitive} */ (gltfMesh.primitives[i])
1927
2424
  const attributes = new SeparateAttributeData()
1928
2425
  const mesh = new Mesh(attributes)
2426
+ mesh.topology = primitive.mode
1929
2427
  if (primitive.indices !== undefined) {
1930
2428
  const [dataView, accessor] = getAccessorData(
1931
2429
  primitive.indices,
@@ -1960,11 +2458,27 @@ function parseGeometry(gltfMesh, gltf) {
1960
2458
  * @returns {Skin}
1961
2459
  */
1962
2460
  function parseSkin(gltfSkin, gltf, entityMap) {
1963
- const [bindPoseData] = getAccessorData(gltfSkin.inverseBindMatrices, gltf)
1964
- const bindPose = convertToInverseBindPose(bindPoseData)
2461
+ /** @type {Affine3[]} */
2462
+ let bindPose = []
2463
+
2464
+ if (gltfSkin.inverseBindMatrices !== undefined) {
2465
+ const bindPoseAccessor = gltf.accessors[gltfSkin.inverseBindMatrices]
2466
+ if (
2467
+ !bindPoseAccessor ||
2468
+ bindPoseAccessor.type !== GLTFAccessorType.Mat4 ||
2469
+ bindPoseAccessor.componentType !== GLTFComponentType.Float ||
2470
+ bindPoseAccessor.normalized
2471
+ ) {
2472
+ throw "Attribute types do not match"
2473
+ }
2474
+
2475
+ const [bindPoseData] = getAccessorData(gltfSkin.inverseBindMatrices, gltf)
2476
+ bindPose = convertToInverseBindPose(bindPoseData)
2477
+ }
2478
+
1965
2479
  const skin = new Skin()
1966
2480
 
1967
- if (bindPose.length !== gltfSkin.joints.length) {
2481
+ if (gltfSkin.inverseBindMatrices !== undefined && bindPose.length !== gltfSkin.joints.length) {
1968
2482
  console.warn(
1969
2483
  "GLTF skin inverse bind matrix count does not match joint count",
1970
2484
  bindPose.length,
@@ -1972,7 +2486,7 @@ function parseSkin(gltfSkin, gltf, entityMap) {
1972
2486
  )
1973
2487
  }
1974
2488
 
1975
- skin.inverseBindPose = bindPose
2489
+ skin.inverseBindPose = gltfSkin.joints.map((_, index) => bindPose[index] || new Affine3())
1976
2490
  skin.bones = gltfSkin.joints.map(joint => {
1977
2491
  const entity = entityMap.get(joint)
1978
2492
  if (!(entity instanceof Bone3D)) {
@@ -2019,18 +2533,28 @@ function convertToInverseBindPose(poseData) {
2019
2533
  * @param {GLTF} gltf
2020
2534
  * @param {[Mesh,number | undefined][][]} geometries
2021
2535
  * @param {StandardMaterial[]} materials
2536
+ * @param {Map<number, DirectionalLight | PointLight | SpotLight>} lightCache
2022
2537
  */
2023
- function parseObject(index, node, gltf, geometries, materials) {
2538
+ function parseObject(index, node, gltf, geometries, materials, lightCache) {
2024
2539
  const { mesh, transform, name } = node
2540
+ const light = parseGLTFLight(node, gltf, lightCache)
2025
2541
 
2026
2542
  let object
2027
2543
  if (mesh !== undefined) {
2028
2544
  object = parseMeshObject(mesh, gltf.meshes, geometries, materials)
2545
+ if (light) {
2546
+ object.add(light)
2547
+ }
2029
2548
  } else {
2030
2549
  const bone = parseBone(index, gltf)
2031
2550
 
2032
2551
  if (bone) {
2033
2552
  object = bone
2553
+ if (light) {
2554
+ object.add(light)
2555
+ }
2556
+ } else if (light) {
2557
+ object = light
2034
2558
  } else {
2035
2559
  object = new Object3D()
2036
2560
  }
@@ -2045,6 +2569,101 @@ function parseObject(index, node, gltf, geometries, materials) {
2045
2569
  return object
2046
2570
  }
2047
2571
 
2572
+ /**
2573
+ * @param {GLTFNode} node
2574
+ * @param {GLTF} gltf
2575
+ * @param {Map<number, DirectionalLight | PointLight | SpotLight>} lightCache
2576
+ * @returns {DirectionalLight | PointLight | SpotLight | undefined}
2577
+ */
2578
+ function parseGLTFLight(node, gltf, lightCache) {
2579
+ const nodeLightExtension = node.extensions[GLTF_LIGHTS_PUNCTUAL_EXTENSION]
2580
+
2581
+ if (!(nodeLightExtension instanceof Object)) {
2582
+ return undefined
2583
+ }
2584
+
2585
+ const lightIndex = nodeLightExtension.light
2586
+ if (typeof lightIndex !== "number") {
2587
+ throw "GLTF light node is missing a light index"
2588
+ }
2589
+
2590
+ const extension = gltf.extensions[GLTF_LIGHTS_PUNCTUAL_EXTENSION]
2591
+ if (!(extension instanceof Object) || !(extension.lights instanceof Array)) {
2592
+ throw "GLTF punctual lights extension is missing its light table"
2593
+ }
2594
+
2595
+ const gltfLight = extension.lights[lightIndex]
2596
+ if (!(gltfLight instanceof Object)) {
2597
+ throw "GLTF light index is invalid"
2598
+ }
2599
+
2600
+ const cachedLight = lightCache.get(lightIndex)
2601
+ if (cachedLight) {
2602
+ return cachedLight.clone()
2603
+ }
2604
+
2605
+ const prototype = createGLTFLight(gltfLight)
2606
+ lightCache.set(lightIndex, prototype)
2607
+ return prototype.clone()
2608
+ }
2609
+
2610
+ /**
2611
+ * @param {any} gltfLight
2612
+ * @returns {DirectionalLight | PointLight | SpotLight}
2613
+ */
2614
+ function createGLTFLight(gltfLight) {
2615
+ const color = Array.isArray(gltfLight.color) ? gltfLight.color : []
2616
+ const red = Number.isFinite(color[0]) ? color[0] : 1
2617
+ const green = Number.isFinite(color[1]) ? color[1] : 1
2618
+ const blue = Number.isFinite(color[2]) ? color[2] : 1
2619
+ const intensity = Number.isFinite(gltfLight.intensity) ? gltfLight.intensity : 1
2620
+ const name = typeof gltfLight.name === "string" ? gltfLight.name : ""
2621
+
2622
+ if (gltfLight.type === "directional") {
2623
+ const light = new DirectionalLight()
2624
+ light.color.set(red, green, blue)
2625
+ light.intensity = intensity
2626
+ light.name = name
2627
+ return light
2628
+ }
2629
+
2630
+ if (gltfLight.type === "point") {
2631
+ const light = new PointLight()
2632
+ light.color.set(red, green, blue)
2633
+ light.intensity = intensity
2634
+ light.radius = Number.isFinite(gltfLight.range) && gltfLight.range > 0
2635
+ ? gltfLight.range
2636
+ : DEFAULT_GLTF_LIGHT_RANGE
2637
+ light.name = name
2638
+ return light
2639
+ }
2640
+
2641
+ if (gltfLight.type === "spot") {
2642
+ const light = new SpotLight()
2643
+ const spot = gltfLight.spot instanceof Object ? gltfLight.spot : {}
2644
+ const innerConeAngle = Number.isFinite(spot.innerConeAngle) && spot.innerConeAngle >= 0
2645
+ ? spot.innerConeAngle
2646
+ : 0
2647
+ const outerConeAngle = Number.isFinite(spot.outerConeAngle) && spot.outerConeAngle > 0
2648
+ ? spot.outerConeAngle
2649
+ : Math.PI / 4
2650
+ const normalizedInnerConeAngle = Math.min(innerConeAngle, outerConeAngle)
2651
+ const normalizedOuterConeAngle = Math.max(innerConeAngle, outerConeAngle)
2652
+
2653
+ light.color.set(red, green, blue)
2654
+ light.intensity = intensity
2655
+ light.range = Number.isFinite(gltfLight.range) && gltfLight.range > 0
2656
+ ? gltfLight.range
2657
+ : DEFAULT_GLTF_LIGHT_RANGE
2658
+ light.innerAngle = normalizedInnerConeAngle * 2
2659
+ light.outerAngle = normalizedOuterConeAngle * 2
2660
+ light.name = name
2661
+ return light
2662
+ }
2663
+
2664
+ throw `Unsupported glTF light type: ${gltfLight.type}`
2665
+ }
2666
+
2048
2667
  /**
2049
2668
  * @param {number} index
2050
2669
  * @param {GLTF} gltf
@@ -2080,7 +2699,11 @@ function transferTransform(object, transform) {
2080
2699
  object.transform.scale.z = transform.scale[2]
2081
2700
  }
2082
2701
  if (transform instanceof MatrixTransform) {
2083
- throw "matrix transform not yet supported"
2702
+ const [position, rotation, scale] = transform.value.decompose()
2703
+
2704
+ object.transform.position.copy(position)
2705
+ object.transform.orientation.copy(rotation)
2706
+ object.transform.scale.copy(scale)
2084
2707
  }
2085
2708
  }
2086
2709
 
@@ -2090,79 +2713,6 @@ function transferTransform(object, transform) {
2090
2713
  * @param {new (...args:any[])=>TypedArray} to
2091
2714
  * @returns
2092
2715
  */
2093
- function widenTypedArray(from, to) {
2094
- const result = new to(from.length);
2095
- for (let i = 0; i < from.length; i++) {
2096
- result[i] = /**@type {bigint | number}*/(from[i])
2097
- }
2098
- return result;
2099
- }
2100
-
2101
- /**
2102
- * @param {VertexFormat} vertexFormat
2103
- */
2104
- function mapToGLTFComponentType(vertexFormat) {
2105
- switch (vertexFormat) {
2106
- case VertexFormat.Uint8:
2107
- case VertexFormat.Uint8x2:
2108
- case VertexFormat.Uint8x3:
2109
- case VertexFormat.Uint8x4:
2110
- case VertexFormat.Unorm8:
2111
- case VertexFormat.Unorm8x2:
2112
- case VertexFormat.Unorm8x3:
2113
- case VertexFormat.Unorm8x4:
2114
- return GLTFComponentType.UnsignedByte;
2115
- case VertexFormat.Snorm8:
2116
- case VertexFormat.Snorm8x2:
2117
- case VertexFormat.Snorm8x3:
2118
- case VertexFormat.Snorm8x4:
2119
- case VertexFormat.Sint8:
2120
- case VertexFormat.Sint8x2:
2121
- case VertexFormat.Sint8x3:
2122
- case VertexFormat.Sint8x4:
2123
- return GLTFComponentType.Byte;
2124
- case VertexFormat.Uint16:
2125
- case VertexFormat.Uint16x2:
2126
- case VertexFormat.Uint16x3:
2127
- case VertexFormat.Uint16x4:
2128
- case VertexFormat.Unorm16:
2129
- case VertexFormat.Unorm16x2:
2130
- case VertexFormat.Unorm16x3:
2131
- case VertexFormat.Unorm16x4:
2132
- return GLTFComponentType.UnsignedShort;
2133
- case VertexFormat.Snorm16:
2134
- case VertexFormat.Snorm16x2:
2135
- case VertexFormat.Snorm16x3:
2136
- case VertexFormat.Snorm16x4:
2137
- case VertexFormat.Sint16:
2138
- case VertexFormat.Sint16x2:
2139
- case VertexFormat.Sint16x3:
2140
- case VertexFormat.Sint16x4:
2141
- return GLTFComponentType.Short;
2142
- // 32-bit unsigned ints
2143
- case VertexFormat.Uint32:
2144
- case VertexFormat.Uint32x2:
2145
- case VertexFormat.Uint32x3:
2146
- case VertexFormat.Uint32x4:
2147
- return GLTFComponentType.UnsignedInt;
2148
-
2149
- // 32-bit signed ints
2150
- case VertexFormat.Sint32:
2151
- case VertexFormat.Sint32x2:
2152
- case VertexFormat.Sint32x3:
2153
- case VertexFormat.Sint32x4:
2154
- return GLTFComponentType.Int;
2155
- case VertexFormat.Float32:
2156
- case VertexFormat.Float32x2:
2157
- case VertexFormat.Float32x3:
2158
- case VertexFormat.Float32x4:
2159
- return GLTFComponentType.Float
2160
- default:
2161
- throw new Error('Unsupported vertex format: ' + vertexFormat);
2162
- }
2163
- }
2164
-
2165
-
2166
2716
  /**
2167
2717
  *@typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray
2168
2718
  */