Skip to content

Commit 4022055

Browse files
committed
init threejs
1 parent ed471bd commit 4022055

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@types/react": "^18.3.3",
2828
"@types/react-dom": "^18.3.0",
2929
"@types/sanitize-html": "^2.11.0",
30+
"@types/three": "^0.170.0",
3031
"@typescript-eslint/parser": "^7.16.0",
3132
"astro": "^4.10.1",
3233
"eslint": "^8.57.0",
@@ -43,6 +44,7 @@
4344
"remark-mark-highlight": "^0.1.1",
4445
"sanitize-html": "^2.13.0",
4546
"satori": "^0.10.14",
47+
"three": "^0.171.0",
4648
"typescript": "^5.4.5",
4749
"typescript-eslint": "^7.16.0",
4850
"unified": "^11.0.5",

src/pages/experiments/index.astro

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Centered from "../../components/Centered.astro";
55
import { highlight } from "neohome-rs";
66
77
const webringSite = "ayats";
8-
const webringURL = "https://nixwebr.ing"
8+
const webringURL = "https://nixwebr.ing";
99
---
1010

1111
<Base
@@ -14,8 +14,6 @@ const webringURL = "https://nixwebr.ing"
1414
}}
1515
>
1616
<Centered class:list={["test"]}>
17-
18-
1917
<div class="box">
2018
<h2>Nix Webring</h2>
2119

@@ -27,10 +25,49 @@ const webringURL = "https://nixwebr.ing"
2725
<li><a href=`${webringURL}/rand`>🎲</a></li>
2826
<li><a href=`${webringURL}/next/${webringSite}`>→</a></li>
2927
</ul>
28+
29+
<div id="my-canvas"></div>
3030
</div>
3131
</Centered>
3232
</Base>
3333

34+
<script>
35+
import * as THREE from "three";
36+
37+
const width = 600;
38+
const height = 600;
39+
40+
// init
41+
42+
const camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10);
43+
camera.position.z = 1;
44+
45+
const scene = new THREE.Scene();
46+
47+
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
48+
const material = new THREE.MeshNormalMaterial();
49+
50+
const mesh = new THREE.Mesh(geometry, material);
51+
scene.add(mesh);
52+
53+
const renderer = new THREE.WebGLRenderer({ antialias: true });
54+
renderer.setSize(width, height);
55+
renderer.setAnimationLoop(animate);
56+
// document.body.appendChild(renderer.domElement);
57+
const elem = document.getElementById("my-canvas");
58+
if (elem !== null) {
59+
elem.appendChild(renderer.domElement);
60+
}
61+
62+
// animation
63+
64+
function animate(time) {
65+
mesh.rotation.x = time / 2000;
66+
mesh.rotation.y = time / 1000;
67+
68+
renderer.render(scene, camera);
69+
}
70+
</script>
3471

3572
<style>
3673
.box {
@@ -57,4 +94,10 @@ const webringURL = "https://nixwebr.ing"
5794
padding: 10px;
5895
}
5996
}
97+
98+
#my-canvas {
99+
width: 600px;
100+
height: 600px;
101+
background-color: black;
102+
}
60103
</style>

0 commit comments

Comments
 (0)