Hi, I’m probably not the first person to look for a “lighter” version of ammo, so what are the options?
Is it possible to reduce the overall size somehow? Is all the “code” that is in the files fully used in PlayCanvas? Perhaps is it possible to re-build only with what the engine uses?
Thanks for any info.
Hi @Newbie_Coder,
Yes, it’s possible, a few people have done this in the past.
PlayCanvas uses a .wasm compiled version of Ammo.js, build steps can be found here:
As soon as you are ready to build, open the ammo.idl
file and remove any methods that you are sure aren’t going to use. For example vehicles or debug drawer are good candidates to reduce the size.
Afterwards build, and replace the three ammo files in your project with the new ones.
Do you remember or have any information on how much of reduction was achieved?
@LeXXik do you remember out of your head any numbers?
Right, so first of all you might want to remove the JS version of Ammo. If you look inside the Ammo folder, there are 3 files - js version, wasm and js glue for wasm. JS version is only used as a fallback, when browser doesn’t support Wasm. Since all browsers do support it today, you can remove the JS version as it is not going to be used anyway and it has the largest size.
Then there is IDL, which you can modify to build a lighter version. Here is normal vs light:
// normal
ammo.wasm.js 441 KB
ammo.wasm.wasm 743 KB
// light
ammo.wasm.js 272 KB
ammo.wasm.wasm 519 KB
// difference
1184 - 791 = 393 KB
Well, that’s a big difference
Is there any chance that you have the files for the “light” version somewhere?
Or a list of what exactly you have removed from IDL?
I’m afraid I don’t have those available.
@TRT made a few different heap size builds for Ammo (JS heap memory Wasm occupies when it instantiates):
He might help building a light version, perhaps?
When I was building it, I removed the following:
- raycast vehicle
- debug drawer
- GIMPACT collision solver
- soft body sim
- kinematic character controller
Thank you guys
I get a lot of errors when I start to build, I must be using the wrong version of the source code?
[ 1%] Generating ammo bindings
[ 1%] Building ammo bindings
glue.cpp:403:33: error: cannot initialize a parameter of type 'btInternalTickCallback' (aka
'void (*)(btDynamicsWorld *, float)') with an lvalue of type 'void *'
self->setInternalTickCallback(cb);
^~
C:/Users/Lenovo/Desktop/Bullet/src/BulletDynamics/Dynamics/btDynamicsWorld.h:117:54: note: passing argument to parameter
'cb' here
void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo = 0, bool isPreTick = false)
^
glue.cpp:407:33: error: cannot initialize a parameter of type 'btInternalTickCallback' (aka
'void (*)(btDynamicsWorld *, float)') with an lvalue of type 'void *'
self->setInternalTickCallback(cb, worldUserInfo);
^~
C:/Users/Lenovo/Desktop/Bullet/src/BulletDynamics/Dynamics/btDynamicsWorld.h:117:54: note: passing argument to parameter
...
...
I have successfully managed to increase the size of lib…
I had forgotten the Google compiler, now I just need to figure out how to remove those unnecessary things before building.
Are these defaults in PlayCanvas?
# Default is 64*1024*1024 = 64MB
set(TOTAL_MEMORY 67108864 CACHE STRING "Total Memory")
# Enable for resizable heap, with some amount of slowness
set(ALLOW_MEMORY_GROWTH 0 CACHE STRING "Allow Memory Growth")
I think yes, those are the settings used in the PlayCanvas build.
I managed to squeeze that much:
But as soon as I get rid of the .JS version, I get errors when running with WASM + GLUE only, is it a bad “riddance” or do I need to do something further?
Example of an error:
TypeError: Ammo.btSphereShape is not a constructor
Update: Just builded fresh unchanged version of Ammo, identical error, I think the way it is loaded to the engine differs from the current Ammo version of Playcanvas
Update2: Ammo.js - Low heap Builds These builds are also having the same error once runned without fallback
Update3: Turns out it was just a little issue, to make it work you have to uncheck ‘Preload’ from every except ‘ammo.wasm.wasm’
Final version
I’m not a super techy guy so the build may not be perfect, I’ve only done basic tests, you can find the project with Ammo Light here:
https://playcanvas.com/project/1098315/overview/ammo-light
Thanks for sharing!