I built with vue3 and vite, and the problem seems to be the same~
if you want to share a project and show us what you are doing, we might be able to help
I have the same problem vite+TS
same goes here
This official sample project shows that Havok can work well with webpack:
Iām trying to figure out whatās about webpack configuration makes it tick here, but fails in my personal project. Which, btw, follows another babylonjs recommended approach of splitting app into 3 sections: app_package, docs and test_package. That may somehow mess up webpack bundling. Dunnoā¦
Not official, but well maintained
And yes - it should work without an issue. I will be happy to debug it with a (non) working project. I didnāt find one (unless I missed it. In that case I apologize :-))
You can try adding the following setting to vite.config:
optimiseDeps: {
exclude: [ā@babylonjs/havokā],
},
Iām stuck on this with a vite app (eg canāt get havok to load via npm) too. Iām completely new to babylonjs + havok, so could be a skill /user issue lol. I stripped out basically everything here in a bare vite app: GitHub - heathhenley/babylon-vite-havok-test
Iām getting errors loading the wasm files for Havok:
It looks like itās looking for it in ānode_modules/.vite/deps/HavokPhysics.wasmā, but itās installed in ānode_modules/@babylonjs/havok/lib/esmā.
As a hack I copied it over to ānode_modules/.vite/depsā and it loads at least - maybe there is some config to set up for this with vite?
Please bear with the response time as @RaananW is off until next Wednesday
Hi!
Has there been any update on this?
I am working with Vite and Babylon too and encountered same issue with Havok physics. As a work around in dev, we have moved in the node_modules but we are unable to build anything as well.
iāll have to take a look at a vite project with havok. Vite shouldnāt move the path from which the file is loaded, so I am not entirely sure what is going on there.
Assigning to me, iāll find time to look into that
So, this is a known issue in vite. For example - 404 error fetching bindings_wasm_bg.wasm when running rollup on the browser Ā· Issue #14609 Ā· vitejs/vite Ā· GitHub and `new URL(foo, import.meta.url)` doesn't work when dependency was optimized Ā· Issue #8427 Ā· vitejs/vite Ā· GitHub . Until they fix it (the second issue is still open) you will need to add that to your vite config:
This will ignore optimizing the havok package. the only optimization happening there, as it seems, is the wasm file, so it shouldnāt influence your build size or build process.
Hi !
Do you have any update on this ? Even when I add the :
optimizeDeps: {
exclude: ['@babylonjs/havok'],
},
I still got an error, which is :
Uncaught (in promise) TypeError: this._physicsEngine.removeImpostor is not a function
The error is on this line :
ground.physicsImpostor = new PhysicsImpostor(ground, PhysicsImpostor.BoxImpostor, {mass: 0}, scene);
Iām using VueJS + Vite.
PS : This is my first Babylon project, Iām totally new on it so I might miss something :c
Can you share a link to your project?
Sure, here it is : GitHub - Golden-Legends/golden-legends at feature/first-game-logic !
This happens because you are using the old physics API (āPhysicsImpostorā) with a new physics engine (Havok).
You can get started here - Using A Physics Engine | Babylon.js Documentation (babylonjs.com) .
Thank you !! It works fine now !
Hi!
So I just wanted to share some things I done with this to help anyone in the future. My current setup is working with Docker, Vite and TypeScript and I had some issues in relation to the HavokPhysics.wasm file and issues with building what I was working on to say build or run dev and take to a web page for example.
With the HavokPhysics.wasm, in my package.json, I created an additional script called āhavokā and had it copy the wasm file from the node_modules to the correct .vite/deps location in the node_modules. Not the most conventional method but it worked and saved copying and pasting when needed to get it to work on when running my scene. I generally just right click the location and get that copied path.
"havok": "cp *HavokPhysics.wasm location* *.../node_modules/.vite/deps location*",
I also had to make sure when building that the wasm file was in a public folder too and once built and taken to another project to be loaded in, that the āHavokPhysics.wasmā file that came through in the build ādistā folder was included in the project main directory under āassetsā and it worked efficiently for me.
Additionally when building I had to include a āvite.config.jsā file which included the following:
import { defineConfig } from "vite";
export default defineConfig({
esbuild: {
supported: {
'top-level-await': true //browsers can handle top-level-await features
},
}
})
Without this, it didnāt let me build anything. I have seemed to get things working now with Havok Physics etc. Although itās not conventional until I believe Vite side of things work on a solution. I thought Iād share my insight on what Iāve done! If you see anything you think could be tailored or changed to improve, it would be grand to know. I think I may have to include what you mentioned previously to avoid some steps I may have done.
I thought Iād just share some steps on getting scenes to work further with it in this setup and if planning on building!
Thanks!