我在访问事件边界之外的对象时遇到问题。如果我将对象放入一个数组并签出该数组,该数组也是空的,但在事件范围内它是满的。我需要知道如何访问事件范围之外的对象。
for (var i = 0; i < 19; i++){
var loader = new THREE.OBJMTLLoader();
loader.addEventListener( 'load', function ( event ) {
var tree = event.content;
myWorld.setWorldTreePosition(multiplier);
tree.position.y = 0;
tree.position.x = myWorld.myTreePosition.position.x;
tree.position.z = myWorld.myTreePosition.position.z;
tree.rotation.x = -(Math.PI / 2);
tree.scale.set(10,5,5);
scene.add( tree );
collidableMeshList2.push(tree);
tree.castShadow = true;
//collidableMeshList.push(tree);
multiplier += 500;
console.log(collidableMeshList2); // here it is full of trees.
}
);
loader.load( 'obj/Palm_Tree.obj', 'obj/Palm_Tree.mtl' );
//outside this all becomes empty.
console.log(collidableMeshList2); // here is list is empty but I don't know why.