Three.js: setText with TextGeometry during runtime?

Created on 22 Jan 2014  路  5Comments  路  Source: mrdoob/three.js

Thanks for ThreeJS, great stuff, good to learn with the examples. One issue that I face currently is that I cannot change the text at runtime. My code:

var text3dparams = {
    size:           0.3,    // size of the text
    height:     0.05,   // thickness to extrude text
    curveSegments: 2,       // number of points on the curves
    font:           'helvetiker',       // font name
    weight:         'normal',       // font weight (normal, bold)
    style:      'normal',       // font style  (normal, italics)
}
var material = new THREE.MeshBasicMaterial({color: 0xFF5555});
var text3d_volume = new THREE.TextGeometry( "V = 300 m鲁", text3dparams );
var text3dItemV = new THREE.Mesh(text3d_volume, material); 
scene.add(text3dItemV);

I create a cube and label its edges (but labels are not updating the text values): http://www.echteinfach.tv/3d/quader/

Question is, how can the text be changed at runtime?

I hoped there is something like setText("new text"); but there is not :(

_Unfortunately, the text example provided in the source is not using TextGeometry. Other examples I found just add the text but never change it at runtime._



PS: I see only one workaround to remove the 3d text and add it again on every update in render()?

Help (please use the forum)

Most helpful comment

is there plan about supporting this issue?

All 5 comments

I finally did the workaround.

In var render = function () { .... } I remove the 3d text and set it again with the new text values.

scene.remove(text3dItemV);
text3d_volume = new THREE.TextGeometry( 'V = new text', text3dparams );
text3dItemV = new THREE.Mesh(text3d_volume, material); 
scene.add(text3dItemV);

But it would be great if a setText() method could be added to the core.

is there plan about supporting this issue?

When I do this I get a memory leak. :(

Really would be helpful to have text as a parameter to be set at runtime...

For the docs: https://threejs.org/docs/#api/geometries/TextGeometry

I have implemented it along with raycasting and it have terrible performance hit on my app.

http://hiteshsahu.com/#/ModernPeriodicTable

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QuaziKb picture QuaziKb  路  73Comments

mrdoob picture mrdoob  路  75Comments

jonobr1 picture jonobr1  路  95Comments

sunag picture sunag  路  161Comments

WaltzBinaire picture WaltzBinaire  路  67Comments