i have been trying to load my gltf file from the database but its not working. I tried creating separate page for model.js but still no result. Searching for the solution online alot but no sucess. Do note course.content is the link of the model from amazon s3 .
Please help. the code is below:
import React, { useState, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux'
import { Canvas } from "@react-three/fiber";
import { useGLTF } from '@react-three/drei'
import { useLoader } from "@react-three/fiber";
import { Environment, OrbitControls } from "@react-three/drei";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { Suspense } from "react";
import {
listCourseDetails
} from '../actions/courseActions'
const Model = ({ bro }) => {
const gltf = useLoader(GLTFLoader, `/${bro}`);
return <primitive object={gltf} scale={0.005} />;
}
export default function ModelScreen({ history, match }) {
const dispatch = useDispatch()
const courseDetails = useSelector((state) => state.courseDetails)
const { error, course } = courseDetails
useEffect(() => {
if (!course._id || course._id !== match.params.id) {
dispatch(listCourseDetails(match.params.id))
}
}, [dispatch, match])
return (
<>
<div style={{width: '70vw', height: '70vh'}}>
<Canvas>
<Suspense>
<Model bro={course.content}/>
<OrbitControls />
<Environment preset="sunset" background />
</Suspense>
</Canvas>
</div>
</>
);
}