blaine said:
You say that the sky box is rendering correctly but "terrain block (as well as other TriMesh)" is not, yet you provide only the code for your sky box setup. How 'bout sending some code that shows what is not working?
thank you for you reminding.
to make it simpler, i only pasted the key code. here the complete code:
1.class Game:
import java.util.logging.Level;
import java.util.logging.Logger;
import netjava.robo3d.scene.Scene;
import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.InputHandler;
import com.jme.input.action.InputActionEvent;
import com.jme.input.action.InputActionInterface;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
public class Game extends BaseGame {
private Logger logger = Logger.getLogger(Game.class.getName());
private Camera cam;
private Timer timer;
private InputHandler input;
private int width;
private int height;
private int depth;
private int freq;
private boolean fullscreen;
private Scene scene;
public static void main(String[] args) {
Game game = new Game();
game.setConfigShowMode(ConfigShowMode.AlwaysShow, Game.class
.getClassLoader().getResource(
"netjava/robo3d/resource/image/splash.jpg"));
Logger.getLogger("").setLevel(Level.ALL);
game.start();
}
@Override
protected void initSystem() {
width = settings.getWidth();
height = settings.getHeight();
depth = settings.getDepth();
freq = settings.getFrequency();
fullscreen = settings.isFullscreen();
try {
this.display = super.display;
display = DisplaySystem.getDisplaySystem(settings.getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
logger.log(Level.SEVERE, "Could not create displaySystem", e);
System.exit(1);
}
display.setTitle("Robo3D v2.0");
display.getRenderer().setBackgroundColor(ColorRGBA.black.clone());
cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1,
5000);
Vector3f loc = new Vector3f(640.0f, 150.0f, 2560.0f);
Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
// Move our camera to a correct place and orientation.
cam.setFrame(loc, left, up, dir);
cam.update();
display.getRenderer().setCamera(cam);
timer = Timer.getTimer();
}
@Override
protected void initGame() {
input = new KeyboardHandler();
input.addAction(new InputActionInterface() {
public void performAction(InputActionEvent evt) {
Game.this.finished = true;
}
}, "exit", false);
scene = new Scene(input);
}
@Override
protected void update(float interpolation) {
timer.update();
interpolation = timer.getTimePerFrame();
input.update(interpolation);
scene.update(interpolation);
}
@Override
protected void render(float interpolation) {
// Clear the screen
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
}
@Override
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
@Override
protected void cleanup() {
}
}
2.class Scene
import java.util.ArrayList;
import java.util.List;
import netjava.robo3d.tank.Player;
import netjava.robo3d.tank.Robot;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.image.Texture.MagnificationFilter;
import com.jme.image.Texture.MinificationFilter;
import com.jme.input.ChaseCamera;
import com.jme.input.InputHandler;
import com.jme.light.DirectionalLight;
import com.jme.light.Light;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.geom.BufferUtils;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.MidPointHeightMap;
public class Scene extends Node {
private static final long serialVersionUID = 427189480039821532L;
private Player player;
private List<Robot> robots = new ArrayList<Robot>();
private Skybox sky;
private TerrainBlock tb;
private DisplaySystem display;
private InputHandler input;
private Camera cam;
private ChaseCamera chaser;
private Light light;
public Scene(InputHandler input) {
this.setName("scene");
this.display = DisplaySystem.getDisplaySystem();
this.input = input;
this.cam = display.getRenderer().getCamera();
createSkybox();
setModelBound(new BoundingBox());
updateWorldBound();
createTerrainBlock();
lightWorld();
// update the scene graph for rendering
updateGeometricState(0.0f, true);
updateRenderState();
}
private void lightWorld() {
light = new DirectionalLight();
LightState lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.detachAll();
lightState.attach(light);
this.setRenderState(lightState);
}
private void createSkybox() {
sky = new Skybox("sky", 5000, 5000, 5000);
Texture north = TextureManager.loadTexture(Skybox.class
.getClassLoader().getResource(
"netjava/robo3d/resource/image/skyNorth.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture south = TextureManager.loadTexture(Skybox.class
.getClassLoader().getResource(
"netjava/robo3d/resource/image/skySouth.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture east = TextureManager.loadTexture(Skybox.class.getClassLoader()
.getResource("netjava/robo3d/resource/image/skyEast.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture west = TextureManager.loadTexture(Skybox.class.getClassLoader()
.getResource("netjava/robo3d/resource/image/skyWest.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture up = TextureManager.loadTexture(Skybox.class.getClassLoader()
.getResource("netjava/robo3d/resource/image/skyClouds.png"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture down = TextureManager.loadTexture(Skybox.class.getClassLoader()
.getResource("netjava/robo3d/resource/image/skyBottom.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
sky.setTexture(Skybox.Face.North, north);
sky.setTexture(Skybox.Face.West, west);
sky.setTexture(Skybox.Face.South, south);
sky.setTexture(Skybox.Face.East, east);
sky.setTexture(Skybox.Face.Up, up);
sky.setTexture(Skybox.Face.Down, down);
sky.preloadTextures();
this.attachChild(sky);
}
private void createTerrainBlock() {
// Generate a random terrain data
MidPointHeightMap heightMap = new MidPointHeightMap(64, 1f);
// Scale the data
Vector3f terrainScale = new Vector3f(20, 0f, 20);
// create a terrainblock
tb = new TerrainBlock("terrain", heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(0, 0, 0));
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
// assign the texture to the terrain
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
Texture t = TextureManager.loadTexture(Skybox.class.getClassLoader()
.getResource("netjava/robo3d/resource/image/terrain.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
ts.setTexture(t);
tb.setRenderState(ts);
this.attachChild(tb);
}
public void update(float interpolation) {
sky.setLocalTranslation(cam.getLocation());
updateGeometricState(interpolation, true);
}
}