easy way to create text meshes in 3d and 2d for TRHEE.js based on BufferGeometry and ExtrudeBufferGeometry.
npm install three.text --save
note: is possible change the text dinamically without remove and create the text mesh again
Include script
<script src="node_modules/three.text/src/THREE.Text.js"></script>
If you need include THREE.js in script
var THREE = require( 'three' );
Create mesh
var textMesh = new THREE.DText({
text: "hello world"
});
or 3d:
var textMesh = new THREE.DText({
text: "hello world",
_3d:true
});
note: THREE.DText is correct Syntax
Add to scene or group:
scene.add( textMesh );
options
- text : Text to show
- font : Font family of text (default : helvetik) , need a string with font route, the lib load font automatically.
- divisions : Divisions of shape ( default : 2)
- size : Size of text (default : 20)
- color : Text color (default : red - 0xff0000)
- Material : Mesh Material ( default : MeshBasicMaterial)
- _3d : Build Mesh in 3d
- extrudeSettings : Object settings for buid 3d Mesh (reference ExtrudeBufferGeometry)
Additional Method Mesh
- setColor : For set color of Mesh , use color.setHex() method of material;
- setMaterial : Change Material of Mesh
- setFont : Change font of Mesh, need a string with font route.
- setText : Change text of Mesh
- setSize : Change size text
- transform3d : Transform Mesh to 2d to 3d
- transform2d : Transform Mesh to 3d to 2d
- setExtrudeSettings : Change Object settings for build 3d Mesh: (reference ExtrudeBufferGeometry)
Alex Marcos Gutierrez
MIT