Browse Source

BatchedMesh: Add "toJSON" and "copy" support (#27131)

* Add a copy function

* Add "toJSON" support

* Remove toJSON override

* copy paste error

* Remove underscores from json
Garrett Johnson 1 năm trước cách đây
mục cha
commit
d5bd248133
2 tập tin đã thay đổi với 38 bổ sung6 xóa
  1. 18 6
      examples/jsm/objects/BatchedMesh.js
  2. 20 0
      src/core/Object3D.js

+ 18 - 6
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();
 
 	}
 

+ 20 - 0
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 ) {