diff --git a/src/core/InstancedBufferGeometry.js b/src/core/InstancedBufferGeometry.js index a021bbf88fa2428cc4d21866a0c2562e8ac56cf0..718ede5c88f6b262b078ee0e814b4d7d143cd5a8 100644 --- a/src/core/InstancedBufferGeometry.js +++ b/src/core/InstancedBufferGeometry.js @@ -33,6 +33,16 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry return new this.constructor().copy( this ); + }, + + toJSON: function(){ + var data = InstancedBufferGeometry.prototype.toJSON.call( this ); + + data.maxInstancedCount = this.maxInstancedCount; + + data.isInstancedBufferGeometry = true; + + return data; } } ); diff --git a/src/loaders/BufferGeometryLoader.js b/src/loaders/BufferGeometryLoader.js index b6332bfe0c952cb7a008c164f6f50fb7ba18859d..5cadba84d14925565c39feea804a69aee011f0e3 100644 --- a/src/loaders/BufferGeometryLoader.js +++ b/src/loaders/BufferGeometryLoader.js @@ -4,6 +4,8 @@ import { BufferAttribute } from '../core/BufferAttribute.js'; import { BufferGeometry } from '../core/BufferGeometry.js'; import { FileLoader } from './FileLoader.js'; import { DefaultLoadingManager } from './LoadingManager.js'; +import { InstancedBufferGeometry } from '../core/InstancedBufferGeometry.js'; +import { InstancedBufferAttribute } from '../core/InstancedBufferAttribute.js'; /** * @author mrdoob / http://mrdoob.com/ @@ -33,7 +35,7 @@ Object.assign( BufferGeometryLoader.prototype, { parse: function ( json ) { - var geometry = new BufferGeometry(); + var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry(); var index = json.data.index; @@ -50,8 +52,8 @@ Object.assign( BufferGeometryLoader.prototype, { var attribute = attributes[ key ]; var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array ); - - var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ); + var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute; + var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized ); if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name; geometry.addAttribute( key, bufferAttribute ); diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 53594b10244e12a5b9267be35dbcc7836d10ac0d..7e4f52e3e395079769825956616ba125c9c678de 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -430,6 +430,7 @@ Object.assign( ObjectLoader.prototype, { break; case 'BufferGeometry': + case 'InstancedBufferGeometry': geometry = bufferGeometryLoader.parse( data );