-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
329 lines (295 loc) · 7.73 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Обзор</title>
<style>
* {
box-sizing: border-box;
user-select: none;
cursor: default;
}
@font-face {
font-family: "Monofur";
src: url("src/fonts/Monofur.ttf");
}
body {
margin: 0;
background: #EDEDF4;
font-family: Monofur, Menlo, Consolas, monospace;
}
.header-label {
font-size: 150px;
color: #143642;
}
.tile {
background: #aaa;
transition: opacity 0.2s ease-in-out, background 0.2s ease-in-out, color 0.2s ease-in-out;
cursor: pointer;
color: #143642;
padding: 20px;
opacity: 0.75;
font-size: 40px;
}
.tile:hover {
opacity: 1;
}
#tile-abyss:hover {
color: transparent;
}
#tile-abyss-hover {
background: #363537;
color: #00ff7f;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
transition: opacity 0.2s ease-in-out;
cursor: inherit;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#tile-abyss-hover big {
font-size: 1.35em;
cursor: inherit;
}
#tile-redroom:hover {
background: #a00000;
color: #EECF6D;
}
</style>
</head>
<body>
<div id="tile-abyss-hover">
AB<big>Y</big>SS
</div>
<script src="js/three.js"></script>
<script src="js/tween.min.js"></script>
<script src="js/CSS3DRenderer.js"></script>
<script>
const _tileWidth = 300;
const _tileHeight = 150;
const _tileMove = 40;
const _tileMoveDuration = 200;
const _tileInactiveOpacity = 0.7;
const _tilePushDuration = 300;
const _cameraMove = 400;
const _lookAtMove = 200;
const _cameraPositionZ = 1000;
const _cameraMoveSpeed = 0.05;
const _columns = 4;
const _rows = 3;
const _gap = 30;
const _headerHeight = 170;
const _gridWidth = _columns * _tileWidth + (_columns - 1) * _gap;
const _gridHeight = _rows * _tileHeight + (_rows - 1) * _gap;
const data = [
{
label: "First",
link: "html/First.html",
},
{
label: "Hexagon experiment",
link: "html/HexagonExperiment.html"
},
{
label: "Space",
link: "html/Space.html"
},
{
label: "Triangles & Floor",
link: "html/Triangles&Floor.html"
},
{
label: "Sticks scene",
link: "html/SticksScene.html"
},
{
label: "Sticks hole",
link: "html/SticksHole.html"
},
{
label: "Red room",
link: "html/RedRoom.html",
id: "tile-redroom"
},
{
label: "Cubes room [VR]",
link: "html/CubesRoomVR.html"
},
{
label: "Interactive experiment",
link: "html/InteractiveExperiment.html"
},
{
label: "InterActive II",
link: "html/InterActiveII.html"
},
{
label: "Abyss",
link: "html/Abyss.html",
id: "tile-abyss",
init: (tile) => {
let hoverTile = document.getElementById("tile-abyss-hover");
hoverTile.style.visibility = "visible";
tile.hover = hoverTile;
tile.appendChild(hoverTile);
},
act: (tile) => {
tile.hover.style.opacity = 1;
},
deact: (tile) => {
tile.hover.style.opacity = 0;
}
}
];
class Tile {
constructor(position, data) {
this.data = data;
let tile = document.createElement("div");
tile.className = "tile";
tile.style.width = _tileWidth + "px";
tile.style.height = _tileHeight + "px";
tile.textContent = data.label;
if (data.id) tile.id = data.id;
tile.onmouseover = this._mouseOver.bind(this);
tile.onmouseout = this._mouseOut.bind(this);
tile.onmousedown = () => {
this.pushed = true;
this._setMoveTween(3, _tilePushDuration);
this.element.style.opacity = 0;
this.positionTween.onComplete(() => {
window.location = data.link;
});
};
this.object = new THREE.CSS3DObject(tile);
this.object.position.set(
position.x,
position.y,
position.z
);
scene.add(this.object);
if (data.init) data.init(tile);
this.element = tile;
this.positionTween = null;
this.position = position;
this.active = false;
this.pushed = false;
}
_mouseOver() {
if (this.pushed) return;
this.active = true;
}
_mouseOut() {
if (this.pushed) return;
this.active = false;
}
get active() {
return this._act;
}
set active(v) {
if (v != this._act) {
if (v) {
if (this.data.act) this.data.act(this.element);
this._setMoveTween(1, _tileMoveDuration);
} else {
if (this.data.deact) this.data.deact(this.element);
this._setMoveTween(0, _tileMoveDuration);
}
}
this._act = v;
}
_setMoveTween(state, duration) {
if (this.positionTween) this.positionTween.stop();
this.positionTween = new TWEEN.Tween(this.object.position)
.to({z: this.position.z + _tileMove * state}, duration)
.easing(TWEEN.Easing.Quadratic.InOut)
.start();
}
}
function init() {
scene = new THREE.Scene();
renderer = new THREE.CSS3DRenderer({
antialias: true
});
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set(0, 0, _cameraPositionZ);
camTarget = new THREE.Vector3(0, 0, _cameraPositionZ);
lookTarget = new THREE.Vector3(0, 0, 0);
currentLook = new THREE.Vector3(0, 0, 0);
document.body.onmousemove = onMouseMove;
document.body.onmouseleave = onMouseLeave;
window.onresize = onResize;
tiles = [];
for (let i = 0; i < data.length; i++) {
tiles.push(new Tile(
gridPosition(i),
data[i]
));
}
let header = document.createElement("div");
header.className = "header-label";
header.textContent = "three.js"
header.style.width = _gridWidth + "px";
header.style.height = _headerHeight + "px";
let header3d = new THREE.CSS3DObject(header);
header3d.position.set(0, (_gridHeight) / 2, 0);
scene.add(header3d);
}
function animate() {
requestAnimationFrame( animate );
TWEEN.update();
camera.position.x += (camTarget.x - camera.position.x) * _cameraMoveSpeed;
camera.position.y += (camTarget.y - camera.position.y) * _cameraMoveSpeed;
currentLook.x += (lookTarget.x - currentLook.x) * _cameraMoveSpeed;
currentLook.y += (lookTarget.y - currentLook.y) * _cameraMoveSpeed;
camera.lookAt(currentLook);
renderer.render( scene, camera );
}
function onMouseMove(event) {
let wh = window.innerWidth / window.innerHeight;
let vector = new THREE.Vector2(
(event.pageX / window.innerWidth * 2 - 1) * wh,
-(event.pageY / window.innerHeight * 2 - 1)
);
camTarget.set(
vector.x * _cameraMove,
vector.y * _cameraMove,
_cameraPositionZ
);
lookTarget.set(
vector.x * _lookAtMove,
vector.y * _lookAtMove,
0
);
}
function onMouseLeave(event) {
camTarget.set(0, 0, _cameraPositionZ);
lookTarget.set(0, 0, 0);
}
function onResize() {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
function gridPosition(index) {
let c = index % _columns, r = Math.floor(index / _columns);
return new THREE.Vector3(
c * (_tileWidth + _gap) + _tileWidth / 2 - _gridWidth / 2,
-(r * (_tileHeight + _gap) + _tileHeight / 2 - (_gridHeight - _headerHeight) / 2),
0
);
}
let scene, renderer, camera;
let tiles, grid;
let camTarget, lookTarget, currentLook;
init();
animate();
</script>
</body>
</html>