iso74
July 2, 2022, 12:11pm
1
Hello,
I have a question, where I must put the scripts to get this working:
pc.WasmModule.setConfig(‘Ammo’, {
glueUrl: '/lib/ammo/ammo.wasm.js',
wasmUrl: '/lib/ammo/ammo.wasm.wasm',
fallbackUrl: '/lib/ammo/ammo.js',
});
pc.WasmModule.getInstance('Ammo', demo);
iso74
July 2, 2022, 1:02pm
2
…and is this pc.WasmModule existing in engine?
Here’s an example I’ve put together: yaustar.github.io/physics-engine-example at master · yaustar/yaustar.github.io · GitHub
Running example: https://yaustar.github.io/physics-engine-example/
I’m not sure where pc.WasmModule comes from and will need to ask the person who put together the engine examples
iso74
July 4, 2022, 10:46am
4
Hi @yaustar Thank you very much!
I checked the engine commits, its not yet in release version https://github.com/playcanvas/engine/pull/4235
This will be a cool improvement to the engine!
Ah, that explains a lot. I was looking at main instead of the release branch. The released examples in example browser was using an external library file like I was
/* eslint-disable no-unused-vars */
// check for wasm module support
function wasmSupported() {
try {
if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") {
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
if (module instanceof WebAssembly.Module)
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
}
} catch (e) { }
return false;
}
// load a script
function loadScriptAsync(url, doneCallback) {
var tag = document.createElement('script');
tag.onload = function () {
doneCallback();
};
This file has been truncated. show original
iso74
July 4, 2022, 11:00am
6
@yaustar Thanks for clarifying, for now I use it like you did in your example:
if (wasmSupported()) {
loadWasmModuleAsync(
'Ammo',
'/js/ammo/ammo.wasm.js',
'/js/ammo/ammo.wasm.wasm',
modulesLoaded // Trigger event
);
}
Btw. Do you have a fair glue when the above (pc.WasmModule) will be released?
It would be released as part of v1.55 which is going to be in the next week or two
1 Like