super-three 0.184.0 → 0.185.0

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 (366) hide show
  1. package/build/three.cjs +1260 -927
  2. package/build/three.core.js +1104 -829
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +156 -98
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +11 -4
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +7538 -3367
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +7538 -3366
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +3 -0
  13. package/examples/jsm/controls/ArcballControls.js +6 -2
  14. package/examples/jsm/controls/FirstPersonControls.js +79 -42
  15. package/examples/jsm/controls/TransformControls.js +68 -15
  16. package/examples/jsm/csm/CSMFrustum.js +31 -6
  17. package/examples/jsm/csm/CSMShadowNode.js +4 -1
  18. package/examples/jsm/effects/AsciiEffect.js +14 -1
  19. package/examples/jsm/exporters/DRACOExporter.js +27 -6
  20. package/examples/jsm/exporters/GLTFExporter.js +114 -12
  21. package/examples/jsm/exporters/PLYExporter.js +286 -73
  22. package/examples/jsm/exporters/USDZExporter.js +347 -112
  23. package/examples/jsm/generators/CityGenerator.js +346 -0
  24. package/examples/jsm/generators/ForestGenerator.js +347 -0
  25. package/examples/jsm/generators/TerrainGenerator.js +504 -0
  26. package/examples/jsm/generators/TreeGenerator.js +377 -0
  27. package/examples/jsm/generators/city/SidewalkGenerator.js +253 -0
  28. package/examples/jsm/generators/city/SkyscraperGenerator.js +1357 -0
  29. package/examples/jsm/geometries/LoftGeometry.js +355 -0
  30. package/examples/jsm/helpers/LightProbeGridHelper.js +1 -1
  31. package/examples/jsm/helpers/LightProbeHelper.js +5 -4
  32. package/examples/jsm/helpers/ViewHelper.js +16 -6
  33. package/examples/jsm/inspector/Inspector.js +53 -15
  34. package/examples/jsm/inspector/RendererInspector.js +152 -36
  35. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +1 -1
  36. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -1
  37. package/examples/jsm/inspector/tabs/Console.js +200 -18
  38. package/examples/jsm/inspector/tabs/Memory.js +8 -0
  39. package/examples/jsm/inspector/tabs/Parameters.js +64 -4
  40. package/examples/jsm/inspector/tabs/Performance.js +21 -6
  41. package/examples/jsm/inspector/tabs/Settings.js +51 -9
  42. package/examples/jsm/inspector/tabs/Timeline.js +178 -93
  43. package/examples/jsm/inspector/tabs/Viewer.js +628 -16
  44. package/examples/jsm/inspector/ui/Graph.js +162 -25
  45. package/examples/jsm/inspector/ui/Item.js +92 -13
  46. package/examples/jsm/inspector/ui/List.js +1 -1
  47. package/examples/jsm/inspector/ui/Profiler.js +90 -45
  48. package/examples/jsm/inspector/ui/Style.js +1788 -1401
  49. package/examples/jsm/inspector/ui/Tab.js +5 -3
  50. package/examples/jsm/inspector/ui/Values.js +71 -6
  51. package/examples/jsm/inspector/ui/utils.js +130 -10
  52. package/examples/jsm/libs/basis/README.md +0 -1
  53. package/examples/jsm/libs/demuxer_mp4.js +3 -3
  54. package/examples/jsm/libs/draco/README.md +0 -1
  55. package/examples/jsm/libs/meshopt_clusterizer.module.js +421 -0
  56. package/examples/jsm/libs/meshopt_simplifier.module.js +627 -0
  57. package/examples/jsm/libs/mikktspace.module.js +34 -9
  58. package/examples/jsm/lighting/ClusteredLighting.js +55 -0
  59. package/examples/jsm/lighting/LightProbeGrid.js +106 -76
  60. package/examples/jsm/lines/LineMaterial.js +38 -15
  61. package/examples/jsm/lines/LineSegments2.js +8 -0
  62. package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
  63. package/examples/jsm/loaders/3DMLoader.js +1 -1
  64. package/examples/jsm/loaders/DRACOLoader.js +46 -13
  65. package/examples/jsm/loaders/EXRLoader.js +27 -55
  66. package/examples/jsm/loaders/HDRLoader.js +6 -28
  67. package/examples/jsm/loaders/KTX2Loader.js +31 -12
  68. package/examples/jsm/loaders/LDrawLoader.js +8 -8
  69. package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
  70. package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
  71. package/examples/jsm/loaders/LWOLoader.js +4 -0
  72. package/examples/jsm/loaders/LottieLoader.js +1 -1
  73. package/examples/jsm/loaders/MaterialXLoader.js +31 -9
  74. package/examples/jsm/loaders/NRRDLoader.js +3 -3
  75. package/examples/jsm/loaders/PCDLoader.js +7 -7
  76. package/examples/jsm/loaders/PLYLoader.js +218 -55
  77. package/examples/jsm/loaders/SVGLoader.js +547 -495
  78. package/examples/jsm/loaders/TTFLoader.js +1 -1
  79. package/examples/jsm/loaders/USDLoader.js +33 -9
  80. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  81. package/examples/jsm/loaders/usd/USDAParser.js +93 -20
  82. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  83. package/examples/jsm/loaders/usd/USDComposer.js +52 -19
  84. package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
  85. package/examples/jsm/misc/Volume.js +2 -2
  86. package/examples/jsm/objects/GroundedSkybox.js +1 -1
  87. package/examples/jsm/objects/Reflector.js +2 -3
  88. package/examples/jsm/objects/Water2Mesh.js +1 -1
  89. package/examples/jsm/physics/AmmoPhysics.js +15 -8
  90. package/examples/jsm/physics/RapierPhysics.js +27 -2
  91. package/examples/jsm/shaders/VolumeShader.js +31 -44
  92. package/examples/jsm/transpiler/GLSLDecoder.js +6 -6
  93. package/examples/jsm/transpiler/Linker.js +1 -1
  94. package/examples/jsm/tsl/display/BloomNode.js +59 -19
  95. package/examples/jsm/tsl/display/DepthOfFieldNode.js +2 -2
  96. package/examples/jsm/tsl/display/FXAANode.js +11 -12
  97. package/examples/jsm/tsl/display/GTAONode.js +34 -13
  98. package/examples/jsm/tsl/display/GodraysNode.js +1 -1
  99. package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
  100. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -2
  101. package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
  102. package/examples/jsm/tsl/display/SSAAPassNode.js +13 -25
  103. package/examples/jsm/tsl/display/SSGINode.js +89 -39
  104. package/examples/jsm/tsl/display/SSRNode.js +829 -132
  105. package/examples/jsm/tsl/display/SSSNode.js +2 -2
  106. package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
  107. package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
  108. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +1 -1
  109. package/examples/jsm/tsl/math/curlNoise.js +107 -0
  110. package/examples/jsm/tsl/shadows/TileShadowNode.js +1 -1
  111. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +3 -3
  112. package/examples/jsm/tsl/utils/GroundedSkybox.js +62 -0
  113. package/examples/jsm/tsl/utils/RNoise.js +51 -0
  114. package/examples/jsm/tsl/utils/SpecularHelpers.js +325 -0
  115. package/examples/jsm/utils/BufferGeometryUtils.js +126 -59
  116. package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
  117. package/examples/jsm/utils/SceneOptimizer.js +1 -1
  118. package/examples/jsm/webxr/ARButton.js +1 -1
  119. package/examples/jsm/webxr/WebGLXRFallback.js +89 -0
  120. package/examples/jsm/webxr/XRControllerModelFactory.js +2 -2
  121. package/package.json +7 -7
  122. package/src/Three.TSL.js +10 -3
  123. package/src/Three.WebGPU.js +4 -0
  124. package/src/animation/AnimationAction.js +15 -11
  125. package/src/animation/AnimationClip.js +0 -139
  126. package/src/animation/KeyframeTrack.js +2 -2
  127. package/src/animation/PropertyBinding.js +2 -2
  128. package/src/cameras/Camera.js +2 -2
  129. package/src/cameras/StereoCamera.js +5 -2
  130. package/src/constants.js +1 -1
  131. package/src/core/BufferGeometry.js +29 -7
  132. package/src/core/Object3D.js +17 -7
  133. package/src/core/Raycaster.js +1 -1
  134. package/src/core/RenderTarget.js +15 -2
  135. package/src/extras/PMREMGenerator.js +6 -4
  136. package/src/extras/TextureUtils.js +1 -1
  137. package/src/extras/core/ShapePath.js +149 -160
  138. package/src/geometries/SphereGeometry.js +8 -3
  139. package/src/helpers/DirectionalLightHelper.js +2 -0
  140. package/src/helpers/HemisphereLightHelper.js +2 -0
  141. package/src/helpers/PointLightHelper.js +2 -0
  142. package/src/helpers/SpotLightHelper.js +1 -1
  143. package/src/loaders/DataTextureLoader.js +69 -38
  144. package/src/loaders/LoadingManager.js +5 -0
  145. package/src/loaders/MaterialLoader.js +36 -266
  146. package/src/loaders/ObjectLoader.js +3 -1
  147. package/src/materials/LineBasicMaterial.js +4 -0
  148. package/src/materials/Material.js +196 -1
  149. package/src/materials/MeshBasicMaterial.js +24 -0
  150. package/src/materials/MeshDepthMaterial.js +10 -0
  151. package/src/materials/MeshDistanceMaterial.js +10 -0
  152. package/src/materials/MeshLambertMaterial.js +40 -1
  153. package/src/materials/MeshMatcapMaterial.js +25 -1
  154. package/src/materials/MeshNormalMaterial.js +9 -1
  155. package/src/materials/MeshPhongMaterial.js +40 -1
  156. package/src/materials/MeshPhysicalMaterial.js +38 -0
  157. package/src/materials/MeshStandardMaterial.js +42 -1
  158. package/src/materials/MeshToonMaterial.js +34 -1
  159. package/src/materials/PointsMaterial.js +7 -0
  160. package/src/materials/ShaderMaterial.js +86 -0
  161. package/src/materials/SpriteMaterial.js +7 -0
  162. package/src/materials/nodes/Line2NodeMaterial.js +378 -322
  163. package/src/materials/nodes/MeshBasicNodeMaterial.js +2 -2
  164. package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
  165. package/src/materials/nodes/MeshPhongNodeMaterial.js +0 -9
  166. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +0 -30
  167. package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
  168. package/src/materials/nodes/MeshStandardNodeMaterial.js +0 -11
  169. package/src/materials/nodes/NodeMaterial.js +115 -71
  170. package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
  171. package/src/materials/nodes/manager/NodeMaterialObserver.js +49 -20
  172. package/src/math/Box3.js +5 -0
  173. package/src/math/FrustumArray.js +103 -133
  174. package/src/math/Interpolant.js +1 -1
  175. package/src/math/MathUtils.js +2 -2
  176. package/src/math/Matrix3.js +11 -0
  177. package/src/math/Matrix4.js +28 -3
  178. package/src/math/Vector2.js +2 -2
  179. package/src/math/Vector3.js +2 -2
  180. package/src/math/Vector4.js +2 -2
  181. package/src/math/interpolants/BezierInterpolant.js +4 -6
  182. package/src/nodes/Nodes.js +2 -5
  183. package/src/nodes/TSL.js +8 -6
  184. package/src/nodes/accessors/Arrays.js +4 -4
  185. package/src/nodes/accessors/Batch.js +108 -0
  186. package/src/nodes/accessors/Bitangent.js +2 -2
  187. package/src/nodes/accessors/BufferAttributeNode.js +13 -2
  188. package/src/nodes/accessors/Camera.js +7 -7
  189. package/src/nodes/accessors/ClippingNode.js +1 -1
  190. package/src/nodes/accessors/Instance.js +264 -0
  191. package/src/nodes/accessors/MaterialNode.js +18 -2
  192. package/src/nodes/accessors/MaterialProperties.js +4 -3
  193. package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
  194. package/src/nodes/accessors/Normal.js +13 -13
  195. package/src/nodes/accessors/Position.js +5 -1
  196. package/src/nodes/accessors/ReferenceNode.js +1 -0
  197. package/src/nodes/accessors/ReflectVector.js +3 -3
  198. package/src/nodes/accessors/SceneProperties.js +1 -1
  199. package/src/nodes/accessors/Skinning.js +263 -0
  200. package/src/nodes/accessors/StorageBufferNode.js +2 -2
  201. package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
  202. package/src/nodes/accessors/StorageTextureNode.js +39 -7
  203. package/src/nodes/accessors/Tangent.js +4 -4
  204. package/src/nodes/accessors/TextureNode.js +60 -5
  205. package/src/nodes/code/FunctionNode.js +2 -16
  206. package/src/nodes/core/MRTNode.js +7 -2
  207. package/src/nodes/core/Node.js +39 -2
  208. package/src/nodes/core/NodeBuilder.js +201 -41
  209. package/src/nodes/core/NodeUtils.js +13 -13
  210. package/src/nodes/core/OutputStructNode.js +1 -1
  211. package/src/nodes/core/OverrideContextNode.js +153 -0
  212. package/src/nodes/core/PropertyNode.js +51 -5
  213. package/src/nodes/core/StackNode.js +56 -34
  214. package/src/nodes/core/StructNode.js +4 -6
  215. package/src/nodes/core/StructTypeNode.js +6 -6
  216. package/src/nodes/core/VarNode.js +8 -0
  217. package/src/nodes/core/VaryingNode.js +12 -2
  218. package/src/nodes/display/BlendModes.js +1 -41
  219. package/src/nodes/display/BumpMapNode.js +6 -1
  220. package/src/nodes/display/ColorAdjustment.js +10 -9
  221. package/src/nodes/display/FrontFacingNode.js +38 -9
  222. package/src/nodes/display/NormalMapNode.js +2 -2
  223. package/src/nodes/display/PassNode.js +35 -43
  224. package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
  225. package/src/nodes/display/RenderOutputNode.js +12 -3
  226. package/src/nodes/functions/VolumetricLightingModel.js +40 -7
  227. package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
  228. package/src/nodes/lighting/EnvironmentNode.js +2 -2
  229. package/src/nodes/lighting/IESSpotLightNode.js +40 -2
  230. package/src/nodes/lighting/LightingContextNode.js +10 -2
  231. package/src/nodes/lighting/LightsNode.js +90 -37
  232. package/src/nodes/lighting/PointShadowNode.js +6 -1
  233. package/src/nodes/lighting/ShadowFilterNode.js +21 -52
  234. package/src/nodes/lighting/ShadowNode.js +34 -14
  235. package/src/nodes/materialx/lib/mx_noise.js +2 -2
  236. package/src/nodes/math/ConditionalNode.js +3 -3
  237. package/src/nodes/math/MathNode.js +39 -11
  238. package/src/nodes/math/OperatorNode.js +23 -23
  239. package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
  240. package/src/nodes/pmrem/PMREMNode.js +33 -2
  241. package/src/nodes/tsl/TSLCore.js +63 -18
  242. package/src/nodes/utils/EquirectUV.js +30 -5
  243. package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
  244. package/src/nodes/utils/Packing.js +35 -4
  245. package/src/nodes/utils/RTTNode.js +40 -24
  246. package/src/nodes/utils/ReflectorNode.js +1 -0
  247. package/src/nodes/utils/StorageArrayElementNode.js +1 -1
  248. package/src/objects/BatchedMesh.js +22 -14
  249. package/src/objects/InstancedMesh.js +0 -11
  250. package/src/objects/Skeleton.js +0 -9
  251. package/src/renderers/WebGLRenderer.js +19 -15
  252. package/src/renderers/common/Backend.js +49 -5
  253. package/src/renderers/common/Bindings.js +114 -45
  254. package/src/renderers/common/Buffer.js +9 -0
  255. package/src/renderers/common/ClippingContext.js +10 -2
  256. package/src/renderers/common/Info.js +63 -22
  257. package/src/renderers/common/Lighting.js +53 -5
  258. package/src/renderers/common/RenderList.js +41 -4
  259. package/src/renderers/common/RenderObject.js +73 -13
  260. package/src/renderers/common/Renderer.js +281 -108
  261. package/src/renderers/common/Sampler.js +16 -48
  262. package/src/renderers/common/Textures.js +32 -5
  263. package/src/renderers/common/TimestampQueryPool.js +1 -1
  264. package/src/renderers/common/UniformsGroup.js +31 -9
  265. package/src/renderers/common/XRManager.js +340 -22
  266. package/src/renderers/common/extras/PMREMGenerator.js +15 -38
  267. package/src/renderers/common/nodes/NodeBuilderState.js +9 -1
  268. package/src/renderers/common/nodes/NodeLibrary.js +4 -4
  269. package/src/renderers/common/nodes/NodeManager.js +63 -14
  270. package/src/renderers/common/nodes/NodeUniformBuffer.js +13 -0
  271. package/src/renderers/shaders/ShaderChunk/common.glsl.js +13 -4
  272. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +0 -6
  273. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
  274. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
  275. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +1 -1
  276. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
  277. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +1 -1
  278. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
  279. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
  280. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +1 -1
  281. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  282. package/src/renderers/shaders/ShaderLib/distance.glsl.js +1 -1
  283. package/src/renderers/webgl/WebGLOutput.js +2 -1
  284. package/src/renderers/webgl/WebGLProgram.js +5 -4
  285. package/src/renderers/webgl/WebGLPrograms.js +12 -5
  286. package/src/renderers/webgl/WebGLRenderLists.js +9 -1
  287. package/src/renderers/webgl/WebGLShaderCache.js +5 -11
  288. package/src/renderers/webgl/WebGLTextures.js +20 -7
  289. package/src/renderers/webgl/WebGLUniformsGroups.js +66 -38
  290. package/src/renderers/webgl-fallback/WebGLBackend.js +84 -25
  291. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +138 -8
  292. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
  293. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -22
  294. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +4 -2
  295. package/src/renderers/webgpu/WebGPUBackend.js +480 -169
  296. package/src/renderers/webgpu/descriptors/GPUBindGroupDescriptor.js +48 -0
  297. package/src/renderers/webgpu/descriptors/GPUBufferDescriptor.js +57 -0
  298. package/src/renderers/webgpu/descriptors/GPUCommandEncoderDescriptor.js +30 -0
  299. package/src/renderers/webgpu/descriptors/GPUComputePassDescriptor.js +38 -0
  300. package/src/renderers/webgpu/descriptors/GPUComputePipelineDescriptor.js +48 -0
  301. package/src/renderers/webgpu/descriptors/GPUCopyExternalImageDestInfo.js +47 -0
  302. package/src/renderers/webgpu/descriptors/GPUCopyExternalImageSourceInfo.js +50 -0
  303. package/src/renderers/webgpu/descriptors/GPUExtent3D.js +51 -0
  304. package/src/renderers/webgpu/descriptors/GPUPipelineLayoutDescriptor.js +39 -0
  305. package/src/renderers/webgpu/descriptors/GPUQuerySetDescriptor.js +47 -0
  306. package/src/renderers/webgpu/descriptors/GPURenderBundleEncoderDescriptor.js +74 -0
  307. package/src/renderers/webgpu/descriptors/GPURenderPassColorAttachment.js +72 -0
  308. package/src/renderers/webgpu/descriptors/GPURenderPassDepthStencilAttachment.js +99 -0
  309. package/src/renderers/webgpu/descriptors/GPURenderPassDescriptor.js +72 -0
  310. package/src/renderers/webgpu/descriptors/GPURenderPassTimestampWrites.js +49 -0
  311. package/src/renderers/webgpu/descriptors/GPURenderPipelineDescriptor.js +130 -0
  312. package/src/renderers/webgpu/descriptors/GPUSamplerDescriptor.js +119 -0
  313. package/src/renderers/webgpu/descriptors/GPUShaderModuleDescriptor.js +46 -0
  314. package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferInfo.js +57 -0
  315. package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferLayout.js +48 -0
  316. package/src/renderers/webgpu/descriptors/GPUTexelCopyTextureInfo.js +61 -0
  317. package/src/renderers/webgpu/descriptors/GPUTextureDescriptor.js +99 -0
  318. package/src/renderers/webgpu/descriptors/GPUTextureViewDescriptor.js +108 -0
  319. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -1
  320. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +164 -7
  321. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
  322. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +98 -38
  323. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -68
  324. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +164 -69
  325. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +158 -95
  326. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +297 -141
  327. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +33 -18
  328. package/src/renderers/webgpu/utils/WebGPUUtils.js +38 -3
  329. package/src/textures/DepthTexture.js +1 -1
  330. package/src/textures/ExternalTexture.js +0 -3
  331. package/examples/fonts/LICENSE +0 -13
  332. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  333. package/examples/fonts/MPLUSRounded1c/OFL.txt +0 -91
  334. package/examples/fonts/README.md +0 -11
  335. package/examples/fonts/droid/NOTICE +0 -190
  336. package/examples/fonts/droid/README.txt +0 -18
  337. package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
  338. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
  339. package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
  340. package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
  341. package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
  342. package/examples/fonts/gentilis_bold.typeface.json +0 -1
  343. package/examples/fonts/gentilis_regular.typeface.json +0 -1
  344. package/examples/fonts/helvetiker_bold.typeface.json +0 -1
  345. package/examples/fonts/helvetiker_regular.typeface.json +0 -1
  346. package/examples/fonts/optimer_bold.typeface.json +0 -1
  347. package/examples/fonts/optimer_regular.typeface.json +0 -1
  348. package/examples/fonts/ttf/README.md +0 -9
  349. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  350. package/examples/jsm/inspector/extensions/extensions.json +0 -6
  351. package/examples/jsm/libs/ammo.wasm.js +0 -822
  352. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  353. package/examples/jsm/libs/draco/draco_encoder.js +0 -33
  354. package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
  355. package/examples/jsm/libs/lottie_canvas.module.js +0 -14849
  356. package/examples/jsm/libs/opentype.module.js +0 -14506
  357. package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
  358. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
  359. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  360. package/examples/jsm/lighting/TiledLighting.js +0 -42
  361. package/examples/jsm/tsl/display/AnamorphicNode.js +0 -293
  362. package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
  363. package/src/nodes/accessors/BatchNode.js +0 -163
  364. package/src/nodes/accessors/InstanceNode.js +0 -349
  365. package/src/nodes/accessors/InstancedMeshNode.js +0 -50
  366. package/src/nodes/accessors/SkinningNode.js +0 -328
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Reusable descriptor for `GPUTexture.createView()`.
3
+ *
4
+ * @private
5
+ */
6
+ class GPUTextureViewDescriptor {
7
+
8
+ constructor() {
9
+
10
+ /**
11
+ * The label of the texture view.
12
+ *
13
+ * @type {string}
14
+ */
15
+ this.label = '';
16
+
17
+ /**
18
+ * The format of the texture view.
19
+ *
20
+ * @type {string|undefined}
21
+ */
22
+ this.format = undefined;
23
+
24
+ /**
25
+ * The dimension of the texture view.
26
+ *
27
+ * @type {string|undefined}
28
+ */
29
+ this.dimension = undefined;
30
+
31
+ /**
32
+ * The allowed usages for the texture view.
33
+ *
34
+ * @type {number}
35
+ * @default 0
36
+ */
37
+ this.usage = 0;
38
+
39
+ /**
40
+ * Which aspect of the texture is referenced.
41
+ *
42
+ * @type {string}
43
+ * @default 'all'
44
+ */
45
+ this.aspect = 'all';
46
+
47
+ /**
48
+ * The first mip level accessible to the texture view.
49
+ *
50
+ * @type {number}
51
+ * @default 0
52
+ */
53
+ this.baseMipLevel = 0;
54
+
55
+ /**
56
+ * The number of mip levels accessible to the texture view.
57
+ *
58
+ * @type {number|undefined}
59
+ */
60
+ this.mipLevelCount = undefined;
61
+
62
+ /**
63
+ * The first array layer accessible to the texture view.
64
+ *
65
+ * @type {number}
66
+ * @default 0
67
+ */
68
+ this.baseArrayLayer = 0;
69
+
70
+ /**
71
+ * The number of array layers accessible to the texture view.
72
+ *
73
+ * @type {number|undefined}
74
+ */
75
+ this.arrayLayerCount = undefined;
76
+
77
+ /**
78
+ * The component swizzle to apply when sampling the texture view.
79
+ * Requires the `'texture-component-swizzle'` feature; ignored otherwise.
80
+ *
81
+ * @type {string}
82
+ * @default 'rgba'
83
+ */
84
+ this.swizzle = 'rgba';
85
+
86
+ }
87
+
88
+ /**
89
+ * Resets the descriptor to its default state.
90
+ */
91
+ reset() {
92
+
93
+ this.label = '';
94
+ this.format = undefined;
95
+ this.dimension = undefined;
96
+ this.usage = 0;
97
+ this.aspect = 'all';
98
+ this.baseMipLevel = 0;
99
+ this.mipLevelCount = undefined;
100
+ this.baseArrayLayer = 0;
101
+ this.arrayLayerCount = undefined;
102
+ this.swizzle = 'rgba';
103
+
104
+ }
105
+
106
+ }
107
+
108
+ export default GPUTextureViewDescriptor;
@@ -50,7 +50,6 @@ import { linearToneMapping, reinhardToneMapping, cineonToneMapping, acesFilmicTo
50
50
  * used in {@link WebGPURenderer}. It maps lights, tone mapping
51
51
  * techniques and materials to node-based implementations.
52
52
  *
53
- * @private
54
53
  * @augments NodeLibrary
55
54
  */
56
55
  class StandardNodeLibrary extends NodeLibrary {
@@ -91,6 +91,83 @@ const wgslPolyfill = {
91
91
  repeatWrapping_float: new CodeNode( 'fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }' ),
92
92
  mirrorWrapping_float: new CodeNode( 'fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }' ),
93
93
  clampWrapping_float: new CodeNode( 'fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }' ),
94
+ inverse_mat2: new CodeNode( /* wgsl */`
95
+ fn tsl_inverse_mat2( m : mat2x2<f32> ) -> mat2x2<f32> {
96
+
97
+ let det = m[ 0 ][ 0 ] * m[ 1 ][ 1 ] - m[ 0 ][ 1 ] * m[ 1 ][ 0 ];
98
+
99
+ return mat2x2<f32>(
100
+ m[ 1 ][ 1 ], - m[ 0 ][ 1 ],
101
+ - m[ 1 ][ 0 ], m[ 0 ][ 0 ]
102
+ ) * ( 1.0 / det );
103
+
104
+ }
105
+ ` ),
106
+ inverse_mat3: new CodeNode( /* wgsl */`
107
+ fn tsl_inverse_mat3( m : mat3x3<f32> ) -> mat3x3<f32> {
108
+
109
+ let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ];
110
+ let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ];
111
+ let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ];
112
+
113
+ let b01 = a22 * a11 - a12 * a21;
114
+ let b11 = - a22 * a10 + a12 * a20;
115
+ let b21 = a21 * a10 - a11 * a20;
116
+
117
+ let det = a00 * b01 + a01 * b11 + a02 * b21;
118
+
119
+ return mat3x3<f32>(
120
+ b01, ( - a22 * a01 + a02 * a21 ), ( a12 * a01 - a02 * a11 ),
121
+ b11, ( a22 * a00 - a02 * a20 ), ( - a12 * a00 + a02 * a10 ),
122
+ b21, ( - a21 * a00 + a01 * a20 ), ( a11 * a00 - a01 * a10 )
123
+ ) * ( 1.0 / det );
124
+
125
+ }
126
+ ` ),
127
+ inverse_mat4: new CodeNode( /* wgsl */`
128
+ fn tsl_inverse_mat4( m : mat4x4<f32> ) -> mat4x4<f32> {
129
+
130
+ let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; let a03 = m[ 0 ][ 3 ];
131
+ let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; let a13 = m[ 1 ][ 3 ];
132
+ let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; let a23 = m[ 2 ][ 3 ];
133
+ let a30 = m[ 3 ][ 0 ]; let a31 = m[ 3 ][ 1 ]; let a32 = m[ 3 ][ 2 ]; let a33 = m[ 3 ][ 3 ];
134
+
135
+ let b00 = a00 * a11 - a01 * a10;
136
+ let b01 = a00 * a12 - a02 * a10;
137
+ let b02 = a00 * a13 - a03 * a10;
138
+ let b03 = a01 * a12 - a02 * a11;
139
+ let b04 = a01 * a13 - a03 * a11;
140
+ let b05 = a02 * a13 - a03 * a12;
141
+ let b06 = a20 * a31 - a21 * a30;
142
+ let b07 = a20 * a32 - a22 * a30;
143
+ let b08 = a20 * a33 - a23 * a30;
144
+ let b09 = a21 * a32 - a22 * a31;
145
+ let b10 = a21 * a33 - a23 * a31;
146
+ let b11 = a22 * a33 - a23 * a32;
147
+
148
+ let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
149
+
150
+ return mat4x4<f32>(
151
+ a11 * b11 - a12 * b10 + a13 * b09,
152
+ a02 * b10 - a01 * b11 - a03 * b09,
153
+ a31 * b05 - a32 * b04 + a33 * b03,
154
+ a22 * b04 - a21 * b05 - a23 * b03,
155
+ a12 * b08 - a10 * b11 - a13 * b07,
156
+ a00 * b11 - a02 * b08 + a03 * b07,
157
+ a32 * b02 - a30 * b05 - a33 * b01,
158
+ a20 * b05 - a22 * b02 + a23 * b01,
159
+ a10 * b10 - a11 * b08 + a13 * b06,
160
+ a01 * b08 - a00 * b10 - a03 * b06,
161
+ a30 * b04 - a31 * b02 + a33 * b00,
162
+ a21 * b02 - a20 * b04 - a23 * b00,
163
+ a11 * b07 - a10 * b09 - a12 * b06,
164
+ a00 * b09 - a01 * b07 + a02 * b06,
165
+ a31 * b01 - a30 * b03 - a32 * b00,
166
+ a20 * b03 - a21 * b01 + a22 * b00
167
+ ) * ( 1.0 / det );
168
+
169
+ }
170
+ ` ),
94
171
  biquadraticTexture: new CodeNode( /* wgsl */`
95
172
  fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
96
173
 
@@ -150,6 +227,9 @@ const wgslMethods = {
150
227
  equals_bvec2: 'tsl_equals_bvec2',
151
228
  equals_bvec3: 'tsl_equals_bvec3',
152
229
  equals_bvec4: 'tsl_equals_bvec4',
230
+ inverse_mat2: 'tsl_inverse_mat2',
231
+ inverse_mat3: 'tsl_inverse_mat3',
232
+ inverse_mat4: 'tsl_inverse_mat4',
153
233
  inversesqrt: 'inverseSqrt',
154
234
  bitcast: 'bitcast<f32>',
155
235
  floatpack_snorm_2x16: 'pack2x16snorm',
@@ -352,7 +432,7 @@ class WGSLNodeBuilder extends NodeBuilder {
352
432
  */
353
433
  generateWrapFunction( texture ) {
354
434
 
355
- const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }_${ texture.is3DTexture || texture.isData3DTexture ? '3d' : '2d' }T`;
435
+ const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }T_${ texture.is3DTexture || texture.isData3DTexture ? '3d' : '2d' }`;
356
436
 
357
437
  let nodeCode = wgslCodeCache[ functionName ];
358
438
 
@@ -850,6 +930,80 @@ class WGSLNodeBuilder extends NodeBuilder {
850
930
 
851
931
  }
852
932
 
933
+ /**
934
+ * Generates the WGSL snippet for gathering four texels from the given texture.
935
+ *
936
+ * @param {Texture} texture - The texture.
937
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
938
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
939
+ * @param {string} gatherSnippet - A WGSL snippet that represents the index of the channel to read.
940
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
941
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
942
+ * @param {?string} flipYSnippet - A WGSL snippet that represents the y-flip. Only used for WebGL.
943
+ * @return {string} The WGSL snippet.
944
+ */
945
+ generateTextureGather( texture, textureProperty, uvSnippet, gatherSnippet, depthSnippet, offsetSnippet ) {
946
+
947
+ const componentSnippet = texture.isDepthTexture === true ? '' : `${gatherSnippet}, `;
948
+
949
+ if ( depthSnippet ) {
950
+
951
+ if ( offsetSnippet ) {
952
+
953
+ return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
954
+
955
+ }
956
+
957
+ return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
958
+
959
+ }
960
+
961
+ if ( offsetSnippet ) {
962
+
963
+ return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
964
+
965
+ }
966
+
967
+ return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet })`;
968
+
969
+ }
970
+
971
+ /**
972
+ * Generates the WGSL snippet for performing a depth comparison on four texels in the given depth texture.
973
+ *
974
+ * @param {Texture} texture - The texture.
975
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
976
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
977
+ * @param {string} compareSnippet - A WGSL snippet that represents the reference value.
978
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
979
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
980
+ * @param {?string} flipYSnippet - A WGSL snippet that represents the y-flip. Only used for WebGL.
981
+ * @return {string} The WGSL snippet.
982
+ */
983
+ generateTextureGatherCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, offsetSnippet ) {
984
+
985
+ if ( depthSnippet ) {
986
+
987
+ if ( offsetSnippet ) {
988
+
989
+ return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
990
+
991
+ }
992
+
993
+ return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
994
+
995
+ }
996
+
997
+ if ( offsetSnippet ) {
998
+
999
+ return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
1000
+
1001
+ }
1002
+
1003
+ return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet })`;
1004
+
1005
+ }
1006
+
853
1007
  /**
854
1008
  * Generates the WGSL snippet when sampling textures with explicit mip level.
855
1009
  *
@@ -1127,7 +1281,8 @@ class WGSLNodeBuilder extends NodeBuilder {
1127
1281
  texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
1128
1282
 
1129
1283
  // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
1130
- const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false );
1284
+ // Also textureGather always need sampler.
1285
+ const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null;
1131
1286
 
1132
1287
  if ( needsSampler ) {
1133
1288
 
@@ -1908,14 +2063,16 @@ ${ flowData.code }
1908
2063
 
1909
2064
  if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'cubeDepthTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
1910
2065
 
1911
- const texture = uniform.node.value;
2066
+ const textureNode = uniform.node;
2067
+ const texture = textureNode.value;
1912
2068
 
1913
2069
  // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
1914
- const needsSampler = texture.isCubeTexture === true || ( this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true );
2070
+ // Also textureGather always need sampler.
2071
+ const needsSampler = texture.isCubeTexture === true || ( this.isUnfilterable( texture ) === false && textureNode.isStorageTextureNode !== true ) || textureNode.gatherNode !== null;
1915
2072
 
1916
2073
  if ( needsSampler ) {
1917
2074
 
1918
- if ( this.isSampleCompare( texture ) ) {
2075
+ if ( this.isSampleCompare( texture ) && textureNode.compareNode !== null ) {
1919
2076
 
1920
2077
  bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` );
1921
2078
 
@@ -2146,7 +2303,7 @@ ${ flowData.code }
2146
2303
 
2147
2304
  } else {
2148
2305
 
2149
- let structSnippet = '\t@location( 0 ) color: vec4<f32>';
2306
+ let structSnippet = `\t@location( 0 ) color: ${ this.getType( this.getOutputType() ) }`;
2150
2307
 
2151
2308
  const builtins = this.getBuiltins( 'output' );
2152
2309
 
@@ -2156,7 +2313,7 @@ ${ flowData.code }
2156
2313
  stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet );
2157
2314
  stageData.structs += '\nvar<private> output : OutputStruct;';
2158
2315
 
2159
- flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`;
2316
+ flow += `output.color = ${ this.format( flowSlotData.result, mainNode.getNodeType( this ), this.getOutputType() ) };\n\n\treturn output;`;
2160
2317
 
2161
2318
  }
2162
2319
 
@@ -138,7 +138,7 @@ const parse = ( source ) => {
138
138
 
139
139
  } else {
140
140
 
141
- throw new Error( 'FunctionNode: Function is not a WGSL code.' );
141
+ throw new Error( 'THREE.WGSLNodeFunction: Function is not a WGSL code.' );
142
142
 
143
143
  }
144
144
 
@@ -1,8 +1,14 @@
1
1
  import { GPUInputStepMode } from './WebGPUConstants.js';
2
+ import { submit } from './WebGPUUtils.js';
3
+ import GPUBufferDescriptor from '../descriptors/GPUBufferDescriptor.js';
4
+ import GPUCommandEncoderDescriptor from '../descriptors/GPUCommandEncoderDescriptor.js';
2
5
 
3
6
  import { Float16BufferAttribute } from '../../../core/BufferAttribute.js';
4
7
  import { isTypedArray, error } from '../../../utils.js';
5
8
 
9
+ const _bufferDescriptor = new GPUBufferDescriptor();
10
+ const _commandEncoderDescriptor = new GPUCommandEncoderDescriptor();
11
+
6
12
  const typedArraysToVertexFormatPrefix = new Map( [
7
13
  [ Int8Array, [ 'sint8', 'snorm8' ]],
8
14
  [ Uint8Array, [ 'uint8', 'unorm8' ]],
@@ -102,34 +108,66 @@ class WebGPUAttributeUtils {
102
108
 
103
109
  bufferAttribute.array = array;
104
110
 
111
+ let paddedItemSize;
112
+
105
113
  if ( ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) && bufferAttribute.itemSize === 3 ) {
106
114
 
107
- array = new array.constructor( bufferAttribute.count * 4 );
115
+ // WGSL does not support packed vec3 data in storage buffers, pad to vec4
116
+
117
+ paddedItemSize = 4;
118
+
119
+ } else if ( bufferAttribute.itemSize > 1 && ( bufferAttribute.itemSize * array.BYTES_PER_ELEMENT ) % 4 !== 0 ) {
120
+
121
+ // arrayStride must be a multiple of 4
122
+
123
+ const byteStride = bufferAttribute.itemSize * array.BYTES_PER_ELEMENT;
124
+
125
+ paddedItemSize = ( Math.floor( ( byteStride + 3 ) / 4 ) * 4 ) / array.BYTES_PER_ELEMENT;
126
+
127
+ }
128
+
129
+ if ( paddedItemSize !== undefined ) {
130
+
131
+ const itemSize = bufferAttribute.itemSize;
132
+
133
+ const paddedArray = new array.constructor( bufferAttribute.count * paddedItemSize );
108
134
 
109
135
  for ( let i = 0; i < bufferAttribute.count; i ++ ) {
110
136
 
111
- array.set( bufferAttribute.array.subarray( i * 3, i * 3 + 3 ), i * 4 );
137
+ paddedArray.set( array.subarray( i * itemSize, i * itemSize + itemSize ), i * paddedItemSize );
112
138
 
113
139
  }
114
140
 
115
- // Update BufferAttribute
116
- bufferAttribute.itemSize = 4;
117
- bufferAttribute.array = array;
141
+ if ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) {
142
+
143
+ // update the storage attribute so storage bindings access the padded layout
144
+
145
+ bufferAttribute.itemSize = paddedItemSize;
146
+ bufferAttribute.array = paddedArray;
118
147
 
119
- bufferData._force3to4BytesAlignment = true;
148
+ }
149
+
150
+ array = paddedArray;
151
+
152
+ // save the original and padded item size so buffer updates can apply the same padding
153
+
154
+ bufferData._itemSize = itemSize;
155
+ bufferData._paddedItemSize = paddedItemSize;
120
156
 
121
157
  }
122
158
 
123
- // ensure 4 byte alignment
159
+ // total buffer size must be a multiple of 4
124
160
  const byteLength = array.byteLength;
125
161
  const size = byteLength + ( ( 4 - ( byteLength % 4 ) ) % 4 );
126
162
 
127
- buffer = device.createBuffer( {
128
- label: bufferAttribute.name,
129
- size: size,
130
- usage: usage,
131
- mappedAtCreation: true
132
- } );
163
+ _bufferDescriptor.label = bufferAttribute.name;
164
+ _bufferDescriptor.size = size;
165
+ _bufferDescriptor.usage = usage;
166
+ _bufferDescriptor.mappedAtCreation = true;
167
+
168
+ buffer = device.createBuffer( _bufferDescriptor );
169
+
170
+ _bufferDescriptor.reset();
133
171
 
134
172
  new array.constructor( buffer.getMappedRange() ).set( array );
135
173
 
@@ -158,18 +196,28 @@ class WebGPUAttributeUtils {
158
196
 
159
197
  let array = bufferAttribute.array;
160
198
 
161
- // if storage buffer ensure 4 byte alignment
162
- if ( bufferData._force3to4BytesAlignment === true ) {
199
+ const itemSize = bufferData._itemSize;
200
+ const paddedItemSize = bufferData._paddedItemSize;
201
+
202
+ if ( paddedItemSize !== undefined ) {
163
203
 
164
- array = new array.constructor( bufferAttribute.count * 4 );
204
+ // if the attribute data were padded on upload, apply the same padding on updates.
205
+
206
+ array = new array.constructor( bufferAttribute.count * paddedItemSize );
165
207
 
166
208
  for ( let i = 0; i < bufferAttribute.count; i ++ ) {
167
209
 
168
- array.set( bufferAttribute.array.subarray( i * 3, i * 3 + 3 ), i * 4 );
210
+ array.set( bufferAttribute.array.subarray( i * itemSize, i * itemSize + itemSize ), i * paddedItemSize );
169
211
 
170
212
  }
171
213
 
172
- bufferAttribute.array = array;
214
+ if ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) {
215
+
216
+ // keep the storage attribute in sync with the padded layout
217
+
218
+ bufferAttribute.array = array;
219
+
220
+ }
173
221
 
174
222
  }
175
223
 
@@ -197,12 +245,12 @@ class WebGPUAttributeUtils {
197
245
  const range = updateRanges[ i ];
198
246
  let dataOffset, size;
199
247
 
200
- if ( bufferData._force3to4BytesAlignment === true ) {
248
+ if ( paddedItemSize !== undefined ) {
201
249
 
202
- const vertexStart = Math.floor( range.start / 3 );
203
- const vertexCount = Math.ceil( range.count / 3 );
204
- dataOffset = vertexStart * 4 * byteOffsetFactor;
205
- size = vertexCount * 4 * byteOffsetFactor;
250
+ const vertexStart = Math.floor( range.start / itemSize );
251
+ const vertexCount = Math.ceil( ( range.start + range.count ) / itemSize ) - vertexStart;
252
+ dataOffset = vertexStart * paddedItemSize * byteOffsetFactor;
253
+ size = vertexCount * paddedItemSize * byteOffsetFactor;
206
254
 
207
255
  } else {
208
256
 
@@ -263,6 +311,14 @@ class WebGPUAttributeUtils {
263
311
  arrayStride = geometryAttribute.itemSize * bytesPerElement;
264
312
  stepMode = geometryAttribute.isInstancedBufferAttribute ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex;
265
313
 
314
+ if ( geometryAttribute.itemSize > 1 && arrayStride % 4 !== 0 ) {
315
+
316
+ // packed attribute data are padded per vertex on upload
317
+
318
+ arrayStride = Math.floor( ( arrayStride + 3 ) / 4 ) * 4;
319
+
320
+ }
321
+
266
322
  }
267
323
 
268
324
  // patch for INT16 and UINT16
@@ -342,7 +398,7 @@ class WebGPUAttributeUtils {
342
398
 
343
399
  if ( target._mapped === true ) {
344
400
 
345
- throw new Error( 'WebGPURenderer: ReadbackBuffer must be released before being used again.' );
401
+ throw new Error( 'THREE.WebGPUAttributeUtils: ReadbackBuffer must be released before being used again.' );
346
402
 
347
403
  }
348
404
 
@@ -351,11 +407,13 @@ class WebGPUAttributeUtils {
351
407
  // initialize the GPU-side read copy buffer if it is not present
352
408
  if ( readbackInfo.readBufferGPU === undefined ) {
353
409
 
354
- readBufferGPU = device.createBuffer( {
355
- label: `${ target.name }_readback`,
356
- size: target.maxByteLength,
357
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
358
- } );
410
+ _bufferDescriptor.label = `${ target.name }_readback`;
411
+ _bufferDescriptor.size = target.maxByteLength;
412
+ _bufferDescriptor.usage = GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ;
413
+
414
+ readBufferGPU = device.createBuffer( _bufferDescriptor );
415
+
416
+ _bufferDescriptor.reset();
359
417
 
360
418
  // release / dispose
361
419
  const releaseCallback = () => {
@@ -396,18 +454,20 @@ class WebGPUAttributeUtils {
396
454
  } else {
397
455
 
398
456
  // create a new temp buffer for array buffers otherwise
399
- readBufferGPU = device.createBuffer( {
400
- label: `${ attribute.name }_readback`,
401
- size: byteLength,
402
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
403
- } );
457
+ _bufferDescriptor.label = `${ attribute.name }_readback`;
458
+ _bufferDescriptor.size = byteLength;
459
+ _bufferDescriptor.usage = GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ;
460
+
461
+ readBufferGPU = device.createBuffer( _bufferDescriptor );
462
+
463
+ _bufferDescriptor.reset();
404
464
 
405
465
  }
406
466
 
407
467
  // copy the data
408
- const cmdEncoder = device.createCommandEncoder( {
409
- label: `readback_encoder_${ attribute.name }`
410
- } );
468
+ _commandEncoderDescriptor.label = `readback_encoder_${ attribute.name }`;
469
+ const cmdEncoder = device.createCommandEncoder( _commandEncoderDescriptor );
470
+ _commandEncoderDescriptor.reset();
411
471
 
412
472
  cmdEncoder.copyBufferToBuffer(
413
473
  bufferGPU,
@@ -418,7 +478,7 @@ class WebGPUAttributeUtils {
418
478
  );
419
479
 
420
480
  const gpuCommands = cmdEncoder.finish();
421
- device.queue.submit( [ gpuCommands ] );
481
+ submit( device, gpuCommands );
422
482
 
423
483
  // map the data to the CPU
424
484
  await readBufferGPU.mapAsync( GPUMapMode.READ, 0, byteLength );