As a beginner with Three.js, I am trying to add my 'model' object to an array. I believe my code is correct.
I have declared my variable as nextobj = [ ];.
function Loadobj() {
var mx = [-1500,1500] , my = [350,350] , mz = [-1000,-1000];
var nextobj = []; //Keeping Array Model
for(var i = 0; i < 2; i++) {
var mtloader = new THREE.MTLLoader();
mtloader.load('obj1/az-mp0076.mtl', function (materials) {
materials.preload();
var objloader = new THREE.OBJLoader();
objloader.setMaterials( materials );
objloader.load('obj1/az-mp0076.obj', function (object){
model = object;
model.position.set(mx[i],my[i],mz[i]);
scen.add(model);
nextobj.push(model);
console.log(nextobj.length); //Checking data in Object
});
});
}
}
Step 1:
When I loop through 1 Object, it's displayed
https://i.sstatic.net/3ktGD.jpg
Step 2
When I loop through more than 1 object, it is not displayed, but my data is complete.
https://i.sstatic.net/IIZVv.png
How can I add my objects to the array? Thank you.
I am unsure of what might be wrong in my code.