Hello every one, i have design a 3D box and i have named it cajon.dae. I'm using the next portion of code to import it:
public void import3dBox(){
InputStream source;
try {
source = new FileInputStream("res/cajon.dae");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
ColladaImporter.load(source,"res/cajon.dae");
compasBox = ColladaImporter.getModel();
}
This file is in directory compas/src/gamestates/gamestate.java and the model is at compas/src/res/cajon.dae. My problem is when i execute it, i obtain de next error:
Exception in thread "main" java.lang.RuntimeException: java.io.FileNotFoundException: res/cajon.dae (No such file or directory)
at gamestates.GameState.import3dBox(GameState.java:28)
at gamestates.GameState.<init>(GameState.java:17)
at gamestates.MenuState.<init>(MenuState.java:33)
at main.Compas.main(Compas.java:20)
Caused by: java.io.FileNotFoundException: res/cajon.dae (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at gamestates.GameState.import3dBox(GameState.java:26)
… 3 more
I have ensured myself that the permissions of the directorys and files are correct. Could anyone tell me what i am doing bad?. Thank you.
It has been fixed modifying like this:
public void import3dBox(){
InputStream source;
try {
URL modelURL = GameState.class.getClassLoader().getResource("res/cajon.dae");
source = modelURL.openStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
ColladaImporter.load(source,"compasBox");
compasBox = ColladaImporter.getModel();
}
But now the problem is this:
05-jul-2010 13:26:27 com.jmex.model.collada.ColladaImporter load
INFO: Version: 1.4.1
05-jul-2010 13:26:27 com.jme.util.resource.ResourceLocatorTool locateResource
ADVERTENCIA: Unable to locate: cajon/texture0.jpg
05-jul-2010 13:26:27 com.jmex.model.collada.ColladaImporter loadTexture
ADVERTENCIA: Invalid or missing texture: "cajon/texture0.jpg"
It can not load the texture that is at the same directory than cajon.dae.
What i am trying to do is load a 3D model and show but i can not get it done, all the code is this:
package gamestates;
import java.io.InputStream;
import java.net.URISyntaxException;
import com.jme.bounding.BoundingBox;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;
import com.jme.util.geom.Debugger;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jmex.game.state.BasicGameState;
import com.jmex.model.collada.ColladaImporter;
public class GameState extends BasicGameState{
public Node compasBox;
public GameState(){
super("GameState");
compasBox = import3dBox();
getRootNode().attachChild(compasBox);
getRootNode().updateRenderState();
}
public Node import3dBox(){
InputStream source;
source = GameState.class.getClassLoader().getResourceAsStream("res/cajon.dae");
if (source == null){
System.out.println("Collada data file not found");
System.exit(0);
}
try {
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(GameState.class
.getClassLoader().getResource(
"res/cajon/")));
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
ColladaImporter.load(source, "compasBox");
Node n = ColladaImporter.getModel();
if(n==null){
System.out.println("CASCO");
System.exit(0);
}
n.setModelBound(new BoundingBox());
n.updateModelBound();
return n;
}
public void render(float tpf){
Debugger.drawBounds(rootNode, DisplaySystem.getDisplaySystem().getRenderer(), true);
}
}
It seems to work fine, i dont get any warning, but the model is not showed. Anyone could say to me the link of a tutorial to do this fine? Thank you.