Author Topic: How to reapply textures from TextureManager?  (Read 3414 times)

Offline dudo24

  • byte
  • *
  • Posts: 5
    • View Profile
How to reapply textures from TextureManager?
« on: May 14, 2014, 10:03:00 pm »
The concept of my project is that I have a textured 3D model of a car.
And I want to be able to change textures on the 3d model by press of a button (like a yellow car after button press turns to blue for example).
I have my textured 3D model rendered, that wasn't a problem.
My approach to the texture change was that I have two .3ds files of the same model but each file has different textures (but same names).
So I would remove all the textures which belong to the model from the TextureManager and load new textures from file and store them in the TextureManager.
But now I don't know how to tell TextureManager to apply all those textures.
Because it does automatically and I couldn't find function for this in the specification.
Only way I got it to work was to reload the whole object with the new textures. But that is not very efficient.

So my question: Am I using the right approach? and: How to tell TextureManager to reapply textures on a 3D model.

Thank you


Offline dudo24

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to reapply textures from TextureManager?
« Reply #2 on: May 15, 2014, 03:58:57 am »
It didn't quite work. I'll give it a few hours tomorrow and we'll see.
« Last Edit: May 15, 2014, 05:15:38 am by dudo24 »

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: How to reapply textures from TextureManager?
« Reply #3 on: May 15, 2014, 05:52:28 am »
Hi Egon,

Does the method proposed process sequentially per texture during the next render pass? Or all textures are loaded first, then remove the existing textures? Or vice-versa?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to reapply textures from TextureManager?
« Reply #4 on: May 15, 2014, 10:48:11 am »
It will removes all old textures at once in the new frame and then upload the new ones on demand.

Offline dudo24

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to reapply textures from TextureManager?
« Reply #5 on: May 16, 2014, 03:45:21 am »
Ok, so I successfully replaced textures. First I unloaded them and then I replaced them. Thank you for your advice.

I also figured out how to change material color. I just needed to find out how does TextureManager store materials. The process was the same I unloaded the material and replaced it with a new texture of set color that i created.

But I have more questions regarding this topic. I can only replace already existing textures. If I add new textures into TextureManager it has no effect, those textures do not render. So I was thinking that when creating 3D model (a cube lets say) in Blender I add a fully transparent texture layer on each side of the cube on top of material. And then later I'm able to replace those transparent textures with other textures if needed. But when I rendered the cube the whole object was transparent the material layer underneath was not visible. And I couldn't quite figure out how to use the TextureInfo class if I wanted the TextureManager to automatically apply the textures on the cube model.

So my question is how to effectively solve problem of adding texture on already rendered 3D object in a way that TextureManager does all the work for me like when I first load the object.
If I'm not clear enough I can try to explain myself better.

Thank you. I appreciate your help.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to reapply textures from TextureManager?
« Reply #6 on: May 16, 2014, 08:22:15 am »
I'm not sure what the exact question is, but i'll give some general hints. Maybe they help...

jPCT's file importers load either the texture or the diffuse color of a material. They don't load both. So once you assign a texture to a polygon, this will be taken instead of the material's color.

Before the first rendering, the object will be compiled. After that, you can still change the textures but what should become an individual texture can only do so if it was one before compilation. An example: A six sided cube that had the same texture on all sides can't be changed in a way that each side gets its own texture. If you want that, you have to assign an individual texture to each side before the compilation happens.

Offline dudo24

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to reapply textures from TextureManager?
« Reply #7 on: May 16, 2014, 01:54:12 pm »
Ok, now I get it completely. Thank you very much for your advice and your time.