This commit is contained in:
Mackie 2026-06-07 06:35:39 +08:00
parent d3b5111744
commit da0d7ba0d2
11 changed files with 648 additions and 1 deletions

View file

@ -0,0 +1,8 @@
'use client';
import { useGLTF } from '@react-three/drei';
export function Model({ url }: { url: string }) {
const { scene } = useGLTF(url);
return <primitive object={scene} />;
}

View file

@ -0,0 +1,36 @@
'use client';
import { Canvas } from '@react-three/fiber';
import { OrbitControls, Stage } from '@react-three/drei';
import { Suspense } from 'react';
import { EffectComposer, Bloom, Noise, Vignette } from '@react-three/postprocessing';
import { useAssetLoader } from '@/hooks/useAssetLoader';
import { Model } from './Model';
export default function ShowcaseCanvas() {
const { asset, loading, error } = useAssetLoader('/assets.json');
if (loading || error) return null;
return (
<div className="h-[500px] w-full border border-zinc-800 rounded-xl overflow-hidden bg-black">
<Canvas dpr={[1, 2]} shadows camera={{ fov: 45 }}>
<color attach="background" args={['#050505']} />
<Suspense fallback={null}>
<Stage intensity={0.5} environment="city">
{asset && <Model url={asset.modelUrl} />}
</Stage>
</Suspense>
<EffectComposer disableNormalPass>
<Bloom luminanceThreshold={1} mipmapBlur intensity={1.5} />
<Noise opacity={0.05} />
<Vignette eskil={false} offset={0.1} darkness={1.1} />
</EffectComposer>
<OrbitControls makeDefault />
</Canvas>
</div>
);
}

24
hooks/useAssetLoader.ts Normal file
View file

@ -0,0 +1,24 @@
'use client';
import { useState, useEffect } from 'react';
export function useAssetLoader(url: string) {
const [asset, setAsset] = useState<any>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);
useEffect(() => {
fetch(url)
.then((res) => res.json())
.then((data) => {
setAsset(data);
setLoading(false);
})
.catch(() => {
setError(true);
setLoading(false);
});
}, [url]);
return { asset, loading, error };
}

View file

@ -9,9 +9,14 @@
"lint": "eslint"
},
"dependencies": {
"@react-three/drei": "^10.7.7",
"@react-three/fiber": "^9.6.1",
"@react-three/postprocessing": "^3.0.4",
"@types/three": "^0.184.1",
"next": "16.2.7",
"react": "19.2.4",
"react-dom": "19.2.4"
"react-dom": "19.2.4",
"three": "^0.184.0"
},
"devDependencies": {
"@tailwindcss/postcss": "^4",

567
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

7
public/assets.json Normal file
View file

@ -0,0 +1,7 @@
{
"id": "nike-shoe-001",
"name": "Nike Shoe",
"modelUrl": "/models/shoe.glb",
"category": "Footwear",
"price": 120.00
}

BIN
public/models/model.glb Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB