MeshCollisionShape from a TerrainBlock Applied to a TerrainPage

Hi Im using JME2, I want to create a MeshCollsionShape from a terrainBlock with the same heightmap as My terrainpage.

Problem is the terrainPage stays on 0,0,0… I tried translating the terrainBlock but it seems that the created meshCollisionShape is still on 0,0,0… So, how do i translate my terrainBlock same as the translation of my terrainPage.



Thank You



Screenie:

The colored one is the terrainPage, the grey is the terrainBlock





Here my code,

SpaceTerrain2.class creates the terrainBlock, terrainPage

import com.jme.math.Vector3f;
import com.jme.scene.PassNode;
import com.jme.scene.PassNodeState;
import com.jme.scene.Spatial;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.ImageBasedHeightMap;
import java.net.URL;
import javax.swing.ImageIcon;

public class SpaceTerrain2 {

    protected Spatial terrain;
    protected TerrainPage terrainPage;
    protected TerrainBlock terrainBlock;

    public SpaceTerrain2(){
        setTerrain();
    }

    private void setTerrain() {

        URL heightMapURL = SpaceTerrain2.class.getClassLoader().getResource("data/texture/spaceterrain2.png");
        ImageBasedHeightMap heightMap = new ImageBasedHeightMap(new ImageIcon(heightMapURL).getImage());

        Vector3f terrainScale = new Vector3f(3.0f, 0.1f, 3.0f);
        
        terrainBlock = new TerrainBlock("SPACE TERRAIN BLOCK 2", heightMap.getSize(), terrainScale, heightMap.getHeightMap(),
                new Vector3f(0,0,0));
        terrainPage = new TerrainPage("SPACE TERRAIN 2", 33, heightMap.getSize(), terrainScale, heightMap.getHeightMap());
        terrainPage.setDetailTexture(1, 1);


        TerrainTextureState terrainTexState = new TerrainTextureState();
        terrainTexState.createSplatTextureState("data/texture/5.jpg", null);
        TextureState baseTex = terrainTexState.getTextureState();
        baseTex.setEnabled(true);

        terrainTexState = new TerrainTextureState();
        terrainTexState.createSplatTextureState("data/texture/nicegrass.jpg", "data/texture/spaceterrain2_trail0.png");
        TextureState texState0 = terrainTexState.getTextureState();
        texState0.setEnabled(true);

        terrainTexState = new TerrainTextureState();
        terrainTexState.createSplatTextureState("data/texture/deadgrass.jpg", "data/texture/spaceterrain2_trail1.png");
        TextureState texState1 = terrainTexState.getTextureState();
        texState1.setEnabled(true);

        terrainTexState = new TerrainTextureState();
        terrainTexState.createSplatTextureState("data/texture/baserock.jpg", "data/texture/spaceterrain2_trail2.png");
        TextureState texState2 = terrainTexState.getTextureState();
        texState2.setEnabled(true);

        terrainTexState = new TerrainTextureState();
        terrainTexState.createSplatTextureState("data/texture/stones0.png", "data/texture/spaceterrain2_trail3.png");
        TextureState texState3 = terrainTexState.getTextureState();
        texState3.setEnabled(true);

        BlendState as = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
        as.setBlendEnabled(true);
        as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
        as.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
        as.setTestEnabled(true);
        as.setTestFunction(BlendState.TestFunction.GreaterThan);
        as.setEnabled(true);

        PassNode splatPassNode = new PassNode("SPACE TERRAIN 2: SPLAT PASS NODE");
        splatPassNode.attachChild(terrainPage);

        PassNodeState passNodeState = new PassNodeState();
        passNodeState.setPassState(baseTex);
        splatPassNode.addPass(passNodeState);

        passNodeState = new PassNodeState();
        passNodeState.setPassState(texState0);
        passNodeState.setPassState(as);
        splatPassNode.addPass(passNodeState);

        passNodeState = new PassNodeState();
        passNodeState.setPassState(texState1);
        passNodeState.setPassState(as);
        splatPassNode.addPass(passNodeState);

        passNodeState = new PassNodeState();
        passNodeState.setPassState(texState2);
        passNodeState.setPassState(as);
        splatPassNode.addPass(passNodeState);

        passNodeState = new PassNodeState();
        passNodeState.setPassState(texState3);
        passNodeState.setPassState(as);
        splatPassNode.addPass(passNodeState);

        splatPassNode.lockShadows();
        splatPassNode.lockTransforms();
        splatPassNode.lockBounds();
        
        terrain = splatPassNode;
        terrain.setCullHint(Spatial.CullHint.Dynamic);

    }


    public Spatial getTerrain() {
        return terrain;
    }

    public TerrainPage getTerrainPage() {
        return terrainPage;
    }

    public TerrainBlock getTerrainBlock() {
        return terrainBlock;
    }

}



TestTerrainColShape.class, a simpleGame class

import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.collision.shapes.MeshCollisionShape;
import com.jmex.jbullet.debug.PhysicsDebugger;
import com.jmex.jbullet.nodes.PhysicsNode;
import com.jmex.terrain.TerrainBlock;


public class TestTerrainColShape extends SimpleGame {

    TerrainBlock terrain = new TerrainBlock();
    PhysicsSpace space = PhysicsSpace.getPhysicsSpace();

    public static void main(String[] args) {
        TestTerrainColShape app = new TestTerrainColShape();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }

    protected void simpleInitGame() {
        setTerrain();    
    }

    @Override
    protected void simpleUpdate() {
        space.update(tpf);
    }

    @Override
    protected void simpleRender() {
        PhysicsDebugger.drawWireframes(display.getRenderer());
    }

    private void setTerrain() {

        SpaceTerrain2 spaceterrain2 = new SpaceTerrain2();
        terrain = spaceterrain2.getTerrainBlock();
        rootNode.attachChild(terrain);

        MeshCollisionShape meshShape = new MeshCollisionShape(terrain);
        PhysicsNode pTerrain = new PhysicsNode(spaceterrain2.getTerrain(), meshShape, 0);

        rootNode.attachChild(pTerrain);
        pTerrain.updateRenderState();
        space.add(pTerrain);

    }

}



Thank You!  :)

You can combine multiple mesh shapes in a CompoundCollisionShape, including a translation and rotation for the child shapes. Some time ago a recursion that creates such CompoundCollisionShapes from a TerrainPage was posted here, but its really just a simple loop across the single blocks.



Cheers,

Normen

thanks! I have tried what you said about CompoundCollisionShape, but i had a hard time translating the terrainBlock to the center… After a few hunt i found this thread… http://www.jmonkeyengine.com/forum/index.php?topic=13809.msg102216#msg102216



Thanks  :smiley: i love your jbullet sir

I put SomethingNew's code in my class, at first my character can freely walk in the terrainPage, but there are a parts of the terrain where my character falls. I think the collisionShape is not in place.



I tried to put a PhysicsDebugger so i can see the collisionshape But it gives


SEVERE: Main game loop broken by uncaught exception
java.lang.NoSuchMethodError: com.jme.math.Quaternion.identity()V
        at com.jmex.jbullet.debug.PhysicsDebugger.retrieveAndStoreWorldRotation(PhysicsDebugger.java:194)
        at com.jmex.jbullet.debug.PhysicsDebugger.drawWireframes(PhysicsDebugger.java:93)
        at salipawpaw.AntiphonGameState.render(AntiphonGameState.java:169)
        at com.jmex.game.state.GameStateNode.render(GameStateNode.java:83)
        at com.jmex.game.StandardGame.render(StandardGame.java:399)
        at com.jmex.game.StandardGame.run(StandardGame.java:251)
        at java.lang.Thread.run(Thread.java:619)
AL lib: alSource.c:2361: alcDestroyContext(): deleting 64 Source(s)
08 16, 10 4:53:03 AM com.jme.scene.Node <init>"

what could be the problem?, i wanna use the PhysicsDebugger… I use it in my main project not in the code above.