Skip to content

Commit 48b6d6e

Browse files
authored
Merge pull request #127 from musehq/dev
v2.5.0
2 parents 5d7cbac + e6b264f commit 48b6d6e

File tree

25 files changed

+509
-151
lines changed

25 files changed

+509
-151
lines changed

README.md

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,13 @@ Quickly add an image to your scene
339339

340340
#### Model
341341

342-
Quickly add a GLTF/GLB model to your scene. Will handle Suspense, KTX2, Draco, Meshopt.
342+
Quickly add a GLTF/GLB model to your scene. Will handle Suspense, KTX2, Draco, Meshopt. Clones the gltf scene so the same file can be re-used.
343343

344344
```tsx
345345
<Model
346346
src="https://link-to-your-model.glb"
347-
center={false} // whether to center the model so its bounds are centered on its origin
347+
center // whether to center the model so its bounds are centered on its origin, default false
348+
normalize // whether to normalize the model to a height/width/depth of 1, default false
348349
/>
349350
```
350351

@@ -410,6 +411,33 @@ Enables colliders for its children either by a named collider mesh or using all
410411
/>
411412
```
412413

414+
#### Interactable
415+
416+
Makes its children react to onclick and on hover methods
417+
418+
```tsx
419+
<Interactable
420+
onClick={() => console.log("Ive been clicked!")}
421+
onHovered={() => console.log("Ive been hovered!")}
422+
onUnHovered={() => console.log("Ive been unhovered?")}
423+
>
424+
<Stuff />
425+
</Interactable>
426+
```
427+
428+
#### Anchor
429+
430+
Makes its children link out to when clicked. handles leaving vr session.
431+
432+
```tsx
433+
<Anchor
434+
href="https://link-to-your-website.com"
435+
target="_blank" // optional, default is _self
436+
>
437+
<Stuff />
438+
</Anchor>
439+
```
440+
413441
#### FacePlayer
414442

415443
Turns its children into a billboard, always facing the camera.
@@ -426,20 +454,6 @@ Lazily floats its children.
426454
<Floating height={0.2} speed={1} />
427455
```
428456

429-
#### Interactable
430-
431-
Makes its children react to onclick and on hover methods
432-
433-
```tsx
434-
<Interactable
435-
onClick={() => console.log("Ive been clicked!")}
436-
onHovered={() => console.log("Ive been hovered!")}
437-
onUnHovered={() => console.log("Ive been unhovered?")}
438-
>
439-
<Stuff />
440-
</Interactable>
441-
```
442-
443457
#### LookAtPlayer
444458

445459
Makes its children face the player, but with easing.
@@ -502,6 +516,25 @@ An arrow icon
502516
<Arrow dark={false} />
503517
```
504518

519+
#### Button
520+
521+
A simple button
522+
523+
```tsx
524+
<Button
525+
onClick={() => console.log("Ive been clicked!")}
526+
font="https://link-to-your-font.ttf" // optional font, default is Quicksand
527+
fontSize={0.1} // font size, default 0.05
528+
maxWidth={1} // max width, default no max width
529+
textColor="red" // text color, default black
530+
color="green" // button color, default white
531+
outline={false} // whether to show an outline, default true
532+
outlineColor="#9f9f9f" // outline color, default white
533+
>
534+
Click me!
535+
</Button>
536+
```
537+
505538
#### Switch
506539

507540
A boolean switch
@@ -510,7 +543,7 @@ A boolean switch
510543
const [value, setValue] = useState(false);
511544

512545
<Switch
513-
value={value} // value and setValue are optional but obviously recommended
514-
setValue={setValue}
546+
value={value} // control the switch value
547+
onChange={setValue} // optional onChange function
515548
/>;
516549
```

examples/ideas/Link.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { FacePlayer, Anchor, Button } from "spacesvr";
2+
import { GroupProps } from "@react-three/fiber";
3+
4+
type LinkProps = {
5+
href: string;
6+
children: string;
7+
} & GroupProps;
8+
9+
export default function Link(props: LinkProps) {
10+
const { href, children, ...rest } = props;
11+
12+
return (
13+
<group name={`link-${href}`} {...rest}>
14+
<FacePlayer>
15+
<Anchor href={href}>
16+
<Button>{children}</Button>
17+
</Anchor>
18+
</FacePlayer>
19+
</group>
20+
);
21+
}

examples/ideas/Text.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ReactNode } from "react";
2+
import { GroupProps } from "@react-three/fiber";
3+
import { Text } from "@react-three/drei";
4+
import { DoubleSide } from "three";
5+
6+
type TestProps = {
7+
children: ReactNode | ReactNode[];
8+
name: string;
9+
sideLength?: number;
10+
} & GroupProps;
11+
12+
const FONT = "https://d27rt3a60hh1lx.cloudfront.net/fonts/Quicksand_Bold.otf";
13+
14+
export default function Test(props: TestProps) {
15+
const { children, name, sideLength = 1.1, ...rest } = props;
16+
17+
const FONT_SIZE = 0.075;
18+
19+
return (
20+
<group name="test" {...rest}>
21+
<group
22+
name="content"
23+
position={[0, sideLength / 2 + 0.001, -sideLength / 2]}
24+
>
25+
{children}
26+
<mesh>
27+
<boxBufferGeometry args={[sideLength, sideLength, sideLength]} />
28+
<meshBasicMaterial color="black" wireframe />
29+
</mesh>
30+
</group>
31+
<group
32+
name="nameplate"
33+
position-y={(FONT_SIZE + 0.1 + 0.1) / 2}
34+
position-z={FONT_SIZE / 2}
35+
rotation-x={-0.8}
36+
>
37+
<mesh>
38+
<planeBufferGeometry args={[sideLength, FONT_SIZE + 0.1]} />
39+
<meshBasicMaterial color="black" side={DoubleSide} />
40+
</mesh>
41+
<Text
42+
color="white"
43+
font={FONT}
44+
maxWidth={sideLength}
45+
fontSize={FONT_SIZE}
46+
position-z={0.001}
47+
>
48+
{name}
49+
</Text>
50+
</group>
51+
</group>
52+
);
53+
}

examples/ideas/Title.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { FacePlayer } from "spacesvr";
2+
import { GroupProps } from "@react-three/fiber";
3+
import { Text } from "@react-three/drei";
4+
5+
type LinkProps = {
6+
children: string;
7+
} & GroupProps;
8+
9+
const FONT = "https://d27rt3a60hh1lx.cloudfront.net/fonts/Quicksand_Bold.otf";
10+
11+
export default function Title(props: LinkProps) {
12+
const { children, ...rest } = props;
13+
14+
return (
15+
<group name="title" {...rest}>
16+
<FacePlayer>
17+
<Text color="black" font={FONT} fontSize={0.2}>
18+
{children}
19+
</Text>
20+
</FacePlayer>
21+
</group>
22+
);
23+
}

examples/pages/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dynamic from "next/dynamic";
22

3-
const Lost = dynamic(import("../worlds/Lost"), { ssr: false });
3+
const Hub = dynamic(import("../worlds/Hub"), { ssr: false });
44

55
export default function Index() {
6-
return <Lost />;
6+
return <Hub />;
77
}

examples/pages/media.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import dynamic from "next/dynamic";
2+
3+
const Media = dynamic(import("../worlds/Media"), { ssr: false });
4+
5+
export default function Index() {
6+
return <Media />;
7+
}

examples/pages/starter.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/pages/styled.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/pages/workshop.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import dynamic from "next/dynamic";
2+
3+
const Workshop = dynamic(import("../worlds/Workshop"), { ssr: false });
4+
5+
export default function Index() {
6+
return <Workshop />;
7+
}

examples/worlds/Hub.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { LostWorld, StandardReality, Image } from "spacesvr";
2+
import Link from "../ideas/Link";
3+
import Title from "../ideas/Title";
4+
5+
export default function Hub() {
6+
return (
7+
<StandardReality
8+
environmentProps={{ dev: process.env.NODE_ENV === "development" }}
9+
>
10+
<LostWorld />
11+
<group position-z={-1.5}>
12+
<Title position-y={1.2}>welcome to spacesvr</Title>
13+
<group position-y={0.8}>
14+
<Link href="/multiplayer" position-x={-1}>
15+
test out multiplayer
16+
</Link>
17+
<Link href="/media">test out media</Link>
18+
<Link href="/workshop" position-x={1}>
19+
visit the workshop
20+
</Link>
21+
</group>
22+
<Image
23+
scale={18}
24+
position-y={0.025}
25+
rotation-x={-Math.PI / 2}
26+
src="https://d27rt3a60hh1lx.cloudfront.net/spacesvr/spacesvr.png"
27+
/>
28+
</group>
29+
</StandardReality>
30+
);
31+
}

0 commit comments

Comments
 (0)