-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
369 lines (255 loc) · 11 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>My first three.js app</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
/*canvas { width: 100%; height: 100% }*/
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/ObjectLoader.js"></script>
<script src="js/Stone.js"></script>
<!--<script src="js/main.js"></script>-->
<!--<script src="js/TrackballControls.js"></script>-->
<script>
var cubes = [];
var movables = [];
var clickables = [];
var move = false;
window.addEventListener('click', onDocumentMouseDown, false);
var scene = new THREE.Scene();
// var steve = new Stone(0, 0, 0, scene, 'js/steve.json', function(){console.log('FUCKYEAWWW')})
// steve.load();
var grid = new THREE.GridHelper(50, 5);
var color = new THREE.Color("rgb(255,0,0)");
grid.setColors(color, 0x000000);
scene.add(grid);
var camera = new THREE.PerspectiveCamera( 1, window.innerWidth / window.innerHeight, 1, 10000 );
// //var camera = new THREE.StereoCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
// camera.up = new THREE.Vector3(0, 0, 1);
// var target = new THREE.Vector3(0.00000, 0.00000, 0.00000);
// camera.lookAt(target);
// const left = -1;
// const right = 1;
// const top11 = 1;
// const bottom = -1;
// const near = 5;
// const far = 50;
// const camera = new THREE.OrthographicCamera(left, right, top11, bottom, near, far);
//perspectiveCamera.zoom = -3.2;
// var camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 2198.64063, 16376.29688);
// camera.position.x = 0.00000;
// camera.position.y = 0.00000;//-6292.71484;
// camera.position.z = 0.00000;
// camera.up = new THREE.Vector3(0, 0, 1);
// var target = new THREE.Vector3(0.00000, 0.00000, 0.00000);
// camera.lookAt(target);
var renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xdddddd);
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setSize(1920, 1080 );
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
document.body.appendChild( renderer.domElement );
window.addEventListener('resize', function() {
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix()
});
controls = new THREE.OrbitControls(camera, renderer.domElement);
// var loader = new THREE.ObjectLoader();
//
// loader.load
// (
// 'js/steve.json',
// function(object)
// {
// scene.add(object);
// }
// );
var geometry = new THREE.BoxGeometry( 0.6, 0.3, 0.3 );
// var texture = THREE.ImageUtils.loadTexture('https://preview.ibb.co/hZXYmz/ricoh_theta_s.jpg');
//var fff =new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide } );
//fff.emissive.setRGB() ;
var cubeMaterials = //map: new THREE.TextureLoader().load('js/img.jpg')
[
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide, emissive: 0x2a2a2a,
emissiveIntensity: .5 } ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide, emissive: 0x2a2a2a,
emissiveIntensity: .5 } ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide, emissive: 0x2a2a2a,
emissiveIntensity: .5 } ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide, emissive: 0x2a2a2a,
emissiveIntensity: 1.5 } ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide, emissive: 0x2a2a2a,
emissiveIntensity: 1.5 } ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide, emissive: 0x2a2a2a,
emissiveIntensity: 1.5 } )
]
var cubeMaterials2 = //map: new THREE.TextureLoader().load('js/img.jpg')
[
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide} ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide} ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide} ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide} ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide} ),
new THREE.MeshLambertMaterial( { map: new THREE.TextureLoader().load('js/img.jpg'), side: THREE.DoubleSide} )
]
//maybe just use 2 lists to speed up the looping
//where in the second list the ones get stored that can move
//var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var material = new THREE.MeshFaceMaterial(cubeMaterials);
var material2 = new THREE.MeshFaceMaterial(cubeMaterials2);
// material.emissive = new THREE.Color( 0x00ffff );
// material.emissiveIntensity = 2;
var pos = -30;
for (let i = 0; i < 20; i++) {
if (i%2 === 0) pos = -30; else pos = -31;
for (let y = 0; y < 30; y++ ) {
var min=0;
var max=0.5;
var random = Math.random() * (+max - +min) + +min;
var geometry2 = null;
if (i === 0 || i === 1) {
geometry2 = new THREE.BoxGeometry(2, 0.5, 1);
} else {
geometry2 = new THREE.BoxGeometry(2, 1, 1);
}
var cube = new THREE.Mesh( geometry2, material2 );
cube.castShadow = true;
cube.receiveShadow = true;
cube.position.x = pos;
cube.position.y = i;
cube.position.z = random;
// if (cube.name === '1-1') {
//
// cube.callback = function () {
// console.log(i + '-' + y);
// console.log('weffewfewf');
// // move = true;
// } //this.name
// } else {
cube.callback = function () {
console.log(i + '-' + y);
} //this.name
// }
cube.name = i + '-' + y;
if (cube.name === '1-1') {
cube.callback = function () {
console.log(i + '-' + y);
console.log('weffewfewf');
move = true;
} //this.name
}
//identifier for later usage
//console.log(cube.name);
if (cube.name === '1-2') movables.push(cube);
if (cube.name === '1-3') movables.push(cube);
if (cube.name === '2-0' || cube.name === '2-1' || cube.name === '2-2') {
clickables.push(cube)
}
cubes.push(cube);
scene.add( cube );
pos+=2;
}
}
camera.position.z = 5000;
// var ambientLight = new THREE.AmbientLight(0xFFFFFF, 1.0);
// scene.add(ambientLight);
// var pointLight1 = new THREE.PointLight(0xFF0040, 1, 50);
// scene.add(pointLight1);
// var spotLight = new THREE.SpotLight(0xFFFFFF);
// spotLight.castShadow = true;
// //spotLight.position.set (15, 30, 50);
var spotLight = new THREE.SpotLight( 0xffffff );
spotLight.position.set( 15, 30, 50 );
spotLight.castShadow = true;
spotLight.shadow.mapSize.width = 1024;
spotLight.shadow.mapSize.height = 1024;
spotLight.shadow.camera.near = 500;
spotLight.shadow.camera.far = 4000;
spotLight.shadow.camera.fov = 30;
scene.add( spotLight );
// var pointLight2 = THREE.PointLight(0xFFFFFF, 4, 50);
// scene.add(pointLight2);
//
// var pointLight3 = THREE.PointLight(0xFFFFFF, 4, 50);
// scene.add(pointLight3);
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
function onDocumentMouseDown( event ) {
event.preventDefault();
mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( cubes );
if ( intersects.length > 0 ) {
intersects[0].object.callback();
}
}
var keyFrame = 0;
var distance1 = 0;
var distance2 = 0;
var update = function() {
if (move) {
keyFrame++;
//var cubeM = movables[0];
// first stone
if (keyFrame > 0) {
var direction = 4;
if (direction === 1) { // right
distance1 += 0.05;
if (distance1 < 2) movables[0].position.x += 0.05;
} else if (direction === 2) { // left
distance1 += 0.05;
if (distance1 < 2) movables[0].position.x -= 0.05;
} else if (direction === 3) { // up
distance1 += 0.05;
if (distance1 < 1) movables[0].position.y += 0.05;
} else if (direction === 4) { // down
distance1 += 0.05;
if (distance1 < 1) movables[0].position.y -= 0.05;
}
}
if (keyFrame > 15) {
var direction = 3;
if (direction === 1) { // right
distance2 += 0.05;
if (distance2 < 2) movables[1].position.x += 0.05;
} else if (direction === 2) { // left
distance2 += 0.05;
if (distance2 < 2) movables[1].position.x -= 0.05;
} else if (direction === 3) { // up
distance2 += 0.05;
if (distance2 < 1) movables[1].position.y += 0.05;
} else if (direction === 4) { // down
distance2 += 0.05;
if (distance2 < 1) movables[1].position.y -= 0.05;
}
}
//scene.remove(cubeM);
}
// cube.rotation.x += 0.01;
// cube.rotation.y += 0.01;
//
// cube2.rotation.x += 0.01;
// cube2.rotation.y += 0.01;
}
function animate() {
requestAnimationFrame( animate );
update();
//renderer.render(scene, topViewCamera);
renderer.render(scene, camera);
// renderer.render( scene, camera );
}
animate();
</script>
</body>
</html>