-
Notifications
You must be signed in to change notification settings - Fork 5
/
earthCopyNice.html
465 lines (365 loc) · 19.6 KB
/
earthCopyNice.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shaking Earth</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="container"></div>
<script type="x-shader/x-vertex" id="vertexshader">
attribute float size;
attribute vec2 coords;
uniform float time;
uniform vec3 mouse3D;
varying vec3 vColor;
varying vec2 vCoords;
varying vec3 vPosition;
void main() {
vColor = color;
vCoords = coords;
vPosition = position;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_PointSize = size * ( 300.0 / -mvPosition.z );
gl_Position = projectionMatrix * mvPosition;
// Test wave
float PI = 3.14159;
float distFromMouse = distance(position, mouse3D) / 10.; // length(position);
// if(distFromMouse < 8.){
vec3 newPosition = position * (1. + 10. * sin(distFromMouse * 4. + time * 2.) / (distFromMouse * 100.));
gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );
// }
}
</script>
<script type="x-shader/x-fragment" id="fragmentshader">
uniform sampler2D pointTexture;
uniform sampler2D earthTexture;
uniform sampler2D earthNightTexture;
uniform int modeVisu;
varying vec2 vCoords;
varying vec3 vColor;
varying vec3 vPosition;
void main() {
//gl_FragColor = vec4( vColor, 1.0 );
gl_FragColor = 1.5 * texture2D( pointTexture, gl_PointCoord ); // + texture2D( earthNightTexture, gl_PointCoord );
if(modeVisu > 0){ gl_FragColor = gl_FragColor * texture2D( earthTexture, vCoords );}
// We do horizon culling
//float maxDist = sqrt(length(vPosition) * length(vPosition) + length(cameraPosition) * length(cameraPosition));
}
</script>
<script type="x-shader/x-vertex" id="vertexshaderEarth">
attribute float size;
uniform float time;
uniform vec3 mouse3D;
varying vec3 vColor;
varying vec2 vUv;
varying vec3 vPosition;
varying float distFromMouse;
void main() {
vColor = color;
vUv = uv;
vPosition = position;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
//gl_PointSize = size * ( 300.0 / -mvPosition.z );
//gl_Position = projectionMatrix * mvPosition;
// Test wave
float PI = 3.14159;
distFromMouse = distance(position, mouse3D) / 10.; // length(position);
// if(distFromMouse < 8.){
vPosition = position * (1. + 10. * sin(distFromMouse * 4. + time * 2.) / (distFromMouse * 100.));
// }
gl_Position = projectionMatrix * modelViewMatrix * vec4( vPosition, 1.0 );
}
</script>
<script type="x-shader/x-fragment" id="fragmentshaderEarth">
uniform sampler2D pointTexture;
uniform sampler2D earthTexture;
uniform sampler2D earthNightTexture;
uniform sampler2D earthSpecularTexture;
uniform sampler2D earthBumpTexture;
uniform int modeVisu;
varying vec2 vUv;
varying vec3 vColor;
varying vec3 vPosition;
varying float distFromMouse;
void main() {
gl_FragColor = texture2D( earthNightTexture, vUv); //(1. + (length(vPosition) - 199.) / 10. ) * texture2D( earthBumpTexture, vUv);
if(modeVisu == 1) {
gl_FragColor.a = 1. - distFromMouse / 8.;
}
vec4 col = texture2D( earthSpecularTexture, vUv);
if(col.b > 0.9)
gl_FragColor = vec4(0.,0.,0.,0.); // gl_FragColor.a = 0.;
}
</script>
<script type="module">
import * as THREE from './three.module.js';
import { OrbitControls } from './controls/OrbitControls.js';
var renderer, scene, camera, controls;
var particleSystem, uniforms, geometry;
var particles = 100000;
var cloudsSphere;
var earthSphere;
var earthSphereBackSide;
var wireframe;
var time = 0;
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
var mouse3D = new THREE.Vector3();
init();
/*
var light = new THREE.DirectionalLight(0xffffff,0.5);
light.position.set(-1,0,1);
scene.add(light);
*/
var smokeTexture = THREE.ImageUtils.loadTexture('textures/Smoke-Element.png');
var smokeMaterial = new THREE.MeshLambertMaterial({color: 0xeeeeee, map: smokeTexture, transparent: true});
var smokeGeo = new THREE.PlaneGeometry(300,300);
var smokeParticles = new THREE.Object3D();
for (var p = 0; p < 150; p++) {
var particle = new THREE.Mesh(smokeGeo,smokeMaterial);
particle.position.set(Math.random()*500-250,Math.random()*500-250,Math.random()*1000-100);
particle.rotation.z = Math.random() * 360;
// scene.add(smokeParticles);
smokeParticles.add(particle);
}
function evolveSmoke() {
smokeParticles.rotation.copy(camera.rotation);
var sp = smokeParticles.children.length;
while(sp--) {
smokeParticles.children[sp].rotation.z = (time * 0.3);
}
}
animate();
function init() {
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 5000 );
camera.position.z = 1000;
scene = new THREE.Scene();
uniforms = {
time: {value: time},
mouse3D: {value: mouse3D},
modeVisu: {value: 0},
pointTexture: { value: new THREE.TextureLoader().load( "textures/spark1.png" ) },
earthTexture: { value: new THREE.TextureLoader().load( "textures/8k_earth_daymap.jpg" ) },
earthNightTexture: { value: new THREE.TextureLoader().load( "textures/4k_earth_nightmap.jpg" ) },
earthSpecularTexture: { value: new THREE.TextureLoader().load( "textures/2k_earth_specular_map.jpg" ) },
earthBumpTexture: { value: new THREE.TextureLoader().load( "textures/elev_bump_2k.jpg" ) }
};
var shaderMaterialParticles = new THREE.ShaderMaterial( {
uniforms: uniforms,
vertexShader: document.getElementById( 'vertexshader' ).textContent,
fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
blending: THREE.AdditiveBlending,
depthTest: true,
transparent: true,
vertexColors: true
} );
var radius = 200;
geometry = new THREE.BufferGeometry();
var positions = [];
var colors = [];
var sizes = [];
var coords = [];
var color = new THREE.Color();
var nbPerlongitude = 1000;
var nbPerLatitude = nbPerlongitude / 2;
var particleRadius = radius * 1;
for ( var i = 0; i < nbPerlongitude; ++i){
var phi = i / nbPerlongitude * 2 * Math.PI;
for ( var j = 0; j < nbPerLatitude; ++j){
var theta = j / nbPerLatitude * Math.PI;
var x = - particleRadius * Math.cos(phi) * Math.sin(theta);
var y = particleRadius * Math.cos(theta);
var z = particleRadius * Math.sin(phi) * Math.sin(theta);
coords.push( i / nbPerlongitude, 1 - j / nbPerLatitude);
positions.push(x, y, z);
colors.push(0.5, 0., 1.);
sizes.push(6);
}
}
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
geometry.setAttribute( 'coords', new THREE.Float32BufferAttribute( coords, 2 ) );
geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
geometry.setAttribute( 'size', new THREE.Float32BufferAttribute( sizes, 1 ).setUsage( THREE.DynamicDrawUsage ) );
particleSystem = new THREE.Points( geometry, shaderMaterialParticles );
scene.add( particleSystem );
renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
var container = document.getElementById( 'container' );
container.appendChild( renderer.domElement );
controls = new OrbitControls( camera, renderer.domElement );
//controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
//controls.dampingFactor = 0.05;
controls.screenSpacePanning = false;
controls.minDistance = 100;
controls.maxDistance = 2000;
// controls.maxPolarAngle = Math.PI / 2;
window.addEventListener( 'resize', onWindowResize, false );
// clouds
var geometryClouds = new THREE.SphereGeometry( radius + 3, 32, 32 );
var material = new THREE.MeshBasicMaterial( {
transparent:true,
opacity: 0.2,
map: new THREE.TextureLoader().load( "textures/4k_earth_clouds.jpg" ),
blending: THREE.AdditiveBlending,
});
cloudsSphere = new THREE.Mesh( geometryClouds, material );
scene.add( cloudsSphere );
// Version Mesh of the earth
var uniformsEarth = {
time: {value: time},
mouse3D: {value: mouse3D},
modeVisu: {value: 0},
pointTexture: { value: new THREE.TextureLoader().load( "textures/spark1.png" ) },
earthTexture: { value: new THREE.TextureLoader().load( "textures/4k_earth_daymap.jpg" ) },
earthNightTexture: { value: new THREE.TextureLoader().load( "textures/4k_earth_nightmap.jpg" ) },
earthSpecularTexture: { value: new THREE.TextureLoader().load( "textures/2k_earth_specular_map.jpg" ) },
earthBumpTexture: { value: new THREE.TextureLoader().load( "textures/elev_bump_2k.jpg" ) }
};
var shaderMaterialEarth = new THREE.ShaderMaterial( {
uniforms: uniformsEarth,
vertexShader: document.getElementById( 'vertexshaderEarth' ).textContent,
fragmentShader: document.getElementById( 'fragmentshaderEarth' ).textContent,
//blending: THREE.AdditiveBlending,
//wireframe: true,
side:THREE.FrontSide,
depthTest: true,
transparent: true,
vertexColors: true
} );
var shaderMaterialEarthBackSide = new THREE.ShaderMaterial( {
uniforms: uniformsEarth,
vertexShader: document.getElementById( 'vertexshaderEarth' ).textContent,
fragmentShader: document.getElementById( 'fragmentshaderEarth' ).textContent,
//blending: THREE.AdditiveBlending,
//wireframe: true,
side:THREE.BackSide,
depthTest: true,
transparent: false,
vertexColors: true
} );
var geometryEarth = new THREE.SphereBufferGeometry( radius , 128, 128);
earthSphere = new THREE.Mesh( geometryEarth, shaderMaterialEarth);
var geometryEarthBackSide = new THREE.SphereBufferGeometry( radius , 128, 128);
earthSphereBackSide = new THREE.Mesh( geometryEarthBackSide, shaderMaterialEarthBackSide);
// Version Lines of the earth
var uniformsLines= {
time: {value: time},
mouse3D: {value: mouse3D},
modeVisu: {value: 1},
pointTexture: { value: new THREE.TextureLoader().load( "textures/spark1.png" ) },
earthTexture: { value: new THREE.TextureLoader().load( "textures/4k_earth_daymap.jpg" ) },
earthNightTexture: { value: new THREE.TextureLoader().load( "textures/4k_earth_nightmap.jpg" ) },
earthSpecularTexture: { value: new THREE.TextureLoader().load( "textures/2k_earth_specular_map.jpg" ) },
earthBumpTexture: { value: new THREE.TextureLoader().load( "textures/elev_bump_2k.jpg" ) }
};
var shaderMaterialLines = new THREE.ShaderMaterial( {
uniforms: uniformsLines,
vertexShader: document.getElementById( 'vertexshaderEarth' ).textContent,
fragmentShader: document.getElementById( 'fragmentshaderEarth' ).textContent,
//blending: THREE.AdditiveBlending,
//wireframe: true,
depthTest: true,
transparent: true,
vertexColors: true
} );
const wireframeGeometry = new THREE.WireframeGeometry( geometryEarth );
const wireframeMaterial = new THREE.LineBasicMaterial( { /*color: 0xff0000*/ } );
wireframe = new THREE.LineSegments( wireframeGeometry, shaderMaterialLines );
// earthSphere.add( wireframe );
// scene.add( earthSphere );
scene.add(earthSphereBackSide);
getSeismicData();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
time += 0.001;
cloudsSphere.rotation.y = time / 10.;
particleSystem.material.uniforms.time.value = time * 40.;
earthSphere.material.uniforms.time.value = time * 40.;
earthSphereBackSide.material.uniforms.time.value = time * 40.;
wireframe.material.uniforms.time.value = time * 40.;
geometry.attributes.size.needsUpdate = true;
evolveSmoke();
renderer.render( scene, camera );
}
function onMouseMove( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
// update the picking ray with the camera and mouse position
raycaster.setFromCamera( mouse, camera );
// calculate objects intersecting the picking ray
var intersects = raycaster.intersectObjects( [cloudsSphere] );
for ( var i = 0; i < intersects.length; i++ ) {
mouse3D = intersects[ i ].point;
}
particleSystem.material.uniforms.mouse3D.value = mouse3D;
earthSphere.material.uniforms.mouse3D.value = mouse3D;
earthSphereBackSide.material.uniforms.mouse3D.value = mouse3D;
wireframe.material.uniforms.mouse3D.value = mouse3D;
renderer.render( scene, camera );
}
window.addEventListener( 'mousemove', onMouseMove, false );
document.addEventListener('keyup', (e) => {
//if (e.code === "ArrowUp") playerSpriteX += 10
particleSystem.material.uniforms.modeVisu.value = 1.;
});
/********************************** Part regarding the seismic data ***************************/
// Url to access data: https://service.iris.edu/fdsnws/event/1/query?starttime=2019-12-18T00:00:00&endtime=2019-12-19T23:00:00&includeallmagnitudes=true&orderby=time&format=text&nodata=404
// We get the data using text cause it's much faster to access and lighter
// Seismic event is 12 elements
var seismicArray = [];
function getSeismicData(){
fetch('https://service.iris.edu/fdsnws/event/1/query?starttime=2019-12-18T00:00:00&endtime=2019-12-19T23:00:00&includeallmagnitudes=true&orderby=time&format=text&nodata=404').then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' + response.status);
return;
}
response.text().then(function(data) {
//console.log(data);
var st = data.replace(/[\/]/g, "");
var seismicDataArray = st.split(/[\r\n]+/gm); // split(new RegExp("\n")); // split(/\r?\n/) //split(/[\r\n]+/gm); // replace( /[\r\n]+/gm, "" ).split('|');
//console.log(seismicDataArray);
for(var i = 1; i < seismicDataArray.length; ++i){
var seismicEvent = seismicDataArray[i].split("|");
//console.log(seismicEvent);
seismicArray.push({ eventID : seismicEvent[0],
time : seismicEvent[1],
latitude : seismicEvent[2],
longitude : seismicEvent[3],
depth : seismicEvent[4],
author : seismicEvent[5],
catalog : seismicEvent[6],
contributor : seismicEvent[7],
contributorID : seismicEvent[8],
MagType : seismicEvent[9],
Magnitude : seismicEvent[10],
MagAuthor : seismicEvent[11],
eventLocationName : seismicEvent[12]
});
}
console.log(seismicArray);
// Then we can launch the visualization of that data
displaySeismicData();
});
}
).catch(function(err) {
console.log('Fetch Error :-S', err);
});
}
function displaySeismicData(){
}
</script>
</body>
</html>