@needle-tools/three 0.185.0 → 0.185.2-alpha

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/three",
3
- "version": "0.185.0",
3
+ "version": "0.185.2-alpha",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.cjs",
package/src/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const REVISION = '185.0';
1
+ export const REVISION = '185.2-alpha';
2
2
 
3
3
  /**
4
4
  * Represents mouse buttons and interaction types in context of controls.
@@ -285,7 +285,8 @@ class ShapePath {
285
285
  for ( let j = i - 1; j >= 0; j -- ) {
286
286
 
287
287
  const candidate = entries[ j ];
288
- if ( ! candidate.boundingBox.containsPoint( entry.interiorPoint ) ) continue;
288
+
289
+ if ( ! candidate.boundingBox.containsBox( entry.boundingBox ) ) continue;
289
290
  if ( ! pointInPolygon( entry.interiorPoint, candidate.points ) ) continue;
290
291
 
291
292
  entry.container = candidate.exclude ? candidate.container : candidate;
@@ -23,26 +23,26 @@ const _previousInstanceMatrices = /*@__PURE__*/ new WeakMap();
23
23
  *
24
24
  * @param {NodeBuilder} builder - The current node builder.
25
25
  * @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} instanceMatrix - The matrix buffer attribute.
26
- * @param {number} count - The instance count.
27
26
  * @returns {Node} The matrix node.
28
27
  */
29
- function createInstanceMatrixNode( builder, instanceMatrix, count ) {
28
+ function createInstanceMatrixNode( builder, instanceMatrix ) {
30
29
 
31
30
  let instanceMatrixNode;
31
+ const matrixCount = Math.max( instanceMatrix.count, 1 );
32
32
 
33
33
  const isStorageMatrix = instanceMatrix.isStorageInstancedBufferAttribute === true;
34
34
 
35
35
  if ( isStorageMatrix ) {
36
36
 
37
- instanceMatrixNode = storage( instanceMatrix, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
37
+ instanceMatrixNode = storage( instanceMatrix, 'mat4', matrixCount ).element( instanceIndex );
38
38
 
39
39
  } else {
40
40
 
41
- const uniformBufferSize = count * 16 * 4;
41
+ const uniformBufferSize = matrixCount * 16 * 4;
42
42
 
43
43
  if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
44
44
 
45
- instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
45
+ instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', matrixCount ).element( instanceIndex );
46
46
 
47
47
  } else {
48
48
 
@@ -81,10 +81,9 @@ function createInstanceMatrixNode( builder, instanceMatrix, count ) {
81
81
  * @param {InstancedMesh} instancedMesh - The instanced mesh object.
82
82
  * @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} instanceMatrix - The current matrix buffer attribute.
83
83
  * @param {NodeBuilder} builder - The current node builder.
84
- * @param {number} count - The instance count.
85
84
  * @returns {Node} The previous frame instance matrix node.
86
85
  */
87
- function getPreviousInstance( instancedMesh, instanceMatrix, builder, count ) {
86
+ function getPreviousInstance( instancedMesh, instanceMatrix, builder ) {
88
87
 
89
88
  let data = _previousInstanceMatrices.get( instancedMesh );
90
89
 
@@ -94,7 +93,7 @@ function getPreviousInstance( instancedMesh, instanceMatrix, builder, count ) {
94
93
 
95
94
  data = {
96
95
  previousInstanceMatrix,
97
- node: createInstanceMatrixNode( builder, previousInstanceMatrix, count )
96
+ node: createInstanceMatrixNode( builder, previousInstanceMatrix )
98
97
  };
99
98
 
100
99
  _previousInstanceMatrices.set( instancedMesh, data );
@@ -118,26 +117,22 @@ export const instanceColor = /*@__PURE__*/ varyingProperty( 'vec3', 'vInstanceCo
118
117
  *
119
118
  * @tsl
120
119
  * @function
121
- * @param {number} count - The instance count.
122
120
  * @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} matrices - The instanced transformation matrices.
123
121
  * @param {?InstancedBufferAttribute|StorageInstancedBufferAttribute} [colors=null] - The optional instanced colors.
124
122
  */
125
- export const instance = /*@__PURE__*/ Fn( ( [ count, matrices, colors = null ], builder ) => {
126
-
127
- // get numeric value (non-node)
128
- count = count.value;
123
+ export const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder ) => {
129
124
 
130
125
  const isStorageMatrix = matrices.isStorageInstancedBufferAttribute === true;
131
126
  const isStorageColor = colors && colors.isStorageInstancedBufferAttribute === true;
132
127
 
133
- const instanceMatrixNode = createInstanceMatrixNode( builder, matrices, count );
128
+ const instanceMatrixNode = createInstanceMatrixNode( builder, matrices );
134
129
 
135
130
  // interleaved buffer tracking for matrix
136
131
  let interleavedMatrix = null;
137
132
 
138
133
  if ( ! isStorageMatrix ) {
139
134
 
140
- const uniformBufferSize = count * 16 * 4;
135
+ const uniformBufferSize = Math.max( matrices.count, 1 ) * 16 * 4;
141
136
 
142
137
  if ( uniformBufferSize > builder.getUniformBufferLimit() ) {
143
138
 
@@ -229,7 +224,7 @@ export const instance = /*@__PURE__*/ Fn( ( [ count, matrices, colors = null ],
229
224
 
230
225
  } );
231
226
 
232
- const previousInstanceMatrixNode = getPreviousInstance( instancedMesh, matrices, builder, count );
227
+ const previousInstanceMatrixNode = getPreviousInstance( instancedMesh, matrices, builder );
233
228
  positionPrevious.assign( previousInstanceMatrixNode.mul( positionPrevious ).xyz );
234
229
 
235
230
  }
@@ -262,10 +257,8 @@ export const instance = /*@__PURE__*/ Fn( ( [ count, matrices, colors = null ],
262
257
  */
263
258
  export const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ] ) => {
264
259
 
265
- const { count, instanceMatrix, instanceColor } = instancedMesh;
260
+ const { instanceMatrix, instanceColor } = instancedMesh;
266
261
 
267
- instance( count, instanceMatrix, instanceColor );
262
+ instance( instanceMatrix, instanceColor );
268
263
 
269
264
  }, 'void' );
270
-
271
-
@@ -26,8 +26,8 @@ export const materialEnvIntensity = /*@__PURE__*/ uniform( 1 ).onReference( ( {
26
26
 
27
27
  /**
28
28
  * TSL object that represents the rotation of environment maps.
29
- * When `material.envMap` is set, the value is `material.envMapRotation`. `scene.environmentRotation` controls the
30
- * rotation of `scene.environment` instead.
29
+ * When `material.envMap` is set, the value is `material.envMapRotation`.
30
+ * `scene.environmentRotation` controls the rotation of `scene.environment` or `scene.environmentNode` instead.
31
31
  *
32
32
  * @tsl
33
33
  * @type {Node<mat4>}
@@ -38,7 +38,8 @@ export const materialEnvRotation = /*@__PURE__*/ uniform( new Matrix4() ).onRefe
38
38
 
39
39
  } ).onObjectUpdate( function ( { material, scene } ) {
40
40
 
41
- const rotation = ( scene.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;
41
+ const hasSceneEnvironment = ( scene.environment !== null ) || ( scene.environmentNode && scene.environmentNode.isNode );
42
+ const rotation = ( hasSceneEnvironment && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;
42
43
 
43
44
  if ( rotation ) {
44
45
 
@@ -31,7 +31,7 @@ export const backgroundRotation = /*@__PURE__*/ uniform( new Matrix4() ).setGrou
31
31
 
32
32
  const background = scene.background;
33
33
 
34
- if ( background !== null && background.isTexture && background.mapping !== UVMapping ) {
34
+ if ( ( background !== null && background.isTexture && background.mapping !== UVMapping ) || ( scene.backgroundNode && scene.backgroundNode.isNode ) ) {
35
35
 
36
36
  // note: since the matrix is orthonormal, we can use the more-efficient transpose() in lieu of invert()
37
37
  _m1.makeRotationFromEuler( scene.backgroundRotation ).transpose();
@@ -170,6 +170,10 @@ class MRTNode extends OutputStructNode {
170
170
  for ( const name in outputNodes ) {
171
171
 
172
172
  const index = getTextureIndex( textures, name );
173
+
174
+ // Ignore if the output exists in the MRT but has never been used.
175
+ if ( index === - 1 ) continue;
176
+
173
177
  const type = builder.getOutputType( index );
174
178
 
175
179
  members[ index ] = outputNodes[ name ].convert( type );
@@ -172,9 +172,9 @@ class VolumetricLightingModel extends LightingModel {
172
172
 
173
173
  direct( { lightNode, lightColor }, builder ) {
174
174
 
175
- // Ignore lights with infinite distance
175
+ // Ignore non-analytical lights and lights with infinite distance
176
176
 
177
- if ( lightNode.light.distance === undefined ) return;
177
+ if ( lightNode.isAnalyticLightNode !== true || lightNode.light.distance === undefined ) return;
178
178
 
179
179
  // TODO: We need a viewportOpaque*() ( output, depth ) to fit with modern rendering approaches
180
180
 
@@ -806,12 +806,31 @@ function setValueV4uiArray( gl, v ) {
806
806
 
807
807
  // Array of textures (2D / 3D / Cube / 2DArray)
808
808
 
809
+ const _warnedEmptySamplerArray = new Set();
810
+
809
811
  function setValueT1Array( gl, v, textures ) {
810
812
 
811
813
  const cache = this.cache;
812
814
 
813
815
  const n = v.length;
814
816
 
817
+ // An empty sampler array (`sampler2D x[0]`) has nothing to bind, and Chrome throws
818
+ // "WebGL: INVALID_VALUE: uniform1iv: no array" on `gl.uniform1iv([])` — every frame.
819
+ // Skip the upload (a genuine no-op) and warn once per uniform so the source of the
820
+ // empty array can be tracked down. Seen with empty shadow sampler arrays (ContactShadows).
821
+ if ( n === 0 ) {
822
+
823
+ if ( ! _warnedEmptySamplerArray.has( this.id ) ) {
824
+
825
+ _warnedEmptySamplerArray.add( this.id );
826
+ console.warn( `THREE.WebGLUniforms: skipping empty sampler array uniform '${ this.id }' (nothing to bind).` );
827
+
828
+ }
829
+
830
+ return;
831
+
832
+ }
833
+
815
834
  const units = allocTexUnits( textures, n );
816
835
 
817
836
  if ( ! arraysEqual( cache, units ) ) {