# Reset dynamic texture after drawing on it

**URL:** <https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892>\
**Category:** Questions\
**Created:** [April 30, 2019, 8:31pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892 "2019-04-30T20:31:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos.Mendieta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carlos.mendieta/32/124_2.png) [@Carlos.Mendieta](https://forum.babylonjs.com/u/Carlos.Mendieta)\
**Post date:** [April 30, 2019, 8:31pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/1 "2019-04-30T20:31:14Z")

</div>

Hello!

I’m trying to reset a dynamic material that I’ve already drawn on. In my [PLAYGROUND](https://www.babylonjs-playground.com/#T100FS#21) 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!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 30, 2019, 9:44pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/2 "2019-04-30T21:44:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Carlos.Mendieta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carlos.mendieta/32/124_2.png) [@Carlos.Mendieta](https://forum.babylonjs.com/u/Carlos.Mendieta)\
**Post date:** [May 1, 2019, 12:24pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/3 "2019-05-01T12:24:09Z")

</div>

Hi Delta,

[I’d tried that too](https://www.babylonjs-playground.com/#T100FS#22), 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!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 1, 2019, 2:55pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/4 "2019-05-01T14:55:26Z")

</div>

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](https://www.babylonjs-playground.com/#T100FS#23)

Check line #344 and #370

---

<div class="post-metadata">

**Author:** ![Carlos.Mendieta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carlos.mendieta/32/124_2.png) [@Carlos.Mendieta](https://forum.babylonjs.com/u/Carlos.Mendieta)\
**Post date:** [May 1, 2019, 5:50pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/5 "2019-05-01T17:50:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 1, 2019, 9:44pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/6 "2019-05-01T21:44:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Carlos.Mendieta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carlos.mendieta/32/124_2.png) [@Carlos.Mendieta](https://forum.babylonjs.com/u/Carlos.Mendieta)\
**Post date:** [May 2, 2019, 2:58pm UTC](https://forum.babylonjs.com/t/reset-dynamic-texture-after-drawing-on-it/2892/7 "2019-05-02T14:58:36Z")

</div>

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