diff --git a/examples/jsm/objects/BatchedMesh.js b/examples/jsm/objects/BatchedMesh.js index 786e7e5d341c2f..5b01b3c9621ee5 100644 --- a/examples/jsm/objects/BatchedMesh.js +++ b/examples/jsm/objects/BatchedMesh.js @@ -88,8 +88,8 @@ class BatchedMesh extends Mesh { this._geometryInitialized = false; this._geometryCount = 0; - this._multiDrawCounts = null; - this._multiDrawStarts = null; + this._multiDrawCounts = new Int32Array( maxGeometryCount ); + this._multiDrawStarts = new Int32Array( maxGeometryCount ); this._multiDrawCount = 0; // Local matrix per geometry by using data texture @@ -156,8 +156,6 @@ class BatchedMesh extends Mesh { geometry.setAttribute( ID_ATTR_NAME, new BufferAttribute( idArray, 1 ) ); this._geometryInitialized = true; - this._multiDrawCounts = new Int32Array( maxGeometryCount ); - this._multiDrawStarts = new Int32Array( maxGeometryCount ); } diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 65d327bf4d5f01..15169fcc71e9d2 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -746,7 +746,7 @@ class Object3D extends EventDispatcher { object.geometryInitialized = this._geometryInitialized; object.geometryCount = this._geometryCount; - object.matricesTexture = this._matricesTexture.toJSON(); + object.matricesTexture = this._matricesTexture.toJSON( meta ); if ( this.boundingSphere !== null ) { diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 03e53ee947718e..96223ddb9f5779 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -22,6 +22,7 @@ import { Color } from '../math/Color.js'; import { Object3D } from '../core/Object3D.js'; import { Group } from '../objects/Group.js'; import { InstancedMesh } from '../objects/InstancedMesh.js'; +import { BatchedMesh } from '../../examples/jsm/objects/BatchedMesh.js'; import { Sprite } from '../objects/Sprite.js'; import { Points } from '../objects/Points.js'; import { Line } from '../objects/Line.js'; @@ -59,6 +60,8 @@ import { Loader } from './Loader.js'; import { FileLoader } from './FileLoader.js'; import * as Geometries from '../geometries/Geometries.js'; import { getTypedArray } from '../utils.js'; +import { Box3 } from '../math/Box3.js'; +import { Sphere } from '../math/Sphere.js'; class ObjectLoader extends Loader { @@ -897,6 +900,52 @@ class ObjectLoader extends Loader { break; + case 'BatchedMesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + + object = new BatchedMesh( data.maxGeometryCount, data.maxVertexCount, data.maxIndexCount, material ); + object.geometry = geometry; + object.perObjectFrustumCulled = data.perObjectFrustumCulled; + object.sortObjects = data.sortObjects; + + object._drawRanges = data.drawRanges; + object._reservedRanges = data.reservedRanges; + + object._visible = data.visible; + object._active = data.active; + object._bounds = data.bounds.map( bound => { + + const box = new Box3(); + box.min.fromArray( bound.boxMin ); + box.max.fromArray( bound.boxMax ); + + const sphere = new Sphere(); + sphere.radius = bound.sphereRadius; + sphere.center.fromArray( bound.sphereCenter ); + + return { + boxInitialized: bound.boxInitialized, + box: box, + + sphereInitialized: bound.sphereInitialized, + sphere: sphere + }; + + } ); + + object._maxGeometryCount = data.maxGeometryCount; + object._maxVertexCount = data.maxVertexCount; + object._maxIndexCount = data.maxIndexCount; + + object._geometryInitialized = data.geometryInitialized; + object._geometryCount = data.geometryCount; + + object._matricesTexture = getTexture( data.matricesTexture.uuid ); + + break; + case 'LOD': object = new LOD();