I am new to Three.js and I want to add my 'palmtree' object to an array. I believe my code is correct, but something seems off.
Here is the snippet of my code:
var objects = [];
var mtlLoader = new THREE.MTLLoader();
mtlLoader.load("objects/palmtree.mtl", function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.load("objects/palmtree.obj", function(palmtree) {
palmtree.position.x = 205.12577753354344;
palmtree.position.y = 2;
palmtree.position.z = -600.0613083252872;
palmtree.scale.x = 64;
palmtree.scale.y = 64;
palmtree.scale.z = 64;
scene.add(palmtree);
objects.push(palmtree);
});
});
After adding the palmtree object to the scene, I noticed that when I check objects.length
, it returns 0. I'm not sure what I'm doing wrong.
If you have any suggestions on how to properly push the palmtree object to the objects array, please let me know. Thank you!