Reset dynamic texture after drawing on it

Hello!

I’m trying to reset a dynamic material that I’ve already drawn on. In my PLAYGROUND I have a button that paints a mesh at random points and another button that I want to use to reset the model. I’m sure there’s like one line I need to clear the drawing but I can’t find it. I tried the context’s clearRect but that doesn’t appear to do the trick.

Thoughts?

Thanks!

hey!
what about that:
https://doc.babylonjs.com/api/classes/babylon.dynamictexture#clear

Hi Delta,

I’d tried that too, but no luck. By itself it didn’t do anything. No error, but nothing noticeable happens, either.

When I added the update method afterwards I noticed that each time I clicked the button to reset, the drawing just… faded a bit more But the original texture also faded.

function ResetDynamicTexture() {
    modelTexture.clear();
    modelTexture.update(invertY);
}

Thank you for your time!

Ok! this is because you are changing the state of the context but you do not restore it:
https://www.babylonjs-playground.com/#T100FS#23

Check line #344 and #370

Ok cool, i get what you’re saying about saving and restoring but, I ran the playground and it doesn’t appear to do anything.

You put the save and restore in the _draw method, i see. So what should happen when you click the generate heat button is:

  1. execution moves into the _draw method and saves the context.
  2. heat patterns are drawn to the context.
  3. context is restored.

Correct? But when I click the generate heat button I only see the heat patterns displayed but not disappearing. My goal is to restore the model to the state it was prior to clicking the generate heat button.

Well,are you sure you are not accumulating your data?

1 Like

Thank you, you were right. i was accumulating data!

1 Like