diff --git a/examples/jsm/objects/BatchedMesh.js b/examples/jsm/objects/BatchedMesh.js index 9e01d7118a5184..f133cf87b242f6 100644 --- a/examples/jsm/objects/BatchedMesh.js +++ b/examples/jsm/objects/BatchedMesh.js @@ -563,17 +563,29 @@ class BatchedMesh extends Mesh { } - copy() { + copy( source ) { - // super.copy( source ); + super.copy( source ); - throw new Error( 'BatchedMesh: Copy function not implemented.' ); + this.geometry = source.geometry.clone(); - } + this._drawRanges = source._drawRanges.map( range => ( { ...range } ) ); + this._reservedRanges = source._reservedRanges.map( range => ( { ...range } ) ); + + this._visible = source._visible.slice(); + this._active = source._active.slice(); + + this._maxGeometryCount = source._maxGeometryCount; + this._maxVertexCount = source._maxVertexCount; + this._maxIndexCount = source._maxIndexCount; - toJSON() { + this._geometryInitialized = source._geometryInitialized; + this._geometryCount = source._geometryCount; + this._multiDrawCounts = source._multiDrawCounts.slice(); + this._multiDrawStarts = source._multiDrawStarts.slice(); - throw new Error( 'BatchedMesh: toJSON function not implemented.' ); + this._matricesTexture = source._matricesTexture.clone(); + this._matricesTexture.image.data = this._matricesTexture.image.slice(); } diff --git a/src/core/Object3D.js b/src/core/Object3D.js index d674f668dbc3ad..832984eb87d02b 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -719,6 +719,26 @@ class Object3D extends EventDispatcher { } + if ( this.isBatchedMesh ) { + + object.type = 'BatchedMesh'; + object.drawRanges = this._drawRanges; + object.reservedRanges = this._reservedRanges; + + object.visible = this._visible; + object.active = this._active; + + object.maxGeometryCount = this._maxGeometryCount; + object.maxVertexCount = this._maxVertexCount; + object.maxIndexCount = this._maxIndexCount; + + object.geometryInitialized = this._geometryInitialized; + object.geometryCount = this._geometryCount; + + object.matricesTexture = this._matricesTexture.toJSON(); + + } + // function serialize( library, element ) {