// My CODE =======================================================
import * as THREE from “three”;
import { OrbitControls } from “three/examples/jsm/controls/OrbitControls”;
import { FontLoader } from “three/examples/jsm/loaders/FontLoader”
import { TextGeometry } from “three/examples/jsm/geometries/TextGeometry”
import * as debugUI from “lil-gui”;
// RENDRERE -----------------------------------------------------------
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
document.body.appendChild(renderer.domElement);
// Debug UI
const gui = new debugUI.GUI({width: 300}).hide()
// SCENE -----------------------------------------------------------
const scene = new THREE.Scene();
// scene.add(new THREE.AxesHelper(5));
// CAMERA -----------------------------------------------------------
const cp = {
fov: 50,
ratio: window.innerWidth / window.innerHeight,
near: 0.1,
far: 1000,
};
const camera = new THREE.PerspectiveCamera(cp.fov, cp.ratio, cp.near, cp.far);
camera.position.set(0, 0, 5);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.autoRotate = true;
// const lightA = new THREE.AmbientLight(0x333333)
// scene.add(lightA)
// TEXT
const fontLoader = new FontLoader()
fontLoader.load(“…/node_modules/three/examples/fonts/helvetiker_regular.typeface.json”,
(font) => {
const textG = new TextGeometry(‘POTATO’, {
font: font,
size: 0.5,
height: 0.25,
// curveSegments: 12,
// bevelEnabled: true,
// bevelThickness: 0.2,
// bevelSize: 0.02,
// bevelOffset: 0,
// bevelSegments: 5
})
const textM = new THREE.MeshBasicMaterial()
const textMesh = new THREE.Mesh(textG,textM)
scene.add(textMesh)
})
// const guiCam = gui.addFolder(“Camera”);
// guiCam.add(camera.position, “x”, 1, 20);
// guiCam.add(camera.position, “y”, 1, 20);
// guiCam.add(camera.position, “z”, 1, 20);
// Toggle GUI Visibilty
// window.addEventListener(“keydown”, E => {
// if(E.key === ‘z’){
// (gui._hidden)? gui.show() : gui.hide()
// }
// });
window.addEventListener(“resize”, () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
// RENDER -----------------------------------------------------------
renderer.setAnimationLoop(() => {
controls.update();
renderer.render(scene, camera);
});
ERROR ==========================================================
PROJECT =========================================================
NOTE ============================================================
- Using Parcel as my package Bundler
- Tried 2 approaches for loading font, both not working :
a) fontLoader.load(“…/node_modules/three/examples/fonts/helvetiker_regular.typeface.json”
(I’ve used 2 dots, its showing 3 dots for some weird reason)
b) fontLoader.load(“./assets/fonts/helvetiker_bold.typeface.json”