Skip to content

Commit a839af7

Browse files
authored
RapierPhysics: Add triangular mesh collider (#28993)
* RapierPhysics: Add triangular mesh collider * Formatting * Add support for interleaved buffers
1 parent 9fd398d commit a839af7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

examples/jsm/physics/RapierPhysics.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ function getShape( geometry ) {
2828
const radius = parameters.radius !== undefined ? parameters.radius : 1;
2929
return RAPIER.ColliderDesc.ball( radius );
3030

31+
} else if ( geometry.type === 'BufferGeometry' ) {
32+
33+
const vertices = [];
34+
const vertex = new Vector3();
35+
const position = geometry.getAttribute( 'position' );
36+
37+
for ( let i = 0; i < position.count; i ++ ) {
38+
39+
vertex.fromBufferAttribute( position, i );
40+
vertices.push( vertex.x, vertex.y, vertex.z );
41+
42+
}
43+
44+
// if the buffer is non-indexed, generate an index buffer
45+
const indices = geometry.getIndex() === null
46+
? Uint32Array.from( Array( parseInt( vertices.length / 3 ) ).keys() )
47+
: geometry.getIndex().array;
48+
49+
return RAPIER.ColliderDesc.trimesh( vertices, indices );
50+
3151
}
3252

3353
return null;

0 commit comments

Comments
 (0)