As a JavaScript newbie, I might be making some cringe-worthy mistakes in my code. My goal is to import a model using the Three.js GTLF Loader and define it as 'model' so that I can set it to automatically rotate.
My use of terminology may not be accurate, but this is the best way I can describe what I am attempting to do and where I need help.
I will share my whole code, but the error seems to be in this section:
var model;
var modelLoader = new GLTFLoader().setPath('models/DamagedHelmet/');
modelLoader.load('DamagedHelmet.gltf', function (gltf) {
model = gltf.scene;
gltf.scene.traverse(function (child) {
if (child.isMesh) {
roughnessMipmapper.generateMipmaps(child.material);
}
});
scene.add(model);
roughnessMipmapper.dispose();
render();
});
I have defined the object as model with the intention of having it continuously rotate automatically. I attempted to achieve this a few lines below in the following code snippet:
function render() {
renderer.render(scene, camera);
model.rotation.x += 0.01;
model.rotation.y += 0.005;
}
There might be something obvious that I'm missing or doing incorrectly. The solutions I found online seem to work only when JavaScript is not imported via a module (or so I believe).
Appreciate any guidance you guys have.