Skip to content

Commit d5bd248

Browse files
authored
BatchedMesh: Add "toJSON" and "copy" support (#27131)
* Add a copy function * Add "toJSON" support * Remove toJSON override * copy paste error * Remove underscores from json
1 parent a1906ff commit d5bd248

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

examples/jsm/objects/BatchedMesh.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,17 +563,29 @@ class BatchedMesh extends Mesh {
563563

564564
}
565565

566-
copy() {
566+
copy( source ) {
567567

568-
// super.copy( source );
568+
super.copy( source );
569569

570-
throw new Error( 'BatchedMesh: Copy function not implemented.' );
570+
this.geometry = source.geometry.clone();
571571

572-
}
572+
this._drawRanges = source._drawRanges.map( range => ( { ...range } ) );
573+
this._reservedRanges = source._reservedRanges.map( range => ( { ...range } ) );
574+
575+
this._visible = source._visible.slice();
576+
this._active = source._active.slice();
577+
578+
this._maxGeometryCount = source._maxGeometryCount;
579+
this._maxVertexCount = source._maxVertexCount;
580+
this._maxIndexCount = source._maxIndexCount;
573581

574-
toJSON() {
582+
this._geometryInitialized = source._geometryInitialized;
583+
this._geometryCount = source._geometryCount;
584+
this._multiDrawCounts = source._multiDrawCounts.slice();
585+
this._multiDrawStarts = source._multiDrawStarts.slice();
575586

576-
throw new Error( 'BatchedMesh: toJSON function not implemented.' );
587+
this._matricesTexture = source._matricesTexture.clone();
588+
this._matricesTexture.image.data = this._matricesTexture.image.slice();
577589

578590
}
579591

src/core/Object3D.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,26 @@ class Object3D extends EventDispatcher {
719719

720720
}
721721

722+
if ( this.isBatchedMesh ) {
723+
724+
object.type = 'BatchedMesh';
725+
object.drawRanges = this._drawRanges;
726+
object.reservedRanges = this._reservedRanges;
727+
728+
object.visible = this._visible;
729+
object.active = this._active;
730+
731+
object.maxGeometryCount = this._maxGeometryCount;
732+
object.maxVertexCount = this._maxVertexCount;
733+
object.maxIndexCount = this._maxIndexCount;
734+
735+
object.geometryInitialized = this._geometryInitialized;
736+
object.geometryCount = this._geometryCount;
737+
738+
object.matricesTexture = this._matricesTexture.toJSON();
739+
740+
}
741+
722742
//
723743

724744
function serialize( library, element ) {

0 commit comments

Comments
 (0)