Hi I have run into some trubble with trying to load my own model into the flag rush tutorial.
private void buildPlayer() {
Spatial model = null;
try {
URL bikeFile = Lesson9.class.getClassLoader().getResource("jmetest/data/model/bike.jme");
BinaryImporter importer = new BinaryImporter();
model = (Spatial)importer.load(bikeFile.openStream());
model.setModelBound(new BoundingBox());
model.updateModelBound();
//scale it to be MUCH smaller than it is originally
model.setLocalScale(.0025f);
} catch (IOException e) {
logger
.throwing(this.getClass().toString(), "buildPlayer()",
e);
}
So i have this and this is where my model is /Hummer/src/com/jme/Hummer.obj
I have tried to use the HelloModelLoading model tutorial but that did not work either. am i not importing the model right? Becuase the HelloModelLoading one works fine with no mods to it.
Thanks
the code snippet that you provided is for loading a jME binary file, you will want to use the OBJtoJME class like the following
from jmetest.renderer.loader.TestObjJmeWrite.java
URL objFile=TestObjJmeWrite.class.getClassLoader().getResource("jmetest/data/model/maggie.obj");
converter.setProperty("mtllib",objFile);
ByteArrayOutputStream BO=new ByteArrayOutputStream();
logger.info("Starting to convert .obj to .jme");
converter.convert(objFile.openStream(),BO);
//jbr.setProperty("texurl",new File(".").toURL());
logger.info("Done converting, now watch how fast it loads!");
long time=System.currentTimeMillis();
Node r=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
logger.info("Finished loading time is "+(System.currentTimeMillis()-time));
r.setLocalScale(.1f);
rootNode.attachChild(r);
Is see where my mistake was I have to convert the .obj to .jme. But how can I modify the code to work with the flag rush tutorial?
I have my buildplayer method
private void buildPlayer() {
Spatial model = null;
try {
URL bikeFile = Lesson9.class.getClassLoader().getResource("jmetest/data/model/bike.jme");
BinaryImporter importer = new BinaryImporter();
model = (Spatial)importer.load(bikeFile.openStream());
model.setModelBound(new BoundingBox());
model.updateModelBound();
//scale it to be MUCH smaller than it is originally
model.setLocalScale(.0025f);
} catch (IOException e) {
logger
.throwing(this.getClass().toString(), "buildPlayer()",
e);
}
//set the vehicles attributes (these numbers can be thought
//of as Unit/Second).
player = new Vehicle("Player Node", model);
player.setAcceleration(15);
player.setBraking(15);
player.setTurnSpeed(2.5f);
player.setWeight(25);
player.setMaxSpeed(25);
player.setMinSpeed(15);
player.setLocalTranslation(new Vector3f(100,0, 100));
scene.attachChild(player);
scene.updateGeometricState(0, true);
//we now store this initial value, because we are rotating the wheels the bounding box will
//change each frame.
agl = ((BoundingBox)player.getWorldBound()).yExtent;
player.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
}
So how can I change this to import and convert the .obj file?
I tried this and placing it in the build player method
// Point to a URL of my model
URL model=HelloModelLoading.class.getClassLoader().getResource("/Hummer/src/com/jme/Hummer.obj");
// Create something to convert .obj format to .jme
FormatConverter converter=new ObjToJme();
// Point the converter to where it will find the .mtl file from
converter.setProperty("mtllib",model);
// This byte array will hold my .jme file
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(model.openStream(), BO);
Node hummer =(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
// shrink to fit scean
hummer.setLocalScale(.1f);
hummer.setModelBound(new BoundingSphere());
hummer.updateModelBound();
// Put the hummer on the scene graph
rootNode.attachChild(hummer);
} catch (IOException e) { // Just in case anything happens
logger.logp(Level.SEVERE, this.getClass().toString(),
"simpleInitGame()", "Exception", e);
System.exit(0);
}
}
and it did not work. how can I attach the modle to the scean?
Thanks
Have you checked the size of the model? Try importing the Hummer as well as the maggie.obj model into your favorite 3d application and compare the sizes… The hummer may be huge or tiny and thus, not visible in the scene.