Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BatchedMesh: Add deleteGeometry(). #29523

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/api/en/objects/BatchedMesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ <h3>
<p>
Adds the given geometry to the [name] and returns the associated geometry id referring to it to be used in other functions.
</p>

<h3>
[method:Integer deleteGeometry]( [param:Integer geometryId] )
</h3>
<p>
[page:Integer geometryId]: The id of a geometry to remove from the [name] that was previously added via "addGeometry". Any instances referencing
this geometry will also be removed as a side effect.
</p>
<h3>
[method:Integer addInstance]( [param:Integer geometryId] )
</h3>
Expand Down
74 changes: 53 additions & 21 deletions src/objects/BatchedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) {

Expand Down