1

I was wondering how you use the TextGeometry.js from the extras folder in three.js in your three.js scene. I was trying to add text to my scene. I found this file and have no idea how to implement/use it. Here's a link to the file: https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/TextGeometry.js

1

1 Answer 1

2

First create a JSON font here.

Then load it like this:

var loader = new THREE.FontLoader();

loader.load("fonts/your_font.json", function(font) {

    var textGeo = new THREE.TextGeometry("This is a 3D text", {

        font: font,

        size: 50,
        height: 10,
        curveSegments: 12,

        bevelThickness: 1,
        bevelSize: 1,
        bevelEnabled: true

     });

    var textMat = new THREE.MeshLambertMaterial({color: 0xFF00FF});

    var textMesh = new THREE.Mesh(textGeo, textMat);

    scene.add(textMesh);

});
Sign up to request clarification or add additional context in comments.

5 Comments

I get this error after doing all of this: 'FrontPageNeue.typeface.json:1 Uncaught SyntaxError: Unexpected token :' Here is my font file: 1001freefonts.com/front_page_neue.font I downloaded this and converted the .otf file to json. Is this wrong? should I do a different file?
Lots of errors. Scene loads now though! here they are: three.js:24569 XMLHttpRequest cannot load file:Html/fonts/FrontPageNeue.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. Then this: TextGeometry.js:1 Uncaught SyntaxError: Unexpected token import Then this: FrontPageNeue.json:1 Uncaught SyntaxError: Unexpected token : TextGeometry.js:1 Uncaught SyntaxError: Unexpected token import
Take a look at this question for the Cross origin request error.
I tried your example, adding it to the HTML shown at the end of threejs.org/docs/#Manual/Introduction/Creating_a_scene, and using r81, but I see nothing. I tried both with my own font, and then this font: github.com/mrdoob/three.js/blob/master/examples/fonts/… I see no errors, and I added a console.log so I know the font is loading. Perhaps you could expand your example to make it fully reproducible?
Just to update: I got it working - your size:50,height:10 was much bigger than the rest of my scene. I think my camera was inside it, or something like that. I also needed to add a light! Both the font in the github repository, and my own font, work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.