Author Topic: Removing textures during runtime  (Read 1968 times)

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Removing textures during runtime
« on: January 28, 2013, 09:18:54 pm »
Hi Egon.
Thought I would post here as a general query.

Within my application I (can) re-use an object, such as a cube or arrow, many times... To save re-creation, memory and time I load each object type that is required into a HashMap with a name (like CUBE1) - if the same object is needed again, it is got from the Map and a new Object3D created from it via the Object3D( 'object_a' ) constructor (which I believe clones the original object).

This process also clones the textures assigned to object 'a' on object 'b' - which is fine except I want a different texture on object 'b' than 'a'. I set object 'b's texture to my newly required texture through obj.setTexture(), but it just <i>adds</i> a reference to the new texture, compared to replacing it. This would be fine, but I cannot remove/ change the reference to the original texture, therefore object 'b' now has two textures.

How can I re-use an object many times, whilst minimising replication, but keep changing the texture  - is there a way of doing obj.removeTexture(), obj.deleteTexture() or obj.replaceTexture() ?

Many thanks...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Removing textures during runtime
« Reply #1 on: January 28, 2013, 11:49:28 pm »
You actually don't have to replace or remove it. Just set a new one should do the trick. I've no idea how to manage to stack them that way... :o Can you post some code?

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Removing textures during runtime
« Reply #2 on: January 30, 2013, 03:52:08 pm »
Sorry, my mistake...;)

On closer inspection, what was actually happening was;
I was cloning the object after setting a texture on the original, so when there was an object without a texture being set it retained the original. A removeTexture() function would resolve it, but I have swapped the order around so clones are taken before texture setting.

Cheers,

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Removing textures during runtime
« Reply #3 on: January 30, 2013, 04:41:38 pm »
But even then...i don't see how you managed to stack the textures...anyway...if it works now....