BabylonJS / Editor

Community managed visual editor for Babylon.js
http://editor.babylonjs.com/
813 stars 232 forks source link

Add Support For Multiple Physics Engines #242

Closed undefinederror closed 3 years ago

undefinederror commented 3 years ago

Hi, just cloned the repo and opened the editor v4. The editor looks neat!

How would I enable physics? I see I can set the impostor on meshes but nothing happens when I play the scene. I tried to look for documentation about it but found nothing

Thank you

julien-moreau commented 3 years ago

Hey @undefinederror There is no documentation about physics at the moment as the Editor's documentation is still WIP Anyway, physics is enabled by default in workspaces, when you add an impostor, are you sure that its mass is different from 0 ?

If yes, can you verify that the physics gravity as a working value? You can access physics gravity options in the inspector by selecting the scene in the graph

undefinederror commented 3 years ago

Hi @julien-moreau Thank you for your quick reply!

Yes you are right, I didn't set gravity in Scene. I did it now and it indeed works. I see that cannonjs is the default engine. Should I wanna change it I suppose I should install the npm package and change that attaching a script to scene right?

julien-moreau commented 3 years ago

Hey, You are right only cannon.JS is supported at the moment in the editor but switching to Oimo.JS and Ammo.JS is in my todolist. Unfortunately you can’t switch engine in that easy way at the moment, as the serialized scene stores the physics engine to be « CannonJS ». Which engine would you like to use ?

undefinederror commented 3 years ago

Hey @julien-moreau ,

I would like to use Ammojs I tried onInitialize() image I see I have to disable the physics engine before enabling a different one. That inevitably also destroys all the Impostors created via editor :( I have no idea what impact CannonJS being in the serialized scene would have

julien-moreau commented 3 years ago

@undefinederror you are right, physics impostors created by the Editor are not compatible with AmmoJS as the encapsulated impostor are created using CannonJS :(

I'm adding the option in the Editor to choose the physics engine to use. Once chosen, it'll re-create all impostors taking the same parameters as you provided using the default physics engine.

I'll let you know once done :)

undefinederror commented 3 years ago

Yes that would be great. Thank you!

julien-moreau commented 3 years ago

@undefinederror done! I'm adding a documentation on what developers should handle when changing the physics engine.

undefinederror commented 3 years ago

Hi @julien-moreau, This is awesome. I am going to try it out and let you know

Thank you!

julien-moreau commented 3 years ago

I’m writing some documentation for the dev part. Because by default the project template imports cannonjs (in the index.html) and if the physics engine is changed, this import should be replaced by the desired engine (oimo or ammo in your case). If you don’t change this import, physics will not work anymore :)

julien-moreau commented 3 years ago

Hey @undefinederror just added the documentation: https://github.com/BabylonJS/Editor/blob/release/4.0.0/doc/08%20-%20using-physics/doc.md The last chapter "Choosing physics engine" will be the one for you

Don't hesitate to open another issue if you encounter any bug or have any feedback :)