Seeking a way to efficiently load multiple models and access them outside the loader, I aim to adhere to the DRY (Don't Repeat Yourself) principle by creating a single function for loading and returning the object.
function loadObject(obj, mtl) {
var loader = new THREE.OBJMTLLoader();
return loader.load( obj, mtl, function ( object ) {
return object;
});
}
However, when I utilize this in the main function:
var box = loadObject('box.obj', 'box.mtl');
scene.add(box);
I encounter the following error:
THREE.Object3D.add: object not an instance of THREE.Object3D. undefined