-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
b17ac6e
commit fb6e158
Showing
8 changed files
with
1,182 additions
and
7 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
alexanderristinmaa/app/(experiments)/donut/page.module.css
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,15 @@ | ||
.text { | ||
position: absolute; | ||
z-index: 100; | ||
display:inline; | ||
width: auto; | ||
height: auto; | ||
} | ||
|
||
#thebox { | ||
top: 10%; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
color: white; | ||
font-size: 30px; | ||
} |
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,75 @@ | ||
'use client' | ||
|
||
import { useEffect, useRef } from 'react'; | ||
// style | ||
import styles from './page.module.css'; | ||
|
||
// next | ||
|
||
// other | ||
import * as THREE from 'three'; | ||
import { GLTF, GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; | ||
|
||
export default function Home() { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const scene = new THREE.Scene(); | ||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.01, 10000); | ||
const renderer = new THREE.WebGLRenderer(); | ||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
|
||
containerRef.current?.appendChild(renderer.domElement); | ||
|
||
camera.position.z = 5; | ||
|
||
const loader = new GLTFLoader(); | ||
|
||
(async () => { | ||
let donut = await new Promise((resolve, reject) => loader.load('/donuts.gltf', data => resolve(data), undefined, reject)) as GLTF; | ||
|
||
scene.add(donut.scene); | ||
// Render the scene and camera | ||
|
||
// Add this function inside the useEffect hook | ||
const renderScene = () => { | ||
donut.scene.rotation.x += 0.01; | ||
donut.scene.rotation.y += 0.01; | ||
|
||
renderer.render(scene, camera); | ||
requestAnimationFrame(renderScene); | ||
}; | ||
|
||
// Call the renderScene function to start the animation loop | ||
renderScene(0); | ||
})(); | ||
|
||
|
||
const handleResize = () => { | ||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
|
||
camera.aspect = width / height; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize(width, height); | ||
}; | ||
|
||
window.addEventListener('resize', handleResize); | ||
|
||
return () => { | ||
// Cleanup of the renderer element | ||
// Cleanup of the window element | ||
// Good article here: https://react.dev/learn/synchronizing-with-effects#step-3-add-cleanup-if-needed | ||
renderer.domElement.remove(); | ||
window.removeEventListener('resize', handleResize); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<span className={styles.text} id={styles.thebox}>THE DONUT</span> | ||
<div ref={containerRef} /> | ||
</div> | ||
); | ||
} |
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,19 @@ | ||
export const metadata = { | ||
title: 'Next.js', | ||
description: 'Generated by Next.js', | ||
} | ||
|
||
// styles | ||
import "../globals.css"; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="sv"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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
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 |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
|
||
* { | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: 0; | ||
padding: 0px; | ||
margin: 0px; | ||
} | ||
|
||
html, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.