I recently started working with three.js and I'm experimenting with some basic code. However, I keep encountering the same error message. I was under the impression that I added the object to the scene after using the loader.load function, so I'm confused as to why this issue is arising.
- "three.js:5348 THREE.Object3D.add: object not an instance of THREE.Object3D."
JS -
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement); // add the renderer to html
camera.position.z = 6;
const loader = new THREE.FontLoader();
loader.load('font/UniversalSans-450_Regular.json', function (font) {
// TextGeometry(String, Object)
const textObj = new THREE.TextGeometry('Trying out something new', {
font: font,
size: 80,
height: 5,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 10,
bevelSize: 8,
bevelOffset: 0,
bevelSegments: 5
});
scene.add(textObj);
});
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();