I am currently facing an issue with my animate()
function while using Three.js to generate an animation. Below is a simplified version of the code:
let obj;
let camera = new THREE.PerspectiveCamera(fov, asp, near, far);
let scene = new THREE.Scene();
const loader = new THREE.GLTFLoader();
async function init() {
obj = await loader.loadAsync("./public/modelo/scene.gltf");
scene.add(obj.scene);
animate(obj.scene.children[0]);
renderer.render(scene, camera);
function animate(objeto){
console.log(objeto);
requestAnimationFrame(animate);
objeto.rotation.z += 0.005;
renderer.render(scene, camera);
}
}
init();
Initially, the function performs correctly, but subsequent calls are causing issues as seen in my console.log()
output. The first run of animate()
displays the object as expected. However, all following calls only return a rapidly increasing floating-point number. I double-checked the object's integrity after the initial function call, so I'm perplexed by this behavior. Any recommendations or insights?