From ba0867769b8b26f8dc8f51041fb55cdf3dd14f8e Mon Sep 17 00:00:00 2001 From: Fermin Date: Sat, 27 Jul 2024 01:19:50 +0200 Subject: [PATCH 1/3] RapierPhysics: Add triangular mesh collider --- examples/jsm/physics/RapierPhysics.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/jsm/physics/RapierPhysics.js b/examples/jsm/physics/RapierPhysics.js index 872e082eec96ec..7c06655457b611 100644 --- a/examples/jsm/physics/RapierPhysics.js +++ b/examples/jsm/physics/RapierPhysics.js @@ -28,6 +28,17 @@ function getShape( geometry ) { const radius = parameters.radius !== undefined ? parameters.radius : 1; return RAPIER.ColliderDesc.ball( radius ); + } else if ( geometry.type === 'BufferGeometry' ) { + + const vertices = geometry.getAttribute( 'position' ).array; + + // if the buffer is non-indexed, generate an index buffer + const indices = geometry.getIndex() === null + ? Uint32Array.from( Array( parseInt( vertices.length / 3 ) ).keys() ) + : geometry.getIndex().array; + + return RAPIER.ColliderDesc.trimesh( vertices, indices ); + } return null; From ff1c733421f6f6baaedf79ccda55f6d96bb9112d Mon Sep 17 00:00:00 2001 From: Fermin Date: Sat, 27 Jul 2024 08:47:37 +0200 Subject: [PATCH 2/3] Formatting --- examples/jsm/physics/RapierPhysics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsm/physics/RapierPhysics.js b/examples/jsm/physics/RapierPhysics.js index 7c06655457b611..c925bf83ec0e93 100644 --- a/examples/jsm/physics/RapierPhysics.js +++ b/examples/jsm/physics/RapierPhysics.js @@ -36,7 +36,7 @@ function getShape( geometry ) { const indices = geometry.getIndex() === null ? Uint32Array.from( Array( parseInt( vertices.length / 3 ) ).keys() ) : geometry.getIndex().array; - + return RAPIER.ColliderDesc.trimesh( vertices, indices ); } From 4011369c4e20a95db4d3e625f3a84c22a76c70d3 Mon Sep 17 00:00:00 2001 From: Fermin Date: Sat, 27 Jul 2024 18:41:41 +0200 Subject: [PATCH 3/3] Add support for interleaved buffers --- examples/jsm/physics/RapierPhysics.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/jsm/physics/RapierPhysics.js b/examples/jsm/physics/RapierPhysics.js index c925bf83ec0e93..20ed2af8a817c4 100644 --- a/examples/jsm/physics/RapierPhysics.js +++ b/examples/jsm/physics/RapierPhysics.js @@ -30,7 +30,16 @@ function getShape( geometry ) { } else if ( geometry.type === 'BufferGeometry' ) { - const vertices = geometry.getAttribute( 'position' ).array; + const vertices = []; + const vertex = new Vector3(); + const position = geometry.getAttribute( 'position' ); + + for ( let i = 0; i < position.count; i ++ ) { + + vertex.fromBufferAttribute( position, i ); + vertices.push( vertex.x, vertex.y, vertex.z ); + + } // if the buffer is non-indexed, generate an index buffer const indices = geometry.getIndex() === null