Changes in Physics, adding Controls and more flexibility

Hey Monkeys,



I have made some big changes to the jME3 physics.

Physics objects are no longer Nodes but exist in three different forms:


  • Bullet Controls -

    This is the new recommended way to do physics, these Controls can be applied to a Spatial to make it move according to the physics. These control classes directly extend the new Bullet Objects. Controls should be a way more flexible way to use physics, also dynamically.


  • Bullet Nodes -

    These Nodes have Bullet Controllers attached and wrap their methods to “simulate” the old physics nodes. The setLocalTranslation() info is transferred to the Bullet Objects (although not in a continuous manner anymore).


  • Bullet Objects -

    These are mostly wrapped bullet classes like RigidBody, GhostObject etc. and can be used to create new physics functions. Users will mostly use the former two types which internally use these objects.



    Don’t be afraid, you can continue like you are used to and have only minimal changes to your code by using the supplied new PhysicsNode / PhysicsCharacterNode etc.



    I will commit the changes shortly, any input is very welcome.



    Other changes include a better debug display and the new HullCollisionShape for wrapping complex meshes (also used as “dynamic mesh shape” now instead of GImpactCollisionShape).



    Cheers,

    Normen
5 Likes

Impressive :wink: !

Committed to svn, expect some fixes etc. still

Awesome normen, been watching ur commits. And testin them also… so heres some feedback.

Vehicle wheels act funny: http://img508.imageshack.us/img508/9228/lol2x.png

And the hover tank physics test kinda fels permanent 0 fps…



Best of luck normen, you’re awesome!

Added a possible fix for the lagging wheels and the hover thing might be due to you having assertions enabled? I can run it quite fine, although its not working properly yet.

It looks like the “create/update mesh” in the SceneComposer is broken. When I click on my terrain node and then press the “create/update mesh” button, my terrain is no longer visible in the SceneComposer.



This is the exception:

java.lang.IndexOutOfBoundsException

at java.nio.Buffer.checkIndex(Buffer.java:514)

at java.nio.DirectIntBufferU.get(DirectIntBufferU.java:209)

at com.jme3.scene.mesh.IndexIntBuffer.get(IndexIntBuffer.java:52)

at com.jme3.bullet.util.Converter.convert(Converter.java:171)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:70)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.(MeshCollisionShape.java:65)

at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:183)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:65)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:89)

at com.jme3.bullet.util.CollisionShapeFactory.createMeshCompoundShape(CollisionShapeFactory.java:98)

at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:139)

at com.jme3.gde.scenecomposer.SceneEditorController.doCreatePhysicsMesh(SceneEditorController.java:316)

at com.jme3.gde.scenecomposer.SceneEditorController$4.call(SceneEditorController.java:297)

at com.jme3.app.AppTask.invoke(AppTask.java:141)

Caused: java.util.concurrent.ExecutionException

at com.jme3.app.AppTask.invoke(AppTask.java:157)

at com.jme3.app.Application.update(Application.java:439)

at com.jme3.gde.core.scene.SceneApplication.update(SceneApplication.java:221)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:226)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

[catch] at java.lang.Thread.run(Thread.java:619)

This rather looks like a broken mesh. Specifically a mesh that isnt consisting of triangles.

Ok. That’s strange, because I haven’t changed the terrain before the physics update. After the update my car felt throught the terrain. That’s why I tried to generate the CollisionShape again.



I will try to generate the terrain and the CollisionShape again then.



Thanks for the quick answer.

uhh sorry… not sure if I should have rather asked this in troubleshooting section.



Hi Normen,



not sure if I am totally off track here, but I saw that HelloCollision had an error after doing this update and saw that the CompoundCollisionShape was changed.



I messed around with the code and came up with this, by looking at the TestFancyCar that you updated with the HullCollisionShape:



[java] // We load the scene from the zip file and adjust its size.

assetManager.registerLocator("town.zip", ZipLocator.class.getName());

sceneModel = assetManager.loadModel("main.scene");

sceneModel.setLocalScale(2f);



Node sceneNode = (Node) sceneModel;

final Geometry sceneGeom = findGeom(sceneNode, "level");



// We set up collision detection for the scene by creating a

// compound collision shape and a physics node.



HullCollisionShape sceneShape = new HullCollisionShape(sceneGeom.getMesh());



//CompoundCollisionShape sceneShape =

// CollisionShapeFactory.createMeshCompoundShape((Node) sceneModel);

landscape = new PhysicsNode(sceneModel, sceneShape, 0);

landscape.attachDebugShape(assetManager);

[/java]



It does not seem to work so well to replace it with the HullCollisionShape :stuck_out_tongue:



What would be the best way to now do scenes with a few models in it like the town.zip after the update?



Thanks

Andre

@Norman: I have generated the terrain and the CollisionShape again, but now I get an error when the terrain is loaded in my application. I get this error now:

3-jan-2011 21:54:01 com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.UnsupportedOperationException: Not supported yet.

at com.jme3.bullet.control.PhysicsRigidBodyControl.cloneForSpatial(PhysicsRigidBodyControl.java:49)

at com.jme3.scene.Spatial.clone(Spatial.java:1120)

at com.jme3.scene.Node.clone(Node.java:573)

at com.jme3.scene.Node.clone(Node.java:59)



Do you know what this means ?

Vortex said:
@Norman: I have generated the terrain and the CollisionShape again, but now I get an error when the terrain is loaded in my application. I get this error now:
3-jan-2011 21:54:01 com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.UnsupportedOperationException: Not supported yet.
at com.jme3.bullet.control.PhysicsRigidBodyControl.cloneForSpatial(PhysicsRigidBodyControl.java:49)
at com.jme3.scene.Spatial.clone(Spatial.java:1120)
at com.jme3.scene.Node.clone(Node.java:573)
at com.jme3.scene.Node.clone(Node.java:59)

Do you know what this means ?

u were cloning smth? seems PhysicsRigidBodyControl cant be cloned yet.

Uh, yeah… Gotta add that code soon :smiley:

jatheron said:
It does not seem to work so well to replace it with the HullCollisionShape :P

No feature was taken away, if you were using dynamic mesh shapes for your terrain you were doing it wrong anyway :P If you really need to, you can still use GImpactShape manually.

Got a chance to add all the new physics goodness to jMP, it now displays Controls as subnodes in the SceneExplorer and allows you to create not only MeshCollisionShapes but also HullCollisionShapes for dynamic objects.



The new SceneComposer layout:





The SceneExplorer and Properties with a PhysicsRigidBodyControl.



Need to work on the icons still, anyone wiling to create an icon set for jMP? :smiley:



Also added a new Constructor for PhysicsRigidBodyControl, creating a mesh or hull collision shape is now as easy as

[java]spatial.addControl(new PhysicsRigidBodyControl(mass));[/java]

Based on the mass it will generate a Mesh/HeightMap collision shape (mass=0) or a HullCollisionShape for models etc.



Cheers,

Normen

Hi Norman,



It’s working again. Thanks for fixing this.

Vortex said:
Hi Norman,
It's working again. Thanks for fixing this.

No problem Vortax :P