4

I tried to create 3D text with FontLoader in Three.js, but I got an error.

I use Three.js r99.

  const loader = new THREE.FontLoader();

  //https://github.com/mrdoob/three.js/tree/dev/examples/fonts
  loader.load("./fonts/helvetiker_regular.typeface.json", function(font) {
    const textGeometry = new THREE.TextGeometry("Hello!", {
      font: font,
      size: 20,
      height: 5,
      curveSegments: 12
    });
    const material = new THREE.MeshNormalMaterial();
    const textMesh = new THREE.Mesh(textGeometry, material);
    scene.add(textMesh);
  });

The output of the Chrome developer tool is as follows.

THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.
VM5770:1 Uncaught SyntaxError: Unexpected token T in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.onLoad (three.module.js:39064)
    at XMLHttpRequest.<anonymous> (three.module.js:33974)

And VM 5770(?) seems to point to the contents of index.html. "T" seems to be T of

<meta charset = "UTF-8" />.

I don't know what happened. Any ideas?

1
  • What exactly is in that font file your code tries to load? Commented Dec 28, 2018 at 14:51

1 Answer 1

6

I solved this. The cause was Parcel, not Three.js. Copying the json file to the dist directory worked perfectly.

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

1 Comment

For me it was public. Same idea

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.