Removing a matcap texture

I’m trying to remove a matcap texture from a MeshMatcapMaterial. I dispose of the previous matcap texture. But since this is a event and happens asynchonously I can’t set matcap to null and set the needsUpdate flag for the material. I used a work around of a timeout. But that feels like a terrible hack. Is there an after dispose event I can add a callback to?

When the camera moves the matcap texture doesn’t track with the camera. I notice a texture has a matrix, is it feasible to use this to track the camera movement.

The removal of the GPU resources actually happens when you call dispose(). The respective event listeners (in this case onTextureDispose()) are directly executed. So the following pattern should work:

material.matcap = null;
material.needsUpdate = true;
1 Like

Hi Michael,
Thanks for your reply, you’re always so quick to respond.
I tried what you suggested at first and it retained the previous matcap. I can share a link if it helps.
Cheers Nik

That would be great.

Bizarrely it’s working now! Any thoughts about tracking the texture with camera movement. It ignores the matrix, presumably because mapping isn’t UVMapping.

Texture.matrix has nothing to do with the camera. It represents the uv transformation matrix which is computed from the offset, center, repeat and rotation texture properties.

Yes, I understand that. I was wondering if perhaps multiplying the matrix by mat.setFromMatrix4(camera.matrixWorld) or something like that might make the matcap track the camera.