PhysicsDebugShape is incorrect for scaled objects

Hi @normen @nehon .

I found that DebugShape for RigidBody is incorrect if object was scaled.

[java]
Node nd = assetManager.loadModel(“xx”);
Geometry geo = (Geometry) nd.getChild(0);
CollisionShape mshShape = new MeshCollisionShape(geo.getMesh());

                nd.setLocalScale(Vector3f.UNIT_XYZ.mult(0.5f)); // model is scaled at half
                mshShape.setScale(nd.getLocalScale()); // scale is applied to physics shape

[/java]

I also did video to show the issue:
[video]http://youtu.be/Cexn8S2sSUg[/video]

You can test it here:
Classes - http://code.google.com/p/jme-simple-examples/source/browse/#hg%2FJMESimpleExamples%2Fsrc%2Fcom%2FsimpleCharacterControl
Model - http://jme-simple-examples.googlecode.com/hg/JMESimpleExamples/assets/Models/blender_test_scene/blender_test_scene.blend

All I did just added “nd.setLocalScale(Vector3f.UNIT_XYZ.mult(0.5f))” to CharacterTest.java, Line 91.

1 Like

That’s playing with fire.

[java]Vector3f.UNIT_XYZ.mult(0.5f)[/java]

Just create the shape after you scale the model. At least in jbullet scaling the collision shapes is not consistent so I removed the applying of collision shape scales to the debug geometries.

@madjack said: That's playing with fire.

[java]Vector3f.UNIT_XYZ.mult(0.5f)[/java]

Actually no, as mult does return a scaled copy it’s not.

@madjack said: That's playing with fire.

[java]Vector3f.UNIT_XYZ.mult(0.5f)[/java]


What’s wrong there? It creates a new vector anyway.

@normen said: Just create the shape after you scale the model. At least in jbullet scaling the collision shapes is not consistent so I removed the applying of collision shape scales to the debug geometries.
I already tried it. If i scale before the shape creation, so the same effect.

The issue is that it scales the shape with a different value.It scales not 0.5f. It scales about 0.25f. I would appreciate if you check it.

Thats because you scale the root node. Either make the shape from the root node or scale the object you make the collision shape for. Do not scale the collision shapes.

@normen said: Thats because you scale the root node. Either make the shape from the root node or scale the object you make the collision shape for. Do not scale the collision shapes.

But physics work ok. I can jump on scaled house or cube. The only issue is the debug shape is not the same shape as the physical object.

I said “Playing with fire”, didn’t say it was wrong. :stuck_out_tongue:

I make it a habit to not do that kind of thing.

@mifth said: But physics work ok. I can jump on scaled house or cube. The only issue is the debug shape is not the same shape as the physical object.

As I said, if I add the scaling again then spheres etc. won’t scale correctly in the debug display, theres a reason the applying of scale is commented out.

@normen said: As I said, if I add the scaling again then spheres etc. won't scale correctly in the debug display, theres a reason the applying of scale is commented out.

Then you should to find the way how to solve the scaling issue for spheres and meshes. As the debugshape is in the mess. If i have many objects with a different scale - there will be real mess. Also, if scale>=2.0f , then my viewport will be in a mess of BIG debug shapes.
Old debug shape worked ok as far as i remember.

Another explanation ( @madjack the screen is for you too. Check my sys.out):

And here scale=2f. The debug is all in mess:

I repeat: Do not scale the collision shapes, just generate them from scaled geometry.

@normen said: I repeat: Do not scale the collision shapes, just generate them from scaled geometry.

if i don’t scale CollisionShape, then physics will not be scaled.

See the result:

Gha… Again, you make a collision shape from the UNSCALED geometry. Make the collision shape from the SCALED NODE or SCALE THE GEOMETRY.

1 Like
@normen said: Gha.. Again, you make a collision shape from the UNSCALED geometry. Make the collision shape from the SCALED NODE or SCALE THE GEOMETRY.

I do the collision shape from a geometry already.

Ok, i scaled the geometri instead the node. Result is the same:

Use CollisionShapeFactory.createMeshShape, the mesh is not scaled, the geometry is.

1 Like
@normen said: Use CollisionShapeFactory.createMeshShape

OOOoo!!! This way works ok!!! Thank you a lot! I did not know that i should use CollisionShapeFactory.

Thank you and sorry for bothering.
There are so many details in gamedev. :slight_smile:

The screen:

@normen said: Use CollisionShapeFactory.createMeshShape, the mesh is not scaled, the geometry is.

I found one issue with CollisionShapeFactory class. The class makes exception if jme-terrain library is not added.
But i don’t use Terrain library in my game.

Here is the exception:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NoClassDefFoundError: com/jme3/terrain/geomipmap/TerrainQuad
at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:164)
at com.pr.scene.PRSceneObject.testScene(PRSceneObject.java:117)
at com.pr.scene.PRSceneObject.(PRSceneObject.java:46)
at com.pr.main.PRGameManager.createScene(PRGameManager.java:36)
at com.pr.scene.PRSceneLoader.update(PRSceneLoader.java:72)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:287)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: com.jme3.terrain.geomipmap.TerrainQuad
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
… 11 more

Yeah, thats because it has to recognize terrain to be able to make HeightMapCollisionShapes. You can either just add the terrain libs (they are not exactly huge) or do the same as the CollisionShapeFactory does in your own class.

@normen said: Yeah, thats because it has to recognize terrain to be able to make HeightMapCollisionShapes. You can either just add the terrain libs (they are not exactly huge) or do the same as the CollisionShapeFactory does in your own class.

Ok, thanks. Then i’ll add the lib to have the code up to date.