Dynamically create 2D text in three.js

前端 未结 8 2081
醉梦人生
醉梦人生 2020-12-12 19:20

I have 3D model which I have created in three.js. Based on some data, I want to create a set of arrows which is decorated by a small text label. These labels should be in 2D

8条回答
  •  無奈伤痛
    2020-12-12 20:08

    Update : This method is Deprecated now and is CPU heavy, don't use it.

    I found out another only three.js based solution,

    var textShapes = THREE.FontUtils.generateShapes( text, options );
    var text = new THREE.ShapeGeometry( textShapes );
    var textMesh = new THREE.Mesh( text, new THREE.MeshBasicMaterial( { color: 0xff0000 } ) ) ;
    scene.add(textMesh);
    // Example text options : {'font' : 'helvetiker','weight' : 'normal', 'style' : 'normal','size' : 100,'curveSegments' : 300};
    

    Now to edit this text dynamically,

    var textShapes = THREE.FontUtils.generateShapes( text, options );
    var text = new THREE.ShapeGeometry( textShapes );
    textMesh.geometry = text;
    textMesh.geometry.needsUpdate = true;
    

提交回复
热议问题