Here’s a repo that uses Rollup to bundle BJS. Fast, lightweight, and fun. But keep reading…
I’m a newcomer to this community. And just I’m learning TypeScript ( so double Newbie!). I thought writing games would be a fun way to learn. But almost immediately I found a bug in BJS https://playground.babylonjs.com/#6QF3KP#3 - watch the middle pins.
I figured out the problem and solution from the Bullet/Ammo site. And thought, well, if it must be fixed, then I probably should fix it. More fun things to learn. So I forked BJS and downloaded it.
Two problems. The BJS build system is, well, impressive. I’m using a laptop, and it has never worked so hard for so long. It was smoking. The builder carries the legacy of every step of Babylon’s development. @trevordev shared this with me… Our Journey into the Module World. – Babylon.js – Medium Makes me feel better about the two days in hell I spent getting Rollup to work.
And BJS isn’t really written in TypeScript, there are all sorts of leftover JS chunks. TypeScript and VSCode have amazing tools available to refactor and improve big projects, but they need a cleaner codebase to start.
My guess is that very few of us are willing to touch the BJS codebase because of these two problems.
==================
OK, grab my repo (never mind the silly name, I was fiddling a game involving asteroids). Save it as a peer to the Babylon.js repo (I have them both in my /htdocs directory). run ‘npm install’ and then run ‘npm dev run’. Don’t laugh at my code, this is barely more than my ‘Hello World’.
It will fail. There are some circular references in Babylon that need to be fixed first. But you can get basic Babylon running with this ugly patch: Open 'Babyon.js/src/engines/engine.ts and
- comment out the "import { Materials } … " statement on line 16.
- neuter the _drawMode() function starting on line 3098.
==================
Now I need to fix the circular references before I can fix the Ammo problem. And that’s definitely not Newbie territory. There’s a bunch of draw___() functions in engine.ts that need to be moved out (probably to the render directory), and then the call to _drawMode() eliminated (it isn’t necessary when instantiating the engine). I’m happy to give it a try, but I need a mentor.
Using Rollup as a builder, with the speed and modern tooling that it provides, might be a wonderful platform to clean up the codebase. So I’m sharing what I have, and asking for feedback from the community.