-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
333 lines (297 loc) · 11.7 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
330
331
332
333
<html>
<head>
<meta charset="utf-8"/>
<script>
/*
// ページの読み込みを待つ
window.addEventListener('load', init);
var field = [];
var turn = 0;
const C = 6;
function tipOver(turn, x, y, z) {
const addx = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1];
const addy = [1, 1, 1, 0, 0, 0, -1, -1, -1, 1, 1, 1, 0, 0, -1, -1, -1, 1, 1, 1, 0, 0, 0, -1, -1, -1];
const addz = [1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1];
const rangex = [-1, -1, -1, -1, -1, -1, -1, -1, -1, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C];
const rangey = [-1, -1, -1, C, C, C, C, C, C, -1, -1, -1, C, C, C, C, C, -1, -1, -1, C, C, C, C, C, C];
const rangez = [-1, C, C, -1, C, C, -1, C, C, -1, C, C, -1, C, -1, C, C, -1, C, C, -1, C, C, -1, C, C];
field[z][y][x] = turn;
for (var v = 0; v < 26; ++v) {
for (var xx = x - addx[v], yy = y - addy[v], zz = z - addz[v]; xx != rangex[v] && yy != rangey[v] && zz != rangez[v]; xx -= addx[v], yy -= addy[v], zz -= addz[v]) {
var breakFlag = false;
if (field[zz][yy][xx] == turn) {
for (var nonex = xx, noney = yy, nonez = zz; (nonex != x || addx[v] == 0) && (noney != y || addy[v] == 0) && (nonez != z || addz[v] == 0); nonex += addx[v], noney += addy[v], nonez += addz[v] ) {
if (field[nonez][noney][nonex] == -1) {
breakFlag = true;
break;
}
}
if (breakFlag) {
break;
}
for (var xxx = x, yyy = y, zzz = z; (xxx != xx || addx[v] == 0) && (yyy != yy || addy[v] == 0) && (zzz != zz || addz[v] == 0); xxx -= addx[v], yyy -= addy[v], zzz -= addz[v]) {
field[zzz][yyy][xxx] = turn;
}
break;
}
}
}
}
var textureCube0;
function createCubeMap (geom, imageFile) {
var imgPath = '/raycast/clouds1/';
var urls = [
imgPath+'clouds1_east.bmp',
imgPath+'clouds1_west.bmp',
imgPath+'clouds1_up.bmp',
imgPath+'clouds1_down.bmp',
imgPath+'clouds1_north.bmp',
imgPath+'clouds1_south.bmp'
];
const cubeTextureLoader = new THREE.CubeTextureLoader();
//const textureCube = cubeTextureLoader.load(urls);
return cubeTextureLoader.load( urls, function( cubeTexture){
textureCube0 = cubeTexture;
return textureCube0;
});
}
function init() {
// サイズを指定
const width = 1280;
const height = 960;
// マウス座標管理用のベクトルを作成
const mouse = new THREE.Vector2();
var look = [];
for (var x = -0.4; x <= 0.4; x += 0.8) {
for (var y = -0.4; y <= 0.4; y += 0.8) {
look.push( new THREE.Vector2(x, y) );
}
}
look.push( new THREE.Vector2(0.0, 0.0) );
// canvas 要素の参照を取得する
const canvas = document.querySelector('#myCanvas');
// レンダラーを作成
const renderer = new THREE.WebGLRenderer({
canvas: canvas,
antialias: true
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height);
renderer.setClearColor(0xccffcc, 1.0);
// シーンを作成
const scene = new THREE.Scene();
// カメラを作成
const camera = new THREE.PerspectiveCamera(45, width / height);
camera.position.set(C * 15, C * 15, C * 15);
var controls = new THREE.OrbitControls(camera);
// controls.autoRotate = true;
//skyboxを作成
var imgPath = '/raycast/clouds1/';
var urls = [
imgPath+'clouds1_east.bmp',
imgPath+'clouds1_west.bmp',
imgPath+'clouds1_up.bmp',
imgPath+'clouds1_down.bmp',
imgPath+'clouds1_north.bmp',
imgPath+'clouds1_south.bmp'
];
const cubeTextureLoader = new THREE.CubeTextureLoader();
//const textureCube = cubeTextureLoader.load(urls);
cubeTextureLoader.load( urls, function( textureCube){
textureCube.format = THREE.RGBFormat;
textureCube.mapping = THREE.CubeReflectionMapping; // 屈折
// CubeMapに基づいて環境を作成できる特殊なshader
const shader = THREE.ShaderLib["cube"];
shader.uniforms["tCube"].value = textureCube;
const material = new THREE.ShaderMaterial({
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: shader.uniforms,
depthWrite: false,
side: THREE.DoubleSide
});
const skybox = new THREE.Mesh(new THREE.BoxGeometry(10000, 10000, 10000), material);
scene.add(skybox);
// 地面用のPlaneを作成
var plane = new THREE.Mesh(
new THREE.PlaneGeometry(500, 500, 10, 10),
new THREE.MeshLambertMaterial({
color: 0xffffff
})
);
plane.position.y = -80;
plane.rotation.x = -Math.PI / 2;
scene.add(plane);
// const geometry = new THREE.BoxGeometry( 5,5,5 );
// マウスとの交差を調べたいものは配列に格納する
const meshList = []; var xyz = [];
for (let z = - C/2; z < C/2; z++) {var yy = []; var yyy = [];
for (let y = - C/2; y < C/2; y++) {var xx = []; var xxx = [];
for (let x = - C/2; x < C/2; x++) {
const geometry = new THREE.SphereGeometry( 3, 32, 32 );
const material = new THREE.MeshPhongMaterial({
color: 0xffffff,
envMap: textureCube,
reflectivity: 1.0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.x = x * 15 + 7.5;
mesh.position.y = y * 15 + 7.5;
mesh.position.z = z * 15 + 7.5;
mesh.material.opacity = 0.1;
mesh.material.transparent = true;
// if(-1 <= x && x >= 1 &&
// -1 <= y && y >= 1 &&
// -1 <= z && z >= 1) {
// mesh.visible = true;
// } else {
// mesh.visible = false;
// }
scene.add(mesh);
meshList.push(mesh);
xx.push(mesh);
xxx.push(-1);
// 影を有効化
mesh.castShadow = true;
mesh.receiveShadow = true;
}
yy.push(xx);
yyy.push(xxx);
}
xyz.push(yy);
field.push(yyy);
}
// 平行光源
const directionalLight = new THREE.DirectionalLight(0xFFFFFF);
directionalLight.position.set(50,50,50);
scene.add(directionalLight);
// 環境光源
const ambientLight = new THREE.AmbientLight(0x333333);
scene.add(ambientLight);
// レイキャストを作成
const raycaster = new THREE.Raycaster();
canvas.addEventListener('mousemove', handleMouseMove);
canvas.addEventListener("mousedown" , handleMouseDown);
// ライトの影表示を有効化
directionalLight.castShadow = true;
// directionalLight.shadow.camera.near = 0;
// directionalLight.shadow.camera.far = 50;
directionalLight.shadow.camera.top = 80;
directionalLight.shadow.camera.bottom = -80;
directionalLight.shadow.camera.left = -80;
directionalLight.shadow.camera.right = 80;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
// 地面の影を受ける設定を有効化
plane.receiveShadow = true;
// レンダラーの影レンダリングを有効化
renderer.shadowMap.enabled = true;
// var directionalLightShadowHelper = new THREE.CameraHelper( directionalLight.shadow.camera);
// scene.add( directionalLightShadowHelper);
//
// var directionalLightHelper = new THREE.DirectionalLightHelper( directionalLight);
// scene.add( directionalLightHelper);
tick();
// マウスを動かしたときのイベント
function handleMouseMove(event) {
const element = event.currentTarget;
// canvas要素上のXY座標
const x = event.clientX - element.offsetLeft;
const y = event.clientY - element.offsetTop;
// canvas要素の幅・高さ
const w = element.offsetWidth;
const h = element.offsetHeight;
// -1〜+1の範囲で現在のマウス座標を登録する
mouse.x = ( x / w ) * 2 - 1;
mouse.y = -( y / h ) * 2 + 1;
}
var mouseDownFlag = false;
function handleMouseDown(event) {
mouseDownFlag = true;
}
var frameFloatCount = 0.0;
// 毎フレーム時に実行されるループイベントです
function tick() {
directionalLight.position.set(50 * Math.cos(frameFloatCount), 50, 50 * Math.sin(frameFloatCount));
frameFloatCount += 0.006;
controls.update();
for (let z = 0; z < C; z++) {
for (let y = 0; y < C; y++) {
for (let x = 0; x < C; x++) {
// xyz[z][y][x].material.opacity = 1.0;
// xyz[z][y][x].material.transparent = false;
}
}
}
// レイキャスト = マウス位置からまっすぐに伸びる光線ベクトルを生成
for (var v = 0; v < 5; ++v) {
raycaster.setFromCamera(look[v], camera);
// その光線とぶつかったオブジェクトを得る
const intersects = raycaster.intersectObjects(meshList);
for (let z = 0; z < C; z++) {
for (let y = 0; y < C; y++) {
for (let x = 0; x < C; x++) {
if(intersects.length > 0 && xyz[z][y][x] === intersects[0].object && intersects[0].distance < 16.0) {
// xyz[z][y][x].material.opacity = 0.5;
// xyz[z][y][x].material.transparent = true;
}
}
}
}
}
raycaster.setFromCamera(mouse, camera);
// その光線とぶつかったオブジェクトを得る
const intersects2 = raycaster.intersectObjects(meshList);
for (let z = 0; z < C; z++) {
for (let y = 0; y < C; y++) {
for (let x = 0; x < C; x++) {
if(intersects2.length > 0 && xyz[z][y][x] === intersects2[0].object) {
if (mouseDownFlag && field[z][y][x] == -1) {
xyz[z][y][x].material.color.setHex(0xFF0000);
tipOver(turn % 2, x, y, z);
++turn;
}
}
}
}
}
var score0 = 0;
var score1 = 0;
for (let z = 0; z < C; z++) {
for (let y = 0; y < C; y++) {
for (let x = 0; x < C; x++) {
if (field[z][y][x] == 0) {
++score0;
xyz[z][y][x].material.opacity = 1.0;
xyz[z][y][x].material.transparent = false;
xyz[z][y][x].material.color.setHex(0x00FF00);
}
if (field[z][y][x] == 1) {
++score1;
xyz[z][y][x].material.opacity = 1.0;
xyz[z][y][x].material.transparent = false;
xyz[z][y][x].material.color.setHex(0xFF0000);
}
}
}
}
mouseDownFlag = false;
document.getElementById("score").innerHTML = "GREEN:" + score0 + "<br>" + "RED:" + score1;
// レンダリング
renderer.render(scene, camera);
requestAnimationFrame(tick);
}
});
}*/
</script>
</head>
<body>
<canvas id="myCanvas" width="960" height="540"></canvas>
<div id="score" style="font-size: 48px;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
<script src="src/riversi.js"></script>
<script src="src/mesh.js"></script>
<script src="src/renderer.js"></script>
<script src="src/game.js"></script>
</body>
</html>