I use my own system getFile() function to retrieve files from our secure app. I fetched the file helvetiker_regular.typeface.json and then parsed it like so:
let loader = new THREE.FontLoader();
let font = loader.parse( jsonFile);
As you can see in my 3 attachments, the parse method returns a generic object, not an instance of a THREE Font object.
When I use loader.load() method it returns an instance of THREE Font object.
Is this a bug?
Alejandro
I guess you have to do this:
const loader = new THREE.FontLoader();
const json = JSON.parse( jsonFile ); // you have to parse the data so it becomes a JS object
const font = loader.parse( json );
BTW: Even in you "incorrect" result, the result object is an instance of type THREE.Font
. You just have a wrong data
property.
Aha! I did try JSON.parse() but inadvertently parsed it backwards!
I did this and of course it wouldn't work...
let font = loader.parse( jsonFile );
font = JSON.parse( font );
This is my final working code, thank you!
getFile( "/fonts/helvetiker_regular.typeface.json", ( jsonString ) =>
{
let jsonParsed = JSON.parse(jsonString);
let loader = new THREE.FontLoader();
let font = loader.parse( jsonParsed );
let shapes = font.generateShapes( "SAMPLE TEXT", 100, 2 );
} );
Most helpful comment
I guess you have to do this:
BTW: Even in you "incorrect" result, the result object is an instance of type
THREE.Font
. You just have a wrongdata
property.