Jump to content

The new Physics Engine architecture


RaananW
 Share

Recommended Posts

So!

I don't know how many of you have noticed the commit from yesterday, but Babylon's physics engine has a new architecture.

There is now a physics impostor class that will be your one-stop-shop for all physics needs. Applying impulse, force, changing velocity, everything is there. There is also a way to register callbacks to be called before and after the physics step and when the mesh collides against other meshes.

Those API might change a bit until 2.4 is officially out, but get used to the new architecture!

What's new? A lot!

A short list (before I finish writing the full documentation and tutorials):

  • Dedicated PhysicsImpostor for each mesh, dedicated PhysicsJoint for each joint/constraint
  • New Joint-System - Is is now possible to add many kinds of links (depends on the underlying physics plugin) - A Distance Joint, A Hinge, a Ball-And-Socket and more. Documentation is being written :) But just to get people interested - @Wingnut, you might find this a lot of fun - http://www.babylonjs-playground.com/#1ND6TH 
  • Physics plugin is mainly transparent - changing from cannon to oimo (and soon to the new energy engine) should simply work. Try it in the last playground example. 
  • Having said that - there is a way to execute native cannon/oimo code in a very simple way
  • New callback mechanism for before and after the physics step AND when an impostor collides against a specific impostor.
  • Two-Way transformation update - No need to execute updatePhysicsBody[Position]() - physics rotation and position is automatically updated.
  • A way to recreate the body, in case parameters like the scale has changed.
  • Physics Plugins rebuilt with performance adjustments. 
  • Set Velocity
  • Apply Force
  • And many many other little things

For those who want to see what was done under the hood, the PR is here - https://github.com/BabylonJS/Babylon.js/pull/983

Fell free to ask questions, and please wait patiently for the documentation that will arrive soon. (Or "sooner or later").

There are a lot of things on my TODO list to add to this engine (Spring objects, Physics-Particle-System, further joints and constraints and more), but this is step 1. And it is finally done :)

Enjoy physics!

 

Link to comment
Share on other sites

Thanks Raanan! 

Man, is it fast (with Cannon).  Much slower with Oimo, for me.  Did anyone else test the demo with Oimo?  Please report, thx.

Raanan, will you be attempting backwards-compat?

(Wingy notices a tiny water puddle under a frozen API)  :)  Global warming?

Link to comment
Share on other sites

@Wingnut - I did my best to keep everything backwards-compatible. If something is not working i would love to know in order to fix it.

Oimo was not changed, Cannon didn't either. The only thing that changed was the Babylon architecture. A bit of performance issues were fixed, but nothing that will really be noticeable on a normal computer. 

Having said that - My new favorite is Cannon.js for implementing complex physics scenes. The newest version is wonderful. Oimo's newest version is not working correctly for some reason. When I find out why I will upgrade to the newest Oimo as well. 

 

Link to comment
Share on other sites

  • 2 weeks later...
On 2/23/2016 at 1:13 AM, RaananW said:

and more. Documentation is being written :) But just to get people interested - @Wingnut, you might find this a lot of fun - http://www.babylonjs-playground.com/#1ND6TH

This playground seems to not work, I get an error of n is not a function. I would really like to see a working example of this so I can do a fully deployed vehicle demo, which I will include comments on for others to be able to do the same.

Link to comment
Share on other sites

Am I mistaken but can I dig through the methods available in my physics plugin by console.log(new BABYLON.CannonJSPlugin()) or Oimo depending on which I wanna dig through and checking what that objects prototypes are and locating what ever methods I need for rigging a vehicle?

Ive never done this before but I was just thinking that this might work, then I could stop bugging you guys for methods.

Link to comment
Share on other sites

Wow I'm a dummy... Yea this is the stuff I needed to look at the whole time.  I will be able to make it happen now thank you.


**EDIT**
http://www.babylonjs-playground.com/#TX01V#0

Im about to add controls and joints but I think I am going in the right direction?

*** ANOTHER EDIT ***
So I am trying to connect one tire at this point could someone help me figure out whats going on here?  Im not dropping any errors, but adding the joint effectively does nothing?
http://www.babylonjs-playground.com/#TX01V#4

Link to comment
Share on other sites

  • 2 weeks later...

Is the documentation of the new architecture of the phisics available?

I saw that on the mesh class had access to getPhysicMass() but no setPhysicsMass() function. But observing the new architecture, I saw that there was a setter getPhysicsImpostor().setParam("mass", 0) for changing the mass for example. I almost add the missing functions in the class AbstracMesh but this is not helpful with the new architecture. But the documentation would be cool  and seParam is cool too. :D

 

Link to comment
Share on other sites

so!

Basic usage (without getting too much into more advanced features) is documented here - http://doc.babylonjs.com/overviews/Using_The_Physics_Engine

To your question - physics and mesh are now totally separated. The old functions are there for legacy reasons, but from now on changing the physics mass, friction, or anything else will be done in the impostor.

I will document the more advanced features (like real-time mass changing and its consequences) in the next tutorial. 

I am planning at least two more tutorials - advanced usage and deeper understanding of joints. This might take some time, let me know if you have any questions to the basic usage. And the code is always there :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...