Hi.
I've been trying to load a .obj model (a simple chest, made with Wings 3d) into jme. I use the sample from TestObjJmeWrite. It took me 2 hours to get Texture.MM_LINEAR_LINEAR to work (the texture was blocky first). After trying passing parameters to the converter, setting TextureKey and trying some other things found in the forums, I came acrross some code here that replaced the texture in the model. I did, and it didn't work.
Finally, while debugging the Node (to see if the change was really applied), I noticed that the model has 2 childs (on purpouse, the box and the soon-hopefully-rotating lid). It worked when the texture was replaced directly in the child. I've always thought that texture, materials, and the like are changed down the tree, if changed in a parent node.
Is this really needed (the change in texture) or am I doing something wrong? It can be left as is… but…
Am I wrong about the node hierarchy?
Thanks in advance.
PD: here is the working code (some test, not needed, still there).
protected void simpleInitGame() {
ObjToJme converter = new ObjToJme();
try {
URL objFile = TestObjJmeWrite.class.getClassLoader().getResource("cofre.obj");
URL textureFile = TestObjJmeWrite.class.getClassLoader().getResource("cube4_auv.bmp");
converter.setProperty("mtllib", objFile);
converter.setProperty("tex_mm", new Integer(Texture.MM_LINEAR_LINEAR));
converter.setProperty("tex_fm", new Integer(Texture.FM_LINEAR));
converter.setProperty("tex_aniso", new Float(1.0f));
ByteArrayOutputStream BO = new ByteArrayOutputStream();
System.out.println("Starting to convert .obj to .jme");
converter.convert(objFile.openStream(), BO);
//jbr.setProperty("texurl",new File(".").toURL());
System.out.println("Done converting, now watch how fast it loads!");
long time = System.currentTimeMillis();
Node r = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
// texture
r.clearRenderState(RenderState.RS_TEXTURE);
r.clearRenderState(RenderState.RS_MATERIAL);
r.updateRenderState();
Texture t = TextureManager.loadTexture(
TestOBJLoad.class.getClassLoader().getResource("cube4_auv.bmp"),
Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
TextureKey tkey = new TextureKey(textureFile, Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR, 1.0f, true, Image.GUESS_FORMAT);
t.setTextureKey(tkey);
t.setWrap(Texture.WM_WRAP_S_WRAP_T);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(t);
r.getChild(0).setRenderState(ts);
//r.setRenderState(ts); // BOOO
// material
MaterialState ms = display.getRenderer().createMaterialState();
ms.setAmbient(new ColorRGBA(0f, 0f, 0f, 1.0f));
ms.setDiffuse(new ColorRGBA(1.0f, 1f, 1.0f, 1.0f));
ms.setColorMaterial(MaterialState.CM_DIFFUSE);
r.getChild(1).setRenderState(ms);
r.updateRenderState();
r.setModelBound(new BoundingBox());
r.updateModelBound();
System.out.println("Finished loading time is " + (System.currentTimeMillis() - time));
System.out.println(" tris: " + r.getTriangleCount());
r.setLocalScale(1f);
rootNode.attachChild(r);
lightState.setSeparateSpecular(true);
} catch (IOException e) {
e.printStackTrace();
}
}