regna
July 6, 2025, 5:56am
1
Could we please have an option to inject a self-loaded MeshoptDecoder ?
Although we can do something like
BABYLON.MeshoptCompression.Configuration = {
decoder: {
url: "<url to the meshopt decoder library>"
}
};
this only works in the browser (but not Node , since BABYLON.Tools.LoadBabylonScriptAsync() doesn’t work in Node )
I’d like to be able to self-load meshopt_decoder.js and have Babylon.js detect that MeshoptDecoder is already loaded so that it doesn’t try to load it again
Thank you for your help
As a quick workaround, this should work, too:
// ↓↓↓ see also e.g. https://github.com/JamesJansson/importScripts/blob/master/importscripts.js
global.importScripts = function(url) { console.log("URL", url); }
const scriptUrl = "www.babylonjs.com";
const onSuccess = ()=>{ console.log("Success"); };
const onError = (msg)=>{ throw new Error(msg); };
//https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Misc/tools.ts#L583
if (typeof importScripts === "function") {
try {
importScripts(scriptUrl);
if (onSuccess) {
onSuccess();
}
} catch (e) {
onError?.(`Unable to load script '${scriptUrl}' in worker`, e);
}
}
When running in Node.js, it prints the url and “success”.
1 Like
regna
July 6, 2025, 10:57pm
3
Thank you so much, @Joe_Kerr , your approach works great! It inspired the workaround I ended up going with for now (overriding LoadBabylonScriptAsync() with an empty function):
BABYLON.Tools.LoadBabylonScriptAsync = async (url: string): Promise<void> => {};
1 Like