This is correct!
So I tested with the the linked version of Ammo and had no issue with creating my build. I investigated the glue code to see if it had any similar import commands to the dist of the joly-physics library, and it did not.
The specific line of code that can be found on line 11 jolt-physics.wasm.js (from ‘dist’) is:
```if(fa){const {createRequire:a}=await import(“module”);var require=a(import.meta.url)}```
Removing this line results in a successful build, but there are a couple of interesting caveats.
- Scripts cannot be concatenated (Sounds like this is a known issue)
It seems like the paths to the resources are broken.
When I attempt to visit the built project, the Jolt initialization fails because it cannot find the glue code. Closer inspection reveals that the project is looking for the files at:
[PROJECT]/js/esm-scripts/Scripts/lib/js/esm-scripts/Scripts/lib/jolt-physics.wasm.mjs
While the files are actually at:
[PROJECT]/js/esm-scripts/Scripts/lib/jolt-physics.wasm.mjs
If I add the extra folder layers in my S3 bucket, the project works with no issues. It’s weird because I use ```assets.find().getFileUrl()``` to find the required assets:
import { Script } from 'playcanvas';
import { init } from './lib/physics.min.mjs';
export class PhysicsInit extends Script {
static scriptName = 'joltPhysics';
async initialize() {
try {
console.log("Initializing Jolt Physics...");
const wasmAsset = this.app.assets.find('jolt-physics.wasm.wasm').getFileUrl();
const glueAsset = this.app.assets.find('jolt-physics.wasm.mjs').getFileUrl();
const dispatcherAsset = this.app.assets.find('dispatcher.min.mjs').getFileUrl();
await init(this.app, {
fixedStep: 1 / 60,
// useSharedArrayBuffer: true,
// useWebWorker: true,
useMotionState: true,
wasmUrl: wasmAsset,
glueUrl: glueAsset,
dispatcherUrl: dispatcherAsset,
contactEventsEnabled: true,
});
this.app.fire('physics:ready');
console.log("Jolt Physics Initialized!");
} catch (err) {
console.error("Failed to init physics:", err);
}
}
}
I’m going to try setting them as Asset attributes and see if that fixes the pathing issues.
Edit: Actually scratch that. I thought through it. Setting the assets to attributes would result in the same problem since the physics init function requires URL’s as the asset parameters.
Edit: I think I fixed the file finding my reconstructing my asset URL’s the same way the physic’s library does, at least for Playcanvas hosted builds, but I’m assuming it should work for self hosted builds. Will report back, if not.