I am facing an issue where I have declared a global variable to store an OBJ loaded through THREE.OBJLoader, but when trying to animate the position or rotation of the object, I receive an error stating that the variable is undefined.
Below is how I have set up the scene including the variable spaceCraft:
<script>
var container;
var camera, scene, renderer;
var mouseX = 0,
mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var spaceCraft;
init();
animate();
function init() {
container = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);
camera.position.z = 250;
// Rest of the initialization code...
Here is how I load my model:
// Model loading
var loaderModello = new THREE.OBJLoader(manager);
var OBJPath = 'spaceCraft3.obj';
spaceCraft = loaderModello.load(OBJPath, function(object) {
// Loading and setting up the object...
Lastly, here are the animate() and render() functions:
//
}
function onWindowResize() {
// Resizing logic...
}
// Rest of the resize, mouse move and animation logic...
</script>
If anyone could provide some guidance on what might be causing this issue or suggest any improvements in clarity, it would be greatly appreciated. Thank you!