最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to include typeface.json font file in three.js? - Stack Overflow

programmeradmin5浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 3

You'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..

发布评论

评论列表(0)

  1. 暂无评论