feat: added task 3 in r3f
This commit is contained in:
parent
34f4bc743d
commit
3970740f88
@ -1,10 +1,12 @@
|
|||||||
* {
|
.app-container {
|
||||||
margin: 0;
|
width: 100vw;
|
||||||
padding: 0;
|
height: 100vh;
|
||||||
box-sizing: border-box;
|
position: relative;
|
||||||
|
background-color: white;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
.canvas-wrapper {
|
||||||
overflow: hidden;
|
width: 100%;
|
||||||
background-color: #111;
|
height: 100%;
|
||||||
font-family: sans-serif;
|
}
|
||||||
@ -1,5 +1,64 @@
|
|||||||
export default function App() {
|
import React, { useState } from 'react';
|
||||||
|
import { Canvas } from '@react-three/fiber';
|
||||||
|
import { OrbitControls, PerspectiveCamera } from '@react-three/drei';
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
|
const variants = {
|
||||||
|
black: {
|
||||||
|
geometry: <boxGeometry args={[2, 2, 2]} />,
|
||||||
|
material: { color: "black", roughness: 1, metalness: 0 }
|
||||||
|
},
|
||||||
|
silver: {
|
||||||
|
geometry: <sphereGeometry args={[1.5, 32, 32]} />,
|
||||||
|
material: { color: "#C0C0C0", roughness: 0.3, metalness: 1 }
|
||||||
|
},
|
||||||
|
gold: {
|
||||||
|
geometry: <torusGeometry args={[1.2, 0.4, 16, 100]} />,
|
||||||
|
material: { color: "#FFD700", roughness: 0.4, metalness: 1 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function Product({ variant }) {
|
||||||
|
const { geometry, material } = variants[variant];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<></>
|
<mesh>
|
||||||
)
|
{geometry}
|
||||||
|
<meshStandardMaterial {...material} />
|
||||||
|
</mesh>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
const [activeVariant, setActiveVariant] = useState('black');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="app-container">
|
||||||
|
<div id="controls">
|
||||||
|
{Object.keys(variants).map((variant) => (
|
||||||
|
<button
|
||||||
|
key={variant}
|
||||||
|
className={activeVariant === variant ? 'active' : ''}
|
||||||
|
onClick={() => setActiveVariant(variant)}
|
||||||
|
>
|
||||||
|
{variant.charAt(0).toUpperCase() + variant.slice(1)}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="canvas-wrapper">
|
||||||
|
<Canvas dpr={[1, 2]}>
|
||||||
|
<color attach="background" args={["white"]} />
|
||||||
|
<PerspectiveCamera makeDefault position={[0, 0, 5]} />
|
||||||
|
|
||||||
|
<ambientLight intensity={0.6 * Math.PI} />
|
||||||
|
<pointLight position={[5, 5, 5]} intensity={1.0 * Math.PI} />
|
||||||
|
|
||||||
|
<Product variant={activeVariant} />
|
||||||
|
|
||||||
|
<OrbitControls makeDefault enableDamping dampingFactor={0.05} />
|
||||||
|
</Canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user