瀏覽代碼

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

* Keep instanceColor for InstancedMesh in toJSON and ObjectLoader

* instanceColor ignored if not present
Michael Harvey 4 年之前
父節點
當前提交
46c947c509
共有 2 個文件被更改,包括 3 次插入0 次删除
  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;