Skip to content

Commit b8dc63c

Browse files
committed
feat: controls anchor
1 parent 1bf0b2a commit b8dc63c

6 files changed

Lines changed: 260 additions & 3309 deletions

File tree

example/index.tsx

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,11 @@ import * as ReactDOM from 'react-dom';
44
import { animated } from 'react-spring';
55
import { a } from '@react-spring/three';
66
import { Canvas, useLoader } from 'react-three-fiber';
7+
import { Text } from 'drei';
78
import * as THREE from 'three';
89
import { Controls, ControlsProvider, useControl, BaseControl } from '../src';
9-
import fontFile from './resources/unknown';
1010
import { 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-
4612
const 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
);

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "parcel build index.html"
99
},
1010
"dependencies": {
11+
"drei": "^1.3.2",
1112
"react": ">= 16.8.0",
1213
"react-app-polyfill": "^1.0.6",
1314
"react-dom": ">= 16.8.0",

0 commit comments

Comments
 (0)