|
|
@@ -145,8 +145,9 @@ class BatchedMesh extends Mesh {
|
|
|
// stores visible, active, and geometry id per object
|
|
|
this._drawInfo = [];
|
|
|
|
|
|
- // instance ids that have been set as inactive, and are available to be overwritten
|
|
|
+ // instance, geometry ids that have been set as inactive, and are available to be overwritten
|
|
|
this._availableInstanceIds = [];
|
|
|
+ this._availableGeometryIds = [];
|
|
|
|
|
|
// geometry information
|
|
|
this._drawRanges = [];
|
|
|
@@ -400,13 +401,6 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
this._validateGeometry( geometry );
|
|
|
|
|
|
- // ensure we're not over geometry
|
|
|
- if ( this._drawInfo.length >= this._maxInstanceCount ) {
|
|
|
-
|
|
|
- throw new Error( 'BatchedMesh: Maximum item count reached.' );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
// get the necessary range fo the geometry
|
|
|
const reservedRange = {
|
|
|
vertexStart: - 1,
|
|
|
@@ -481,23 +475,40 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // update id
|
|
|
- const geometryId = this._geometryCount;
|
|
|
- this._geometryCount ++;
|
|
|
-
|
|
|
// add the reserved range and draw range objects
|
|
|
- reservedRanges.push( reservedRange );
|
|
|
- drawRanges.push( {
|
|
|
+ const drawRange = {
|
|
|
start: hasIndex ? reservedRange.indexStart : reservedRange.vertexStart,
|
|
|
- count: - 1
|
|
|
- } );
|
|
|
- bounds.push( {
|
|
|
+ count: - 1,
|
|
|
+ active: true,
|
|
|
+ };
|
|
|
+
|
|
|
+ const boundsInfo = {
|
|
|
boxInitialized: false,
|
|
|
box: new Box3(),
|
|
|
|
|
|
sphereInitialized: false,
|
|
|
sphere: new Sphere()
|
|
|
- } );
|
|
|
+ };
|
|
|
+
|
|
|
+ // update id
|
|
|
+ let geometryId;
|
|
|
+ if ( this._availableGeometryIds.length > 0 ) {
|
|
|
+
|
|
|
+ geometryId = this._availableGeometryIds.pop();
|
|
|
+ reservedRanges[ geometryId ] = reservedRange;
|
|
|
+ drawRanges[ geometryId ] = drawRange;
|
|
|
+ bounds[ geometryId ] = boundsInfo;
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ geometryId = this._geometryCount;
|
|
|
+ this._geometryCount ++;
|
|
|
+ reservedRanges.push( reservedRange );
|
|
|
+ drawRanges.push( drawRange );
|
|
|
+ bounds.push( boundsInfo );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
// update the geometry
|
|
|
this.setGeometryAt( geometryId, geometry );
|
|
|
@@ -617,13 +628,34 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
deleteGeometry( geometryId ) {
|
|
|
|
|
|
- // TODO: delete geometry and associated instances
|
|
|
+ const drawRanges = this._drawRanges;
|
|
|
+ if ( geometryId >= drawRanges.length || drawRanges[ geometryId ].active === false ) {
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // delete any instances associated with this geometry
|
|
|
+ const drawInfo = this._drawInfo;
|
|
|
+ for ( let i = 0, l = drawInfo.length; i < l; i ++ ) {
|
|
|
+
|
|
|
+ if ( drawInfo[ i ].geometryIndex === geometryId ) {
|
|
|
+
|
|
|
+ this.deleteInstance( i );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ drawRanges[ geometryId ].active = false;
|
|
|
+ this._availableGeometryIds.push( geometryId );
|
|
|
+ this._visibilityChanged = true;
|
|
|
+
|
|
|
+ return this;
|
|
|
|
|
|
}
|
|
|
- */
|
|
|
|
|
|
deleteInstance( instanceId ) {
|
|
|
|