From c5f6063662cf0c7a12e2ee75d3d17c66fd96298f Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 Nov 2023 21:15:43 +0900 Subject: [PATCH 1/5] Add a copy function --- examples/jsm/objects/BatchedMesh.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/jsm/objects/BatchedMesh.js b/examples/jsm/objects/BatchedMesh.js index 9e01d7118a5184..65a6faf32789bd 100644 --- a/examples/jsm/objects/BatchedMesh.js +++ b/examples/jsm/objects/BatchedMesh.js @@ -563,11 +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; + + this._geometryInitialized = source._geometryInitialized; + this._geometryCount = source._geometryCount; + this._multiDrawCounts = source._multiDrawCounts.slice(); + this._multiDrawStarts = source._multiDrawCounts.slice(); + + this._matricesTexture = source._matricesTexture.clone(); + this._matricesTexture.image.data = this._matricesTexture.image.slice(); } From 97be669416cbb54b7f140fa2fd5b64918ac0bb16 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 Nov 2023 21:16:16 +0900 Subject: [PATCH 2/5] Add "toJSON" support --- src/core/Object3D.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index d674f668dbc3ad..5141dc75afd08b 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 ) { From 7b4169bdef0315433f782cb6528f1881c0b2ecae Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 Nov 2023 21:17:10 +0900 Subject: [PATCH 3/5] Remove toJSON override --- examples/jsm/objects/BatchedMesh.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/jsm/objects/BatchedMesh.js b/examples/jsm/objects/BatchedMesh.js index 65a6faf32789bd..78402821104ae7 100644 --- a/examples/jsm/objects/BatchedMesh.js +++ b/examples/jsm/objects/BatchedMesh.js @@ -589,12 +589,6 @@ class BatchedMesh extends Mesh { } - toJSON() { - - throw new Error( 'BatchedMesh: toJSON function not implemented.' ); - - } - dispose() { // Assuming the geometry is not shared with other meshes From 98400d50450cca6cdd394260ecaa22765d02f675 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 Nov 2023 21:18:50 +0900 Subject: [PATCH 4/5] copy paste error --- examples/jsm/objects/BatchedMesh.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsm/objects/BatchedMesh.js b/examples/jsm/objects/BatchedMesh.js index 78402821104ae7..f133cf87b242f6 100644 --- a/examples/jsm/objects/BatchedMesh.js +++ b/examples/jsm/objects/BatchedMesh.js @@ -582,7 +582,7 @@ class BatchedMesh extends Mesh { this._geometryInitialized = source._geometryInitialized; this._geometryCount = source._geometryCount; this._multiDrawCounts = source._multiDrawCounts.slice(); - this._multiDrawStarts = source._multiDrawCounts.slice(); + this._multiDrawStarts = source._multiDrawStarts.slice(); this._matricesTexture = source._matricesTexture.clone(); this._matricesTexture.image.data = this._matricesTexture.image.slice(); From f6afefe847b276f12d818d44ccee8cc8f5277df2 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 Nov 2023 18:55:11 +0900 Subject: [PATCH 5/5] Remove underscores from json --- src/core/Object3D.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 5141dc75afd08b..832984eb87d02b 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -722,20 +722,20 @@ class Object3D extends EventDispatcher { if ( this.isBatchedMesh ) { object.type = 'BatchedMesh'; - object._drawRanges = this._drawRanges; - object._reservedRanges = this._reservedRanges; + object.drawRanges = this._drawRanges; + object.reservedRanges = this._reservedRanges; - object._visible = this._visible; - object._active = this._active; + object.visible = this._visible; + object.active = this._active; - object._maxGeometryCount = this._maxGeometryCount; - object._maxVertexCount = this._maxVertexCount; - object._maxIndexCount = this._maxIndexCount; + object.maxGeometryCount = this._maxGeometryCount; + object.maxVertexCount = this._maxVertexCount; + object.maxIndexCount = this._maxIndexCount; - object._geometryInitialized = this._geometryInitialized; - object._geometryCount = this._geometryCount; + object.geometryInitialized = this._geometryInitialized; + object.geometryCount = this._geometryCount; - object._matricesTexture = this._matricesTexture.toJSON(); + object.matricesTexture = this._matricesTexture.toJSON(); }