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! :)