Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-#9905 objectloader parse fonts #11026

Closed
wants to merge 10 commits into from
60 changes: 57 additions & 3 deletions src/loaders/ObjectLoader.js
Expand Up @@ -50,6 +50,7 @@ import { MaterialLoader } from './MaterialLoader';
import { BufferGeometryLoader } from './BufferGeometryLoader';
import { JSONLoader } from './JSONLoader';
import { FileLoader } from './FileLoader';
import { FontLoader } from './FontLoader';
import * as Geometries from '../geometries/Geometries';

/**
Expand Down Expand Up @@ -121,9 +122,19 @@ Object.assign( ObjectLoader.prototype, {

},

parse: function ( json, onLoad ) {
parse: function ( json, onLoad ) {

var geometries = this.parseGeometries( json.geometries );
var fonts = this.parseFonts( json.fonts, function () {

if ( onLoad !== undefined ) onLoad( object );

} );

var geometries = this.parseGeometries( json.geometries, fonts, function () {

if ( onLoad !== undefined ) onLoad( object );

});

var images = this.parseImages( json.images, function () {

Expand Down Expand Up @@ -152,7 +163,36 @@ Object.assign( ObjectLoader.prototype, {

},

parseGeometries: function ( json ) {
parseFonts: function ( json, onLoad ) {

var scope = this;
var fonts = {};

if ( json !== undefined && json.length > 0 ) {

var manager = new LoadingManager( onLoad );

var loader = new FontLoader( manager );

for ( var i = 0, l = json.length; i < l; i++ ) {

var font = json[i];

if ( font.glyphs.hasOwnProperty( 'glyphs' )) {

fonts[ font.uuid ] = loader.parse( font.glyphs );

}

}

}

return fonts;

},

parseGeometries: function ( json, fonts ) {

var geometries = {};

Expand Down Expand Up @@ -279,6 +319,20 @@ Object.assign( ObjectLoader.prototype, {

break;

case 'TextGeometry':
case 'TextBufferGeometry':

data.parameters.font = fonts[data.parameters.glyphs];

geometry = new Geometries[data.type](

data.text,
data.parameters

);

break;

case 'TorusGeometry':
case 'TorusBufferGeometry':

Expand Down