Skip to content

Commit 456aeca

Browse files
committed
AmmoPhysics: Add restitution support
1 parent e95f661 commit 456aeca

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

examples/jsm/physics/AmmoPhysics.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function AmmoPhysics() {
8383

8484
if ( physics ) {
8585

86-
addMesh( child, physics.mass );
86+
addMesh( child, physics.mass, physics.restitution );
8787

8888
}
8989

@@ -93,19 +93,19 @@ async function AmmoPhysics() {
9393

9494
}
9595

96-
function addMesh( mesh, mass = 0 ) {
96+
function addMesh( mesh, mass = 0, restitution = 0 ) {
9797

9898
const shape = getShape( mesh.geometry );
9999

100100
if ( shape !== null ) {
101101

102102
if ( mesh.isInstancedMesh ) {
103103

104-
handleInstancedMesh( mesh, shape, mass );
104+
handleInstancedMesh( mesh, shape, mass, restitution );
105105

106106
} else if ( mesh.isMesh ) {
107107

108-
handleMesh( mesh, shape, mass );
108+
handleMesh( mesh, shape, mass, restitution );
109109

110110
}
111111

@@ -129,6 +129,7 @@ async function AmmoPhysics() {
129129
shape.calculateLocalInertia( mass, localInertia );
130130

131131
const rbInfo = new AmmoLib.btRigidBodyConstructionInfo( mass, motionState, shape, localInertia );
132+
rbInfo.m_restitution = restitution;
132133

133134
const body = new AmmoLib.btRigidBody( rbInfo );
134135
// body.setFriction( 4 );
@@ -144,7 +145,7 @@ async function AmmoPhysics() {
144145

145146
}
146147

147-
function handleInstancedMesh( mesh, shape, mass ) {
148+
function handleInstancedMesh( mesh, shape, mass, restitution ) {
148149

149150
const array = mesh.instanceMatrix.array;
150151

@@ -163,6 +164,7 @@ async function AmmoPhysics() {
163164
shape.calculateLocalInertia( mass, localInertia );
164165

165166
const rbInfo = new AmmoLib.btRigidBodyConstructionInfo( mass, motionState, shape, localInertia );
167+
rbInfo.m_restitution = restitution;
166168

167169
const body = new AmmoLib.btRigidBody( rbInfo );
168170
world.addRigidBody( body );
@@ -302,6 +304,7 @@ async function AmmoPhysics() {
302304
* @name AmmoPhysics#addMesh
303305
* @param {Mesh} mesh The mesh to add.
304306
* @param {number} [mass=0] The mass in kg of the mesh.
307+
* @param {number} [restitution=0] The restitution of the mesh, usually from 0 to 1. Represents how "bouncy" objects are when they collide with each other.
305308
*/
306309
addMesh: addMesh,
307310

0 commit comments

Comments
 (0)