How to properly dispose a displacement map? And how to reset mesh verts position to where before the displacement texture got applied?

Hey folks,

How should I dispose a displacement map or effects properly?

I apply a displacement texture to a mesh, then I wish to dispose that displacement maps properly after in the same scene:

Many thanks
Tawibox

There’s nothing to dispose, because the image you pass through the url is loaded as an HTML image, and not as a texture (so it will be disposed automatically by the browser).

1 Like

@Evgeni_Popov
Thank you for the response!

OK. it makes sense to the dispose texture question. Sorry I think my original question is confusing.

What about I ask it this way: If I want to reset the verts position to the original position before the displacement map been apply. Is there a proper way?

Thank you!

No, it’s not supported directly. The easiest way would be to retrieve the positions / normals of the mesh (with getVerticesData) before applying the displacement map, and re-set these positions / normals (with setVerticesData) when you want to reset the effect.

2 Likes

@Evgeni_Popov

Gotcha. So what if I clone the original mesh and apply displacement to the cloned one. Then dispose the cloned mesh after. Will this approach work? If so compare to the approach you just mentioned which way is better? (in terms more efficient or less system load)

Yes, this will work, but you need to call makeGeometryUnique() on the clone so that the geometry is not shared between the two meshes.

I don’t think there is really a better or more efficient way to do this, so use what is easiest for you!

1 Like

@Evgeni_Popov

Awsomeee! Thank you so much! These answers are super helpful!