I am making a game with an upside down pyramid. This I imported from blender, because there are some details on the pyramid. Anyway, i have a box as a board on which the pyramid stands, and a skybox with some weird magic textures. However, i want to put a texture on the pyramid. I give it a LightState, MaterialState, and TextureState with my image. However, the texture doesnt show up for some reason. Does anyone know why? Here is my code:
/**
*
*/
package classes;
import com.jme.app.FixedLogicrateGame;
import com.jme.image.Texture;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.math.Vector2f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import java.net.URL;
import com.jmex.model.XMLparser.XMLtoBinary;
import com.jmex.model.XMLparser.JmeBinaryReader;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import com.jme.math.Quaternion;
import com.jme.scene.state.MaterialState;
import com.jme.light.PointLight;
import com.jme.scene.state.LightState;
import com.jme.util.geom.BufferUtils;
import com.jme.scene.TriMesh;
import com.jme.scene.Skybox;
/**
* @author Gibi
*
*/
public class TiltBall extends FixedLogicrateGame {
static TiltBall tb = new TiltBall();
private int width, height, depth, frequency;
private boolean fullScreen;
private Camera camera;
private Timer timer;
private Node rootNode;
private InputHandler input;
private Skybox skybox;
public static void main(String[] args) {
System.out.println("In main( String[] args )");
//set the dialog behavior
tb.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
//start the application
tb.start();
}
protected void cleanup() {
System.out.println("In initGame( )");
camera = null;
timer = null;
rootNode = null;
}
protected void initGame() {
System.out.println("In initGame( )");
//set the logic ticks per second
tb.setLogicTicksPerSecond(100);
// create the root node (scenegraph base)
rootNode = new Node("Root Node");
//import models from blender
Node boxNode = new Node();
//Node playNode = new Node();
String XMLFileName = "Box.xml";
//String XMLFileName2 = "Play.xml";
URL modelURL = this.getClass().getClassLoader().getResource(XMLFileName);
//URL model2URL = this.getClass().getClassLoader().getResource(XMLFileName2);
XMLtoBinary converter = new XMLtoBinary();
JmeBinaryReader jbr = new JmeBinaryReader();
//XMLtoBinary converter2 = new XMLtoBinary();
//JmeBinaryReader jbr2 = new JmeBinaryReader();
jbr.setProperty("bound", "box");
//jbr2.setProperty("bound", "box");
ByteArrayOutputStream BO = new ByteArrayOutputStream();
//ByteArrayOutputStream BO2 = new ByteArrayOutputStream();
try {
converter.sendXMLtoBinary(modelURL.openStream(), BO);
boxNode = jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
// converter2.sendXMLtoBinary(model2URL.openStream(), BO2);
// playNode = jbr2.loadBinaryFormat(new ByteArrayInputStream(BO2.toByteArray()));
} catch (Exception ex) {
ex.printStackTrace();
}
//Create the box itself (an upside down pyramid)
/*Box boxF = new Box("Front", new Vector3f(30,0,35), new Vector3f(-30,-20,-15));
Box boxR = new Box("Right", new Vector3f(30,0,35), new Vector3f(-30,-20,-15));
Box boxB = new Box("Back", new Vector3f(20,0,0), new Vector3f(-20,-20,-5));
Box boxL = new Box("Left", new Vector3f(30,0,35), new Vector3f(-30,-20,-15));
boxNode.attachChild(boxF);
boxNode.attachChild(boxR);
boxNode.attachChild(boxB);
boxNode.attachChild(boxL);*/
//Create the board on which the box stands
Box board = new Box("Board", new Vector3f(30,30,55), new Vector3f(-30,-20,-15));
board.setLocalTranslation(new Vector3f(0,10,-45));
//Texture the board
Texture tex = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"BoardTex.jpg"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);
TextureState ts = display.getRenderer().createTextureState();
ts.setTexture(tex);
board.setRenderState(ts);
// create a skybox
skybox = new Skybox("skybox", 14, 14, 14);
Texture north = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"SkyTex.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture south = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"SkyTex.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture east = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"SkyTex.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture west = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"SkyTex.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture up = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"SkyTex.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture down = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"SkyTex.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
skybox.setTexture(Skybox.NORTH, north);
skybox.setTexture(Skybox.WEST, west);
skybox.setTexture(Skybox.SOUTH, south);
skybox.setTexture(Skybox.EAST, east);
skybox.setTexture(Skybox.UP, up);
skybox.setTexture(Skybox.DOWN, down);
skybox.preloadTextures();
rootNode.attachChild(skybox);
//create the room node, add objects and render states to it
Node boardNode = new Node();
boardNode.attachChild(board);
boardNode.setLocalTranslation(new Vector3f(0,-47.6f,0));
//boardNode.setRenderState(ls);
//create boxNode renderStates
LightState ls = display.getRenderer().createLightState();
MaterialState ms = display.getRenderer().createMaterialState();
PointLight pl = new PointLight();
pl.setLocation(camera.getLocation());
ls.setEnabled(true);
ls.attach(pl);
ms.setDiffuse(ColorRGBA.blue);
ms.setEnabled(true);
//Texture the box
Texture boxTex = TextureManager.loadTexture(
TiltBall.class.getClassLoader().getResource(
"BoxTex.jpg"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);
TextureState boxTS = display.getRenderer().createTextureState();
boxTS.setTexture(boxTex);
boxTS.setEnabled(true);
//edit the box node, move, add render states
boxNode.setLocalTranslation(new Vector3f(-24,-20,-60));
boxNode.setRenderState(ls);
boxNode.setRenderState(ms);
boxNode.setRenderState(boxTS);
//attach the nodes to the scenegraph
rootNode.attachChild(boardNode);
rootNode.attachChild(boxNode);
//update the scene graph for rendering
rootNode.updateGeometricState(0.0f, true);
rootNode.updateRenderState();
}
protected void initSystem() {
System.out.println("In initSystem( )");
//save values in variables, so user can change that later
width = properties.getWidth();
depth = properties.getDepth();
frequency = properties.getFreq();
height = properties.getHeight();
fullScreen = properties.getFullscreen();
try{
//create display system, window, and camera
display = DisplaySystem.getDisplaySystem(properties.getRenderer());
display.createWindow(width,height,depth,frequency,fullScreen);
camera = display.getRenderer().createCamera(width,height);
}
catch(Exception ex){
// handle the exception and exit
ex.printStackTrace();
System.exit(0);
}
//make the background color random
display.getRenderer().setBackgroundColor(ColorRGBA.randomColor());
//set camera frustrum
camera.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
// create vectors for camera frame dat
Vector3f loc = new Vector3f(0.0f, 0.0f, 25.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.1f, -1.0f);
// set camera data
camera.setFrame(loc, left, up, dir);
camera.update();
// create and enable the input handler
input = new InputHandler();
input.setEnabled(true);
//create the timer (for tracking fps)
timer = Timer.getTimer();
// set camera
display.getRenderer().setCamera(camera);
//rotate the camera
Vector3f direction = new Vector3f(-0.2f, 0.1f, -1.0f);
camera.setDirection(direction);
//set the key input actions
KeyBindingManager.getKeyBindingManager().add("exit", KeyInput.KEY_ESCAPE);
}
protected void reinit() {
System.out.println("In reinit( )");
display.recreateWindow(width, height, depth, frequency, fullScreen);
}
protected void render(float interpolation) {
display.getRenderer().clearBuffers();
display.getRenderer().draw(rootNode);
}
protected void update(float interpolation) {
//Update time for timer and input handler
timer.update();
interpolation = timer.getTimePerFrame();
input.update(interpolation);
//Respond to key presses
if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit")){
finished = true;
}
}
}
Can anyone please help?