add about page model loading

This commit is contained in:
DefectingCat
2023-09-18 11:11:02 +08:00
parent a67c419f77
commit d7c6362bb6
3 changed files with 22 additions and 1 deletions

View File

@ -3,10 +3,14 @@
import { Canvas } from '@react-three/fiber'; import { Canvas } from '@react-three/fiber';
import clsx from 'clsx'; import clsx from 'clsx';
import { Suspense, lazy } from 'react'; import { Suspense, lazy } from 'react';
import useStore from 'store';
import Loading from 'components/rua/loading/rua-loading';
const CloudModel = lazy(() => import('components/models/cloud-model')); const CloudModel = lazy(() => import('components/models/cloud-model'));
const AboutModel = () => { const AboutModel = () => {
const modelLoading = useStore((state) => state.modelLoading);
return ( return (
<> <>
<div className={clsx('fixed top-0 left-0 -z-10', 'w-full h-full')}> <div className={clsx('fixed top-0 left-0 -z-10', 'w-full h-full')}>
@ -16,6 +20,19 @@ const AboutModel = () => {
<CloudModel /> <CloudModel />
</Suspense> </Suspense>
</Canvas> </Canvas>
<div
className={clsx(
'h-full w-full absolute',
'top-0 left-0 flex',
'justify-center items-center',
'bg-bluish-gray dark:bg-rua-gray-900',
'transition-all duration-300',
!modelLoading && 'opacity-0',
)}
>
<Loading />
</div>
{/* <Leva /> */} {/* <Leva /> */}
</div> </div>
</> </>

View File

@ -16,6 +16,7 @@ const CatModel = () => {
GLTFLoader, GLTFLoader,
'./models/just_a_hungry_cat/modelDraco.gltf', './models/just_a_hungry_cat/modelDraco.gltf',
(loader) => { (loader) => {
toggleLoading(true);
const dracoLoader = new DRACOLoader(); const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./libs/draco/'); dracoLoader.setDecoderPath('./libs/draco/');
loader.setDRACOLoader(dracoLoader); loader.setDRACOLoader(dracoLoader);

View File

@ -7,10 +7,11 @@ import * as THREE from 'three';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader'; import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'; import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { rotationX, rotationY } from './home-model'; import { rotationX, rotationY } from './home-model';
import useStore from 'store';
const CloudModel = () => { const CloudModel = () => {
const mixer = useRef<THREE.AnimationMixer | null>(null); const mixer = useRef<THREE.AnimationMixer | null>(null);
const toggleLoading = useStore((state) => state.toggleLoading);
const camera = useThree((state) => state.camera); const camera = useThree((state) => state.camera);
// After model loading, set theme to dark mode. // After model loading, set theme to dark mode.
@ -49,6 +50,7 @@ const CloudModel = () => {
GLTFLoader, GLTFLoader,
'./models/cloud_station/modelDraco.gltf', './models/cloud_station/modelDraco.gltf',
(loader) => { (loader) => {
toggleLoading(true);
const dracoLoader = new DRACOLoader(); const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./libs/draco/'); dracoLoader.setDecoderPath('./libs/draco/');
loader.setDRACOLoader(dracoLoader); loader.setDRACOLoader(dracoLoader);
@ -61,6 +63,7 @@ const CloudModel = () => {
}); });
gltf.scene.position.set(0, 0, 0); gltf.scene.position.set(0, 0, 0);
camera.lookAt(0, 1, 0); camera.lookAt(0, 1, 0);
toggleLoading(false);
const halfWidth = Math.floor(window.innerWidth / 2); const halfWidth = Math.floor(window.innerWidth / 2);
const halfHeight = Math.floor(window.innerHeight / 2); const halfHeight = Math.floor(window.innerHeight / 2);