super-three 0.172.0 → 0.173.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 (180) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +439 -380
  3. package/build/three.core.js +413 -41
  4. package/build/three.core.min.js +2 -2
  5. package/build/three.module.js +28 -344
  6. package/build/three.module.min.js +2 -2
  7. package/build/three.tsl.js +11 -3
  8. package/build/three.tsl.min.js +2 -2
  9. package/build/three.webgpu.js +7550 -1798
  10. package/build/three.webgpu.min.js +2 -2
  11. package/build/three.webgpu.nodes.js +7551 -1798
  12. package/build/three.webgpu.nodes.min.js +2 -2
  13. package/examples/jsm/animation/CCDIKSolver.js +6 -5
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +23 -21
  16. package/examples/jsm/exporters/GLTFExporter.js +26 -25
  17. package/examples/jsm/geometries/TextGeometry.js +1 -12
  18. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  19. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  20. package/examples/jsm/loaders/GCodeLoader.js +3 -1
  21. package/examples/jsm/loaders/GLTFLoader.js +0 -2
  22. package/examples/jsm/loaders/TDSLoader.js +0 -1
  23. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  24. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  25. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  26. package/examples/jsm/misc/ProgressiveLightMapGPU.js +4 -3
  27. package/examples/jsm/misc/Volume.js +7 -5
  28. package/examples/jsm/misc/VolumeSlice.js +5 -3
  29. package/examples/jsm/objects/WaterMesh.js +25 -20
  30. package/examples/jsm/physics/JoltPhysics.js +7 -7
  31. package/examples/jsm/physics/RapierPhysics.js +4 -4
  32. package/examples/jsm/postprocessing/EffectComposer.js +23 -2
  33. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  34. package/examples/jsm/postprocessing/Pass.js +6 -1
  35. package/examples/jsm/shaders/OutputShader.js +5 -1
  36. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  37. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  38. package/package.json +1 -1
  39. package/src/Three.Core.js +2 -0
  40. package/src/Three.TSL.js +9 -1
  41. package/src/cameras/ArrayCamera.js +1 -0
  42. package/src/constants.js +6 -1
  43. package/src/core/BufferAttribute.js +4 -0
  44. package/src/core/EventDispatcher.js +8 -6
  45. package/src/extras/ImageUtils.js +1 -11
  46. package/src/loaders/nodes/NodeObjectLoader.js +1 -1
  47. package/src/materials/nodes/MeshBasicNodeMaterial.js +1 -1
  48. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +1 -1
  49. package/src/materials/nodes/NodeMaterial.js +5 -5
  50. package/src/materials/nodes/NodeMaterials.js +0 -1
  51. package/src/materials/nodes/PointsNodeMaterial.js +109 -7
  52. package/src/materials/nodes/SpriteNodeMaterial.js +1 -1
  53. package/src/materials/nodes/VolumeNodeMaterial.js +3 -3
  54. package/src/materials/nodes/manager/NodeMaterialObserver.js +8 -0
  55. package/src/nodes/Nodes.js +4 -0
  56. package/src/nodes/TSL.js +4 -0
  57. package/src/nodes/accessors/Arrays.js +30 -8
  58. package/src/nodes/accessors/BatchNode.js +3 -3
  59. package/src/nodes/accessors/BufferAttributeNode.js +1 -1
  60. package/src/nodes/accessors/Camera.js +64 -3
  61. package/src/nodes/accessors/InstanceNode.js +1 -1
  62. package/src/nodes/accessors/MaterialNode.js +9 -9
  63. package/src/nodes/accessors/ModelViewProjectionNode.js +1 -1
  64. package/src/nodes/accessors/Normal.js +6 -2
  65. package/src/nodes/accessors/Object3DNode.js +0 -1
  66. package/src/nodes/accessors/Position.js +6 -6
  67. package/src/nodes/accessors/ReferenceBaseNode.js +2 -4
  68. package/src/nodes/accessors/ReferenceNode.js +2 -3
  69. package/src/nodes/accessors/StorageBufferNode.js +42 -5
  70. package/src/nodes/accessors/Tangent.js +2 -2
  71. package/src/nodes/accessors/Texture3DNode.js +1 -1
  72. package/src/nodes/accessors/TextureNode.js +12 -5
  73. package/src/nodes/accessors/UniformArrayNode.js +9 -3
  74. package/src/nodes/accessors/VelocityNode.js +0 -2
  75. package/src/nodes/code/ScriptableNode.js +3 -3
  76. package/src/nodes/core/ArrayNode.js +125 -0
  77. package/src/nodes/core/ConstNode.js +8 -0
  78. package/src/nodes/core/Node.js +14 -1
  79. package/src/nodes/core/NodeBuilder.js +229 -19
  80. package/src/nodes/core/NodeUtils.js +11 -1
  81. package/src/nodes/core/NodeVar.js +17 -1
  82. package/src/nodes/core/OutputStructNode.js +19 -9
  83. package/src/nodes/core/StackNode.js +20 -1
  84. package/src/nodes/core/StructNode.js +121 -0
  85. package/src/nodes/core/StructType.js +13 -0
  86. package/src/nodes/core/StructTypeNode.js +82 -21
  87. package/src/nodes/core/TempNode.js +1 -1
  88. package/src/nodes/core/VarNode.js +94 -7
  89. package/src/nodes/core/VaryingNode.js +19 -3
  90. package/src/nodes/display/BlendModes.js +88 -1
  91. package/src/nodes/display/BumpMapNode.js +6 -6
  92. package/src/nodes/display/NormalMapNode.js +6 -6
  93. package/src/nodes/display/PassNode.js +3 -1
  94. package/src/nodes/display/ScreenNode.js +9 -0
  95. package/src/nodes/fog/Fog.js +17 -0
  96. package/src/nodes/gpgpu/AtomicFunctionNode.js +20 -4
  97. package/src/nodes/gpgpu/ComputeBuiltinNode.js +8 -0
  98. package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
  99. package/src/nodes/lighting/ShadowNode.js +1 -1
  100. package/src/nodes/math/ConditionalNode.js +8 -1
  101. package/src/nodes/math/MathNode.js +14 -1
  102. package/src/nodes/math/OperatorNode.js +96 -18
  103. package/src/nodes/pmrem/PMREMUtils.js +1 -1
  104. package/src/nodes/shapes/Shapes.js +33 -0
  105. package/src/nodes/tsl/TSLBase.js +1 -0
  106. package/src/nodes/tsl/TSLCore.js +22 -2
  107. package/src/nodes/utils/ArrayElementNode.js +1 -1
  108. package/src/nodes/utils/LoopNode.js +8 -1
  109. package/src/nodes/utils/MemberNode.js +68 -0
  110. package/src/nodes/utils/StorageArrayElementNode.js +14 -0
  111. package/src/nodes/utils/Timer.js +21 -0
  112. package/src/objects/BatchedMesh.js +1 -1
  113. package/src/objects/Line.js +6 -6
  114. package/src/renderers/WebGLRenderer.js +7 -0
  115. package/src/renderers/common/Animation.js +23 -1
  116. package/src/renderers/common/Backend.js +58 -15
  117. package/src/renderers/common/Background.js +14 -0
  118. package/src/renderers/common/Binding.js +1 -1
  119. package/src/renderers/common/BufferUtils.js +1 -1
  120. package/src/renderers/common/BundleGroup.js +1 -1
  121. package/src/renderers/common/ChainMap.js +9 -7
  122. package/src/renderers/common/ClippingContext.js +1 -1
  123. package/src/renderers/common/Color4.js +7 -3
  124. package/src/renderers/common/Geometries.js +2 -23
  125. package/src/renderers/common/Info.js +1 -45
  126. package/src/renderers/common/Lighting.js +8 -6
  127. package/src/renderers/common/Pipelines.js +3 -3
  128. package/src/renderers/common/PostProcessing.js +24 -8
  129. package/src/renderers/common/QuadMesh.js +1 -1
  130. package/src/renderers/common/RenderBundles.js +9 -3
  131. package/src/renderers/common/RenderContext.js +37 -3
  132. package/src/renderers/common/RenderContexts.js +30 -17
  133. package/src/renderers/common/RenderList.js +2 -2
  134. package/src/renderers/common/RenderLists.js +9 -3
  135. package/src/renderers/common/RenderObject.js +76 -17
  136. package/src/renderers/common/RenderObjects.js +9 -7
  137. package/src/renderers/common/Renderer.js +86 -67
  138. package/src/renderers/common/SampledTexture.js +0 -1
  139. package/src/renderers/common/StorageBufferAttribute.js +1 -1
  140. package/src/renderers/common/StorageInstancedBufferAttribute.js +1 -1
  141. package/src/renderers/common/StorageTexture.js +1 -1
  142. package/src/renderers/common/Textures.js +14 -7
  143. package/src/renderers/common/TimestampQueryPool.js +39 -0
  144. package/src/renderers/common/Uniform.js +37 -1
  145. package/src/renderers/common/UniformsGroup.js +2 -0
  146. package/src/renderers/common/XRManager.js +1193 -0
  147. package/src/renderers/common/XRRenderTarget.js +74 -0
  148. package/src/renderers/common/extras/PMREMGenerator.js +53 -8
  149. package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
  150. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  151. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -1
  152. package/src/renderers/common/nodes/NodeUniform.js +54 -2
  153. package/src/renderers/common/nodes/Nodes.js +25 -18
  154. package/src/renderers/webgl/WebGLBackground.js +4 -0
  155. package/src/renderers/webgl-fallback/WebGLBackend.js +295 -110
  156. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -17
  157. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +57 -0
  158. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  159. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  160. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  161. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +167 -21
  162. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  163. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  164. package/src/renderers/webgpu/WebGPUBackend.js +132 -149
  165. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +6 -4
  166. package/src/renderers/webgpu/WebGPURenderer.js +5 -4
  167. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +615 -41
  168. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +85 -6
  169. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +85 -0
  170. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  171. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  172. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +257 -9
  173. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  174. package/src/renderers/webgpu/utils/WebGPUUtils.js +86 -4
  175. package/src/renderers/webxr/WebXRManager.js +13 -2
  176. package/src/textures/VideoFrameTexture.js +35 -0
  177. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  178. package/examples/jsm/objects/InstancedPoints.js +0 -19
  179. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -209
  180. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -37
@@ -468,7 +468,7 @@ class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
468
468
  /**
469
469
  * Setups the clearcoat normal node.
470
470
  *
471
- * @return {Node<vec3>} The clearcoat noraml.
471
+ * @return {Node<vec3>} The clearcoat normal.
472
472
  */
473
473
  setupClearcoatNormal() {
474
474
 
@@ -198,7 +198,7 @@ class NodeMaterial extends Material {
198
198
  * material.transparent = true;
199
199
  *
200
200
  * // everything behind the object will be monochromatic
201
- * material.backdropNode = viewportSharedTexture().rgb.saturation( 0 );
201
+ * material.backdropNode = saturation( viewportSharedTexture().rgb, 0 );
202
202
  * ```
203
203
  *
204
204
  * Backdrop computations are part of the lighting so only lit materials can use this property.
@@ -249,7 +249,7 @@ class NodeMaterial extends Material {
249
249
  /**
250
250
  * This node property is intended for logic which modifies geometry data once or per animation step.
251
251
  * Apps usually place such logic randomly in initialization routines or in the animation loop.
252
- * `geometryNode` is intended as a dedicated API so there is an intended spot where goemetry modiciations
252
+ * `geometryNode` is intended as a dedicated API so there is an intended spot where geometry modifications
253
253
  * can be implemented.
254
254
  *
255
255
  * The idea is to assign a `Fn` definition that holds the geometry modification logic. A typical example
@@ -521,9 +521,9 @@ class NodeMaterial extends Material {
521
521
 
522
522
  builder.addFlow( 'fragment', builder.removeStack() );
523
523
 
524
- // < MONITOR >
524
+ // < OBSERVER >
525
525
 
526
- builder.monitor = this.setupObserver( builder );
526
+ builder.observer = this.setupObserver( builder );
527
527
 
528
528
  }
529
529
 
@@ -636,7 +636,7 @@ class NodeMaterial extends Material {
636
636
 
637
637
  /**
638
638
  * Setups the position node in view space. This method exists
639
- * so derived node materials can modifiy the implementation e.g. sprite materials.
639
+ * so derived node materials can modify the implementation e.g. sprite materials.
640
640
  *
641
641
  * @param {NodeBuilder} builder - The current node builder.
642
642
  * @return {Node<vec3>} The position in view space.
@@ -3,7 +3,6 @@
3
3
  export { default as NodeMaterialObserver } from './manager/NodeMaterialObserver.js';
4
4
 
5
5
  export { default as NodeMaterial } from './NodeMaterial.js';
6
- export { default as InstancedPointsNodeMaterial } from './InstancedPointsNodeMaterial.js';
7
6
  export { default as LineBasicNodeMaterial } from './LineBasicNodeMaterial.js';
8
7
  export { default as LineDashedNodeMaterial } from './LineDashedNodeMaterial.js';
9
8
  export { default as Line2NodeMaterial } from './Line2NodeMaterial.js';
@@ -1,4 +1,10 @@
1
- import NodeMaterial from './NodeMaterial.js';
1
+ import SpriteNodeMaterial from './SpriteNodeMaterial.js';
2
+ import { viewport } from '../../nodes/display/ScreenNode.js';
3
+ import { positionGeometry, positionLocal, positionView } from '../../nodes/accessors/Position.js';
4
+ import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
5
+ import { materialPointSize } from '../../nodes/accessors/MaterialNode.js';
6
+ import { rotate } from '../../nodes/utils/RotateNode.js';
7
+ import { float, vec2, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';
2
8
 
3
9
  import { PointsMaterial } from '../PointsMaterial.js';
4
10
 
@@ -7,14 +13,9 @@ const _defaultValues = /*@__PURE__*/ new PointsMaterial();
7
13
  /**
8
14
  * Node material version of `PointsMaterial`.
9
15
  *
10
- * Since WebGPU can render point primitives only with a size of one pixel,
11
- * this material type does not evaluate the `size` and `sizeAttenuation`
12
- * property of `PointsMaterial`. Use {@link InstancedPointsNodeMaterial}
13
- * instead if you need points with a size larger than one pixel.
14
- *
15
16
  * @augments NodeMaterial
16
17
  */
17
- class PointsNodeMaterial extends NodeMaterial {
18
+ class PointsNodeMaterial extends SpriteNodeMaterial {
18
19
 
19
20
  static get type() {
20
21
 
@@ -31,6 +32,14 @@ class PointsNodeMaterial extends NodeMaterial {
31
32
 
32
33
  super();
33
34
 
35
+ /**
36
+ * This node property provides an additional way to set the point size.
37
+ *
38
+ * @type {Node<vec2>?}
39
+ * @default null
40
+ */
41
+ this.sizeNode = null;
42
+
34
43
  /**
35
44
  * This flag can be used for type testing.
36
45
  *
@@ -46,6 +55,99 @@ class PointsNodeMaterial extends NodeMaterial {
46
55
 
47
56
  }
48
57
 
58
+ setupPositionView() {
59
+
60
+ const { positionNode } = this;
61
+
62
+ return modelViewMatrix.mul( vec3( positionNode || positionLocal ) ).xyz;
63
+
64
+ }
65
+
66
+ setupVertex( builder ) {
67
+
68
+ const mvp = super.setupVertex( builder );
69
+
70
+ // skip further processing if the material is not a node material
71
+
72
+ if ( builder.material.isNodeMaterial !== true ) {
73
+
74
+ return mvp;
75
+
76
+ }
77
+
78
+ // ndc space
79
+
80
+ const { rotationNode, scaleNode, sizeNode } = this;
81
+
82
+ const alignedPosition = positionGeometry.xy.toVar();
83
+ const aspect = viewport.z.div( viewport.w );
84
+
85
+ // rotation
86
+
87
+ if ( rotationNode && rotationNode.isNode ) {
88
+
89
+ const rotation = float( rotationNode );
90
+
91
+ alignedPosition.assign( rotate( alignedPosition, rotation ) );
92
+
93
+ }
94
+
95
+ // point size
96
+
97
+ let pointSize = sizeNode !== null ? vec2( sizeNode ) : materialPointSize;
98
+
99
+ if ( this.sizeAttenuation === true ) {
100
+
101
+ pointSize = pointSize.mul( pointSize.div( positionView.z.negate() ) );
102
+
103
+ }
104
+
105
+ // scale
106
+
107
+ if ( scaleNode && scaleNode.isNode ) {
108
+
109
+ pointSize = pointSize.mul( vec2( scaleNode ) );
110
+
111
+ }
112
+
113
+ alignedPosition.mulAssign( pointSize.mul( 2 ) );
114
+
115
+ alignedPosition.assign( alignedPosition.div( viewport.z ) );
116
+ alignedPosition.y.assign( alignedPosition.y.mul( aspect ) );
117
+
118
+ // back to clip space
119
+ alignedPosition.assign( alignedPosition.mul( mvp.w ) );
120
+
121
+ //clipPos.xy += offset;
122
+ mvp.addAssign( vec4( alignedPosition, 0, 0 ) );
123
+
124
+ return mvp;
125
+
126
+ }
127
+
128
+ /**
129
+ * Whether alpha to coverage should be used or not.
130
+ *
131
+ * @type {Boolean}
132
+ * @default true
133
+ */
134
+ get alphaToCoverage() {
135
+
136
+ return this._useAlphaToCoverage;
137
+
138
+ }
139
+
140
+ set alphaToCoverage( value ) {
141
+
142
+ if ( this._useAlphaToCoverage !== value ) {
143
+
144
+ this._useAlphaToCoverage = value;
145
+ this.needsUpdate = true;
146
+
147
+ }
148
+
149
+ }
150
+
49
151
  }
50
152
 
51
153
  export default PointsNodeMaterial;
@@ -113,7 +113,7 @@ class SpriteNodeMaterial extends NodeMaterial {
113
113
 
114
114
  if ( scaleNode !== null ) {
115
115
 
116
- scale = scale.mul( scaleNode );
116
+ scale = scale.mul( float( scaleNode ) );
117
117
 
118
118
  }
119
119
 
@@ -13,7 +13,7 @@ import { Color } from '../../math/Color.js';
13
13
  /** @module VolumeNodeMaterial **/
14
14
 
15
15
  /**
16
- * Node material intended for volume rendering. The volumetic data are
16
+ * Node material intended for volume rendering. The volumetric data are
17
17
  * defined with an instance of {@link Data3DTexture}.
18
18
  *
19
19
  * @augments NodeMaterial
@@ -83,10 +83,10 @@ class VolumeNodeMaterial extends NodeMaterial {
83
83
  * The volume rendering of this material works by shooting rays
84
84
  * from the camera position through each fragment of the mesh's
85
85
  * surface and sample the inner volume in a raymarching fashion
86
- * mutiple times.
86
+ * multiple times.
87
87
  *
88
88
  * This node can be used to assign a callback function of type `Fn`
89
- * that will be exexuted per sample. The callback receives the
89
+ * that will be executed per sample. The callback receives the
90
90
  * texture, the sampled texture value as well as position on the surface
91
91
  * where the rays enters the volume. The last parameter is a color
92
92
  * that allows the callback to determine the final color.
@@ -143,6 +143,7 @@ class NodeMaterialObserver {
143
143
  data = {
144
144
  material: this.getMaterialData( material ),
145
145
  geometry: {
146
+ id: geometry.id,
146
147
  attributes: this.getAttributesData( geometry.attributes ),
147
148
  indexVersion: geometry.index ? geometry.index.version : null,
148
149
  drawRange: { start: geometry.drawRange.start, count: geometry.drawRange.count }
@@ -362,6 +363,13 @@ class NodeMaterialObserver {
362
363
  const storedAttributeNames = Object.keys( storedAttributes );
363
364
  const currentAttributeNames = Object.keys( attributes );
364
365
 
366
+ if ( storedGeometryData.id !== geometry.id ) {
367
+
368
+ storedGeometryData.id = geometry.id;
369
+ return false;
370
+
371
+ }
372
+
365
373
  if ( storedAttributeNames.length !== currentAttributeNames.length ) {
366
374
 
367
375
  renderObjectData.geometry.attributes = this.getAttributesData( attributes );
@@ -2,6 +2,7 @@
2
2
  export * from './core/constants.js';
3
3
 
4
4
  // core
5
+ export { default as ArrayNode } from './core/ArrayNode.js';
5
6
  export { default as AssignNode } from './core/AssignNode.js';
6
7
  export { default as AttributeNode } from './core/AttributeNode.js';
7
8
  export { default as BypassNode } from './core/BypassNode.js';
@@ -28,6 +29,8 @@ export { default as TempNode } from './core/TempNode.js';
28
29
  export { default as UniformGroupNode } from './core/UniformGroupNode.js';
29
30
  export { default as UniformNode } from './core/UniformNode.js';
30
31
  export { default as VaryingNode } from './core/VaryingNode.js';
32
+ export { default as StructNode } from './core/StructNode.js';
33
+ export { default as StructTypeNode } from './core/StructTypeNode.js';
31
34
  export { default as OutputStructNode } from './core/OutputStructNode.js';
32
35
  export { default as MRTNode } from './core/MRTNode.js';
33
36
 
@@ -52,6 +55,7 @@ export { default as StorageArrayElementNode } from './utils/StorageArrayElementN
52
55
  export { default as TriplanarTexturesNode } from './utils/TriplanarTexturesNode.js';
53
56
  export { default as ReflectorNode } from './utils/ReflectorNode.js';
54
57
  export { default as RTTNode } from './utils/RTTNode.js';
58
+ export { default as MemberNode } from './utils/MemberNode.js';
55
59
 
56
60
  // accessors
57
61
  export { default as UniformArrayNode } from './accessors/UniformArrayNode.js';
package/src/nodes/TSL.js CHANGED
@@ -11,6 +11,7 @@ export * from './core/IndexNode.js';
11
11
  export * from './core/ParameterNode.js';
12
12
  export * from './core/PropertyNode.js';
13
13
  export * from './core/StackNode.js';
14
+ export * from './core/StructNode.js';
14
15
  export * from './core/UniformGroupNode.js';
15
16
  export * from './core/UniformNode.js';
16
17
  export * from './core/VaryingNode.js';
@@ -142,6 +143,9 @@ export * from './pmrem/PMREMUtils.js';
142
143
  // procedural
143
144
  export * from './procedural/Checker.js';
144
145
 
146
+ // shapes
147
+ export * from './shapes/Shapes.js';
148
+
145
149
  // materialX
146
150
  export * from './materialx/MaterialXNodes.js';
147
151
 
@@ -9,14 +9,25 @@ import { getLengthFromType, getTypedArrayFromType } from '../core/NodeUtils.js';
9
9
  * TSL function for creating a storage buffer node with a configured `StorageBufferAttribute`.
10
10
  *
11
11
  * @function
12
- * @param {Number} count - The data count.
13
- * @param {String} [type='float'] - The data type.
12
+ * @param {Number|TypedArray} count - The data count. It is also valid to pass a typed array as an argument.
13
+ * @param {String|Struct} [type='float'] - The data type.
14
14
  * @returns {StorageBufferNode}
15
15
  */
16
16
  export const attributeArray = ( count, type = 'float' ) => {
17
17
 
18
- const itemSize = getLengthFromType( type );
19
- const typedArray = getTypedArrayFromType( type );
18
+ let itemSize, typedArray;
19
+
20
+ if ( type.isStruct === true ) {
21
+
22
+ itemSize = type.layout.getLength();
23
+ typedArray = getTypedArrayFromType( 'float' );
24
+
25
+ } else {
26
+
27
+ itemSize = getLengthFromType( type );
28
+ typedArray = getTypedArrayFromType( type );
29
+
30
+ }
20
31
 
21
32
  const buffer = new StorageBufferAttribute( count, itemSize, typedArray );
22
33
  const node = storage( buffer, type, count );
@@ -29,14 +40,25 @@ export const attributeArray = ( count, type = 'float' ) => {
29
40
  * TSL function for creating a storage buffer node with a configured `StorageInstancedBufferAttribute`.
30
41
  *
31
42
  * @function
32
- * @param {Number} count - The data count.
33
- * @param {String} [type='float'] - The data type.
43
+ * @param {Number|TypedArray} count - The data count. It is also valid to pass a typed array as an argument.
44
+ * @param {String|Struct} [type='float'] - The data type.
34
45
  * @returns {StorageBufferNode}
35
46
  */
36
47
  export const instancedArray = ( count, type = 'float' ) => {
37
48
 
38
- const itemSize = getLengthFromType( type );
39
- const typedArray = getTypedArrayFromType( type );
49
+ let itemSize, typedArray;
50
+
51
+ if ( type.isStruct === true ) {
52
+
53
+ itemSize = type.layout.getLength();
54
+ typedArray = getTypedArrayFromType( 'float' );
55
+
56
+ } else {
57
+
58
+ itemSize = getLengthFromType( type );
59
+ typedArray = getTypedArrayFromType( type );
60
+
61
+ }
40
62
 
41
63
  const buffer = new StorageInstancedBufferAttribute( count, itemSize, typedArray );
42
64
  const node = storage( buffer, type, count );
@@ -76,9 +76,9 @@ class BatchNode extends Node {
76
76
 
77
77
  const getIndirectIndex = Fn( ( [ id ] ) => {
78
78
 
79
- const size = textureSize( textureLoad( this.batchMesh._indirectTexture ), 0 );
80
- const x = int( id ).modInt( int( size ) );
81
- const y = int( id ).div( int( size ) );
79
+ const size = int( textureSize( textureLoad( this.batchMesh._indirectTexture ), 0 ) );
80
+ const x = int( id ).modInt( size );
81
+ const y = int( id ).div( size );
82
82
  return textureLoad( this.batchMesh._indirectTexture, ivec2( x, y ) ).x;
83
83
 
84
84
  } ).setLayout( {
@@ -271,7 +271,7 @@ class BufferAttributeNode extends InputNode {
271
271
  /**
272
272
  * Sets the `instanced` property to the given value.
273
273
  *
274
- * @param {Number} value - The value to set.
274
+ * @param {Boolean} value - The value to set.
275
275
  * @return {BufferAttributeNode} A reference to this node.
276
276
  */
277
277
  setInstanced( value ) {
@@ -1,9 +1,18 @@
1
1
  import { uniform } from '../core/UniformNode.js';
2
- import { renderGroup } from '../core/UniformGroupNode.js';
2
+ import { renderGroup, sharedUniformGroup } from '../core/UniformGroupNode.js';
3
3
  import { Vector3 } from '../../math/Vector3.js';
4
+ import { Fn } from '../tsl/TSLBase.js';
5
+ import { uniformArray } from './UniformArrayNode.js';
4
6
 
5
7
  /** @module Camera **/
6
8
 
9
+ /**
10
+ * TSL object that represents the current `index` value of the camera if used ArrayCamera.
11
+ *
12
+ * @type {UniformNode<uint>}
13
+ */
14
+ export const cameraIndex = /*@__PURE__*/ uniform( 0, 'uint' ).setGroup( sharedUniformGroup( 'cameraIndex' ) ).toVarying( 'v_cameraIndex' );
15
+
7
16
  /**
8
17
  * TSL object that represents the `near` value of the camera used for the current render.
9
18
  *
@@ -23,7 +32,33 @@ export const cameraFar = /*@__PURE__*/ uniform( 'float' ).label( 'cameraFar' ).s
23
32
  *
24
33
  * @type {UniformNode<mat4>}
25
34
  */
26
- export const cameraProjectionMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrix );
35
+ export const cameraProjectionMatrix = /*@__PURE__*/ ( Fn( ( { camera } ) => {
36
+
37
+ let cameraProjectionMatrix;
38
+
39
+ if ( camera.isArrayCamera && camera.cameras.length > 0 ) {
40
+
41
+ const matrices = [];
42
+
43
+ for ( const subCamera of camera.cameras ) {
44
+
45
+ matrices.push( subCamera.projectionMatrix );
46
+
47
+ }
48
+
49
+ const cameraProjectionMatrices = uniformArray( matrices ).setGroup( renderGroup ).label( 'cameraProjectionMatrices' );
50
+
51
+ cameraProjectionMatrix = cameraProjectionMatrices.element( cameraIndex ).toVar( 'cameraProjectionMatrix' );
52
+
53
+ } else {
54
+
55
+ cameraProjectionMatrix = uniform( 'mat4' ).label( 'cameraProjectionMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrix );
56
+
57
+ }
58
+
59
+ return cameraProjectionMatrix;
60
+
61
+ } ).once() )();
27
62
 
28
63
  /**
29
64
  * TSL object that represents the inverse projection matrix of the camera used for the current render.
@@ -37,7 +72,33 @@ export const cameraProjectionMatrixInverse = /*@__PURE__*/ uniform( 'mat4' ).lab
37
72
  *
38
73
  * @type {UniformNode<mat4>}
39
74
  */
40
- export const cameraViewMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraViewMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorldInverse );
75
+ export const cameraViewMatrix = /*@__PURE__*/ ( Fn( ( { camera } ) => {
76
+
77
+ let cameraViewMatrix;
78
+
79
+ if ( camera.isArrayCamera && camera.cameras.length > 0 ) {
80
+
81
+ const matrices = [];
82
+
83
+ for ( const subCamera of camera.cameras ) {
84
+
85
+ matrices.push( subCamera.matrixWorldInverse );
86
+
87
+ }
88
+
89
+ const cameraViewMatrices = uniformArray( matrices ).setGroup( renderGroup ).label( 'cameraViewMatrices' );
90
+
91
+ cameraViewMatrix = cameraViewMatrices.element( cameraIndex ).toVar( 'cameraViewMatrix' );
92
+
93
+ } else {
94
+
95
+ cameraViewMatrix = uniform( 'mat4' ).label( 'cameraViewMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorldInverse );
96
+
97
+ }
98
+
99
+ return cameraViewMatrix;
100
+
101
+ } ).once() )();
41
102
 
42
103
  /**
43
104
  * TSL object that represents the world matrix of the camera used for the current render.
@@ -95,7 +95,7 @@ class InstanceNode extends Node {
95
95
  /**
96
96
  * A reference to a buffer that is used by `instanceColorNode`.
97
97
  *
98
- * @type {InstancedInterleavedBuffer}
98
+ * @type {InstancedBufferAttribute}
99
99
  */
100
100
  this.bufferColor = null;
101
101
 
@@ -435,7 +435,7 @@ MaterialNode.LINE_DASH_SIZE = 'dashSize';
435
435
  MaterialNode.LINE_GAP_SIZE = 'gapSize';
436
436
  MaterialNode.LINE_WIDTH = 'linewidth';
437
437
  MaterialNode.LINE_DASH_OFFSET = 'dashOffset';
438
- MaterialNode.POINT_WIDTH = 'pointWidth';
438
+ MaterialNode.POINT_SIZE = 'size';
439
439
  MaterialNode.DISPERSION = 'dispersion';
440
440
  MaterialNode.LIGHT_MAP = 'light';
441
441
  MaterialNode.AO = 'ao';
@@ -520,7 +520,7 @@ export const materialReflectivity = /*@__PURE__*/ nodeImmutable( MaterialNode, M
520
520
 
521
521
  /**
522
522
  * TSL object that represents the roughness of the current material.
523
- * The value is composed via `roughness` * `roughnessMap.g`
523
+ * The value is composed via `roughness` * `roughnessMap.g`.
524
524
  *
525
525
  * @type {Node<float>}
526
526
  */
@@ -528,7 +528,7 @@ export const materialRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, Mate
528
528
 
529
529
  /**
530
530
  * TSL object that represents the metalness of the current material.
531
- * The value is composed via `metalness` * `metalnessMap.b`
531
+ * The value is composed via `metalness` * `metalnessMap.b`.
532
532
  *
533
533
  * @type {Node<float>}
534
534
  */
@@ -540,7 +540,7 @@ export const materialMetalness = /*@__PURE__*/ nodeImmutable( MaterialNode, Mate
540
540
  *
541
541
  * @type {Node<vec3>}
542
542
  */
543
- export const materialNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.NORMAL ).context( { getUV: null } );
543
+ export const materialNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.NORMAL );
544
544
 
545
545
  /**
546
546
  * TSL object that represents the clearcoat of the current material.
@@ -552,7 +552,7 @@ export const materialClearcoat = /*@__PURE__*/ nodeImmutable( MaterialNode, Mate
552
552
 
553
553
  /**
554
554
  * TSL object that represents the clearcoat roughness of the current material.
555
- * The value is composed via `clearcoatRoughness` * `clearcoatRoughnessMap.r`
555
+ * The value is composed via `clearcoatRoughness` * `clearcoatRoughnessMap.r`.
556
556
  *
557
557
  * @type {Node<float>}
558
558
  */
@@ -564,7 +564,7 @@ export const materialClearcoatRoughness = /*@__PURE__*/ nodeImmutable( MaterialN
564
564
  *
565
565
  * @type {Node<vec3>}
566
566
  */
567
- export const materialClearcoatNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_NORMAL ).context( { getUV: null } );
567
+ export const materialClearcoatNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_NORMAL );
568
568
 
569
569
  /**
570
570
  * TSL object that represents the rotation of the current sprite material.
@@ -583,7 +583,7 @@ export const materialSheen = /*@__PURE__*/ nodeImmutable( MaterialNode, Material
583
583
 
584
584
  /**
585
585
  * TSL object that represents the sheen roughness of the current material.
586
- * The value is composed via `sheenRoughness` * `sheenRoughnessMap.a` .
586
+ * The value is composed via `sheenRoughness` * `sheenRoughnessMap.a`.
587
587
  *
588
588
  * @type {Node<float>}
589
589
  */
@@ -690,11 +690,11 @@ export const materialLineWidth = /*@__PURE__*/ nodeImmutable( MaterialNode, Mate
690
690
  export const materialLineDashOffset = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_OFFSET );
691
691
 
692
692
  /**
693
- * TSL object that represents the point width of the current points material.
693
+ * TSL object that represents the point size of the current points material.
694
694
  *
695
695
  * @type {Node<float>}
696
696
  */
697
- export const materialPointWidth = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.POINT_WIDTH );
697
+ export const materialPointSize = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.POINT_SIZE );
698
698
 
699
699
  /**
700
700
  * TSL object that represents the dispersion of the current material.
@@ -11,4 +11,4 @@ export const modelViewProjection = /*@__PURE__*/ ( Fn( ( builder ) => {
11
11
 
12
12
  return builder.context.setupModelViewProjection();
13
13
 
14
- }, 'vec4' ).once() )().varying( 'v_modelViewProjection' );
14
+ }, 'vec4' ).once() )().toVarying( 'v_modelViewProjection' );
@@ -77,7 +77,9 @@ export const normalWorld = /*@__PURE__*/ varying( normalView.transformDirection(
77
77
  */
78
78
  export const transformedNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
79
79
 
80
- return builder.context.setupNormal();
80
+ // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
81
+
82
+ return builder.context.setupNormal().context( { getUV: null } );
81
83
 
82
84
  }, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedNormalView' );
83
85
 
@@ -95,7 +97,9 @@ export const transformedNormalWorld = /*@__PURE__*/ transformedNormalView.transf
95
97
  */
96
98
  export const transformedClearcoatNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
97
99
 
98
- return builder.context.setupClearcoatNormal();
100
+ // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
101
+
102
+ return builder.context.setupClearcoatNormal().context( { getUV: null } );
99
103
 
100
104
  }, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedClearcoatNormalView' );
101
105
 
@@ -73,7 +73,6 @@ class Object3DNode extends Node {
73
73
  /**
74
74
  * Overwritten since the node type is inferred from the scope.
75
75
  *
76
- * @param {NodeBuilder} builder - The current node builder.
77
76
  * @return {String} The node type.
78
77
  */
79
78
  getNodeType() {
@@ -16,7 +16,7 @@ export const positionGeometry = /*@__PURE__*/ attribute( 'position', 'vec3' );
16
16
  *
17
17
  * @type {AttributeNode<vec3>}
18
18
  */
19
- export const positionLocal = /*@__PURE__*/ positionGeometry.varying( 'positionLocal' );
19
+ export const positionLocal = /*@__PURE__*/ positionGeometry.toVarying( 'positionLocal' );
20
20
 
21
21
  /**
22
22
  * TSL object that represents the previous vertex position in local space of the current rendered object.
@@ -24,21 +24,21 @@ export const positionLocal = /*@__PURE__*/ positionGeometry.varying( 'positionLo
24
24
  *
25
25
  * @type {AttributeNode<vec3>}
26
26
  */
27
- export const positionPrevious = /*@__PURE__*/ positionGeometry.varying( 'positionPrevious' );
27
+ export const positionPrevious = /*@__PURE__*/ positionGeometry.toVarying( 'positionPrevious' );
28
28
 
29
29
  /**
30
30
  * TSL object that represents the vertex position in world space of the current rendered object.
31
31
  *
32
32
  * @type {VaryingNode<vec3>}
33
33
  */
34
- export const positionWorld = /*@__PURE__*/ modelWorldMatrix.mul( positionLocal ).xyz.varying( 'v_positionWorld' ).context( { needsPositionReassign: true } );
34
+ export const positionWorld = /*@__PURE__*/ modelWorldMatrix.mul( positionLocal ).xyz.toVarying( 'v_positionWorld' ).context( { needsPositionReassign: true } );
35
35
 
36
36
  /**
37
37
  * TSL object that represents the position world direction of the current rendered object.
38
38
  *
39
39
  * @type {Node<vec3>}
40
40
  */
41
- export const positionWorldDirection = /*@__PURE__*/ positionLocal.transformDirection( modelWorldMatrix ).varying( 'v_positionWorldDirection' ).normalize().toVar( 'positionWorldDirection' ).context( { needsPositionReassign: true } );
41
+ export const positionWorldDirection = /*@__PURE__*/ positionLocal.transformDirection( modelWorldMatrix ).toVarying( 'v_positionWorldDirection' ).normalize().toVar( 'positionWorldDirection' ).context( { needsPositionReassign: true } );
42
42
 
43
43
  /**
44
44
  * TSL object that represents the vertex position in view space of the current rendered object.
@@ -49,11 +49,11 @@ export const positionView = /*@__PURE__*/ ( Fn( ( builder ) => {
49
49
 
50
50
  return builder.context.setupPositionView();
51
51
 
52
- }, 'vec3' ).once() )().varying( 'v_positionView' ).context( { needsPositionReassign: true } );
52
+ }, 'vec3' ).once() )().toVarying( 'v_positionView' ).context( { needsPositionReassign: true } );
53
53
 
54
54
  /**
55
55
  * TSL object that represents the position view direction of the current rendered object.
56
56
  *
57
57
  * @type {VaryingNode<vec3>}
58
58
  */
59
- export const positionViewDirection = /*@__PURE__*/ positionView.negate().varying( 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' );
59
+ export const positionViewDirection = /*@__PURE__*/ positionView.negate().toVarying( 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' );