createBox = (width, height, depth, position) => {
const mesh = new THREE.Mesh(boxGeometry, boxMaterial);
mesh.castShadow = true;
mesh.scale.set(width, height, depth);
mesh.position.copy(position);
scene.add(mesh);
const shape = new CANNON.Box(
new CANNON.Vec3(width * 0.5, height * 0.5, depth * 0.5)
);
const body = new CANNON.Body({
mass: 1,
position: new CANNON.Vec3(0, 3, 0),
shape,
material: defaultMaterial
});
body.position.copy(position);
world.addBody(body);
objectsToUpdate.push({ mesh, body });
}