-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { createRoot } from 'react-dom/client' | ||
import React, { useRef, useState } from 'react' | ||
import { Canvas, useFrame } from '@react-three/fiber' | ||
import './styles.css' | ||
|
||
function Box(props) { | ||
// This reference will give us direct access to the mesh | ||
const meshRef = useRef() | ||
// Set up state for the hovered and active state | ||
const [hovered, setHover] = useState(false) | ||
const [active, setActive] = useState(false) | ||
// Subscribe this component to the render-loop, rotate the mesh every frame | ||
useFrame((state, delta) => (meshRef.current.rotation.x += delta)) | ||
// Return view, these are regular three.js elements expressed in JSX | ||
return ( | ||
<mesh | ||
{...props} | ||
ref={meshRef} | ||
scale={active ? 1.5 : 1} | ||
onClick={(event) => setActive(!active)} | ||
onPointerOver={(event) => setHover(true)} | ||
onPointerOut={(event) => setHover(false)}> | ||
<boxGeometry args={[1, 1, 1]} /> | ||
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} /> | ||
</mesh> | ||
) | ||
} | ||
|
||
createRoot(document.getElementById('root')).render( | ||
<Canvas> | ||
<ambientLight intensity={Math.PI / 2} /> | ||
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} /> | ||
<pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} /> | ||
<Box position={[-1.2, 0, 0]} /> | ||
<Box position={[1.2, 0, 0]} /> | ||
</Canvas>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
html,body,#root {height:100%;margin:unset;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters