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?
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?
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)
2 Likes
THX! I have read that part in tutorial but I just forgot about uvs.
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”…);
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”…);
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) to clear just the rectangular area where the text lies. But this would clear anything else on that area too.
1 Like
thx! i would try your advice later
1 Like