From e0bfd6552ccca16537a0d816c53280d13eb4874a Mon Sep 17 00:00:00 2001 From: Temdog007 Date: Mon, 13 May 2019 20:48:16 -0700 Subject: [PATCH] Serialize InstancedBufferGeometry --- src/core/InstancedBufferGeometry.js | 10 ++++++++++ src/loaders/BufferGeometryLoader.js | 8 +++++--- src/loaders/ObjectLoader.js | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/core/InstancedBufferGeometry.js b/src/core/InstancedBufferGeometry.js index a021bbf88f..718ede5c88 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 b6332bfe0c..5cadba84d1 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 53594b1024..7e4f52e3e3 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 ); -- GitLab