# Use Dynamic Texture and drawText on custom mesh

**URL:** <https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942>\
**Category:** Questions\
**Tags:** material, mesh, texture\
**Created:** [September 15, 2022, 2:20am UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942 "2022-09-15T02:20:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 15, 2022, 2:20am UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/1 "2022-09-15T02:20:54Z")

</div>

Hi guys!

I’m trying to build a custom mesh and apply some text on it, so I create a triangle and try to use dynamic texture and drawText(), but I can’t see my text anywhere on target mesh.

I try to adjust font size, dynamic texture size, font x-y-positions, but still I can’t see any word on it.

However the color of the mesh is successfully transferred to canvas color set in drawText() method, so I believe that dynamic texture is already given to that mesh.

So what can I do to fit the text to that mesh?

> **[Babylon.js Playground](https://playground.babylonjs.com/#VKBJN%233381)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 15, 2022, 9:19am UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/2 "2022-09-15T09:19:58Z")

</div>

Seems that only plane mesh and ground mesh can apply drawText() on it?

Is it due to these meshes have fixed size (length\width), so text could easily target its location reference?

---

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 15, 2022, 9:41am UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/3 "2022-09-15T09:41:00Z")

</div>

hmmm anyone?

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 15, 2022, 12:44pm UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/4 "2022-09-15T12:44:02Z")

</div>

There are less people awake at this time of the day so it takes a bit to answer 🙂 Anyways you need uvs in your custom mesh: [Donut | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#VKBJN#3385)

---

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 16, 2022, 12:41am UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/5 "2022-09-16T00:41:24Z")

</div>

THX! I have read that part in tutorial but I just forgot about uvs.

---

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 16, 2022, 9:13am UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/7 "2022-09-16T09:13:37Z")

</div>

Hi carol, thx for solving my problem! 🙂  
I have an extra quick question about updating my text, is there any way to update my text, but not dispose the entire dynamicTexture?  
like  
//draw some text  
myDynamicTexture.drawText(“123”…);  
…  
//update text, but keep the texture  
myDynamicTexture.clearText();  
myDynamicTexture.drawText(“456”…);

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 16, 2022, 12:00pm UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/8 "2022-09-16T12:00:57Z")

</div>

That should work 😃

---

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 16, 2022, 12:40pm UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/9 "2022-09-16T12:40:50Z")

</div>

Hi carol, @carolhmj  
Well that is exactly where my problem lies, where could I find the code that functions to clear the previous texts ?

//draw some text  
myDynamicTexture.drawText(“123”…);  
…  
//update text, but keep the texture  
myDynamicTexture.clearText(); “_This code is my imagination, where can I find code to do this job?_”  
myDynamicTexture.drawText(“456”…);

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 16, 2022, 12:43pm UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/10 "2022-09-16T12:43:45Z")

</div>

Ooooh, sorry, I misunderstood, you want to clear just the text, not the entire texture. Unfortunately that doesn’t exist, as the texture itself has no concept of text, just pixels 😅 What you could do is use the clearRect method from the context [CanvasRenderingContext2D.clearRect() - Web APIs | MDN (mozilla.org)](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clearRect) to clear just the rectangular area where the text lies. But this would clear anything else on that area too.

---

<div class="post-metadata">

**Author:** ![Richardo](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@Richardo](https://forum.babylonjs.com/u/Richardo)\
**Post date:** [September 16, 2022, 1:17pm UTC](https://forum.babylonjs.com/t/use-dynamic-texture-and-drawtext-on-custom-mesh/33942/11 "2022-09-16T13:17:12Z")

</div>

thx! i would try your advice later
