-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalium_earth.php
366 lines (316 loc) · 16.6 KB
/
globalium_earth.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Globalium</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&family=Scope+One&display=swap" rel="stylesheet">
</head>
<body>
<script src="js/threejs/build/three.js"></script>
<script src="js/master/examples/js/controls/TrackballControls.js"></script>
<script src="js/OrbitControls.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Basic setup
const scene = new THREE.Scene();
const aspect = window.innerWidth / window.innerHeight;
let ambientLight;
let pointLight;
// CAMERA
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 20, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 1000;
const camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
camera.zoom = 0.4;
camera.position.set(0, 0, 15);
camera.lookAt(scene.position);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio); // Millora la resolució
document.body.appendChild(renderer.domElement);
// OrbitControls
const controls = new THREE.TrackballControls(camera, renderer.domElement);
controls.rotateSpeed = 4;
controls.zoomSpeed = 0.02;
controls.panSpeed = 0.8;
controls.noRotate = false;
controls.noZoom = false;
controls.noPan = true;
controls.staticMoving = false;
controls.dynamicDampingFactor = 0.3;
controls.keys = [65, 83, 68]; // A, S, D
// Defineix l'objectiu dels controls
controls.target.set(0, 0, 0);
// Add event listener for resizing the window
window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
camera.updateProjectionMatrix();
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
camera.zoom = SCREEN_WIDTH < 400 ? 0.29 : 0.4;
}
// Add event listeners for zoom using touch pinch
let touchStartDistance = 0;
let initialZoom = camera.zoom;
function getTouchDistance(event) {
const dx = event.touches[0].pageX - event.touches[1].pageX;
const dy = event.touches[0].pageY - event.touches[1].pageY;
return Math.sqrt(dx * dx + dy * dy);
}
window.addEventListener('touchstart', function(event) {
if (event.touches.length === 2) {
touchStartDistance = getTouchDistance(event);
initialZoom = camera.zoom;
}
});
window.addEventListener('touchmove', function(event) {
if (event.touches.length === 2) {
const touchMoveDistance = getTouchDistance(event);
camera.zoom = initialZoom * (touchMoveDistance / touchStartDistance);
camera.updateProjectionMatrix();
}
});
// Inicial setup
onWindowResize();
// Define colors for the six spots
const colors = [
new THREE.Color(0x00FFFF), // North (Cyan)
new THREE.Color(0xFF0000), // South (Red)
new THREE.Color(0x0000FF), // East (Blue)
new THREE.Color(0x00FF00), // West (Green)
new THREE.Color(0xFFFF00), // Front (Yellow)
new THREE.Color(0xFF00FF) // Rear (Magenta)
];
// Carrega la textura
const textureLoader = new THREE.TextureLoader();
textureLoader.load('https://labs.opengea.org/metamodeler/v1/img/8k_earth_nightmap.jpg', function(texture) {
const material = new THREE.MeshPhongMaterial({
map: texture,
});
// Sphere geometry and material
const geometry = new THREE.SphereGeometry(5, 64, 64);
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
// Crear una llum ambiental com a objecte mòbil
ambientLight = new THREE.AmbientLight(0x444444); // Llum suau
// scene.add(ambientLight);
// Afegir llum direccional fixa
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(10, 10, 10); // Posició fixa de la llum
// scene.add(directionalLight);
// Afegir llum puntual fixa
pointLight = new THREE.PointLight(0xffffff, 3, 100);
pointLight.position.set(5, 5, 5); // Posició fixa de la llum puntual
scene.add(pointLight);
function updateAmbientLightPosition() {
// Defineix una trajectòria circular o qualsevol altra trajectòria
const time = Date.now() * 0.001; // Utilitza el temps per a crear moviment
ambientLight.position.set(Math.sin(time) * 10, Math.cos(time) * 10, 10); // Exemple de trajectòria circular
console.log('x');
}
// Helper function to create an orbit
function createOrbit(radius, segments, axis) {
const geometry = new THREE.BufferGeometry();
const positions = [];
for (let i = 0; i <= segments; i++) {
const theta = (i / segments) * Math.PI * 2;
const x = radius * Math.cos(theta);
const y = radius * Math.sin(theta);
positions.push(x, y, 0);
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
const material = new THREE.LineDashedMaterial({
color: 0x444444,
linewidth: 5,
dashSize: 0.1,
gapSize: 0.1
});
const orbit = new THREE.LineLoop(geometry, material);
orbit.rotation.set(axis.x, axis.y, axis.z);
orbit.computeLineDistances();
scene.add(orbit);
}
// Create the orbits
createOrbit(5.5, 64, new THREE.Vector3(Math.PI / 2, 0, 0)); // Equador
createOrbit(5.5, 64, new THREE.Vector3(0, 0, 0)); // Transversal
createOrbit(5.5, 64, new THREE.Vector3(0, Math.PI / 2, 0)); // Vertical
// Helper function to create a circle orbiting the north pole and slightly above the sphere
function createOrbitingCircle(radius, distanceFromSurface, verticalDistance, segments) {
const positions = [];
for (let i = 0; i <= segments; i++) {
const theta = (i / segments) * Math.PI * 2;
const x = radius * Math.cos(theta);
const y = radius * Math.sin(theta);
positions.push(x, y, verticalDistance);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
const material = new THREE.LineDashedMaterial({
color: 0x444444,
linewidth: 5,
dashSize: 0.1,
gapSize: 0.1
});
const circle = new THREE.LineLoop(geometry, material);
circle.position.set(0, radius + distanceFromSurface, 0); // Position it slightly above the sphere
circle.rotation.x = Math.PI / 2; // Rotate to be parallel to the x-z plane
circle.computeLineDistances(); // Necessary for dashed lines
scene.add(circle);
}
// Helper function to find the midpoint on the surface
function midpointOnSurface(p1, p2, radius) {
const midpoint = new THREE.Vector3(
(p1.x + p2.x) / 2,
(p1.y + p2.y) / 2.7, //distancia rectificada per facilitat d'us
(p1.z + p2.z) / 2
);
return midpoint.normalize().multiplyScalar(radius);
}
// Helper function to find the midpoint between 3 points on the surface
function midpoint3OnSurface(p1, p2, p3, radius) {
const midpoint = new THREE.Vector3(
(p1.x + p2.x + p3.x) / 3,
(p1.y + p2.y + p3.y) / 3,
(p1.z + p2.z) / 3
);
return midpoint.normalize().multiplyScalar(radius);
}
// Create canvas-based text labels
function createTextLabel(text, position, color, fontSize = '36px') {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
context.font = `${fontSize} 'Roboto'`;
const textWidth = context.measureText(text).width;
canvas.width = textWidth + 20; // Add some padding
canvas.height = parseInt(fontSize) + 20; // Font size + some padding
context.font = `bold ${fontSize} 'Roboto'`;
context.textBaseline = 'top';
context.lineJoin = 'round';
context.lineWidth = 0; // Border thickness
// Draw text
context.fillStyle = color;
context.fillText(text, 10, 10); // Slightly offset the text to leave space for the border
const texture = new THREE.CanvasTexture(canvas);
const spriteMaterial = new THREE.SpriteMaterial({
map: texture,
depthTest: false, // Disable depth test for sprites
transparent: true // Enable transparency
});
const sprite = new THREE.Sprite(spriteMaterial);
sprite.scale.set(canvas.width / 100, canvas.height / 100, 1); // Adjust the scale
sprite.position.copy(position);
sprite.userData = { originalOpacity: 1 }; // Store original opacity
scene.add(sprite);
return sprite;
}
// Add main labels
const radius = 5;
const posTEO = new THREE.Vector3(0, radius, 0); // North
const posPRA = new THREE.Vector3(0, -radius, 0); // South
const posOBJ = new THREE.Vector3(radius, 0, 0); // East
const posSUB = new THREE.Vector3(-radius, 0, 0); // West
const posFEN = new THREE.Vector3(0, 0, radius); // Front
const posNOU = new THREE.Vector3(0, 0, -radius); // Rear
const labels = [];
labels.push(createTextLabel('TEO', posTEO, 'black'));
labels.push(createTextLabel('PRA', posPRA, 'black'));
labels.push(createTextLabel('OBJ', posOBJ, 'black'));
labels.push(createTextLabel('SUB', posSUB, 'black'));
labels.push(createTextLabel('FEN', posFEN, 'black'));
labels.push(createTextLabel('NOU', posNOU, 'black'));
// Add extra labels in 36px
const posSTT = midpointOnSurface(posSUB, posTEO, radius);
const posSTM = midpointOnSurface(posSUB, posPRA, radius);
const posSGE = midpointOnSurface(posOBJ, posPRA, radius);
const posSGT = midpointOnSurface(posOBJ, posTEO, radius);
const posANA = midpointOnSurface(posFEN, posTEO, radius);
const posSIN = midpointOnSurface(posNOU, posTEO, radius);
const posEXP = midpointOnSurface(posFEN, posPRA, radius);
const posAMO = midpointOnSurface(posNOU, posPRA, radius);
const posCIE = midpointOnSurface(posFEN, posOBJ, radius);
const posART = midpointOnSurface(posFEN, posSUB, radius);
const posMTF = midpointOnSurface(posNOU, posOBJ, radius);
const posMTP = midpointOnSurface(posNOU, posSUB, radius);
labels.push(createTextLabel('STT', posSTT, 'black', '26px'));
labels.push(createTextLabel('STM', posSTM, 'black', '26px'));
labels.push(createTextLabel('SGE', posSGE, 'black', '26px'));
labels.push(createTextLabel('SGT', posSGT, 'black', '26px'));
labels.push(createTextLabel('ANA', posANA, 'black', '26px'));
labels.push(createTextLabel('SIN', posSIN, 'black', '26px'));
labels.push(createTextLabel('EXP', posEXP, 'black', '26px'));
labels.push(createTextLabel('AMO', posAMO, 'black', '26px'));
labels.push(createTextLabel('CIE', posCIE, 'black', '26px'));
labels.push(createTextLabel('ART', posART, 'black', '26px'));
labels.push(createTextLabel('MTF', posMTF, 'black', '26px'));
labels.push(createTextLabel('MTP', posMTP, 'black', '26px'));
// Create additional labels
const posLOG = midpoint3OnSurface(posTEO, posOBJ, posFEN, radius);
const posEST = midpoint3OnSurface(posTEO, posSUB, posFEN, radius);
const posMIT = midpoint3OnSurface(posTEO, posSUB, posNOU, radius);
const posIDE = midpoint3OnSurface(posTEO, posOBJ, posNOU, radius);
const posTEC = midpoint3OnSurface(posPRA, posOBJ, posFEN, radius);
const posPSI = midpoint3OnSurface(posPRA, posSUB, posFEN, radius);
const posMIS = midpoint3OnSurface(posPRA, posSUB, posNOU, radius);
const posETI = midpoint3OnSurface(posPRA, posOBJ, posNOU, radius);
labels.push(createTextLabel('LOG', posLOG, 'black', '26px'));
labels.push(createTextLabel('EST', posEST, 'black', '26px'));
labels.push(createTextLabel('MIT', posMIT, 'black', '26px'));
labels.push(createTextLabel('IDE', posIDE, 'black', '26px'));
labels.push(createTextLabel('TEC', posTEC, 'black', '26px'));
labels.push(createTextLabel('PSI', posPSI, 'black', '26px'));
labels.push(createTextLabel('MIS', posMIS, 'black', '26px'));
labels.push(createTextLabel('ETI', posETI, 'black', '26px'));
// Create orbiting circles
createOrbitingCircle(4.2, 1.5, 2.7, 64);
createOrbitingCircle(4.2, 1.4, 8.5, 64);
// Adjust opacity based on visibility
function updateLabelVisibility() {
labels.forEach(sprite => {
const directionToCamera = camera.position.clone().sub(sprite.position).normalize();
const directionToSprite = sprite.position.clone().normalize();
const dot = directionToCamera.dot(directionToSprite);
sprite.material.opacity = dot < 0 ? 0.2 : sprite.userData.originalOpacity;
sprite.material.needsUpdate = true; // Ensure the material update is applied
});
}
// Sort and render scene
function render() {
// Sort the scene by distance from the camera
scene.children.sort((a, b) => {
const distanceA = camera.position.distanceTo(a.position);
const distanceB = camera.position.distanceTo(b.position);
return distanceB - distanceA;
});
renderer.render(scene, camera);
}
// Animation loop
function animate() {
requestAnimationFrame(animate);
// Actualitza la posició de la llum ambiental
//updateAmbientLightPosition();
// ambientLight.position.copy(camera.position);
pointLight.position.copy(camera.position);
// Mantenir eix vertical del model (TEO-PRA)
const up = new THREE.Vector3(0, 1, 0);
const targetDirection = new THREE.Vector3().subVectors(controls.target, camera.position).normalize();
const right = new THREE.Vector3().crossVectors(up, targetDirection).normalize();
const cameraUp = new THREE.Vector3().crossVectors(targetDirection, right);
camera.up.copy(cameraUp);
camera.lookAt(controls.target);
controls.update();
updateLabelVisibility();
render();
}
animate();
});
});
</script>
</body>
</html>