Skip to content

Commit 5bbab90

Browse files
committed
add Model idea, put example in multiplayer world
1 parent 8e7de34 commit 5bbab90

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

examples/worlds/Multiplayer/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StandardReality, Background } from "spacesvr";
1+
import { StandardReality, Background, Model } from "spacesvr";
22
import LightSwitch from "./ideas/LightSwitch";
33

44
export default function Multiplayer() {
@@ -15,6 +15,7 @@ export default function Multiplayer() {
1515
<planeBufferGeometry args={[200, 200]} />
1616
<meshBasicMaterial color={"purple"} />
1717
</mesh>
18+
<Model src="https://d27rt3a60hh1lx.cloudfront.net/models/Camera-1652915410/camera_02_cleaned.glb.gz" />
1819
</StandardReality>
1920
);
2021
}

src/ideas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export * from "./physical/Fog";
1414
export * from "./physical/Frame";
1515
export * from "./physical/HDRI";
1616
export * from "./physical/InfinitePlane";
17+
export * from "./physical/Model";
1718
export * from "./physical/Video";

src/ideas/physical/Model.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Fragment, Suspense } from "react";
2+
import { GroupProps } from "@react-three/fiber";
3+
import { Center } from "@react-three/drei";
4+
import { useModel } from "../../logic";
5+
6+
type ModelProps = {
7+
src: string;
8+
center?: boolean;
9+
} & GroupProps;
10+
11+
function UnsuspensedModel(props: ModelProps) {
12+
const { src, center, ...rest } = props;
13+
const gltf = useModel(src);
14+
15+
const Parent = center ? Center : Fragment;
16+
17+
return (
18+
<group name="spacesvr-model" {...rest}>
19+
<Parent>
20+
<primitive object={gltf.scene} />
21+
</Parent>
22+
</group>
23+
);
24+
}
25+
26+
export function Model(props: ModelProps) {
27+
return (
28+
<Suspense fallback={null}>
29+
<UnsuspensedModel {...props} />
30+
</Suspense>
31+
);
32+
}

0 commit comments

Comments
 (0)