I want to add 3D text in my website using the code (according to Labelling the vertices in AxisHelper of THREE.js ) below:
var textGeo = new THREE.TextGeometry('Test', {
size: 10,
height: 5,
curveSegments: 6,
font: "helvetiker",
style: "normal"});
var color = new THREE.Color();
color.setRGB(255, 250, 250);
var textMaterial = new THREE.MeshBasicMaterial({ color: color });
var text = new THREE.Mesh(textGeo , textMaterial);
scene.add(text);
This requires including helvetiker_regular.typeface.js font file before using text Geometry as Three.js needs it for loading text geomtery.
What I find is json file such as "helvetiker_regular.typeface.json" (.js/tree/master/examples/fonts).
Just a rookie in JS programing. Can someone tell me how to include it to make my code work?
I want to add 3D text in my website using the code (according to Labelling the vertices in AxisHelper of THREE.js ) below:
var textGeo = new THREE.TextGeometry('Test', {
size: 10,
height: 5,
curveSegments: 6,
font: "helvetiker",
style: "normal"});
var color = new THREE.Color();
color.setRGB(255, 250, 250);
var textMaterial = new THREE.MeshBasicMaterial({ color: color });
var text = new THREE.Mesh(textGeo , textMaterial);
scene.add(text);
This requires including helvetiker_regular.typeface.js font file before using text Geometry as Three.js needs it for loading text geomtery.
What I find is json file such as "helvetiker_regular.typeface.json" (https://github./mrdoob/three.js/tree/master/examples/fonts).
Just a rookie in JS programing. Can someone tell me how to include it to make my code work?
Share Improve this question edited May 23, 2017 at 12:26 CommunityBot 11 silver badge asked Jul 14, 2016 at 7:32 hrcow88hrcow88 411 gold badge1 silver badge3 bronze badges1 Answer
Reset to default 3You'll need to use a font loader to load the font first:
var fontLoader = new THREE.FontLoader();
fontLoader.load("../path/to/font.json",function(tex){
var textGeo = new THREE.TextGeometry('Test', {
size: 10,
height: 5,
curveSegments: 6,
font: tex,
});
var color = new THREE.Color();
color.setRGB(255, 250, 250);
var textMaterial = new THREE.MeshBasicMaterial({ color: color });
var text = new THREE.Mesh(textGeo , textMaterial);
scene.add(text);
})
Something like that will work if you just want to load it once and dont care about keeping the texture for another time. If you need to keep the "tex" object you could preload it somewhere in the code, and have it accessible for all future textgeometry objects..