Compare commits
No commits in common. "1201660c3c8f9ec4698706a49f75f894a5b76e5f" and "91d55fdc902bd0ca8eef7d3b00393c30871b806d" have entirely different histories.
1201660c3c
...
91d55fdc90
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Task 3 — Hover Interaction (R3F)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script type="module" src="/src/main.jsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "task-3-r3f",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"private": true,
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "vite build"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@react-three/fiber": "^8.16.8",
|
|
||||||
"react": "^18.3.1",
|
|
||||||
"react-dom": "^18.3.1",
|
|
||||||
"three": "^0.163.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
|
||||||
"vite": "^5.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
import { Canvas } from '@react-three/fiber'
|
|
||||||
import Box from './Box'
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
return (
|
|
||||||
<div style={{ width: '100vw', height: '100vh', background: '#111' }}>
|
|
||||||
<Canvas camera={{ position: [0, 0, 5], fov: 75 }}>
|
|
||||||
<Box />
|
|
||||||
</Canvas>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
import { useRef, useState } from 'react'
|
|
||||||
import { useFrame } from '@react-three/fiber'
|
|
||||||
|
|
||||||
function Box() {
|
|
||||||
const meshRef = useRef()
|
|
||||||
const [hovered, setHover] = useState(false)
|
|
||||||
|
|
||||||
useFrame(() => {
|
|
||||||
meshRef.current.rotation.x += 0.01
|
|
||||||
meshRef.current.rotation.y += 0.01
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<mesh
|
|
||||||
ref={meshRef}
|
|
||||||
onPointerOver={() => {
|
|
||||||
setHover(true)
|
|
||||||
document.body.style.cursor = 'pointer'
|
|
||||||
}}
|
|
||||||
onPointerOut={() => {
|
|
||||||
setHover(false)
|
|
||||||
document.body.style.cursor = 'default'
|
|
||||||
}}
|
|
||||||
scale={hovered ? 1.15 : 1}
|
|
||||||
>
|
|
||||||
<boxGeometry args={[2, 2, 2]} />
|
|
||||||
<meshBasicMaterial color={hovered ? 'hotpink' : 'orange'} />
|
|
||||||
</mesh>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Box
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { createRoot } from 'react-dom/client'
|
|
||||||
import App from './App.jsx'
|
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(<App />)
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
import react from '@vitejs/plugin-react'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [react()],
|
|
||||||
})
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Task 3 — Hover Interaction (Vanilla Three.js)</title>
|
|
||||||
<link rel="stylesheet" href="style.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script type="module" src="main.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
import * as THREE from 'three'
|
|
||||||
|
|
||||||
const scene = new THREE.Scene()
|
|
||||||
scene.background = new THREE.Color('#111111')
|
|
||||||
|
|
||||||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
||||||
camera.position.z = 5
|
|
||||||
|
|
||||||
const renderer = new THREE.WebGLRenderer()
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
||||||
document.body.appendChild(renderer.domElement)
|
|
||||||
|
|
||||||
const geometry = new THREE.BoxGeometry(2, 2, 2)
|
|
||||||
const material = new THREE.MeshBasicMaterial({ color: 'orange' })
|
|
||||||
const cube = new THREE.Mesh(geometry, material)
|
|
||||||
scene.add(cube)
|
|
||||||
|
|
||||||
const raycaster = new THREE.Raycaster()
|
|
||||||
const mouse = new THREE.Vector2()
|
|
||||||
let isHovered = false
|
|
||||||
|
|
||||||
window.addEventListener('mousemove', (e) => {
|
|
||||||
mouse.x = (e.clientX / window.innerWidth) * 2 - 1
|
|
||||||
mouse.y = -(e.clientY / window.innerHeight) * 2 + 1
|
|
||||||
|
|
||||||
raycaster.setFromCamera(mouse, camera)
|
|
||||||
const hits = raycaster.intersectObject(cube)
|
|
||||||
|
|
||||||
if (hits.length > 0) {
|
|
||||||
if (!isHovered) {
|
|
||||||
isHovered = true
|
|
||||||
cube.material.color.set('hotpink')
|
|
||||||
cube.scale.set(1.15, 1.15, 1.15)
|
|
||||||
document.body.style.cursor = 'pointer'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isHovered) {
|
|
||||||
isHovered = false
|
|
||||||
cube.material.color.set('orange')
|
|
||||||
cube.scale.set(1, 1, 1)
|
|
||||||
document.body.style.cursor = 'default'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
|
||||||
camera.aspect = window.innerWidth / window.innerHeight
|
|
||||||
camera.updateProjectionMatrix()
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
||||||
})
|
|
||||||
|
|
||||||
function animate() {
|
|
||||||
requestAnimationFrame(animate)
|
|
||||||
cube.rotation.x += 0.01
|
|
||||||
cube.rotation.y += 0.01
|
|
||||||
renderer.render(scene, camera)
|
|
||||||
}
|
|
||||||
|
|
||||||
animate()
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "task-3-vanilla",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"private": true,
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "vite build"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"vite": "^5.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"three": "^0.163.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body, html {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
background: #111;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user