LOOP ADDING ALL THE PLANETS TO THE SCENE
for (let i = 0; i < planets.length; i++) {
const planet = new Planet(planets[i]);
this.scene.add(planet.mesh);
//add the body to the scene
this.world.addBody(planet.body);
console.log(planet.body);
}
ANIMATE FUNCTION
animate() {
const timeElapsed = 1/60;
const dt = timeElapsed;
//update the world
this.world.step(1/60);
// Update the positions of the planets
for (let i = 0; i < planets.length; i++) {
planets[i].calculateOrbit(dt);
//set planets mesh to the planets body position
planets[i].mesh.position.copy(planets[i].body.position);
//animate the mesh to follow the updated position
planets[i].mesh.quaternion.copy(planets[i].body.quaternion);
planets[i].mesh.rotateY(0.01);
}
updateMeshes();
//call the distanceBetweenEarthAndSun function
this.distanceBetweenEarthAndSun();
this.controls.update(dt);
requestAnimationFrame(this.animate.bind(this));
this.renderer.render(this.scene, this.camera);
}```