Skip to content

Commit

Permalink
AmmoPhysics: Added addScene()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Oct 27, 2023
1 parent 5e43514 commit 92c71d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions examples/jsm/physics/AmmoPhysics.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ async function AmmoPhysics() {
const meshes = [];
const meshMap = new WeakMap();

function addScene( scene ) {

scene.traverse( function ( child ) {

if ( child.isMesh ) {

const physics = child.userData.physics;

if ( physics ) {

addMesh( child, physics.mass );

}

}

} );

}

function addMesh( mesh, mass = 0 ) {

const shape = getShape( mesh.geometry );
Expand Down Expand Up @@ -245,6 +265,7 @@ async function AmmoPhysics() {
setInterval( step, 1000 / frameRate );

return {
addScene: addScene,
addMesh: addMesh,
setMeshPosition: setMeshPosition
// addCompoundMesh
Expand Down
8 changes: 4 additions & 4 deletions examples/physics_ammo_instancing.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
);
floor.position.y = - 2.5;
floor.receiveShadow = true;
floor.userData.physics = { mass: 0 };
scene.add( floor );
physics.addMesh( floor );

//

Expand All @@ -83,6 +83,7 @@
boxes.instanceMatrix.setUsage( THREE.DynamicDrawUsage ); // will be updated every frame
boxes.castShadow = true;
boxes.receiveShadow = true;
boxes.userData.physics = { mass: 1 };
scene.add( boxes );

for ( let i = 0; i < boxes.count; i ++ ) {
Expand All @@ -93,15 +94,14 @@

}

physics.addMesh( boxes, 1 );

// Spheres

const geometrySphere = new THREE.IcosahedronGeometry( 0.05, 4 );
spheres = new THREE.InstancedMesh( geometrySphere, material, 400 );
spheres.instanceMatrix.setUsage( THREE.DynamicDrawUsage ); // will be updated every frame
spheres.castShadow = true;
spheres.receiveShadow = true;
spheres.userData.physics = { mass: 1 };
scene.add( spheres );

for ( let i = 0; i < spheres.count; i ++ ) {
Expand All @@ -112,7 +112,7 @@

}

physics.addMesh( spheres, 1 );
physics.addScene( scene );

//

Expand Down

0 comments on commit 92c71d7

Please sign in to comment.