SimpleResourceLocator sr1 = new SimpleResourceLocator(modelFile);
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL, sr1);
SimpleResourceLocator sr2 = new SimpleResourceLocator(modelFolder);
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, sr2);
FormatConverter converter = new ObjToJme();
converter.setProperty("mtllib", modelFolder);
converter.setProperty("texdir", modelFolder);
ByteArrayOutputStream BO = new ByteArrayOutputStream();
converter.convert(modelFile.openStream(), BO);
Spatial model = (Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
model.setLocalScale(.1f);
model.setModelBound(new BoundingSphere());
model.setName("Model");
model.updateModelBound();
model.updateRenderState();
return model;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Well, there is another anoying problem: When I load a model in jME, "round" parts of the models
are not rendered well. That means, if I move around with the mouse, the surfaces switching
between "light" and "dark", looks like some kind of Z-Fighting, but I don't think its such a
problem. Is there any problem with round parts of models in jME? Could it be Misfit Model 3D?
I hope you can help me with these problems, its getting really anoyint :/
First off, I probably wouldn't be using the obj format to load your models, that could be the cause of the faceting you're experiencing, or it may have something to do with normals? It could even be that you ahven't set a material so you ahve no ambient property on the models material…
I would probably use ogre for static meshes (as you don't need to atatch to a bone like you do with MD5) and probably for animated meshes as well, or you could alternatively use MD5 for animated, it's up to you.
With regards to the resource locater, you need to enter the folder for where the models and textures are stored etc. The other thing you need to make sure is that the folder is in the classpath, otherwise it won't be able to locate anything. You then use it like this to get a texture:
ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "name of the texture");
I'm pretty sure that the obj format doesn't work with textures, at least I could never get it to work. The maggie model in the jmetest is using materials with diffuse colours I believe, if you want textures, use either ogre or MD5.
Spatial s = getModel("data/models/test.obj");
rootNode.attachChild(s);
And it also worked, even handling multiple textures perfectly.
So as far as I can see, the obj importer works fine, albeit in jme1.
Do you have any errors in the log for failing to find resources etc.
Whilst you can apply the texture manually, I was referring to the use of obj material (.mtl) files, never could get them working and I quickly moved on to MD5.
I take it this means you need to break your model up into submeshes with one texture per submesh? Possibly Wasserleiche has applied multiple textures to a single mesh in the modelling program without breaking up the mesh…
different parts of the model are represented by different children of the node you imported.
You can add a different texture to each child.
But the obj importer can handle complex models with multiple textures. I have tested this. What exactly are you expecting?
I didn't know that the model is splited into different nodes. That would be a possibility, but you first have
to test which node exactly is what mesh... very complicated with complex models.
And which code do you exactly take for model-loading with textures? And how do the paths has to be?
Is the *.mtl-file important? I would be pleased if you could show me the code you're using :)
Still thanks for your replies ;)
Both pieces of code I posted were working code (for me) with nothing important left out - the ony thing I snipped was a basic class extending simplegame, and the method you had already posted, which I used unmodified.
The model I used was a human figure with different textures for face, body, hair, clothes. I did not do anything to prepare the model for jme, only exported it as an obj.
I don't know the innards of the obj importer, guess it just handles some models better than others.