所以我有我的Car类的这个方法,我想返回网格,但它返回未定义。问题是,即使我在离开carLoader后尝试在控制台上显示它也是未定义的,如果我在carLoader.load(..)中调用console.log就可以了。问题是如何存储它以便我可以使用它?
this.loadCarToScene = function ( carsVector,carName ) {
var carLoader = new THREE.BinaryLoader();
var mesh;
carLoader.load( carsVector[Object.keys(carsVector)[0]].url, function( geometry ) {
geometry.sortFacesByMaterialIndex();
console.log("url--->"+carsVector[Object.keys(carsVector)[0]].url);
var m = [],
s = carsVector[ Object.keys(carsVector)[0] ].scale * 1,
p = carsVector[ Object.keys(carsVector)[0] ].position,
r =carsVector[ Object.keys(carsVector)[0] ].init_rotation;
for ( var i in carsVector[ Object.keys(carsVector)[0] ].mmap ) {
m[ i ] = carsVector[ Object.keys(carsVector)[0] ].mmap[ i ];
}
mesh = new THREE.Mesh( geometry, m );
mesh.rotation.x = r[ 0 ];
mesh.rotation.y = r[ 1 ];
mesh.rotation.z = r[ 2 ];
mesh.scale.x = mesh.scale.y = mesh.scale.z = s;
mesh.position.set( p[0], p[1], p[2]);
scene.add(mesh);
return mesh;
});
console.log("mesh---->" + mesh );
}