I am trying to create some 3d text but I get the following error:
Uncaught (in promise) SyntaxError: Unexpected string in JSON at position 2
at JSON.parse (<anonymous>)
at Object.onLoad (FontLoader.js:34:17)
at three.module.js:39650:38
My code looks something like this:
import { FontLoader } from 'three/examples/jsm/loaders/FontLoader'
import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry'
const fontLoader = new FontLoader()
fontLoader.load(
'/helvetiker_bold.typeface.json',
(font) => {
const textGeometry = new TextGeometry('Font Loaded', {
font: font,
})
}
)
I thought this was due to the parsing were JavaScript turns JSON into an object, so I decided to import the font directly and use it with textGeometry changing my code to:
import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry'
import font from './fonts/helvetiker_bold.typeface.json'
const textGeometry = new TextGeometry('Font Loaded', {
font: JSON.parse(JSON.stringify(font)),
})
This gave me a new error that said:
Uncaught TypeError: font.generateShapes is not a function
at new TextGeometry (TextGeometry.js:34:24)
at Object.6yeCB.three (index.js:8:22)
at newRequire (index.b59b4001.js:71:24)
at index.b59b4001.js:122:5
at index.b59b4001.js:145:3
I have no idea why this is happening or what I can do to fix it, I’ve tried multiple fonts and many different file nesting structures but the problem seems that the font itself isn’t compatible, which is weird considering most of the fonts I used are from the three.js fonts file.
Some things to note:
- I have the latest three.js version
- I am using parcel as a development server but I don’t think it’s the issue
Please help : (