Skip to content

Commit a87141c

Browse files
authored
Merge pull request #133 from musehq/dev
v2.5.4
2 parents a3e26f6 + 644c78d commit a87141c

File tree

7 files changed

+69
-73
lines changed

7 files changed

+69
-73
lines changed

examples/worlds/Media.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StandardReality, LostWorld, Model, Button } from "spacesvr";
1+
import { StandardReality, LostWorld, Model, Button, Image } from "spacesvr";
22
import Link from "../ideas/Link";
33
import Title from "../ideas/Title";
44
import Test from "../ideas/Text";
@@ -8,9 +8,7 @@ import Analytics from "../ideas/Analytics";
88
export default function Media() {
99
const MODELS = [
1010
"https://d27rt3a60hh1lx.cloudfront.net/content/on-air-light/light_and_mic_01.glb.br",
11-
"https://d27rt3a60hh1lx.cloudfront.net/models/MortHead-1644445725/mort_head_00.glb.gz",
1211
"https://d27rt3a60hh1lx.cloudfront.net/models/spotLight-1642615872/spotLight_2.glb.gz",
13-
"https://d27rt3a60hh1lx.cloudfront.net/models/jesus-1622883798/jesus.glb.gz",
1412
"https://d1htv66kutdwsl.cloudfront.net/ae483f1d-77dc-4402-963d-b4105cd6c944/334823a4-b069-45fb-92e8-c88c2b55ba4a.glb",
1513
];
1614

@@ -32,22 +30,30 @@ export default function Media() {
3230
</Link>
3331

3432
<group position-z={-5}>
35-
<Button onClick={next} position={[-0.75, 0.5, 0]}>
33+
<Button onClick={next} position={[0.5, 0.5, 0]}>
3634
next model
3735
</Button>
38-
<Test name="basic model">
36+
<Test name="basic model" position-x={1.2}>
3937
<Model src={MODEL_URL} />
4038
</Test>
41-
<Test name="center model" position-x={1.2}>
39+
<Test name="center model" position-x={1.2 * 2}>
4240
<Model center src={MODEL_URL} />
4341
</Test>
44-
<Test name="normalize model" position-x={1.2 * 2}>
42+
<Test name="normalize model" position-x={1.2 * 3}>
4543
<Model normalize src={MODEL_URL} />
4644
</Test>
47-
<Test name="normalize and center model" position-x={1.2 * 3}>
45+
<Test name="normalize and center model" position-x={1.2 * 4}>
4846
<Model normalize center src={MODEL_URL} />
4947
</Test>
5048
</group>
49+
<group position-z={-5}>
50+
<Test name="fallback model (wireframe)" position-x={-1.2}>
51+
<Model normalize center src="sdjkfnoi" />
52+
</Test>
53+
<Test name="fallback image" position-x={-1.2 * 2}>
54+
<Image src="sdjkfnoi" />
55+
</Test>
56+
</group>
5157
</StandardReality>
5258
);
5359
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spacesvr",
3-
"version": "2.5.3",
3+
"version": "2.5.4",
44
"private": true,
55
"description": "A standardized reality for future of the 3D Web",
66
"keywords": [
@@ -66,7 +66,8 @@
6666
"nipplejs": "0.8.1",
6767
"node-fetch": "^2.6.1",
6868
"peerjs": "^1.4.6",
69-
"react-device-detect": "^1.13.1"
69+
"react-device-detect": "^1.13.1",
70+
"react-error-boundary": "^3.1.4"
7071
},
7172
"peerDependencies": {
7273
"react": ">=18.1",

src/ideas/media/Model.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GroupProps } from "@react-three/fiber";
33
import { useModel } from "../../logic";
44
import { Box3, Vector3 } from "three";
55
import { SkeletonUtils } from "three-stdlib";
6+
import { ErrorBoundary } from "react-error-boundary";
67

78
type ModelProps = {
89
src: string;
@@ -37,10 +38,28 @@ function UnsuspensedModel(props: ModelProps) {
3738
);
3839
}
3940

41+
function FallbackModel(props: ModelProps) {
42+
const { src, center, normalize, ...rest } = props;
43+
44+
return (
45+
<group name="spacesvr-fallback-model" {...rest}>
46+
<mesh>
47+
<boxBufferGeometry args={[1, 1, 1]} />
48+
<meshStandardMaterial color="black" wireframe />
49+
</mesh>
50+
</group>
51+
);
52+
}
53+
4054
export function Model(props: ModelProps) {
4155
return (
42-
<Suspense fallback={null}>
43-
<UnsuspensedModel {...props} />
44-
</Suspense>
56+
<ErrorBoundary
57+
fallbackRender={() => <FallbackModel {...props} />}
58+
onError={(err) => console.error(err)}
59+
>
60+
<Suspense fallback={null}>
61+
<UnsuspensedModel {...props} />
62+
</Suspense>
63+
</ErrorBoundary>
4564
);
4665
}

src/layers/Environment/ui/PauseMenu/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function PauseMenu(props: PauseMenuProps) {
4848
const PAUSE_ITEMS: PauseItem[] = [
4949
...pauseMenuItems,
5050
{
51-
text: "v2.5.3",
51+
text: "v2.5.4",
5252
link: "https://www.npmjs.com/package/spacesvr",
5353
},
5454
...menuItems,

src/logic/assets.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useThree } from "@react-three/fiber";
44
import { useGLTF } from "@react-three/drei";
55
import { suspend } from "suspend-react";
66
import { useMemo } from "react";
7-
import { getFallbackModel, getFallbackTexture } from "./fallback";
7+
import { getFallbackTexture } from "./fallback";
88
import { GLTF } from "three-stdlib";
99

1010
let ktx2loader: KTX2Loader | undefined;
@@ -52,19 +52,12 @@ export function useImage(url: string): Texture {
5252
export function useModel(url: string): GLTF {
5353
const gl = useThree((st) => st.gl);
5454

55-
try {
56-
return useGLTF(url, true, true, (loader) => {
57-
if (!ktx2loader) {
58-
ktx2loader = new KTX2Loader();
59-
ktx2loader.setTranscoderPath(KTX_CDN);
60-
ktx2loader.detectSupport(gl);
61-
}
62-
loader.setKTX2Loader(ktx2loader);
63-
});
64-
} catch {
65-
return suspend(
66-
(): Promise<GLTF> => new Promise((res) => getFallbackModel().then(res)),
67-
[]
68-
);
69-
}
55+
return useGLTF(url, true, true, (loader) => {
56+
if (!ktx2loader) {
57+
ktx2loader = new KTX2Loader();
58+
ktx2loader.setTranscoderPath(KTX_CDN);
59+
ktx2loader.detectSupport(gl);
60+
}
61+
loader.setKTX2Loader(ktx2loader);
62+
});
7063
}

src/logic/fallback.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import {
2-
BoxBufferGeometry,
3-
CanvasTexture,
4-
Group,
5-
Mesh,
6-
MeshStandardMaterial,
7-
} from "three";
8-
import { GLTF } from "three-stdlib";
9-
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
10-
import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter";
1+
import { CanvasTexture } from "three";
112

123
let fallbackTexture: CanvasTexture | undefined;
134

@@ -54,36 +45,3 @@ export function getFallbackTexture(): CanvasTexture {
5445

5546
return fallbackTexture;
5647
}
57-
58-
/**
59-
* Provides a default model
60-
*/
61-
export function getFallbackModel(): Promise<GLTF> {
62-
const group = new Group();
63-
const geo = new BoxBufferGeometry(1, 1, 1);
64-
const mat = new MeshStandardMaterial({ color: "black", wireframe: true });
65-
const mesh = new Mesh(geo, mat);
66-
group.add(mesh);
67-
68-
const exporter = new GLTFExporter();
69-
const loader = new GLTFLoader();
70-
return new Promise((res) =>
71-
exporter.parse(
72-
group,
73-
(gltf) => {
74-
loader.parse(
75-
gltf as ArrayBuffer,
76-
"",
77-
// @ts-ignore
78-
(gltf) => res(gltf as GLTF),
79-
(err) => console.error(err)
80-
);
81-
},
82-
{
83-
binary: true,
84-
embedImages: true,
85-
onlyVisible: false,
86-
}
87-
)
88-
);
89-
}

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,13 @@
967967
dependencies:
968968
regenerator-runtime "^0.13.4"
969969

970+
"@babel/runtime@^7.12.5":
971+
version "7.20.1"
972+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.20.1.tgz#1148bb33ab252b165a06698fde7576092a78b4a9"
973+
integrity sha512-mrzLkl6U9YLF8qpqI7TB82PESyEGjm/0Ly91jG575eVxMMlb8fYfOXFZIJ8XfLrJZQbm7dlKry2bJmXBUEkdFg==
974+
dependencies:
975+
regenerator-runtime "^0.13.10"
976+
970977
"@babel/template@^7.16.7":
971978
version "7.16.7"
972979
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.7.tgz#8d126c8701fde4d66b264b3eba3d96f07666d155"
@@ -3729,6 +3736,13 @@ react-dom@^18.1.0:
37293736
loose-envify "^1.1.0"
37303737
scheduler "^0.22.0"
37313738

3739+
react-error-boundary@^3.1.4:
3740+
version "3.1.4"
3741+
resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-3.1.4.tgz#255db92b23197108757a888b01e5b729919abde0"
3742+
integrity sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA==
3743+
dependencies:
3744+
"@babel/runtime" "^7.12.5"
3745+
37323746
react-is@^16.13.1, react-is@^16.7.0:
37333747
version "16.13.1"
37343748
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
@@ -3796,6 +3810,11 @@ regenerate@^1.4.2:
37963810
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.2.tgz#b9346d8827e8f5a32f7ba29637d398b69014848a"
37973811
integrity sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==
37983812

3813+
regenerator-runtime@^0.13.10:
3814+
version "0.13.10"
3815+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.10.tgz#ed07b19616bcbec5da6274ebc75ae95634bfc2ee"
3816+
integrity sha512-KepLsg4dU12hryUO7bp/axHAKvwGOCV0sGloQtpagJ12ai+ojVDqkeGSiRX1zlq+kjIMZ1t7gpze+26QqtdGqw==
3817+
37993818
regenerator-runtime@^0.13.4:
38003819
version "0.13.9"
38013820
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"

0 commit comments

Comments
 (0)