[SOLVED] Trying to build a robot arm grabber using Ammo.js

Rag dolls are typically constructed from a number of sphere and capsule rigid bodies connected by hinge and cone-twist constraints/joints. @evandarcy previously linked a project I made ages ago which was an attempt to implement rag dolls:

https://playcanvas.com/editor/scene/468930

But frankly I’m not too happy with the implementation. I couldn’t quite figure out why certain joint were not rotating quite as I expected. That’s one of the reasons I started this new project, to resolve all of the issues I had before.

I was looking through the Ammo.js Git repository and reading about the process of exposing functions and then adding them to the ammo.idl file.

Is there a way for me to use my own version of ammo.js in Playcanvas or would I have to wait until a PR is submitted to ammo.js and you guys update your version?

I can see the functions I need in the Bullet Git repo but they’re out of reach through Playcanvas!

What is the reason that all functions aren’t exposed in ammo.js? Would that bloat the library too much?

There’s no official way to override/replace the version of ammo.js that we use. I’m wondering what would happen if you dropped a different version of ammo.js into your project and loaded that one after PlayCanvas’ one. I suspect there’d be some problems, but I’d have to try it.

We are doing some work at the moment though to allow you to add external JS libs and control how other frameworks in your project are loaded. Once we’ve done this, we could make ammo.js loading overridable potentially.

And you suspicions are correct. The ammo.idl was added because the library used to be huge and not everything was useful. So now, API has to be proactively requested in the build process for it to be exposed in ammo.js.

Okay good to know.

Is there anywhere I can get an idea of your planned roadmap/timeline? The reason I ask is because I am planning to use Playcanvas for a fairly major product we are developing in my startup revolving around robotics simulation. There are API functions that we don’t need exposed right now but we definitely will down the line.

I think it would be awesome if the option was there for developers to expose as much of the Bullet API as they needed and include it in their own build in Playcanvas.

I agree. There’s isn’t currently a public roadmap. We’re considering putting one together though.

For this particular feature though, the first part is actually done and about to be deployed to our dev server. The next step is an exploratory phase to figure out what this means for the ammo library. The thing we often find is that it’s difficult to commit a feature to a roadmap until we’ve investigated whether something is practical/possible. But yeah, we’re on it.

I forked ammo.js and exposed all functions I need for the slider. If I submit a PR and it gets merged, will Playcanvas update their version of Ammo.js?

I’m afraid it’s not as simple as that. In our version of ammo.js, once ammo is loaded, we can call Ammo.* quite happily. In the recent versions, you must do the following after loading ammo to initialize the Ammo object:

Ammo().then(function (Ammo) {
   // Use ammo here...
});

So we’d have to make some tweaks to the engine itself.

Like I explained before, we should first deploy our change to allow you to include JS frameworks in new ways (burn into the HTML page as a script tag before or after the engine, or specify external URLs to scripts in the page). This mechanism is the foundation of what we need for you to build your own version of ammo and replace whatever default we give you.

Okay and to reiterate, you are actively working on this change?

Yes but I’m not promising a delivery date at this stage. :slight_smile:

Once this script include feature is done, the dev team can have the conversation about what we can now do about ammo.js and webvr-polyfill too.

1 Like

But I will do my very best to make this work for you!

1 Like

Hey @will, I hope you would be willing to help me too please :slight_smile: I’m asking here, instead of creating a new topic, since this question is not to old and mine is pretty much just an extension.

I’m currently trying to build a trial bike, and your constraints helped me a great deal already. But I think I’m missing a crucial one, a spring constraint. I need it for the suspension of the front wheel.

I copied parts of the code you used to create several of your constraints, and then created a new Ammo.btGeneric6DofSpringConstraint(...), which kind of worked. But now I’m failing to set the right parameter for the spring, like setStiffness() and setDamping(). Also, I can’t find anything to give the spring an equilibrium point, like it’s described in the Bullet Documentation… Can you maybe help me please?

Thanks

1 Like

@will, although ammo is great, it falls short in some areas, namely sparse docs and absence of mesh to mesh collision. NVIDIA has recently made it’s popular physics engine, PhysX, open source. Since that’s written in C++, could we convert that to JS via Emscripten and then use it in PC? That would be absolutely fantastic.

Ammo is based off Bullet Physics, which is pretty much on par with PhysX.

@Mal_Duffin, the shortcomings I mentioned are addressed by PhysX.

@evandarcy The feature has now been deployed to production. Now, you can create a project and import the very latest build of Ammo into your project. This version of Ammo includes the fast WebAssembly based build. You can even replace the files with a custom build of Ammo. Enjoy!

1 Like

Fantastic! Thanks Will!

Instead of using PlayCanvas, I’d like to create my own webpage with a robot arm grasping a cube using Ammo.js.

I was really happy seeing this is already solved. Can you please that we know where I can find the code?

Many thanks in advance!

@Kavita_Krishnaswamy,

I don’t know if this is the right place for this. However, you could refer to Bullet Physics Documentation to get what you need.