-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalium1.php
491 lines (416 loc) · 19.9 KB
/
globalium1.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
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!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;
// CAMERA
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 20, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 1000;
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
camera.zoom=0.4;
camera.position.set(0,0,0);
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.1;
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);
if (SCREEN_WIDTH<400) camera.zoom=0.29; else camera.zoom=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
var textureLoader = new THREE.TextureLoader();
textureLoader.load(
'https://labs.opengea.org/metamodeler/v1/img/2k_earth_nightmap.jpg', // Canvia això per la ruta de la teva textura
function(texture) {
const uniforms = {
ambientLightColor: { value: new THREE.Color(0x404040) },
directionalLightColor: { value: new THREE.Color(0xffffff) },
directionalLightPosition: { value: new THREE.Vector3(10, 10, 10) },
pointLightColor: { value: new THREE.Color(0xffffff) },
pointLightPosition: { value: new THREE.Vector3(5, 5, 5) },
colors: { value: colors },
type: 't',
value: texture
};
// Crea el material amb la textura utilitzant ShaderMaterial
var material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: `
varying vec3 vNormal;
varying vec3 vPosition;
// varying vec2 vUv;
void main() {
// vUv = uv;
vNormal = normalize(normalMatrix * normal);
vPosition = vec3(modelViewMatrix * vec4(position, 1.0));
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform vec3 ambientLightColor;
uniform vec3 directionalLightColor;
uniform vec3 directionalLightPosition;
uniform vec3 pointLightColor;
uniform vec3 pointLightPosition;
uniform vec3 colors[6];
varying vec3 vNormal;
varying vec3 vPosition;
// uniform sampler2D texture1;
// varying vec2 vUv;
void main() {
vec3 lightDirection = normalize(directionalLightPosition - vPosition);
float directionalLightWeighting = max(dot(vNormal, lightDirection), 0.0);
vec3 lightWeighting = ambientLightColor + directionalLightColor * directionalLightWeighting;
vec3 pointLightDirection = normalize(pointLightPosition - vPosition);
float pointLightWeighting = max(dot(vNormal, pointLightDirection), 0.0);
lightWeighting += pointLightColor * pointLightWeighting;
vec3 p = normalize(vPosition);
float northWeight = clamp(p.y, 0.0, 1.0);
float southWeight = clamp(-p.y, 0.0, 1.0);
float eastWeight = clamp(p.x, 0.0, 1.0);
float westWeight = clamp(-p.x, 0.0, 1.0);
float frontWeight = clamp(p.z, 0.0, 1.0);
float rearWeight = clamp(-p.z, 0.0, 1.0);
vec3 color =
northWeight * colors[0] +
southWeight * colors[1] +
eastWeight * colors[2] +
westWeight * colors[3] +
frontWeight * colors[4] +
rearWeight * colors[5];
gl_FragColor = vec4(color * lightWeighting, 1.0); // Set alpha to 1 for no transparency
// vec4 color = texture2D(texture1, vUv);
//gl_FragColor = color;
// gl_FragColor = vec4(color.rgb, 1); // Ajusta el valor alpha
}
`,
side: THREE.DoubleSide,
transparent: false,
wireframe: false
});
// Sphere geometry and material
var geometry = new THREE.SphereGeometry(5, 64, 64);
var sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
// Afegir llum puntual
const pointLight = new THREE.PointLight(0x00ff00, 1, 100);
pointLight.position.set(5, 5, 5); // Posició de la llum
scene.add(pointLight);
},
undefined,
function(err) {
// On Texture Load Error
console.error('An error occurred loading the texture:', err);
}
);
/*
// Carrega la textura
var textureLoader = new THREE.TextureLoader();
var texture = textureLoader.load('https://labs.opengea.org/metamodeler/v1/img/2k_earth_nightmap.jpg');
// Sphere geometry and material
const geometry = new THREE.SphereGeometry(5, 64, 64);
const material = new THREE.ShaderMaterial({
uniforms: {
texture1: { type: 't', value: texture },
colors: { value: colors }
},
vertexShader: `
varying vec3 vPosition;
void main() {
vPosition = position;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform vec3 colors[6];
varying vec3 vPosition;
void main() {
vec3 p = normalize(vPosition);
float northWeight = clamp(p.y, 0.0, 1.0);
float southWeight = clamp(-p.y, 0.0, 1.0);
float eastWeight = clamp(p.x, 0.0, 1.0);
float westWeight = clamp(-p.x, 0.0, 1.0);
float frontWeight = clamp(p.z, 0.0, 1.0);
float rearWeight = clamp(-p.z, 0.0, 1.0);
vec3 color =
northWeight * colors[0] +
southWeight * colors[1] +
eastWeight * colors[2] +
westWeight * colors[3] +
frontWeight * colors[4] +
rearWeight * colors[5];
gl_FragColor = vec4(color, 0.9); // Set alpha to 0.9 for slight transparency
}
`,
side: THREE.DoubleSide,
transparent: false, // Disable transparency
wireframe: false // Disable wireframe mode
});
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
*/
camera.position.set(0, 0, 15);
camera.lookAt(0, 0, 0);
// 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 + p3.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);
// 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>