@@ -4,45 +4,11 @@ import * as ReactDOM from 'react-dom';
44import { animated } from 'react-spring' ;
55import { a } from '@react-spring/three' ;
66import { Canvas , useLoader } from 'react-three-fiber' ;
7+ import { Text } from 'drei' ;
78import * as THREE from 'three' ;
89import { Controls , ControlsProvider , useControl , BaseControl } from '../src' ;
9- import fontFile from './resources/unknown' ;
1010import { useEffect } from 'react' ;
1111
12- function Text ( { children, size = 1 , letterSpacing = 0.01 , color = '#000000' } ) {
13- const [ font ] = React . useState ( ( ) => new THREE . FontLoader ( ) . parse ( fontFile ) ) ;
14- const [ shapes , [ x , y ] ] = React . useMemo ( ( ) => {
15- let x = 0 ,
16- y = 0 ;
17- let letters = [ ...children ] ;
18- let mat = new THREE . MeshBasicMaterial ( {
19- color,
20- opacity : 1 ,
21- transparent : true ,
22- } ) ;
23- return [
24- letters . map ( letter => {
25- const geom = new THREE . ShapeGeometry ( font . generateShapes ( letter , size ) ) ;
26- geom . computeBoundingBox ( ) ;
27- const mesh = new THREE . Mesh ( geom , mat ) ;
28- mesh . position . x = x ;
29- x += geom . boundingBox ?. max ?. x ! + letterSpacing ;
30- y = Math . max ( y , geom . boundingBox ?. max ?. y ! ) ;
31- return mesh ;
32- } ) ,
33- [ x , y ] ,
34- ] ;
35- } , [ children ] ) ;
36-
37- return (
38- < group position = { [ - x / 2 , - y / 2 , 0 ] } >
39- { shapes . map ( ( shape , index ) => (
40- < primitive key = { index } object = { shape } />
41- ) ) }
42- </ group >
43- ) ;
44- }
45-
4612const Next = ( ) => {
4713 const rotationX = useControl ( 'Mega' , {
4814 group : 'Test' ,
@@ -91,7 +57,7 @@ const Box = () => {
9157 group : 'More' ,
9258 type : 'xypad' ,
9359 value : { x : 0 , y : 0 } ,
94- distance : Math . PI ,
60+ distance : 2 ,
9561 } ) ;
9662 const dropdown = useControl ( 'Pick one' , {
9763 group : 'More' ,
@@ -135,7 +101,13 @@ const Box = () => {
135101 < boxGeometry attach = "geometry" args = { [ 1 , 1 , 1 ] } />
136102 < a . meshPhongMaterial attach = "material" map = { texture } color = { color } />
137103 </ a . mesh >
138- < Text > { str } </ Text >
104+ < Text
105+ fontSize = { 1.6 }
106+ color = "black"
107+ font = "https://fonts.gstatic.com/s/raleway/v14/1Ptrg8zYS_SKggPNwK4vaqI.woff"
108+ >
109+ { str }
110+ </ Text >
139111 { dropdown === 'bar' && < Next /> }
140112 </ >
141113 ) ;
0 commit comments