/*
* Copyright (C) 2014 Torge Rothe, VenJinX <http://www.venjinx.de/>
*
* This file is part of VenJinX.
*
* VenJinX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this VenJinX.
* If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von VenJinX.
*
* VenJinX ist Freie Software: Sie k�nnen es unter den Bedingungen
* der GNU Lesser General Public License, wie von der Free Software
* Foundation, Version 3 der Lizenz oder (nach Ihrer Wahl) jeder
* neueren ver�ffentlichten Version, weiterverbreiten und/oder
* modifizieren.
*
* Dieses Programm wird in der Hoffnung, dass es n�tzlich sein wird,
* aber OHNE JEDE GEW�HRLEISTUNG, bereitgestellt; sogar ohne die
* implizite Gew�hrleistung der MARKTF�HIGKEIT oder EIGNUNG F�R
* EINEN BESTIMMTEN ZWECK. Siehe die GNU Lesser General Public
* License f�r weitere Details.
*
* Sie sollten eine Kopie der GNU Lesser General Public License
* zusammen mit VenJinX erhalten haben.
* Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*/
package de.venjinx.editor;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.texture.Texture;
import de.venjinx.core.VoxelWorld.VoxelMode;
import de.venjinx.editor.debug.DebugMouse;
import de.venjinx.editor.debug.DebugState;
import de.venjinx.jme3.VoxelObjectNode;
import de.venjinx.jme3.VoxelState;
import de.venjinx.jme3.tests.AdvancedApplication;
import de.venjinx.util.Materials;
public class VenJinXEditor extends AdvancedApplication {
protected DebugMouse mouse;
protected DebugState debugState;
protected VoxelState worldState;
public VenJinXEditor() {
super(new VoxelState(), new DebugState());
}
@Override
public void simpleInitApp() {
// cam.setLocation(new Vector3f(0, 2, 0));
cam.setLocation(new Vector3f(8, 8, 8));
cam.setFrustumFar(1000);
viewPort.setBackgroundColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1));
debugState = stateManager.getState(DebugState.class);
worldState = stateManager.getState(VoxelState.class);
// worldState.am = assetManager;
/*
* load heightMap
*/
Texture heightMapImage =
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap4x4_01.gif");
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap8x8_01.gif");
assetManager.loadTexture("textures/terrain/heightMaps/heightMap16x16_02.gif");
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap32x32_02.gif");
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap64x64_01.gif");
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap128x128_02.gif");
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap256x256_01.gif");
// assetManager.loadTexture("textures/terrain/heightMaps/heightMap512x512_02.gif");
ImageBasedHeightMap heightMap;
heightMap = new ImageBasedHeightMap(heightMapImage.getImage());
heightMap.load(false, false);
float[][][] data = VoxelState.loadFromHeightMap(heightMap, VoxelMode.LINE_2D);
/*
* create terrain material
*/
Material mat = new Material(assetManager, Materials.LIGHTING);
// Material mat = new Material(assetManager, Materials.NORMALS);
mat.setTexture("DiffuseMap",
assetManager.loadTexture("textures/terrain/ground/grass512x512_01.gif"));
mat.setTexture("NormalMap",
assetManager.loadTexture("textures/terrain/ground/grass512x512_01_normal.gif"));
// mat.setBoolean("UseMaterialColors", true);
// mat.setColor("Diffuse", ColorRGBA.White);
VoxelObjectNode terrain = new VoxelObjectNode(data);
terrain.setName("VoxelTerrain");
terrain.setMaterial(mat);
worldState.addObject(terrain);
}
@Override
public void simpleUpdate(float tpf) {
secondCounter += getTimer().getTimePerFrame();
frameCounter++;
}
@Override
public void simpleRender(RenderManager rm) {
}
private float secondCounter;
private int frameCounter;
public void printFPS() {
if (secondCounter >= 1.0f) {
int fps = (int) (frameCounter / secondCounter);
System.out.println(fps);
secondCounter = 0.0f;
frameCounter = 0;
}
}
public static void main(String[] args) {
VenJinXEditor app = new VenJinXEditor();
app.start();
}
}