Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

javascript - How to load a font and render it with TextGeometry

I recently started working on three.js and now im facing issue on textgeometry. Im using three.js version 75 and i used js/helvetiker_bold.typeface.js font.

var geometry = new THREE.TextGeometry( this.txt, {
  size: this.textSize,
  height: this.textHeight,
  curveSegments: 3,
  font: this.textFont,
  weight: "bold",
  style: "normal",
  bevelEnabled: false
});

test is not rendering because of the following issue

1 Uncaught ReferenceError: _typeface_js is not defined

2.three.min.js:889 THREE.TextGeometry: font parameter is not an instance of THREE.Font

Can anyone please help me out.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use this pattern to load a font and render it with TextGeometry:

var loader = new THREE.FontLoader();

loader.load( 'fonts/helvetiker_bold.typeface.json', function ( font ) {

    var textGeo = new THREE.TextGeometry( "My Text", {

        font: font,

        size: 200,
        height: 50,
        curveSegments: 12,

        bevelThickness: 2,
        bevelSize: 5,
        bevelEnabled: true

    } );

    var textMaterial = new THREE.MeshPhongMaterial( { color: 0xff0000 } );

    var mesh = new THREE.Mesh( textGeo, textMaterial );
    mesh.position.set( x, y, z );

    scene.add( mesh );

} );

three.js r.82


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...