Tips on adding custom fonts for text geometry in three.js

Currently, I am delving into the realm of three.js to create text geometry, although my expertise in JavaScript is fairly limited.

Initially, I attempted to utilize my custom JSON font, which resulted in the same error encountered when using fonts from the three.js examples. I came across a solution where someone employed the self = this technique.

this.pageTitles = [];
const self = this;
const loader = new THREE.FontLoader();

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

    self.pages.forEach((page) => {

        self.pageTitles.push(
            new THREE.TextGeometry( page, {
                font: font,
                    size: 80,
                    height: 1,
                    curveSegments: 12,
                    bevelEnabled: false
             })
        );

    });


});

The error message I am currently facing is:

Uncaught SyntaxError: Unexpected string in JSON at position 1
    at JSON.parse (<anonymous>)
    at Object.eval [as onLoad] (three.module.js?5a89:40134)
    at XMLHttpRequest.eval (three.module.js?5a89:34850)

It's worth noting that I am utilizing VueJS, and the code in question resides within a separate JavaScript file that exports a class.

As a follow-up question, how would I go about loading a font that I obtained from Google Fonts and converted into .json format?

Answer №1

VueJs is unable to interpret paths that are not located within the dist folder. Make sure to place the helvetiker_bold.typeface.json file inside the dist folder.

const fontLoader = new THREE.FontLoader();
fontLoader.load( '/helvetiker_bold.typeface.json', (font) => {
   ...//perform any desired actions
});

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

Having issues with displaying a pie chart in a React application using Chart.js

I am currently experiencing a problem with displaying a pie chart in a React component using the react-chartjs-2 library and Chart.js. The data for the chart is retrieved from an API, and I expect the chart to appear once the data is ready. However, despit ...

How can I conceal the element that came before in JavaScript?

<div onclick="toggleContent(this)" class="iptv"><div class="triangle"></div><b>LUZ HD</b> - 98 channels (including 32 HD channels) <div class="iptv_price"><b><img src="img/rj45.png" class="icon_ofert ...

Fetching the Key-Value pairs from a HashMap in JavaScript/AngularJS

I am currently working with a HashMap in the Frontend that is being retrieved from the Backend: var myVar = {"24":{"amount":2,"minutes":30},"32":{"amount":3,"minutes":30}} Can anyone offer guidance on how to access both the keys and values in Javascript ...

Having issues with the POST method in node.js and express when connecting to a MySQL database

My GET method is functioning perfectly I have a database called stage4 and I am attempting to insert values into it from a frontend page The connection is established, I'm using Postman to test it first, but it keeps returning a "404 error" which is ...

Extracting information from various tables when exporting in Laravel

I currently have two tables on hand: Accessory Request Table Accessory Details Table It's worth noting that one accessory request can have multiple entries in the accessory details table. However, when I attempt to export the data, only information ...

Unable to conceal adjacent element when z-index is set as 1

I encountered an issue where a modal is overlapping another element, and the close button of the underlying element has a z-index of 1. Despite creating a new modal with its own close button, the original close button remains visible on top. I attempted t ...

Tricking ASP.NET and IE8 with a Pseudo Asynchronous File Upload Method

Just a heads up, I have to cater to IE8 for a few different reasons. I've come across various methods that involve placing a file upload control inside a form element, and then using an iframe to mimic an AJAX file upload (like this one at How to make ...

What is the method for enabling or disabling a text field based on the chosen value in a b-form-select?

Can anyone assist me with enabling or disabling an input text field based on the values selected in a b-form-select element? Your help would be greatly appreciated. ...

The 'userEvent.type' function in React Testing Library is failing to update the input value in a Material UI TextField component that has

I am currently facing an issue with a material UI TextField element that is meant to track the latitude value. The requirement is for the latitude to fall within the range of -90 to 90 degrees. I have implemented a unit test as a validation measure, howeve ...

Tips for customizing the color of the current date in the angular-material datepicker

I've created a function in angular-material to disable dates two days from now, but I'm struggling to change the color of the current date if it's disabled. The issue is that when the current date is disabled, it displays in a very light blu ...

Is there a way to reverse the confirmation of a sweet alert?

Hey there, I'm currently using Sweet Alert to remove a product from my website. I want to implement it with two options - 'ok' and 'cancel'. However, I'm facing an issue where clicking anywhere on the page removes the product ...

I'm looking to achieve a horizontal wrapping alignment of cards in Vuetify 2. How can I accomplish this?

In my current project using vuetify 2, I am facing an issue where all my cards are displaying vertically within a col of width 7 instead of in a horizontal overflow. My goal is to have the cards arranged vertically with five counts on each row, and any ov ...

What is the best way to display table rows for a specified date range?

I am working with a table and need to display only the rows that fall between two specific dates. <table id ="Table"> <thead> <tr> <th>Date</th> <th>Name</th> <th>Desc</th> </tr> </thead> ...

Learn how to eliminate all text characters from a string using jQuery, leaving only the numerical values behind

My webpage features a variety of different products, each with their own values. When trying to calculate the total sum of these products and display it in the shopping cart, I encountered an error displaying NaN. How can I remove this NaN from the strin ...

Is it possible to utilize `const` in place of `let` universally?

When utilizing flowtype, our preference is to use const over let I have a function that needs to be executed with optimal performance, and it effectively compares two arrays with ids. This serves as a great example for my question: /** * @function compar ...

What is the process for establishing a connection between two sets of data?

I am working with two mongoose models: user.js and note.js, which correspond to the collections notes and users. I want users to be able to save their notes, but I'm unsure how to create relationships between these collections. Ideally, I would like t ...

Progressive rendering of particles in THREE.js

I am new to the world of 3D and I'm trying to render particles as they are created. My goal is to have these 2000 particles render individually as they are created, but with the current code, they only render once all particles have been created. I h ...

What is the technical process behind conducting A/B testing at Optimizely?

I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless. To utilize the Google API properly, a few steps need to be taken. Firstly, I nee ...

Switching to '@mui/material' results in the components failing to render

I have a JavaScript file (react) that is structured like this: import { Grid, TextField, makeStyles } from '@material-ui/core' import React from 'react' import {useState} from 'react' //remove this function and refresh. see ...

Can a material be blended with a reflection (using cubemap) in Three.js?

I have a three.js object with a colorful texture applied to it, such as a car. I'm interested in adding a partial reflection to the surface to create a final material that combines shiny red metal and reflects the scene. How can I achieve this? While ...