I have written the code below to create two spheres using cannonjs with Three.js for rendering.
var world, mass, body, shape, timeStep=1/60,
camera, scene, renderer, geometry, material, mesh;
initThree();
initCannon();
animate();
function initCannon() {
// Code for initializing Cannon physics
}
function initThree() {
// Code for initializing Three.js graphics
}
function animate() {
// Animation loop
}
function updatePhysics() {
// Update physics
}
function render() {
// Render scene
}
When I run this code, only the second sphere animates while the first one remains static. The association between the cannonjs body and Three.js mesh seems to be off. I tried adding "body.mesh=mesh", but it didn't solve the issue.
The mesh declaration was originally in initThree(), but I'm unsure if that is causing the problem.
Can someone please help me figure out what I am doing wrong? Let me know if you need more details.