-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
48 lines (42 loc) · 1.27 KB
/
App.jsx
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
import React, { useEffect, useState } from "react";
import { Canvas } from "@react-three/fiber";
import { OrbitControls } from "@react-three/drei";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
function Model() {
const [model, setModel] = useState(null);
useEffect(() => {
fetch("/path/to/file.buf")
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.arrayBuffer();
})
.then(buffer => {
const loader = new GLTFLoader();
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath("/draco/");
loader.setDRACOLoader(dracoLoader);
loader.parse(buffer, "", (gltf) => {
setModel(gltf.scene);
}, (error) => {
console.error("An error happened while parsing the glTF:", error);
});
})
.catch(error => {
console.error("Error fetching the .buf file:", error);
});
}, []);
return model ? <primitive object={model} /> : null;
}
const App = () => {
return (
<Canvas>
<OrbitControls />
<Model />
<ambientLight />
</Canvas>
);
};
export default App;