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 setGeometryIdAt getGeometryIdAt #29343

Merged
merged 4 commits into from
Sep 13, 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
23 changes: 22 additions & 1 deletion docs/api/en/objects/BatchedMesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,15 @@ <h3>
[page:Integer instanceId]: The id of an instance to get the visibility state of.
</p>
<p>Get whether the given instance is marked as "visible" or not.</p>


<h3>
[method:Integer getGeometryIdAt]( [param:Integer instanceId] )
</h3>
<p>
[page:Integer instanceId]: The id of an instance to get the geometryIndex of.
</p>
<p>Get the geometryIndex of the defined instance.</p>

<h3>
[method:undefined setColorAt]( [param:Integer instanceId], [param:Color color] )
</h3>
Expand Down Expand Up @@ -207,6 +215,19 @@ <h3>
Sets the visibility of the instance at the given index.
</p>

<h3>
[method:this setGeometryIdAt]( [param:Integer instanceId], [param:Integer geometryId] )
</h3>
<p>
[page:Integer instanceId]: The id of the instance to set the geometryIndex of.
</p>
<p>
[page:Integer geometryId]: The geometryIndex to be use by the instance.
</p>
<p>
Sets the geometryIndex of the instance at the given index.
</p>

<h3>
[method:Integer addGeometry]( [param:BufferGeometry geometry], [param:Integer reservedVertexRange], [param:Integer reservedIndexRange] )
</h3>
Expand Down
15 changes: 10 additions & 5 deletions examples/webgpu_mesh_batch.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
perObjectFrustumCulled: true,
opacity: 1,
useCustomSort: true,
randomizeGeometry: ()=>{

for ( let i = 0; i < api.count; i ++ ) {

mesh.setGeometryIdAt( i, Math.floor( Math.random() * geometries.length ) );

}

}
};


Expand Down Expand Up @@ -187,8 +196,6 @@

}



function init( forceWebGL = false ) {

if ( renderer ) {
Expand Down Expand Up @@ -270,15 +277,13 @@
gui.add( api, 'sortObjects' );
gui.add( api, 'perObjectFrustumCulled' );
gui.add( api, 'useCustomSort' );
gui.add( api, 'randomizeGeometry' );


// listeners

window.addEventListener( 'resize', onWindowResize );




function onWindowResize() {

const width = window.innerWidth;
Expand Down
36 changes: 36 additions & 0 deletions src/objects/BatchedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,42 @@ class BatchedMesh extends Mesh {

}

setGeometryIdAt( instanceId, geometryId ) {

// return early if the geometry is out of range or not active
const drawInfo = this._drawInfo;
if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {

return null;

}

// check if the provided geometryId is within the valid range
if ( geometryId < 0 || geometryId >= this._geometryCount ) {

return null;

}

drawInfo[ instanceId ].geometryIndex = geometryId;
Makio64 marked this conversation as resolved.
Show resolved Hide resolved

return this;

}

getGeometryIdAt( instanceId ) {

const drawInfo = this._drawInfo;
if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {

return - 1;

}

return drawInfo[ instanceId ].geometryIndex;

}

raycast( raycaster, intersects ) {

const drawInfo = this._drawInfo;
Expand Down