diff --git a/examples/threejs.html b/examples/threejs.html
index 00e35477..a8a6bec3 100644
--- a/examples/threejs.html
+++ b/examples/threejs.html
@@ -32,8 +32,6 @@
// cannon.js variables
let world
let body
- const timeStep = 1 / 60
- let lastCallTime
initThree()
initCannon()
@@ -87,27 +85,13 @@
requestAnimationFrame(animate)
// Step the physics world
- updatePhysics()
+ world.fixedStep()
// Copy coordinates from cannon.js to three.js
mesh.position.copy(body.position)
mesh.quaternion.copy(body.quaternion)
- render()
- }
-
- function updatePhysics() {
- const time = performance.now() / 1000
- if (!lastCallTime) {
- world.step(timeStep)
- } else {
- const dt = time - lastCallTime
- world.step(timeStep, dt)
- }
- lastCallTime = time
- }
-
- function render() {
+ // Render three.js
renderer.render(scene, camera)
}
diff --git a/examples/threejs_cloth.html b/examples/threejs_cloth.html
index d34c9685..156654e7 100644
--- a/examples/threejs_cloth.html
+++ b/examples/threejs_cloth.html
@@ -27,10 +27,6 @@
* https://viscomp.alexandra.dk/?p=147
*/
- // Specify the simulation constants
- const timeStep = 1 / 60
- let lastCallTime
-
const clothMass = 1 // 1 kg in total
const clothSize = 1 // 1 meter
const Nx = 12 // number of horizontal particles in the cloth
@@ -210,24 +206,20 @@
function animate() {
requestAnimationFrame(animate)
controls.update()
- updatePhysics()
- render()
- stats.update()
- }
- // Step the physics world
- function updatePhysics() {
- const time = performance.now() / 1000
- if (!lastCallTime) {
- world.step(timeStep)
- } else {
- const dt = time - lastCallTime
- world.step(timeStep, dt)
- }
- lastCallTime = time
+ // Step the physics world
+ world.fixedStep()
+
+ // Sync the three.js meshes with the bodies
+ updateMeshes()
+
+ // Render three.js
+ renderer.render(scene, camera)
+
+ stats.update()
}
- function render() {
+ function updateMeshes() {
// Make the three.js cloth follow the cannon.js particles
for (let i = 0; i < Nx + 1; i++) {
for (let j = 0; j < Ny + 1; j++) {
@@ -246,8 +238,6 @@
// Make the three.js ball follow the cannon.js one
// Copying quaternion is not needed since it's a sphere
sphereMesh.position.copy(sphereBody.position)
-
- renderer.render(scene, camera)
}