Procházet zdrojové kódy

InstancedMesh: Honor instanceColor in toJSON() and ObjectLoader. (#21486)

* Keep instanceColor for InstancedMesh in toJSON and ObjectLoader

* instanceColor ignored if not present
Michael Harvey před 4 roky
rodič
revize
46c947c509
2 změnil soubory, kde provedl 3 přidání a 0 odebrání
  1. 1 0
      src/core/Object3D.js
  2. 2 0
      src/loaders/ObjectLoader.js

+ 1 - 0
src/core/Object3D.js

@@ -700,6 +700,7 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 			object.type = 'InstancedMesh';
 			object.count = this.count;
 			object.instanceMatrix = this.instanceMatrix.toJSON();
+			if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
 
 		}
 

+ 2 - 0
src/loaders/ObjectLoader.js

@@ -961,9 +961,11 @@ class ObjectLoader extends Loader {
 				material = getMaterial( data.material );
 				const count = data.count;
 				const instanceMatrix = data.instanceMatrix;
+				const instanceColor = data.instanceColor;
 
 				object = new InstancedMesh( geometry, material, count );
 				object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
+				if ( instanceColor !== undefined ) object.instanceColor = new BufferAttribute( new Float32Array( instanceColor.array ), 3 );
 
 				break;