Browse Source

Merge pull request #17639 from Mugen87/dev38

InstancedMesh: Added support for serialization/deserialization.
Michael Herzog 5 years ago
parent
commit
cd8cfdad27
2 changed files with 23 additions and 1 deletions
  1. 8 0
      src/core/Object3D.js
  2. 15 1
      src/loaders/ObjectLoader.js

+ 8 - 0
src/core/Object3D.js

@@ -683,6 +683,14 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 		if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
 
+		if ( this.isInstancedMesh ) {
+
+			object.type = 'InstancedMesh';
+			object.count = this.count;
+			object.instanceMatrix = this.instanceMatrix.toJSON();
+
+		}
+
 		//
 
 		function serialize( library, element ) {

+ 15 - 1
src/loaders/ObjectLoader.js

@@ -19,9 +19,11 @@ import {
 	LinearMipmapNearestFilter,
 	LinearMipmapLinearFilter
 } from '../constants.js';
+import { BufferAttribute } from '../core/BufferAttribute.js';
 import { Color } from '../math/Color.js';
 import { Object3D } from '../core/Object3D.js';
 import { Group } from '../objects/Group.js';
+import { InstancedMesh } from '../objects/InstancedMesh.js';
 import { Sprite } from '../objects/Sprite.js';
 import { Points } from '../objects/Points.js';
 import { Line } from '../objects/Line.js';
@@ -858,7 +860,17 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				}
 
-				if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
+				break;
+
+			case 'InstancedMesh':
+
+				var geometry = getGeometry( data.geometry );
+				var material = getMaterial( data.material );
+				var count = data.count;
+				var instanceMatrix = data.instanceMatrix;
+
+				object = new InstancedMesh( geometry, material, count );
+				object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
 
 				break;
 
@@ -949,6 +961,8 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 		if ( data.userData !== undefined ) object.userData = data.userData;
 		if ( data.layers !== undefined ) object.layers.mask = data.layers;
 
+		if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
+
 		if ( data.children !== undefined ) {
 
 			var children = data.children;