Collision detection with moving custom Mesh

Hi,



i have discovered few weeks ago JME and i have a problem with collision detection.

I’m making a game in which user is allowed to modify ground (composed by square).

So i made a custom mesh in order to control which square the user want to move.

I follow advices given in an other topic in order to detect collision with the cursor position.

But detection ignore ground modifications (as if ground hasn’t been modified).



I haven’t found where the problem is. Please help me!



Here is part of my code:

[ collision detection ]

[java]

Ray ray = new Ray(cam.getWorldCoordinates(mouseCoords, 0),

cam.getWorldCoordinates(mouseCoords, 1).subtractLocal(

cam.getWorldCoordinates(mouseCoords, 0)).normalizeLocal());

CollisionResults results = new CollisionResults();

rootNode.updateModelBound();

rootNode.updateGeometricState();

rootNode.collideWith(ray, results);

CollisionResult collision = results.getClosestCollision();

Vector3f contact = collision.getContactPoint();

[/java]



[ modify heigh (altitude) of my custom mesh ]

[java]

public void setAltitude(int x, int y, int altitude){

Mesh mesh = this.m_geometry.getMesh();

FloatBuffer fb = (FloatBuffer)mesh.getBuffer(Type.Position).getData();

// Prepare buffer for read/write operations

fb.clear();



int index = (xthis.m_lines + y)43 + 2;

float alt = altitude
m_units.z;

fb.put(index, alt);

fb.put(index+3, alt);

fb.put(index+6, alt);

fb.put(index+9, alt);



// End buffer about read/write operations

mesh.getBuffer(Type.Position).updateData(fb);

fb.clear();

this.m_geometry.updateModelBound();

this.m_geometry.updateGeometricState();

}

[/java]

http://hub.jmonkeyengine.org/groups/physics/forum/topic/detaching-child-and-collision/



possibly it will be helpful.

Hi,



I think that’s not a node problem.

maybe a picture will be easier to understand where the problem is.



http://imgur.com/yFumC.png



PS: The picture representing a bear head is applyied to 1 Mesh, and the green thing was made qith an other mesh. (Total: 2 meshes for the ground, 1 mesh for the ‘ground cursor’)

What version of jME are you using? Alpha-3 or the latest nightly, I think the collision data has to be reset for the terrain when its modified, maybe @Sploreg can tell us more?



Edit: Oh, I thought you were using TerraMonkey. So yeah, the BIH collision data has to be rebuilt for the change to work via mesh.createCollisionData().

2 Likes

Thank you normen, it works!

Awesome, thanks guys. I have been stuck on a very similar issue for hours… I modified a custom mesh but the collision data wouldn’t update.



I tried searching for jme3 updateModelBound collision issue updateData updateBounds picking updateCollisionTree updateData. I list the search terms here so if anyone else is stuck on the same issue it might help direct them to this post.