I am looking to efficiently load multiple JSON models and store them in global variables for easy access. This will streamline tasks like copying, translating, and more without the need to reload a model each time.
After trying various methods, I have noticed that the loading of these models occurs asynchronously.
It seems that the models are being loaded after all other processes have completed. Consequently, when I try to access the variables, they remain empty or do not function as expected. Is there a way to prioritize loading the models first, waiting for completion, and then proceeding with the rest of my code including functions like init()?
For example:
var loader = new THREE.JSONLoader();
// Global object variables
var test1 = new THREE.Object3D();
var test2 = new THREE.Object3D();
// More Object3D declarations follow
loadParts();
init();
animate();
function init() {
// Clone object
var newPart = test1.clone();
console.log("new part ID: " + newPart.id);
// Additional functionalities...
}
function loadParts() {
// Load different models using the Three.js loader
}
function createPart(geometry, materials, object3Dtemp) {
// Create a new three.js Mesh object
}
function placePart(object3Dtemp, x, y, z) {
// Place a cloned object at specific coordinates
}
In the console, you may see output similar to:
New part ID: 12
THREE.WebGLRenderer framework initialized
Model parts created: 21, 22, 23, and so on...