This commit is contained in:
2025-03-24 14:34:06 +08:00
parent 2216a3fd14
commit a5c4ef3a8f
8 changed files with 1119 additions and 117 deletions

View File

@ -23,6 +23,9 @@ export default tseslint.config(
'warn', 'warn',
{ allowConstantExport: true }, { allowConstantExport: true },
], ],
// disable no unused imports
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
}, },
}, },
) )

View File

@ -10,8 +10,13 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@react-three/drei": "^10.0.4",
"@react-three/fiber": "^9.1.0",
"@types/three": "^0.174.0",
"leva": "^0.10.0",
"react": "^19.0.0", "react": "^19.0.0",
"react-dom": "^19.0.0" "react-dom": "^19.0.0",
"three": "^0.174.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.21.0", "@eslint/js": "^9.21.0",

1072
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}

View File

@ -1,35 +1,43 @@
import { Grid, useBVH, useGLTF, CameraControls, AccumulativeShadows, OrbitControls, Stats } from '@react-three/drei'
import { Camera, Canvas, useFrame, useThree, useLoader } from '@react-three/fiber'
import { useState } from 'react' import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
function App() { const Scene = () => {
const [count, setCount] = useState(0) function Floor() {
return (
<mesh rotation-x={-Math.PI / 2} position-y={-0.05} receiveShadow>
<planeGeometry args={[15, 15]} />
<meshStandardMaterial color="#ccc" />
</mesh>
)
}
const Axes = () => {
return <axesHelper args={[15]} />
}
return ( return (
// Note that we don't need to import anything, All three.js objects will be treated
// as native JSX elements, just like you can just write <div /> or <span /> in
// regular ReactDOM. The general rule is that Fiber components are available under
// the camel-case version of their name in three.js.
<> <>
<div> <CameraControls />
<a href="https://vite.dev" target="_blank"> {/* <OrbitControls /> */}
<img src={viteLogo} className="logo" alt="Vite logo" /> <ambientLight intensity={0.05} />
</a> <directionalLight castShadow position={[3.3, 6, 4.4]} intensity={5} />
<a href="https://react.dev" target="_blank"> <Floor />
<img src={reactLogo} className="logo react" alt="React logo" /> <Axes />
</a> <Stats />
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</> </>
) )
} }
function App() {
return (
<Canvas shadows style={{ background: "#e9e9e9", width: "100vw", height: "100vh" }}>
<Scene />
</Canvas>
)
}
export default App export default App

View File

@ -1,5 +1,5 @@
:root { :root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif; font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5; line-height: 1.5;
font-weight: 400; font-weight: 400;
@ -13,15 +13,6 @@
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body { body {
margin: 0; margin: 0;
display: flex; display: flex;
@ -29,40 +20,3 @@ body {
min-width: 320px; min-width: 320px;
min-height: 100vh; min-height: 100vh;
} }
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

View File

@ -2,9 +2,11 @@ import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client' import { createRoot } from 'react-dom/client'
import './index.css' import './index.css'
import App from './App.tsx' import App from './App.tsx'
import { Leva } from 'leva'
createRoot(document.getElementById('root')!).render( createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<Leva />
<App /> <App />
</StrictMode>, </StrictMode>,
) )

View File

@ -17,7 +17,7 @@
/* Linting */ /* Linting */
"strict": true, "strict": true,
"noUnusedLocals": true, "noUnusedLocals": false,
"noUnusedParameters": true, "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true "noUncheckedSideEffectImports": true