First commit
This commit is contained in:
39
src/components/App.jsx
Normal file
39
src/components/App.jsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import '../styles/styles.scss';
|
||||
import { useRef, useState } from 'react';
|
||||
import { Canvas, useFrame } from '@react-three/fiber';
|
||||
|
||||
const Box = (props) => {
|
||||
// This reference gives us direct access to the THREE.Mesh object
|
||||
const ref = useRef()
|
||||
// Hold state for hovered and clicked events
|
||||
const [hovered, hover] = useState(false)
|
||||
const [clicked, click] = useState(false)
|
||||
// Subscribe this component to the render-loop, rotate the mesh every frame
|
||||
useFrame((state, delta) => (ref.current.rotation.x += 0.01))
|
||||
// Return the view, these are regular Threejs elements expressed in JSX
|
||||
return (
|
||||
<mesh
|
||||
{...props}
|
||||
ref={ref}
|
||||
scale={clicked ? 1.5 : 1}
|
||||
onClick={(event) => click(!clicked)}
|
||||
onPointerOver={(event) => hover(true)}
|
||||
onPointerOut={(event) => hover(false)}>
|
||||
<boxGeometry args={[1, 1, 1]} />
|
||||
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
|
||||
</mesh>
|
||||
)
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<Canvas>
|
||||
<ambientLight />
|
||||
<pointLight position={[10, 10, 10]} />
|
||||
<Box position={[-1.2, 0, 0]} />
|
||||
<Box position={[1.2, 0, 0]} />
|
||||
</Canvas>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
10
src/scripts/app.js
Normal file
10
src/scripts/app.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { render } from 'react-dom';
|
||||
import App from '../components/App';
|
||||
|
||||
render(
|
||||
<App />,
|
||||
document.getElementById("root") );
|
||||
|
||||
if (module['hot']) {
|
||||
module['hot'].accept();
|
||||
}
|
||||
3
src/styles/styles.scss
Normal file
3
src/styles/styles.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
main {
|
||||
background-color: black;
|
||||
}
|
||||
12
src/views/index.html
Normal file
12
src/views/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<main id="root"></main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user