Hi, I’m having problems with my textures… I’m very new to jME and would appreciate it very much if someone could point me in the right direction
Here is a screenshot of my app:
As you can see the problem is that not all of the textures show correctly On one of my other models the textures were on the inside, but not on this one… At first I didn’t have any textures, but when I added some ResourceLocator code it worked…
What do you think could be the problem here?
I’ll include some sourcecode too… first a short version and then a longer version:
short:
URL modelFile = BergenWindow.class.getClassLoader().getResource("..\res/models/group01-skansenFireStation/skansen.obj");
FormatConverter converter = new ObjModelConverter(); //ObjToJme();
URL modelFolder = BergenWindow.class.getClassLoader().getResource("..\res/models/group01-skansenFireStation/");
try
{
SimpleResourceLocator srl = new SimpleResourceLocator(modelFile);
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL,srl);
SimpleResourceLocator sr2 = new SimpleResourceLocator(modelFolder);
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,srl);
}
catch(Exception e)
{
System.out.println("JALLABALLA");
}
converter.setProperty("mtllib", modelFolder);
converter.setProperty("texdir", modelFolder);
//convert and load again..
ByteArrayOutputStream BO = new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(modelFile.openStream(), BO);
Spatial ship = (Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
ship.setLocalScale(.1f);
ship.setModelBound(new BoundingSphere());
ship.updateModelBound();
// Put her on the scene graph
rootNode.attachChild(ship);
} catch (IOException e) { // Just in case anything happens
System.out.println("Damn exceptions!" + e);
e.printStackTrace();
System.exit(0);
}
long version..(messy!):
package net.gulost.monkeybergen3d.gui;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import net.gulost.monkeybergen3d.model.ObjModelConverter;
import net.gulost.monkeybergen3d.model.ObjModelLoader;
import net.gulost.monkeybergen3d.skybox.BergenSkybox;
import net.gulost.monkeybergen3d.terrain.BergenTerrain;
import net.gulost.monkeybergen3d.terrain.ESRIBasedHeightMap;
import jmetest.TutorialGuide.HelloTerrain;
import jmetest.effects.water.TestQuadWater;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.SceneElement;
import com.jme.scene.Skybox;
import com.jme.scene.Spatial;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.AxisRods;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.ObjToJme;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.MidPointHeightMap;
/**********************************************************************************************
* BergenWindow
*
* This class puts the terrain, skybox, buildings, etc. in the scene. For stuff to be
* rendered you have to attach it to the rootNode.
*
* Most of the action is done in DefaultWindow..
*
* @author Thomas
*
*********************************************************************************************/
public class BergenWindow extends DefaultWindow
{
/*******************************************
* instansvariabler
* ps. husk at vi allerede har; camera, rootNode, etc.
***************************************/
private BergenSkybox skybox;
private BergenTerrain terrain;
/********************************
* Main entry of application
* @param args maybe increase memory?
***********************************/
public static void main(String[] args)
{
DefaultWindow application = new BergenWindow();
//application.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG, "image.png");
application.setDialogBehaviour(AbstractGame.NEVER_SHOW_PROPS_DIALOG);
application.start();
}
/*************************************************************
* Initialize stuff here...f.eks.:
* - camera
* - light
* - input handler/bindings (f.eks. styre kamera etter kurve)
************************************************************/
@Override
public void simpleInit()
{
System.out.println("simpleInit");
display.setTitle("Bergen 3D - gulost.net");
display.getRenderer().enableStatistics(false); //don't gather stats..
//TODO: create the skybox
//loadSkyBox();
skybox = new BergenSkybox();
rootNode.attachChild(skybox);
//Debug stuff:
//rootNode.attachChild(new Box("origo",new Vector3f(0,0,0),new Vector3f(1,1,1)));
//generateRandomHeightMap();
rootNode.attachChild(new AxisRods("debugAxis", true, 10, 1));
loadFakeWater();
//TODO: generate terrain, add to scenegraph. textures
//loadTerrain();
terrain = new BergenTerrain();
rootNode.attachChild(terrain.getTerrainBlock());
//TODO: add buildings, position them correctly
loadBuildings();
//TODO: find a good camera position
//TODO: create curves that the camera should follow..
setupCamera();
}
/****************************************************
* All child nodes of rootNode gets rendered.
* This method is for additional rendering, e.g.
* menus, stats, ui, etc...
***************************************************/
@Override
public void simpleRender()
{
//super.simpleRender();
}
/***********************************************************************
* Update application logic.. Very simple version, 1 update per frame..
* TODO: set a fixed framerate?
*
* Here I will update positions, states, etc.. f.eks. camera position..
**********************************************************************/
@Override
public void simpleUpdate()
{
//TODO: update camera position
//update skybox position
if(skybox!=null)
{
skybox.getLocalTranslation().set(camera.getLocation());
skybox.updateGeometricState(0.0f, true);
}
}
private void setupCamera()
{
// TODO
// - look at something nice
// - lock movement keys
// - lock mouse-look?
// - setup splines
// - make camera move along splines..
//placing camera..
camera.setLocation(new Vector3f(10,50,10));
camera.lookAt(new Vector3f(64,0,64), new Vector3f(0,1,0));
}
private void loadBuildings()
{
/***
* the real deal :) fors