Issue in Three JS: I encountered the error message "Unsupported OpenType signature <!DO" and need to

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!

Answer №1

After some trial and error, I finally discovered my mistake. This time around, I opted to use THREE FontLoader instead of TTFLoader and made sure to provide the absolute path from the root project directory. Placing the code snippet this.scene.add(this.textMesh) within the callback function was crucial. I utilized a font example provided by the library:

'node_modules/three/examples/fonts/helvetiker_regular.typeface.json'
, which required an absolute path.

Here's the revised code snippet:

const fontLoader = new FontLoader();
fontLoader.load(
  'node_modules/three/examples/fonts/helvetiker_regular.typeface.json',
   (Helvfont) => {

    this.textGeo = new TextGeometry('Yeah', {
      font: Helvfont,
      size: 0.2,
      height: 0,
    });

    this.textMaterial = new THREE.MeshNormalMaterial();
    this.textMesh = new THREE.Mesh(this.textGeo, this.textMaterial);
    this.textMesh.position.set(-0.5, 0.5, 0);
    this.scene.add(this.textMesh);
  },
);

If you wish to load a .ttf font instead, simply utilize TTFLoader to load the font file and then use FontLoader.parse() to parse the JSON data. This conversion process is necessary for using the .ttf font format.

Here's the updated code snippet for loading a .ttf font:

 const ttfLoader = new TTFLoader();
 const fontLoader = new FontLoader();

 ttfLoader.load('src/fonts/Mont-Regular.ttf', (json) => {
    const MontFont = fontLoader.parse(json);

    this.textGeo = new TextGeometry('Yeah', {
      font: MontFont,
      size: 0.2,
      height: 0,
    });

    this.textMaterial = new THREE.MeshNormalMaterial();
    this.textMesh = new THREE.Mesh(this.textGeo, this.textMaterial);
    this.textMesh.position.set(-0.5, 0.5, 0);
    this.scene.add(this.textMesh);
 });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting a problem with jQuery child items

Could someone help me understand why the second div is affected by the last part of the code and not the first? It's puzzling to see all the content disappear, especially when I expected the first div to be impacted as it seems like the immediate pare ...

Assistance needed for disabled JavaScript

I'm currently working on a small application where I need to display some text wrapped in 3 divs. The goal is to only show one div at a time and provide users with prev and next buttons to switch between them. However, when JavaScript is disabled, I w ...

Detecting onclick on a model in three.js: A simple guide

I am curious if there is a method in three.js that allows users to click on a model (such as an imported gltf file from Blender) and trigger another action upon the click, such as displaying a pop-up box or an image. I attempted to search for this feature ...

"Send the selected radio button options chosen by the user, with the values specified in a JSON format

My current task involves inserting radio button values into a MySql database using Angular. The form consists of radio buttons with predefined values stored in a json file. Below is an example of how the json file is structured: //data.json [{ "surve ...

Creating a 3D visualization with three.js

My project requires me to create a 3D scatter graph using three.js. I have attempted to implement the code provided below. While the code is functional, the resulting graph appears more like a 2D representation. Adjusting the camera position can add depth ...

The aspect ratio of Threejs sprites is appearing distorted

I'm facing an issue with rendering two objects in an Orthographic camera using Three.js. The objects are not rendering correctly and I'm unsure of the reason behind it. The expected look of the two images is as follows: https://i.sstatic.net/hQ ...

What is the best way to display a list of search outcomes?

I've hit a roadblock trying to figure out what's happening. Despite watching videos on maps, arrow functions, and implicit returns, my code still doesn't seem to make sense. Everything checks out when I console log it, all the data is there. ...

Transform the characters within a string into corresponding numerical values, calculate the total sum, and finally display both the sum and the original string

I'm looking to convert a string containing a name into numerical values for each character, ultimately finding the sum of all characters' numerical values. Currently, only the first character's value is being summed using .charAt(). To achie ...

Discovering the Harshad number

I find myself in a predicament where the issue at hand is defined as: Harshad/Niven numbers are positive numbers that are divisible by the sum of their digits. All single-digit numbers are Harshad numbers. For instance, 27 is a Harshad number as 2 + 7 = ...

What is the best way to limit the number of items shown in a cart dropdown using JavaScript

I have a shopping cart feature added to my ecommerce web app. Within the header, there is an icon of a cart. When clicked, a dropdown appears showing the items added to the cart. However, if I have 10 items in the cart, the dropdown becomes too lengthy to ...

I am trying to include the Css Baseline from @mui/material in my project. However, even though it is present in my JSON file, I am encountering an error stating that '@mui/material' needs to be included in the project

Struggling to import Css Baseline from @mui/material, it's listed in my json but I keep getting an error saying '@mui/material' should be included in the project's dependencies. I've been stuck on this issue for a while now! { &q ...

Creating a canvas with multiple label introductions can be achieved by following these

I am looking to group labels and sublabels on the x-axis of a canvas component. Currently, I only have sublabels like: RTI_0, RTI_1... I would like to add labels to these sublabels like: RTI = {RTI_0,RTI_1,RTI_2] BB = {BB_0, BB_1,BB_2,BB_3] <div cla ...

Using AngularJS with angular-google-maps to easily add markers through a form and locate your position with one click

I'm attempting to replicate the functionality demonstrated on since it fulfills 90% of my requirements. However, I'm facing some difficulties. While I can retrieve my location and log it in the console, a marker is not appearing on the map. Add ...

EdgesHelper is malfunctioning

My goal is to showcase the edges of multiple cubes by utilizing the EdgesHelper class. Although I am referencing this example, I am encountering difficulties in replicating the desired effect in my own demonstration: Demo = function(dom, width, height, n) ...

How to automatically scroll to the bottom using jquery/css

I've recently developed a chatroom using li elements, but I'm encountering an issue where the chat doesn't stick to the bottom once it reaches a certain number of messages. I suspect it has something to do with the height settings, but I can ...

Trouble with Mongoose: Data Not Being Saved

I'm encountering difficulties with a basic query on my database. While following this tutorial at https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4, the author receives a JSON object containing the name field (the only custom fi ...

using an x-api-key in the header of a service within Angular

I have been struggling with calling an x-api-key in the header of my Angular service, and I'm encountering an authorization error. It seems like there may be a syntax issue in my code. import { Injectable } from '@angular/core'; import { Htt ...

Custom transaction settings for Mongoose

When conducting transactions, we often have the ability to customize certain options. For example, we can specify transaction options like the ones shown below: const transactionOptions = { readPreference: 'primary', readConcern: { level: &ap ...

Issue with utilizing Vuejs variable in Google Maps Matrix API function

Having trouble accessing a Vue.js variable in a function using the Google Maps Matrix API. I am trying to use the Google Distance Matrix API to calculate the distance between two locations. I have declared a variable globally and changed it within a functi ...

The vertical timeline feature in React does not appear to be displaying properly on the web browser

import { VerticalTimeline, VerticalTimelineElement } from "react-vertical-timeline-component" import { motion } from "framer-motion" import 'react-vertical-timeline-component/style.min.css'; import {styles} from '../styl ...