What is this?
I’d like to share a little project I’ve been working on lately with the Babylon community. It’s a Babylon plugin for loading glTF files with embedded physics information, making it possible to load up a glTF file and get simulation working without any code. It’s very much a beta, but I’ve been using it for months without [too many] problems.
I’ve got a demo app running with some sample assets on GitHub: linky
The plugin is available on NPM here and contains info on how to start using it in your project. Once the extension is loaded, you can load glTF+physics files as normal and stuff will start moving! Bug reports are welcome (bug fixes are even more welcome!)
Not only is there a Babylon plugin to load the physics, there’s also a Blender exporter, allowing physics properties to be configured in Blender and loaded straight into Babylon.
Little bit of extra background
There’s actually two glTF extensions added in the NPM package; one called “MSFT_rigid_bodies” and one called “KHR_rigid_bodies” - they both do pretty much the same thing at the moment. On the Havok team, we made the MSFT_rigid_bodies version a few years ago, while the KHR_rigid_bodies version is a version we (along with several others) want to get officially supported in glTF, so it’s in active development. I can promise we won’t make breaking changes to MSFT_rigid_bodies, but might do so for KHR_rigid_bodies.If you want a stable experience, I’d suggest using the “MSFT” version, while, if you want the bleeding edge, “KHR” is the way to go.
Sounds great! How do I get started?
Easy. Install the plugin:
npm install babylon-gltf-rigid-body-loader
And register it with Babylon:
import { GLTF2 } from "@babylonjs/loaders";
import { MSFT_RigidBodies_Plugin } from "babylon-gltf-rigid-body-loader";
GLTF2.GLTFLoader.RegisterExtension(
"MSFT_rigid_bodies", function (loader) {
return new MSFT_RigidBodies_Plugin(loader);
});
That’s it! Then just load your glTF files!
You want to use Blender to export physics data? Also easy!
Download and unzip the Blender addon, then, in Blender, add the MSFT_rigid_bodies_file.py in the Addons settings. The README has some more info and pictures. This will get you the stable “MSFT” plugin version; if you want the latest-and-greatest, head on over to the main branch and get started (bug reports and bug fixes also welcome!)