Skip to content

Commit a3fe811

Browse files
authored
Examples: Fix shadows in physics instancing demos. (#30988)
* Examples: Fix shadows in physics instancing demos. * Clean up.
1 parent df905b3 commit a3fe811

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

examples/physics_ammo_instancing.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,24 @@
6060
dirLight.shadow.camera.zoom = 2;
6161
scene.add( dirLight );
6262

63-
const floor = new THREE.Mesh(
63+
const shadowPlane = new THREE.Mesh(
64+
new THREE.PlaneGeometry( 10, 10 ),
65+
new THREE.ShadowMaterial( {
66+
color: 0x444444
67+
} ),
68+
);
69+
shadowPlane.rotation.x = - Math.PI / 2;
70+
shadowPlane.receiveShadow = true;
71+
scene.add( shadowPlane );
72+
73+
const floorCollider = new THREE.Mesh(
6474
new THREE.BoxGeometry( 10, 5, 10 ),
65-
new THREE.ShadowMaterial( { color: 0x444444 } )
75+
new THREE.MeshBasicMaterial( { color: 0x666666 } )
6676
);
67-
floor.position.y = - 2.5;
68-
floor.receiveShadow = true;
69-
floor.userData.physics = { mass: 0 };
70-
scene.add( floor );
77+
floorCollider.position.y = - 2.5;
78+
floorCollider.userData.physics = { mass: 0 };
79+
floorCollider.visible = false;
80+
scene.add( floorCollider );
7181

7282
//
7383

examples/physics_jolt_instancing.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,24 @@
5858
dirLight.shadow.camera.zoom = 2;
5959
scene.add( dirLight );
6060

61-
const floor = new THREE.Mesh(
61+
const shadowPlane = new THREE.Mesh(
62+
new THREE.PlaneGeometry( 10, 10 ),
63+
new THREE.ShadowMaterial( {
64+
color: 0x444444
65+
} ),
66+
);
67+
shadowPlane.rotation.x = - Math.PI / 2;
68+
shadowPlane.receiveShadow = true;
69+
scene.add( shadowPlane );
70+
71+
const floorCollider = new THREE.Mesh(
6272
new THREE.BoxGeometry( 10, 5, 10 ),
63-
new THREE.ShadowMaterial( { color: 0x444444 } )
73+
new THREE.MeshBasicMaterial( { color: 0x666666 } )
6474
);
65-
floor.position.y = - 2.5;
66-
floor.receiveShadow = true;
67-
floor.userData.physics = { mass: 0 };
68-
scene.add( floor );
75+
floorCollider.position.y = - 2.5;
76+
floorCollider.userData.physics = { mass: 0 };
77+
floorCollider.visible = false;
78+
scene.add( floorCollider );
6979

7080
//
7181

examples/physics_rapier_instancing.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,24 @@
5858
dirLight.shadow.camera.zoom = 2;
5959
scene.add( dirLight );
6060

61-
const floor = new THREE.Mesh(
61+
const shadowPlane = new THREE.Mesh(
62+
new THREE.PlaneGeometry( 10, 10 ),
63+
new THREE.ShadowMaterial( {
64+
color: 0x444444
65+
} ),
66+
);
67+
shadowPlane.rotation.x = - Math.PI / 2;
68+
shadowPlane.receiveShadow = true;
69+
scene.add( shadowPlane );
70+
71+
const floorCollider = new THREE.Mesh(
6272
new THREE.BoxGeometry( 10, 5, 10 ),
63-
new THREE.ShadowMaterial( { color: 0x444444 } )
73+
new THREE.MeshBasicMaterial( { color: 0x666666 } )
6474
);
65-
floor.position.y = - 2.5;
66-
floor.receiveShadow = true;
67-
floor.userData.physics = { mass: 0 };
68-
scene.add( floor );
75+
floorCollider.position.y = - 2.5;
76+
floorCollider.userData.physics = { mass: 0 };
77+
floorCollider.visible = false;
78+
scene.add( floorCollider );
6979

7080
//
7181

0 commit comments

Comments
 (0)