Removing textures during runtime

Started by AugTech, January 28, 2013, 09:18:54 PM

Previous topic - Next topic

AugTech

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...

EgonOlsen

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?

AugTech

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,

EgonOlsen

But even then...i don't see how you managed to stack the textures...anyway...if it works now....