Hey there, I'm relatively new to Three.js and having some trouble getting basic text to render. Most of the solutions I found on StackOverflow seem outdated, so I thought I'd ask here. The code snippet below only results in a black screen. Any help would be greatly appreciated!
<html>
<head>
<title>Text Test</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/85/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var loader = new THREE.FontLoader();
var font = loader.load(
// resource URL
'helvetiker_bold.typeface.json',
// Function when resource is loaded
function ( font ) {
var geometry = new THREE.TextGeometry( 'Hello three.js!', {
font: font,
size: 80,
height: 5,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 10,
bevelSize: 8,
bevelSegments: 5
} );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var textMesh = new THREE.Mesh( geometry, material );
scene.add( textMesh );
camera.position.z = 5;
var render = function () {
requestAnimationFrame( render );
renderer.render(scene, camera);
};
render();
},
// Function called when download progresses
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// Function called when download errors
function ( xhr ) {
console.log( 'An error happened' );
}
);
</script>
</body>