File size: 3,154 Bytes
2485dd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * EXPERIMENTAL components to play around with but not officially use in the demo while
 * we develop.
 */
import {useEffect, useState} from 'react';
import {Object3DNode, extend} from '@react-three/fiber';
import ThreeMeshUI from 'three-mesh-ui';

import {} from '@react-three/xr';
import {Sparkles, Shadow} from '@react-three/drei';

// import FontImage from './assets/Roboto-msdf.png';
import {FontLoader} from 'three/examples/jsm/loaders/FontLoader.js';
import {TextGeometry} from 'three/examples/jsm/geometries/TextGeometry.js';
import ThreeMeshUIText from './ThreeMeshUIText';
import {ContactShadows, BakeShadows} from '@react-three/drei';

extend({TextGeometry});
extend(ThreeMeshUI);

declare module '@react-three/fiber' {
  interface ThreeElements {
    textGeometry: Object3DNode<TextGeometry, typeof TextGeometry>;
  }
}

// This is for textGeometry.. not using three-mesh-ui to display text
export function TitleMesh() {
  const font = new FontLoader().parse();
  console.log('font', font);
  const [text, setText] = useState('Text');

  useEffect(() => {
    setTimeout(() => {
      setText(text + ' more ');
      console.log('adding more tex..', text);
    }, 1000);
  }, [text]);

  return (
    <mesh>
      <textGeometry args={[text, {font, size: 5, height: 1}]} />
      <meshPhysicalMaterial attach={'material'} color={'white'} />
    </mesh>
  );
}

export function Sphere({
  size = 1,
  amount = 50,
  color = 'white',
  emissive,
  ...props
}) {
  return (
    <mesh {...props}>
      <sphereGeometry args={[size, 64, 64]} />
      <meshPhysicalMaterial
        roughness={0}
        color={color}
        emissive={emissive || color}
        envMapIntensity={0.2}
      />
      <Sparkles count={amount} scale={size * 2} size={6} speed={0.4} />
      <Shadow
        rotation={[-Math.PI / 2, 0, 0]}
        scale={size}
        position={[0, -size, 0]}
        color={emissive}
        opacity={0.5}
      />
    </mesh>
  );
}

export function Title({accentColor}) {
  return (
    <block
      args={[
        {
          width: 1,
          height: 0.25,
          backgroundOpacity: 0,
          justifyContent: 'center',
        },
      ]}>
      <ThreeMeshUIText content={'Hello '} />
      <ThreeMeshUIText content={'world!'} args={[{fontColor: accentColor}]} />
    </block>
  );
}

export function RandomComponents() {
  return (
    <>
      <color args={['#eee']} attach={'background'} />
      <Sphere
        color="white"
        amount={50}
        emissive="green"
        glow="lightgreen"
        position={[1, 1, -1]}
      />
      <Sphere
        color="white"
        amount={30}
        emissive="purple"
        glow="#ff90f0"
        size={0.5}
        position={[-1.5, 0.5, -2]}
      />
      <Sphere
        color="lightpink"
        amount={20}
        emissive="orange"
        glow="#ff9f50"
        size={0.25}
        position={[-1, 0.25, 1]}
      />
      <ContactShadows
        renderOrder={2}
        color="black"
        resolution={1024}
        frames={1}
        scale={10}
        blur={1.5}
        opacity={0.65}
        far={0.5}
      />
      <BakeShadows />
    </>
  );
}