-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
330 lines (278 loc) · 8.16 KB
/
index.js
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
330
let width;
let height;
let r;
var scene;
var camera;
var renderer;
var controls;
var cubelist = [];
var movingon=0
// FIXME 変数名をどうにかしろ
var moving_counter=60;
var centering;
var defColor=0;
let colapse;
const counter_max=200;
const light_color = 0xFFFFFF;
// const cube_default_color = 0xFF8000;
const cube_default_color = 0xFF8000;
const cube_mouseon_color = 0xBF4040;
// FIXME スマホの時のPMOBがちっちゃくなる現象タスケテ
const camera_lights = [
[0, 1000, 0], [500, 1000, 1000], [-500, 1000, -1000], [0, 1000, 500]
];
// リンクページ
const content = {
"P":"Programming", "M":"Mathematics", "O":"Organization", "B":"Belong"
};
const P=[
[0,0],
[0,1],
[0,2],
[0,3],
[0,4],
[0,5],
[1,5],
[2,5],
[3,4],
[3,3],
[2,2],
[1,2]
];
const M=[
[0,0],
[0,1],
[0,2],
[0,3],
[0,4],
[0,5],
[1,4],
[2,3],
[3,4],
[4,0],
[4,1],
[4,2],
[4,3],
[4,4],
[4,5]
];
const O=[
[0,1],
[0,2],
[0,3],
[0,4],
[1,5],
[2,5],
[3,3],
[3,4],
[3,2],
[3,1],
[2,0],
[1,0]
];
const B=[
[0,0],
[0,1],
[0,2],
[0,3],
[0,4],
[0,5],
[1,5],
[2,5],
[3,4],
[2,3],
[1,3],
[3,2],
[3,1],
[2,0],
[1,0]
];
const Pmob={"P":P,"M":M,"O":O,"B":B};
function windSize(){
height = document.documentElement.clientHeight-50;
width = document.documentElement.clientWidth-50;
}
function init(){
windSize();
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(110, width / height, 1, 1000);
controls = new THREE.OrbitControls(camera);
controls.autoRotate = false;
renderer = createRenderer();
var now_total_wid = 0;
var total_wid = -2;
r = (width+50)/300;
// 文字横全長
Object.entries(Pmob).forEach((word)=>{
total_wid += Math.max.apply([],word[1].map((array)=>{
return array[0];
}))+2;
});
centering = total_wid/2;
// 命名が適切でない
var id = 0;
// キューブ作成配列にぶっこむ
Object.entries(Pmob).forEach((word,index)=>{
cubelist[index] = [];
cubelist[index] = word[1].map((item)=>{
return createCube(item[0], item[1], now_total_wid, id, word[0]);
});
id+=1;
now_total_wid += Math.max.apply([],word[1].map((array)=>{
return array[0];
}))+2;
});
camera_lights.forEach((light)=>{
scene.add(createLight(light_color, light[0], light[1], light[2]));
});
camera.position.set(0, 0, 50);
camera.lookAt(new THREE.Vector3(0, 0, 0));
update();
}
function createRenderer(){
// trueにするとrenderが透明に出来るようになる
const renderer = new THREE.WebGLRenderer({alpha:true});
renderer.setSize(width, height);
renderer.setClearColor(light_color, 0); //0:透明
document.body.appendChild(renderer.domElement);
return renderer;
}
function createCube(x, y, wid, id, belong){
const geometry = new THREE.BoxGeometry(r, r, r);
const material = new THREE.MeshPhongMaterial({color: cube_default_color});
const cube = new THREE.Mesh(geometry, material);
cube.color = 1;
cube.position.set(x*r+r*wid-centering*r, y*r, 0);
cube.id = id;
cube.belong = belong;
scene.add(cube);
return cube;
}
function cubecolorChange(obj){
if(obj.color == 0) obj.material.color.setHex(cube_mouseon_color);
else obj.material.color.setHex(cube_default_color);
}
// function cubecoloriGradationChange(obj){
// // obj.material.color.setHex(defColor+=9);
// defColor = Math.floor(Math.random()*light_color);
// obj.material.color.setHex(defColor);
// }
function createLight(color, x, y, z){
const light = new THREE.DirectionalLight(color);
light.position.set(x, y, z);
return light;
}
// ラピュタみたいな動き
function moving(obj){
const xyzxyz = "xyzxyz";
const zxyzxy = "zxyzxy";
const yzxyzx = "yzxyzx";
const index = [10,20,30,40,50,60,counter_max].filter((i)=>{
return moving_counter>i;
}).length;
let movin;
if(index<6){
movingon=1;
if(obj.id%3==0){
movin = xyzxyz[index];
}else if(obj.id%3==1){
movin = zxyzxy[index];
}else{
movin = yzxyzx[index];
}
const onestep = r/7;
if(movin=="x"){
(index<3)?
obj.position.x += onestep : obj.position.x -= onestep;
}else if(movin=="y"){
(index<3)?
obj.position.y += onestep : obj.position.y -= onestep;
}else if(movin=="z"){
(index<3)?
obj.position.z += onestep : obj.position.z -= onestep;
}
}else movingon=0;
}
function update(){
controls.update();
requestAnimationFrame(update);
renderer.render(scene, camera);
moving_counter+=1;
if(!colapse){
(cubelist.flat()).forEach((o)=>{ moving(o) });
}else{
(cubelist.flat()).forEach((o)=>{
if(o.belong != colapse){
o.position.x += Math.floor(Math.random()*10);
o.position.y += Math.floor(Math.random()*10);
o.position.z += Math.floor(Math.random()*10);
o.position.x -= Math.floor(Math.random()*10);
o.position.y -= Math.floor(Math.random()*10);
o.position.z -= Math.floor(Math.random()*10);
o.position.z += 1;
}else{ // こっちくんな こないで
// o.position.z += 0.5;
}
});
}
if(moving_counter>=counter_max){
if(colapse) window.location.href = window.location.href.split("/").pop()=="index.html" ?
window.location.href.replace("index.html", `pages/${colapse}.html`): window.location.href + `pages/${colapse}.html`;
moving_counter=0;
}
var projector = new THREE.Projector();
var mouse = {x:0, y:0};
// カオス
window.onmousemove = function(ev){
if(ev.target == renderer.domElement){
var rect = ev.target.getBoundingClientRect();
mouse.x = ev.clientX - rect.left;
mouse.y = ev.clientY - rect.top;
mouse.x = (mouse.x / width) * 2 - 1;
mouse.y = -(mouse.y / height) * 2 + 1;
var vector = new THREE.Vector3(mouse.x, mouse.y ,1);
projector.unprojectVector(vector, camera);
var ray = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var obj = ray.intersectObjects(cubelist.flat());
if(obj.length > 0){
if(!colapse) document.getElementById("logo").textContent = `${content[obj[0].object.belong]}`;
var save = obj[0].object.belong;
(cubelist.flat()).forEach((o)=>{
if(o.belong == obj[0].object.belong){
o.color=0;
cubecolorChange(o);
// if(o.position.z<=10) o.position.z += 1;
}else{
o.color=1;
cubecolorChange(o);
// if(o.position.z>0) o.position.z -= 1;
}
});
}else{
(cubelist.flat()).forEach((o)=>{
o.color=1;
cubecolorChange(o);
});
if(!colapse) document.getElementById("logo").textContent = "";
}
}
window.onmousedown = function(e){
if(e.target == renderer.domElement){
if(!movingon && obj.length > 0){
(cubelist.flat()).forEach((o)=>{
if(o.belong == obj[0].object.belong){
o.color=1;
cubecolorChange(o);
colapse = obj[0].object.belong;
moving_counter=100;
}
});
}
}
};
// if(!colapse){
// (cubelist.flat()).forEach((o)=>{if(o.position.z>0) o.position.z -= 1;})
// }
};
}
window.addEventListener('DOMContentLoaded', init);