I've been working on a function to load 3D objects using three.js.
My goal is for this function to return the 3D object once it's loaded, but no matter what I try, I keep getting "undefined".
function load3DObject(url, meshMaterial) {
let mesh;
let url3DObject = url;
let Object3dMaterial = meshMaterial;
loader.load(
url3DObject,
function(gltf) {
let ArrowModel = gltf.scene;
mesh = new THREE.Mesh(ArrowModel, Object3dMaterial);
mesh.castShadow = true; //default is false
mesh.receiveShadow = false; //default
scene.add(mesh);
scene.updateMatrixWorld(true);
Objects.push(mesh);
},
undefined,
function(error) {
console.error(error);
}
);
console.log(mesh);
return mesh;
}