提交 e0bfd655 编写于 作者: T Temdog007

Serialize InstancedBufferGeometry

上级 fa398a1c
......@@ -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;
}
} );
......
......@@ -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 );
......
......@@ -430,6 +430,7 @@ Object.assign( ObjectLoader.prototype, {
break;
case 'BufferGeometry':
case 'InstancedBufferGeometry':
geometry = bufferGeometryLoader.parse( data );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册