فهرست منبع

InstancedMesh, BatchedMesh: Fix getColorAt throwing an error when colors have not been set (#33079)

Garrett Johnson 1 ماه پیش
والد
کامیت
3fb1d054bf
2فایلهای تغییر یافته به همراه26 افزوده شده و 2 حذف شده
  1. 17 1
      src/objects/BatchedMesh.js
  2. 9 1
      src/objects/InstancedMesh.js

+ 17 - 1
src/objects/BatchedMesh.js

@@ -1133,7 +1133,23 @@ class BatchedMesh extends Mesh {
 	getColorAt( instanceId, color ) {
 
 		this.validateInstanceId( instanceId );
-		return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
+		if ( this._colorsTexture === null ) {
+
+			if ( color.isVector4 ) {
+
+				return color.set( 1, 1, 1, 1 );
+
+			} else {
+
+				return color.setRGB( 1, 1, 1 );
+
+			}
+
+		} else {
+
+			return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
+
+		}
 
 	}
 

+ 9 - 1
src/objects/InstancedMesh.js

@@ -217,7 +217,15 @@ class InstancedMesh extends Mesh {
 	 */
 	getColorAt( index, color ) {
 
-		return color.fromArray( this.instanceColor.array, index * 3 );
+		if ( this.instanceColor === null ) {
+
+			return color.setRGB( 1, 1, 1 );
+
+		} else {
+
+			return color.fromArray( this.instanceColor.array, index * 3 );
+
+		}
 
 	}
 

粤ICP备19079148号