I'm using the ThreeJS library together with React.
I've installed ThreeJS using npm.
Adding images works fine - I'm importing an image in react like this:
import stockImage from './../../images/download.jpg';
and using it like this works great:
this.addCube(stockImage, { x:2, y:2, z:2 } );
(...)
addCube(imageUrl, aPosition) {
//Load image as material:
var anImageMaterial = new THREE.MeshBasicMaterial({
map : this.textureLoader.load(imageUrl)
});
//Make box geometry:
var box = new THREE.BoxGeometry( 1, 1, 1 );
//Create mesh:
var cube = new THREE.Mesh( box, anImageMaterial );
//Add to scene:
this.scene.add( cube );
return cube;
}
When trying to add text to the canvas using this tutorial.
I'm trying to import the font in react like this:
import helveticaRegular from './../../fonts/helvetiker_regular.typeface.json';
Printing it like this looks good, so it doesn't seem to be a problem with react:
console.log(helveticaRegular);
However using the font like this throws an error:
var loader = new THREE.FontLoader();
loader.load( helveticaRegular, function ( font ) {
var geometry2 = new THREE.TextGeometry( 'Hello three.js!', {
font: font,
size: 80,
height: 5,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 10,
bevelSize: 8,
bevelSegments: 5
} );
this.scene.add(geometry2);
} );
The error is the following:
Please ignore C:/xammp/... as I'm not using xammp, but the folder naming was from when I used xammp.
Loading fonts like this using xammp, using a regular url does not produce the same error.
I don't know if the problem is due to urls or react or the FileLoader.load function in ThreeJS.

