Skip to content

Commit 0c8b0da

Browse files
author
Jaroslaw
committed
Update model loading
1 parent fa79675 commit 0c8b0da

4 files changed

Lines changed: 9 additions & 22 deletions

File tree

src/components/Light.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import React from "react";
33
const Lights = () => {
44
return (
55
<>
6-
{/* Ambient Light illuminates lights for all objects */}
76
<ambientLight intensity={0.1} />
8-
{/* Diretion light */}
97
<directionalLight position={[40, 10, 5]} intensity={0.2} />
108
<directionalLight
119
castShadow
@@ -19,7 +17,6 @@ const Lights = () => {
1917
shadow-camera-top={40}
2018
shadow-camera-bottom={-10}
2119
/>
22-
{/* Spotlight Large overhead light */}
2320
<spotLight intensity={0.5} position={[90, 100, 50]} castShadow />
2421
</>
2522
);

src/components/Model.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useState, useRef } from "react";
2+
import { useFrame } from "react-three-fiber";
23
import * as THREE from "three";
34
import { Html } from "drei";
45
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
56

67
const Model = () => {
8+
const ref = useRef();
79
const [model, setModel] = useState(null);
810
/* Load model */
911
useEffect(() => {
1012
const loader = new GLTFLoader();
11-
loader.load("scene.gltf", true);
13+
loader.load("scene.gltf", (gltf) => {
14+
setModel(gltf);
15+
});
1216
}, []);
1317

18+
useFrame(() => (model ? (ref.current.rotation.y += 0.01) : {}));
19+
1420
return (
1521
<>
1622
{model ? (
1723
<group position={[0, 0, 0]} dispose={null}>
18-
<primitive name="Object_0" object={model.scene} />
24+
<primitive ref={ref} name="Object_0" object={model.scene} />
1925
</group>
2026
) : (
2127
<Html>Loading...</Html>

src/pages/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import "@/styles/styles.css";
21
import React from "react";
32
import { Canvas } from "react-three-fiber";
43
import Loader from "@/components/Loader";

src/styles/styles.css

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

0 commit comments

Comments
 (0)