I'm currently working on a three js project and using parcel as my module bundler. I've encountered an issue while trying to load a font with THREE js TTFLoader. Despite researching similar problems online, some suggesting it may be related to the relative path of the font file, I'm still unable to pinpoint the exact cause of the error.
Here is an image showing the error: https://i.sstatic.net/v8OC7.jpg
Project directory structure:
https://i.sstatic.net/fFKA9.jpg
Snippet of code where the error occurs:
app.js
// Loading font using TTFLoader
const ttfLoader = new TTFLoader();
ttfLoader.load('fonts/Mont-Regular.ttf', (json) => {
const font = new FontLoader(json);
this.textGeo = new TextGeometry('Hello Text', {
font: font,
size: 200,
height: 50,
curveSegments: 12,
});
this.textMaterial = new THREE.MeshPhongMaterial({
color: 0xff0000,
side: THREE.DoubleSide,
});
// Creating text mesh
this.textMesh = new THREE.Mesh(this.textGeo, this.textMaterial);
this.textMesh.position.set(0, 0, 0);
});
this.scene.add(this.textMesh);
Codesandbox link for reference: https://codesandbox.io/s/three-project-0hpqjr
If anyone can help me resolve this issue, I would greatly appreciate it. Thank you!