If have a problem when I use a loader for one of my function.
Here’s the code I writed:
export function loadSTL(filepath, colorRGB) {
let inst;
// Load STL file
const loader = new STLLoader();
loader.load(
filepath,
(geometry) => { inst = STLToInstance(geometry, colorRGB); },
);
return inst;
}
The purpose of this is to return the var inst when the load is done.
Unfortunately, the function return null so I thought that the function return before the end of the load.
Does someone have an idea of what can I do for this?
I looked at the example and didn’t find “loadAsync” in the code. No hits when I entered “loadAsync” into the examples search either. I would be great if there was a good example of how to use this feature - assuming it’s still the latest-greatest solution.
That’s a super helpful article. Thanks for writing it!
The reason that nested callbacks don’t work well for me is that I want to do a bunch of additional things to the model, such as scale it, color it, etc. It’s quite tricky to pass additional parameters into the callback to describe the additional work you want to do. While it is possible by making a separate function that returns the desired callback function, it takes a while to get this code to do what you want, its harder to debug, and what you end up with is hard for someone who’s not experienced with javascript to understand.