Hey,
I want to load a 3D model, which i created using 3d Max, what is the best way to do this? I looked at the tutorial, i just cant get it working that way
Thanks
Give ModelLoader a try…the version in CVS supports 3DS loading and it will show you the model and also save it back out to a .jme binary (which is much faster to load).
Well, first make sure that it can be imported with ModelLoader. It will save back out the .jme file and then you can look at the source code for ModelLoader to figure out how to load a .jme file into your game and manipulate it from there.
Thanx, but how can i place the model in my prefered coordinates?
ok, i have gotten the model loaded, just how can i set the locations of the model? Is there a way of creating random locations for the model on the terrain?
Hello mucker
You can position Your model with model.setLocalTranslation(…)
For positioning it on a terrain i would recommend to take a look at the FlagRush Tutorial series.
this is what i am using but it keeps failing, any ideas why?
public Node models(TerrainPage terrainpage) {
MaxToJme maxtojme = new MaxToJme(); //the converter
Node node = null; //Where to dump mesh.
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); //For loading the raw file
// File Path for the model (dump file in toplevel of classpath)
URL url = ForceFieldFence.class.getClassLoader().getResource("Trees.3ds");
InputStream is=null;
try {
is=url.openStream();
}
catch(Exception err)
{
System.out.println("Could not open Model file: "+err);
}
try
{
// Converts the file into a jme usable file
maxtojme.convert(is, bytearrayoutputstream);
// Used to convert the jme usable file to a TriMesh
BinaryImporter binaryImporter = new BinaryImporter();
ByteArrayInputStream in=new ByteArrayInputStream(bytearrayoutputstream.toByteArray());
//importer returns a Loadable, cast to Node
node = (Node)binaryImporter.load(in);
}
catch(Exception err)
{
System.out.println("Error loading model:"+err);
}
//node.setLocalScale(10);
//attach node to scene graph
node.updateRenderState();
//node.setLocalScale(10);
//node.setLocalTranslation(calcRandomPos(terrainpage));
//rootnode.attachChild(node);
return node;
}
Please be more specific on what fails ???
Does it throw some exceptions ? does it just not show up as You expect ?
Some error output cut'n pasted would also be helpful (if there is any)
edit: for a quick starter You could try changing jmetest.flagrushtut.lession9.Flag.java to load and place Your model instead of the flag
sorry about that, this is the error code i get
INFO: Child (fence) attached to this node (Scene graph node)
Error loading model:java.io.IOException: Header length doesn't match up: End ID
#:0 len left to read=-1065353148 parentID#=b002
java.lang.NullPointerException
at ForceFieldFence.models(ForceFieldFence.java:311)
at Lesson5.buildEnvironment(Lesson5.java:241)
at Lesson5.initGame(Lesson5.java:197)
at com.jme.app.BaseGame.start(Unknown Source)
at Lesson5.main(Lesson5.java:87)
27-Feb-2007 17:12:50 com.jme.app.BaseGame start
INFO: Application ending.
Press any key to continue…
is the way im going about converting and MDS model to Jme format correct?
is the way im going about converting and MDS model to Jme format correct?
don't know, haven't used MaxToJme myself.
To verify that the model can be loaded at all, i'd suggest You try to load it with jmetest.renderer.loader.TestMaxJmeWrite and report results.
how would i use that?
You could try using the ModelLoader in jME and it will handle the conversion to a .jme file for you?
I use the following and it works, except I don't have any textures on my model so I commented that part out.
Replace "BlaApp" by your application name, and "blamodel.3ds" is the model located in the path BlaApp/data/model/ (or where ever you put it).
/** Loads 3DS using com.jmex.model.XMLparser.Converters.MaxToJme() */
public Node loadModel(){
Node gamemap = new Node();
URL modelURL=BlaApp.class.getClassLoader().getResource("data/model/blamodel.3ds");
URL textureURL=BlaApp.class.getClassLoader().getResource("data/model/");
BinaryImporter importer = BinaryImporter.getInstance();
FormatConverter converter=new MaxToJme();
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
converter.convert(modelURL.openStream(), BO);
gamemap=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
gamemap.setCullMode( SceneElement.CULL_NEVER );
gamemap.setModelBound(new BoundingBox());
gamemap.updateModelBound();
/*
// texture
Texture t = TextureManager.loadTexture(
BlaApp.class.getClassLoader().getResource("data/images/default-texture.png"),
Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
t.setWrap(Texture.WM_WRAP_S_WRAP_T);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(t);
gamemap.setRenderState(ts);
// material
MaterialState ms = display.getRenderer().createMaterialState();
ms.setAmbient(new ColorRGBA(1f, 1f, 1f, 1.0f));
ms.setDiffuse(new ColorRGBA(0.8f, 1f, 0.8f, 1.0f));
ms.setColorMaterial(MaterialState.CM_DIFFUSE);
gamemap.setRenderState(ms);
gamemap.updateRenderState();
**/
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
gamemap.setLocalTranslation(new Vector3f(0f,20.0f,0f));
return gamemap;
}
is the way im going about converting and MDS model to Jme format correct?
I assume MDS is a typo and should read 3DS ?
how would i use that?
Well, You'd copy the file (TestMaxJmeWrite.java) over to Your own package,
fix the imports and package statement
edit: ok better rename it and change the classname in below statement too
and change the lines:
modelToLoad = TestMaxJmeWrite.class.getClassLoader().getResource(
"jmetest/data/model/Character.3DS");
then compile, run and see what happens
can i import the models from any file, as long as i provide the correct url, or do i have to place the models in a specific file?
thanks for ur help
ok, i kind of got it working, but there is a slight problem, so i hope this makes sence, the coordinates where i place the model there is nothing there not even the terrain but when i move up close i can make out the cone, so when i pass through the cone, i seem to come back to the start of the terrain
If you use the ModelLoader it will let you browse for the file and select it, it will then convert it, display it, and export it to .jme for you in the same path the original file was in.
ok, i got it kind of working, just i can see an empty space from a distance, but when im right up i can see the model, would you say my frustum perspective is my problem?
the model size is probably just small…I think the ModelLoader sizes down the model by default so you might be fine on size when you actually import it into your game.