Insane textures when reloading models

I’ve made a model loader application for a 3D artist I know, so that he can test models he’s made, in various formats, that are exported to .jme. (This is also my first application using jME). Everything works fine the first time the model is loaded, but if you try to load the model a second time (using the ‘o’ key), then the textures are insane. Um… here’s what I mean:



This is what happens when you try to load Dr. Freak after loading some other model:

http://www.kinostudios.com/images/oddtextures.jpg

Here, everything’s really weird, I can’t see his body, I can see parts of texture that I’m not supposed to see, and half of the texture on his head is missing.



This is what happens when I tried to load a model that was exported from a 3DS file (after first loading a model):

http://www.kinostudios.com/images/oddtextures2.jpg

As you can see, this time it’s not even loading the right texture! (but it does on the first try).



I’m probably missing something obvious… I don’t know. You can look at the source for this application here. (btw, PropertiesManager is just another class I made to manage preferences).



Oh, and any code critique is welcomed!



Thanks for any help!

This is what happens when you try to load Dr. Freak after loading some other model:
http://www.kinostudios.com/images/oddtextures.jpg
Here, everything's really weird, I can't see his body, I can see parts of texture that I'm not supposed to see, and half of the texture on his head is missing.


This image actually looks like a zbuffer issue to me rather than a texture problem. Are you sure you are setting a zbuffer state to the model after loading it the second time?

This is what happens when I tried to load a model that was exported from a 3DS file (after first loading a model):
http://www.kinostudios.com/images/oddtextures2.jpg
As you can see, this time it's not even loading the right texture! (but it does on the first try).


That's certainly odd, it's picking up the font texture.

We'll take a look.
"mojomonk" wrote:
This is what happens when you try to load Dr. Freak after loading some other model:
http://www.kinostudios.com/images/oddtextures.jpg
Here, everything's really weird, I can't see his body, I can see parts of texture that I'm not supposed to see, and half of the texture on his head is missing.


This image actually looks like a zbuffer issue to me rather than a texture problem. Are you sure you are setting a zbuffer state to the model after loading it the second time?
Um no I'm not. Shouldn't the zbuffer of simplegame pass down to the model?
This is what happens when I tried to load a model that was exported from a 3DS file (after first loading a model):
http://www.kinostudios.com/images/oddtextures2.jpg
As you can see, this time it's not even loading the right texture! (but it does on the first try).


That's certainly odd, it's picking up the font texture.

We'll take a look.

Thanks! :)

P.S. I notice you are using Mac OS X. Can you try your same tests on a Windows machine? It might be a mac specific image loading issue. Just something worth checking until I get a chance to go home and play with it.

Sure! I’ll get back to you soon (gotta eat first!).

Um no I'm not. Shouldn't the zbuffer of simplegame pass down to the model?


Yes it should. Are you calling updateRenderState() on your model after loading it?

Well, I am if it’s an MD2 file (and therefore the texture must be set manually). But they all load fine the first time around, so I don’t think that should be a problem.

Ok, tried on a PC; identical problem (with both models).

I’ve had this problem before, both with the odd Z buffering and the font texture on models, and it was caused by RenderStates - it turned out I was calling updateRenderState() on a Node before adding it into the scene graph, and it needed calling afterward instead.



Anyway, try calling updateRenderState() on SimpleGame’s root node after you’ve done all your model loading and adding it to the scene graph. Hope I’m not stepping on anyone’s toes, Mojo and Renanse know the ins and outs of render states better than me…

You know, that’s interesting. I removed the call to updateRenderState() after applying the texture, and now Dr. Freak has the font texture applied to him as well! What’s going on???

chaosdeathfish you hit it dead on! Why though??? :smiley:



I fixed it by moving the call model.updateRenderState() in loadModel() to the very end of loadModel().



Why this worked however, and why jME flips out if it’s not done, I don’t know. Can anyone explain it to me?

It actually is not “flipping out”… If you don’t update the renderstates (ie, set them to active) then nothing is called for those states when rendering that object. OpenGL is a state driven machine and thus the previous state is still in memory. IOW, the font texture is still in memory and thus used to draw Dr. Freak. The same would be true about other states.



Moral of the story: Make sure you call updateRenderState() on things you add to a scene during application runtime. Call it as one of the last things you do.

Ah, that makes perfect sense. Thanks renanse! :slight_smile:

Sure thing!