-
Notifications
You must be signed in to change notification settings - Fork 3
/
tesseract.html
85 lines (68 loc) · 2.08 KB
/
tesseract.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - geometry - cube</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
html, body {
margin: 0;
}
</style>
</head>
<body>
<script type="module">
// four.local.module.js is four.module.js but with a direct three import as below
import * as FOUR from '../build/four.local.module.js'
import * as THREE from '../node_modules/three/build/three.module.js'
let camera, scene, renderer, hyperRenderer, hyperMesh
init()
animate()
function init() {
// Setup scene and renderer
scene = new THREE.Scene()
renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
// Simple camera setup
camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
1,
1000
)
camera.position.set(0, 0, 10)
scene.add(camera)
// Lights setup
scene.add(new THREE.AmbientLight(0x222222))
camera.add(new THREE.PointLight(0xffffff, 1))
// Import tesseract preset shape
const { tesseract } = FOUR.shapes
// Create an HyperRenderer which will be used to make 4d -> 3d projections
hyperRenderer = new FOUR.HyperRenderer(1.5, 5)
// Instantiate the HyperMesh
hyperMesh = new FOUR.HyperMesh(tesseract)
scene.add(hyperMesh)
window.addEventListener('resize', onWindowResize)
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
renderer.setSize(window.innerWidth, window.innerHeight)
}
function animate() {
requestAnimationFrame(animate)
render()
}
function render() {
// Rotate takes the rotation speed around the 6 planes:
hyperRenderer.rotate({ xy: 0, xz: 0, xw: 5, yz: 0, yw: 10, zw: 10 })
// Update the hyperMesh
hyperMesh.update(hyperRenderer)
// Render the updated scene
renderer.render(scene, camera)
}
</script>
</body>
</html>