Browse Source

BufferGeometry: Fix attribute count mismatch in `computeVertexNormals()` and `computeTangents()`. (#33520)

Michael Herzog 1 month ago
parent
commit
6d97cbfc94
1 changed files with 6 additions and 5 deletions
  1. 6 5
      src/core/BufferGeometry.js

+ 6 - 5
src/core/BufferGeometry.js

@@ -841,13 +841,14 @@ class BufferGeometry extends EventDispatcher {
 		const normalAttribute = attributes.normal;
 		const uvAttribute = attributes.uv;
 
-		if ( this.hasAttribute( 'tangent' ) === false ) {
+		let tangentAttribute = this.getAttribute( 'tangent' );
 
-			this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
+		if ( tangentAttribute === undefined || tangentAttribute.count !== positionAttribute.count ) {
 
-		}
+			tangentAttribute = new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 );
+			this.setAttribute( 'tangent', tangentAttribute );
 
-		const tangentAttribute = this.getAttribute( 'tangent' );
+		}
 
 		const tan1 = [], tan2 = [];
 
@@ -993,7 +994,7 @@ class BufferGeometry extends EventDispatcher {
 
 			let normalAttribute = this.getAttribute( 'normal' );
 
-			if ( normalAttribute === undefined ) {
+			if ( normalAttribute === undefined || normalAttribute.count !== positionAttribute.count ) {
 
 				normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
 				this.setAttribute( 'normal', normalAttribute );

粤ICP备19079148号