MCPcopy Create free account
hub / github.com/SuboptimalEng/three-js-tutorials / App

Function App

08-font-loader/src/App.jsx:11–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import SceneInit from './lib/SceneInit';
10
11function App() {
12 useEffect(() => {
13 const test = new SceneInit('myThreeJsCanvas');
14 test.initialize();
15 test.animate();
16
17 // part 0 - comment out template code
18 const boxGeometry = new THREE.BoxGeometry(16, 16, 16);
19 const boxMaterial = new THREE.MeshNormalMaterial();
20 const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);
21 // test.scene.add(boxMesh);
22
23 // part 1 - typeface.json font loader
24 const fontLoader = new FontLoader();
25 fontLoader.load(
26 'node_modules/three/examples/fonts/droid/droid_serif_regular.typeface.json',
27 (droidFont) => {
28 const textGeometry = new TextGeometry('three.js', {
29 size: 20,
30 height: 4,
31 font: droidFont,
32 });
33 const textMaterial = new THREE.MeshNormalMaterial();
34 const textMesh = new THREE.Mesh(textGeometry, textMaterial);
35 textMesh.position.x = -45;
36 textMesh.position.y = 0;
37 test.scene.add(textMesh);
38 }
39 );
40
41 // part 2 - true type font loader
42 const ttfLoader = new TTFLoader();
43 ttfLoader.load('fonts/jet_brains_mono_regular.ttf', (json) => {
44 // First parse the font.
45 const jetBrainsFont = fontLoader.parse(json);
46 // Use parsed font as normal.
47 const textGeometry = new TextGeometry('hello world', {
48 height: 2,
49 size: 10,
50 font: jetBrainsFont,
51 });
52 const textMaterial = new THREE.MeshNormalMaterial();
53 const textMesh = new THREE.Mesh(textGeometry, textMaterial);
54 textMesh.position.x = -46;
55 textMesh.position.y = -10;
56 // test.scene.add(textMesh);
57 });
58 }, []);
59
60 return (
61 <div>
62 <canvas id="myThreeJsCanvas" />
63 </div>
64 );
65}
66
67export default App;

Callers

nothing calls this directly

Calls 2

initializeMethod · 0.95
animateMethod · 0.95

Tested by

no test coverage detected