Skip to content

Commit 3e39fcc

Browse files
authored
RapierPhysics: Support RoundedBoxGeometry (#31351)
1 parent c5f48e4 commit 3e39fcc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

examples/jsm/physics/RapierPhysics.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ function getShape( geometry ) {
1515

1616
// TODO change type to is*
1717

18-
if ( geometry.type === 'BoxGeometry' ) {
18+
if ( geometry.type === 'RoundedBoxGeometry' ) {
19+
20+
const sx = parameters.width !== undefined ? parameters.width / 2 : 0.5;
21+
const sy = parameters.height !== undefined ? parameters.height / 2 : 0.5;
22+
const sz = parameters.depth !== undefined ? parameters.depth / 2 : 0.5;
23+
const radius = parameters.radius !== undefined ? parameters.radius : 0.1;
24+
25+
return RAPIER.ColliderDesc.roundCuboid( sx - radius, sy - radius, sz - radius, radius );
26+
27+
} else if ( geometry.type === 'BoxGeometry' ) {
1928

2029
const sx = parameters.width !== undefined ? parameters.width / 2 : 0.5;
2130
const sy = parameters.height !== undefined ? parameters.height / 2 : 0.5;

examples/physics_rapier_basic.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3333
import { RapierPhysics } from 'three/addons/physics/RapierPhysics.js';
3434
import { RapierHelper } from 'three/addons/helpers/RapierHelper.js';
35+
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
3536
import Stats from 'three/addons/libs/stats.module.js';
3637

3738
let camera, scene, renderer, stats, controls;
@@ -131,9 +132,15 @@
131132

132133
}
133134

135+
const geometries = [
136+
new THREE.BoxGeometry( 1, 1, 1 ),
137+
new THREE.SphereGeometry( 0.5 ),
138+
new RoundedBoxGeometry( 1, 1, 1, 2, 0.25 )
139+
];
140+
134141
function addBody( ) {
135142

136-
const geometry = ( Math.random() > 0.5 ) ? new THREE.SphereGeometry( 0.5 ) : new THREE.BoxGeometry( 1, 1, 1 );
143+
const geometry = geometries[ Math.floor( Math.random() * geometries.length ) ];
137144
const material = new THREE.MeshStandardMaterial( { color: Math.floor( Math.random() * 0xFFFFFF ) } );
138145

139146
const mesh = new THREE.Mesh( geometry, material );

0 commit comments

Comments
 (0)