Here's a HUGE mass of code, nothing renders but the Tile-Loader reports creating everything and I see the skybox created in the output, as well.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fyrestonev01;
import com.jme.app.BaseGame;
import com.jme.input.ChaseCamera;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.light.DirectionalLight;
import com.jme.math.Plane;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.renderer.pass.RenderPass;
import com.jme.scene.Node;
import com.jme.scene.PassNode;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.FogState;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.Timer;
import com.jmex.effects.water.WaterRenderPass;
import java.nio.FloatBuffer;
import java.util.ArrayList;
/**
*
* @author Tyler Trussell
* Copyright 2009 Tyler Trussell
* All Rights Reserved.
* It is illegal to possess this source code unless you have express written consent from Tyler Trussell.
* Any dissemenation, use, transcription, or translation of this source code is forbidden unless express written consent from Tyler Trussell has been provided.
*
*/
public class FyrestoneClient extends BaseGame
{
//DISPLAY SETTINGS
private int width, height, freq, depth;
private boolean fullscreen;
//END DISPLAY SETTINGS
//Camera Setup
Camera cam;
ChaseCamera chaser;
//End Camera Setup
//FPS Setup
Timer timer;
Node fpsNode;
float tpf;
//End FPS Node;
//Terrain Setup
Node terrainNode;
Skybox skybox;
FogState fog;
TileSpace[] loadedTiles = new TileSpace[9];
PassNode[] textures = new PassNode[9];
//End Terrain Setup
//Water setup
BasicPassManager pManager;
Node waterNode;
WaterRenderPass water;
Quad myWater;
//End water setup
//Lighting setup
LightState lightState;
//End lighting setup
//Rendering setup
RenderPass terrainPass;
//End rendering setup
public static void main(String args[])
{
FyrestoneClient app = new FyrestoneClient();
app.setDialogBehaviour(app.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
@Override
protected void initSystem()
{
setupWindow();
makeCamera();
timer = Timer.getTimer();
}
@Override
protected void initGame()
{
terrainNode = new Node("terrain");
waterNode = new Node("water");
terrainPass = new RenderPass();
pManager = new BasicPassManager();
TileSpaceManager.startup();
createLighting();
skybox = EnvironmentalManager.makeSkybox();
fog = EnvironmentalManager.makeFog();
terrainNode.attachChild(skybox);
terrainNode.setRenderState(fog);
terrainPass.add(terrainNode);
pManager.add(terrainPass);
createStartTile();
makeWater();
}
@Override
protected void reinit()
{
display.recreateWindow(width, height, depth, freq, fullscreen);
}
@Override
protected void update(float interpolation)
{
timer.update();
tpf = timer.getTimePerFrame();
interpolation = timer.getTimePerFrame();
updateSkybox();
updateTiles();
checkForInput();
terrainNode.updateGeometricState(tpf, true);
waterNode.updateGeometricState(tpf, true);
}
@Override
protected void render(float interpolation)
{
terrainNode.updateGeometricState(tpf, false);
waterNode.updateGeometricState(tpf, false);
pManager.updatePasses(tpf);
display.getRenderer().clearStatistics();
display.getRenderer().clearBuffers();
pManager.renderPasses(display.getRenderer());
}
@Override
protected void cleanup()
{
}
private void checkForInput()
{
if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit"))
finished = true;
}
private void updateTiles()
{
Vector3f myLoc = cam.getLocation();
int tile_x = (int)myLoc.x / (TileSpaceManager.TERRAINSCALE * TileSpaceManager.MAPSIZE);
int tile_y = (int)myLoc.z / (TileSpaceManager.TERRAINSCALE * TileSpaceManager.MAPSIZE);
ArrayList<TileSpace> mustStayLoaded = TileSpaceManager.getTileSpace(tile_x, tile_y).getNeighbors();
mustStayLoaded.add(TileSpaceManager.getTileSpace(tile_x, tile_y));
for(int i=0; i<loadedTiles.length; i++)
{
if(loadedTiles[i] != null)
{
boolean kill = true;
for(TileSpace ts : mustStayLoaded)
{
if(loadedTiles[i].x == ts.x && loadedTiles[i].y == ts.y)
kill = false;
}
if(kill)
{
System.out.println("************************* Killing page at " + loadedTiles[i].x + " " + loadedTiles[i].y + " *************************");
loadedTiles[i] = null;
textures[i].removeFromParent();
textures[i] = null;
}
}
}
for(TileSpace ts : mustStayLoaded)
{
boolean present = false;
for(int i=0; i<loadedTiles.length; i++)
{
if(loadedTiles[i] != null)
{
if(loadedTiles[i].x == ts.x && loadedTiles[i].y == ts.y)
present = true;
}
}
if(!present)
{
int x = getFirstNullPage();
loadedTiles[x] = TileSpaceManager.getTileSpace(ts.x, ts.y);
textures[x] = TileSpaceManager.makePassNode(TileSpaceManager.makeTerrainPage(ts.x, ts.y), ts.x, ts.y);
terrainNode.attachChild(textures[x]);
terrainNode.updateRenderState();
}
}
}
private WaterRenderPass makeWater()
{
water = new WaterRenderPass(cam, 6, false, true);
water.setWaterPlane(new Plane(new Vector3f(0f, 1f, 0f), 1f));
water.setClipBias(-1f);
water.setReflectionThrottle(0f);
water.setRefractionThrottle(0f);
myWater = new Quad("myWater", 1, 1);
FloatBuffer normBuf = myWater.getNormalBuffer(0);
normBuf.clear();
normBuf.put(0).put(1).put(0);
normBuf.put(0).put(1).put(0);
normBuf.put(0).put(1).put(0);
normBuf.put(0).put(1).put(0);
water.setWaterEffectOnSpatial(myWater);
waterNode.attachChild(myWater);
water.setReflectedScene(terrainNode);
water.setReflectedScene(skybox);
water.setSkybox(skybox);
pManager.add(water);
return water;
}
private int getFirstNullPage()
{
for(int i=0; i<loadedTiles.length; i++)
{
if(loadedTiles[i] == null)
return i;
}
return 0;
}
private void createStartTile()
{
Vector3f myLoc = cam.getLocation();
int tile_x = (int)myLoc.x / (TileSpaceManager.TERRAINSCALE * TileSpaceManager.MAPSIZE);
int tile_y = (int)myLoc.z / (TileSpaceManager.TERRAINSCALE * TileSpaceManager.MAPSIZE);
loadedTiles[0] = TileSpaceManager.getTileSpace(tile_x, tile_y);
textures[0] = TileSpaceManager.makePassNode(TileSpaceManager.makeTerrainPage(tile_x, tile_y), tile_x, tile_y);
terrainNode.attachChild(textures[0]);
}
private void makeCamera()
{
cam = display.getRenderer().createCamera(width, height);
Vector3f location = new Vector3f(SystemManager.CAMSTARTX, SystemManager.CAMSTARTY, SystemManager.CAMSTARTZ);
Vector3f left = new Vector3f(-1f, 0f, 0f);
Vector3f up = new Vector3f(0f, 1f, 0f);
Vector3f dir = new Vector3f(0f, 0f, -1f);
cam.setFrame(location, left, up, dir);
cam.update();
display.getRenderer().setCamera(cam);
}
private void setupWindow()
{
width = properties.getWidth();
height = properties.getHeight();
freq = properties.getFreq();
depth = properties.getDepth();
fullscreen = properties.getFullscreen();
display = DisplaySystem.getDisplaySystem(properties.getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
display.setTitle("Fyrestone: Development Edition v. 0.1");
display.getRenderer().setBackgroundColor(ColorRGBA.pink);
}
private void setupKeyBindings()
{
KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
}
private void setTextureCoords(int buffer, float x, float y, float textureScale)
{
x *= textureScale * 0.5f;
y *= textureScale * 0.5f;
textureScale = EnvironmentalManager.fogEnd * textureScale;
FloatBuffer texBuf;
texBuf = myWater.getTextureBuffer(0, buffer);
texBuf.clear();
texBuf.put(x).put(textureScale + y);
texBuf.put(x).put(y);
texBuf.put(textureScale + x).put(y);
texBuf.put(textureScale + x).put(textureScale + y);
}
private void updateSkybox()
{
Vector3f camLoc = cam.getLocation();
skybox.setLocalTranslation(camLoc);
}
private void updateWater()
{
Vector3f transVec = new Vector3f(cam.getLocation().x, water.getWaterHeight(), cam.getLocation().z);
setTextureCoords(0, transVec.y, -transVec.z, .07f);
setVertexCoords(transVec.x, transVec.y, transVec.z);
}
private void createLighting()
{
lightState = display.getRenderer().createLightState();
DirectionalLight sun = EnvironmentalManager.makeSun();
lightState.attach(sun);
lightState.setEnabled(true);
}
private void setVertexCoords(float x, float y, float z)
{
FloatBuffer vertBuf = myWater.getVertexBuffer(0);
vertBuf.clear();
vertBuf.put(x - EnvironmentalManager.fogEnd).put(y).put(z - EnvironmentalManager.fogEnd);
vertBuf.put(x - EnvironmentalManager.fogEnd).put(y).put(z + EnvironmentalManager.fogEnd);
vertBuf.put(x + EnvironmentalManager.fogEnd).put(y).put(z + EnvironmentalManager.fogEnd);
vertBuf.put(x + EnvironmentalManager.fogEnd).put(y).put(z - EnvironmentalManager.fogEnd);
}
}