Deformable physical terrain

Hi,
I’ve modified the demo for deformable terrain (TerrainTestModifyHeight.java) by making the terrain solid and walkable: but when I change the height, the RigidBody of the Terrain is not modified (I see the “new” landscape but I walk on the “old” landscape). So I tried the following:

[java] public void adjH(Vector3f loc){
int tpf=5;
adjustHeight(loc, 64, -tpf * 6f);
//bulletAppState.getPhysicsSpace().remove(landscape);
CollisionShape sceneShape =
CollisionShapeFactory.createMeshShape(terrain);
terrain.addControl(landscape);
landscape = new RigidBodyControl(sceneShape, 0);
bulletAppState.getPhysicsSpace().add(landscape);

}[/java]

But unfortunately, it still doesn’t work :frowning:

Do you have any advice on modifying the heightmap? Should I load another image heightmap?

Thanks! :slight_smile:

You should activate the physics boundaries debugger. Will show you what boundaries are used.

I guess you don’t remove the old boundaries correctly and end up with the old and new one being used. Totally a shot in the dark though :smiley:

@Pesegato said: Hi, I've modified the demo for deformable terrain (TerrainTestModifyHeight.java) by making the terrain solid and walkable: but when I change the height, the RigidBody of the Terrain is not modified (I see the "new" landscape but I walk on the "old" landscape). So I tried the following:

[java] public void adjH(Vector3f loc){
int tpf=5;
adjustHeight(loc, 64, -tpf * 6f);
//bulletAppState.getPhysicsSpace().remove(landscape);
CollisionShape sceneShape =
CollisionShapeFactory.createMeshShape(terrain);
terrain.addControl(landscape);
landscape = new RigidBodyControl(sceneShape, 0);
bulletAppState.getPhysicsSpace().add(landscape);

}[/java]

But unfortunately, it still doesn’t work :frowning:

Do you have any advice on modifying the heightmap? Should I load another image heightmap?

Thanks! :slight_smile:

This is some of my old code that worked back when:

[java]
public void adjustHeight(Vector2f xz, float delta) {
terrain.adjustHeight(xz, delta);
bulletAppState.getPhysicsSpace().remove(terrain);
terrain.removeControl(terrainCollisionControl);
CollisionShape terrainShape =
CollisionShapeFactory.createMeshShape((Node) terrain);
createRigidbody(terrainShape);
bulletAppState.getPhysicsSpace().addAll(terrain);
}
[/java]

1 Like

@loopies I have debug active (I can see physic item and ghost item), but I don’t see terrain boudaries!

@Johan, thanks for your help, now my code looks like this:

[java] public void adjH(Vector3f loc){
int tpf=5;
adjustHeight(loc, 64, -tpf * 6f);
bulletAppState.getPhysicsSpace().remove(terrain);
terrain.removeControl(landscape);
CollisionShape terrainShape =
CollisionShapeFactory.createMeshShape((Node) terrain);
landscape = new RigidBodyControl(terrainShape, 0);
bulletAppState.getPhysicsSpace().addAll(terrain);

}[/java]

But I fall under the ground… I suspect your createRigidbody is different from my code…

I have a vague memory that jBullet does not show coliision shapes for terrain (although the native Bullet integration will). Anyhoo, my “createRigidBody” method has been lost in the mists of time but I don’t think it basically was anything more than new RigidBodyControl(terrainShape, 0); so I’m out of ideas, sorry I couldn’t help.

I’ve never used the terrain thingy so maybe something happening there, but my track editor allows adding and removing (physical) tracks so I’ll give you the code for that which I know works fine. Try that see if it works.

[java]
// no idea if order is important here
groupGroupNode.removeControl(physicsControl);
application.getStateManager().getState(BulletAppState.class).getPhysicsSpace().remove(physicsControl);
[/java]

[java]
private void makePhysical(Node groupGroupNode) {
CollisionShape nodeShape =
CollisionShapeFactory.createMeshShape((Node) groupGroupNode);
physicsControl = new RigidBodyControl(nodeShape, 0);
setCollisionGroups(physicsControl);//you probably don’t need that at this stage
groupGroupNode.addControl(physicsControl);//didn’t see you do that
gateCircuit.getApplication().getStateManager().getState(BulletAppState.class).getPhysicsSpace().add(physicsControl);
}
[/java]

1 Like

@loopies Many thanks! IT WORKS!!!

Here’s the code:

[java] public void adjH(Vector3f loc){
int tpf=5;
adjustHeight(loc, 64, -tpf * 6f);
terrain.removeControl(landscape);
bulletAppState.getPhysicsSpace().remove(landscape);
CollisionShape terrainShape =
CollisionShapeFactory.createMeshShape((Node) terrain);
landscape = new RigidBodyControl(terrainShape, 0);
terrain.addControl(landscape);
bulletAppState.getPhysicsSpace().add(landscape);

}

[/java] =D =D =D =D =D =D

You welcome :slight_smile: