I have also noticed that if I add rounded physics object at the center point (x, z = 0, 0) of the terrain it also falls through the terrain.
I can share a video if that would help.
I prefer executable sourcecode to video.
Sorry I can’t. Happens in my editor.
If you can’t reproduce the issue, how could anyone else do so?
The key take away from sgold’s message is that a simple test case makes a big difference.
…and from experience, 9 times out of 10, things will work fine in the simple test case and the issue-reporter has something to look into on their end.
Without a test case, no matter how hard someone looks into it, there will be this nagging thought in the back of their mind “Maybe it’s just a problem with ndebruyn’s editor setup”… which even if untrue will prevent the brain from really considering all solutions.
…and it might be true.
Thanks @pspeed for your thought on this.
Sometimes it helps to be kind.
I am in the process of setting up a TestCase for this. In my editor adding a terrain and quickly adding a sphere is a few seconds. However setting this up in code will take a bit more time.
At the end of the day, I am just trying to help the Minie library.
Sometimes it helps to be kind.
I love troubleshooting, and I appreciate your help with Minie. If my comments were brusque or rude, I apologize for that.
a simple test case makes a big difference.
Indeed.
Perhaps I am unusually code-oriented (or reluctant to “play 20 questions”). To me, any test case—even a complex one—is more welcome than a video or a verbal description of an issue.
Okay here is a test case that causes the issue. Seems like it has to do with:
CollisionShapeFactory.createDynamicMeshShape(ball)
Anyways, here is my test case:
public class TerrainTest extends SimpleApplication {
private BulletAppState bulletAppState;
private RigidBodyControl landscape;
private RigidBodyControl ballBody;
private Geometry ball;
private TerrainQuad terrain;
private Material mat_terrain;
public static void main(String[] args) {
TerrainTest app = new TerrainTest();
app.start();
}
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
flyCam.setMoveSpeed(100);
mat_terrain = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
mat_terrain.setTexture("Alpha", assetManager.loadTexture(
"Textures/Terrain/splat/alphamap.png"));
Texture grass = assetManager.loadTexture(
"Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex1", grass);
mat_terrain.setFloat("Tex1Scale", 64f);
Texture dirt = assetManager.loadTexture(
"Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex2", dirt);
mat_terrain.setFloat("Tex2Scale", 32f);
Texture rock = assetManager.loadTexture(
"Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
mat_terrain.setTexture("Tex3", rock);
mat_terrain.setFloat("Tex3Scale", 128f);
AbstractHeightMap heightmap = null;
Texture heightMapImage = assetManager.loadTexture(
"Textures/Terrain/splat/mountains512.png");
heightmap = new FlatHeightmap(128);
heightmap.load();
terrain = new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());
terrain.setMaterial(mat_terrain);
terrain.setLocalTranslation(0, 0, 0);
terrain.setLocalScale(2f, 0.5f, 2f);
rootNode.attachChild(terrain);
TerrainLodControl control = new TerrainLodControl(terrain, cam);
terrain.addControl(control);
terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().add(terrain);
//Add the ball
Sphere sphere = new Sphere(20, 20, 2);
ball = new Geometry("ball", sphere);
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", ColorRGBA.White);
ball.setMaterial(material);
rootNode.attachChild(ball);
ball.move(0, 20, 0);
ballBody = new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape(ball), 1);
// ballBody = new RigidBodyControl(new SphereCollisionShape(2), 1);
ball.addControl(ballBody);
bulletAppState.getPhysicsSpace().add(ballBody);
cam.setLocation(new Vector3f(-50, 30, 50));
cam.lookAt(new Vector3f(0, 10, 0), Vector3f.UNIT_Y);
}
}
@ndebruyn: Please provide code for the FlatHeightmap
class.
public class FlatHeightmap extends AbstractHeightMap {
private int size;
private float[] heightmapData;
public FlatHeightmap(int size) {
this.size = size;
}
@Override
public boolean load() {
heightmapData = new float[size * size];
return true;
}
@Override
public float[] getHeightMap() {
return heightmapData;
}
}
@ndebruyn: I’ve reproduced the issue you reported, and it’s a bug in Minie.
In the test app, disabling contact filtering as follows works around the bug:
RigidBodyControl rbc = new RigidBodyControl(0);
terrain.addControl(rbc);
rbc.getCollisionShape().setContactFilterEnabled(false);
bulletAppState.getPhysicsSpace().add(terrain);
So I’m convinced it’s related to contact filtering.
Contact filtering is a feature I added to Minie v4.5 in order to solve Minie issue #18. If you don’t plan to use BetterCharacterControl
with terrain, then perhaps you don’t need contact filtering.
It’s curious that the bug manifests when the ball has a HullCollisionShape
(generated by createDynamicMeshShape()
) but not with a MultiSphere
, nor with a SphereCollisionShape
(which is what new RigidBodyControl(1)
would generate). So far, I don’t have a good explanation for why the ball’s collision shape matters.
I’ll continue investigating.
EDIT: I’ve opened an issue at GitHub.