Hi all,
I am new to jme, so this is probarly a noob question.
I want to make a simple flightsimulator.
I use the Terra engine of llama for my terrain.
Now i want to paste a texture on it, but there it goes wrong. I use the ProceduralTextureGenerator class for a mix of textures.
When i run my code, i get this:
I want normal textures, not with black holes in it.
this is my code:
import java.net.URL;
import javax.swing.ImageIcon;
import jmetest.terrain.TestTerrain;
import org.llama.jmex.task.TaskManager;
import org.llama.jmex.terra.TerraManager;
import org.llama.jmex.terra.TerraView;
import org.llama.jmex.terra.TerraViewProperties;
import org.llama.jmex.terra.format.JMEXMapStore;
import org.llama.jmex.terra.util.SimpleTerraView;
import org.llama.test.ViewJMEXTest;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.light.DirectionalLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.terrain.util.AbstractHeightMap;
import com.jmex.terrain.util.HillHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;
import com.jmex.terrain.util.MidPointHeightMap;
public class Test3 extends SimpleGame {
TaskManager taskManager;
TerraView tv;
FogState fogstate;
CullState cullstate;
float fogstart = 450;
float fogend = 550;
final String CMD_FOG = "fog";
int blocksize = 64;
int mapsize = 128*20;
float hillsize = 75.0f;
int loading = 900;
int rendering = 700;
int iterations = 200000;
public int mapmulti = 3;
TerraManager tm;
private boolean tex = true;
int[] lod = new int[] {128, 64+128, 128+128};
ProceduralTextureGenerator pt;
AbstractHeightMap ahm;
public Test3(){
}
public void simpleInitGame(){
taskManager = new TaskManager(timer);
DirectionalLight dl = new DirectionalLight();
dl.setEnabled(true);
dl.setDirection(new Vector3f(.1f, -1, .1f));
dl.setAmbient(new ColorRGBA(.5f, .5f, .5f, .9f));
lightState.detachAll();
lightState.attach(dl);
fogstate = display.getRenderer().createFogState();
fogstate.setDensity(0.5f);
fogstate.setColor(ColorRGBA.black);
fogstate.setEnd(fogend);
fogstate.setStart(fogstart);
fogstate.setDensityFunction(FogState.DF_LINEAR);
fogstate.setApplyFunction(FogState.AF_PER_VERTEX);
rootNode.setRenderState(fogstate);
Thread.currentThread().setPriority(Thread.NORM_PRIORITY + 1);
display.setTitle("Press F to toggle Fog");
KeyBindingManager.getKeyBindingManager().set(CMD_FOG, KeyInput.KEY_F);
cam.setFrustumPerspective(45f, 640f / 480f, 1f, fogend);
cam.setLocation(new Vector3f(0, 200.5f, 0));
cam.update();
cam.lookAt(new Vector3f(0, 0, 0), new Vector3f(1f, 0.5f, 1f));
cam.update();
cullstate = display.getRenderer().createCullState();
cullstate.setCullMode(CullState.CS_BACK);
tv = getView();
tv.updateNextFrame();
tv.setRenderState(cullstate);
tv.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
rootNode.attachChild(tv);
// if (tex) {
// Texture tex = TextureManager.loadTexture(getUrl("128.png"), Texture.MM_NEAREST, Texture.FM_NEAREST);
// tex.setWrap(Texture.WM_WRAP_S_WRAP_T);
// TextureState ts = display.getRenderer().createTextureState();
// ts.setTexture(tex);
// tv.setRenderState(ts);
// }
ProceduralTextureGenerator pt = new ProceduralTextureGenerator(ahm);
pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
.getResource("jmetest/data/texture/grassb.png")),
-128, 0, 128);
pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
.getResource("jmetest/data/texture/dirt.jpg")),
0, 128, 255);
pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
.getResource("jmetest/data/texture/highest.jpg")),
128, 255,
384);
pt.createTexture(64);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
Texture t1 = TextureManager.loadTexture(
pt.getImageIcon().getImage(),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR, true);
t1.setStoreTexture(true);
ts.setTexture(t1, 0);
Texture t2 = TextureManager.loadTexture(
TestTerrain.class.getClassLoader().getResource(
"jmetest/data/texture/Detail.jpg"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);
ts.setTexture(t2, 1);
t2.setWrap(Texture.WM_WRAP_S_WRAP_T);
t1.setApply(Texture.AM_COMBINE);
t1.setCombineFuncRGB(Texture.ACF_MODULATE);
t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t1.setCombineScaleRGB(1.0f);
t2.setApply(Texture.AM_COMBINE);
t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t2.setCombineScaleRGB(1.0f);
tv.setRenderState(ts);
rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
fpsNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
}
protected void simpleUpdate() {
tv.update();
taskManager.runTasks(0.02f);
if (KeyBindingManager.getKeyBindingManager().isValidCommand(CMD_FOG, false)) {
fogstate.setEnabled(!fogstate.isEnabled());
if (fogstate.isEnabled())
cam.setFrustumFar(fogend);
else
cam.setFrustumFar(5000);
cam.update();
}
}
public TerraView getView() {
tm = getManager();
tv = new SimpleTerraView("my world", tm, taskManager, cam, getProperties(0.01f, 1), false, loading, -1, rendering, lod, false);
return tv;
}
public TerraManager getManager() {
TerraManager tm = new TerraManager("My Terrain", blocksize * 3, blocksize);
AbstractHeightMap.NORMALIZE_RANGE = 10000f;
ahm = new HillHeightMap(mapsize, iterations, 10.0f, hillsize, (byte) 3);
// ahm = new MidPointHeightMap(64, 1f);
// ahm = new FaultFractalHeightMap(32*32, 32*32, 0, 255, 0.75f);
tm.setGlobalMapStore(new JMEXMapStore(ahm, blocksize * mapmulti));
return tm;
}
private URL getUrl(String name) {
return ViewJMEXTest.class.getClassLoader().getResource("res/" + name);
}
public TerraViewProperties getProperties(float heightscale, int texturesPerBlock) {
TerraViewProperties tvp = new TerraViewProperties(new Vector3f(1, heightscale, 1f), ColorRGBA.white, texturesPerBlock);
return tvp;
}
public static void main(String[] ars){
Test3 app = new Test3();
app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
}
Thanks in advance,
BTBORIBOSs