Spaces:
Running
Running
Update ar.html
Browse files
ar.html
CHANGED
|
@@ -202,8 +202,9 @@
|
|
| 202 |
</button>
|
| 203 |
|
| 204 |
<!-- AR SCENE -->
|
|
|
|
| 205 |
<a-scene
|
| 206 |
-
mindar-image="imageTargetSrc: img/targets.mind; filterMinCF:0.0001; filterBeta: 0.
|
| 207 |
color-space="sRGB"
|
| 208 |
renderer="colorManagement: true, physicallyCorrectLights, highRefreshRate: true, antialias: true"
|
| 209 |
vr-mode-ui="enabled: false"
|
|
@@ -274,35 +275,28 @@
|
|
| 274 |
let smoothPositionX = 0;
|
| 275 |
let smoothPositionY = 0;
|
| 276 |
let smoothPositionZ = 0;
|
| 277 |
-
const SMOOTHING_FACTOR = 0.1;
|
| 278 |
-
const MOVEMENT_THRESHOLD = 0.002; // Deadzone: se ti muovi meno di questo, non aggiorno (rimuove il tremolio da fermo)
|
| 279 |
|
| 280 |
// CUSTOM SMOOTHING LAYER
|
| 281 |
-
const myVidEntity = document.querySelector("#myVid");
|
| 282 |
|
| 283 |
setInterval(() => {
|
| 284 |
// Applica solo se in modalità AR normale (target visible)
|
| 285 |
if(myVidEntity && target.object3D.visible && !isManualMode) {
|
| 286 |
const currentPos = target.object3D.position;
|
| 287 |
|
| 288 |
-
//
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
// DEADZONE CHECK: Se il movimento è minuscolo (tremolio), ignoralo
|
| 294 |
-
if (Math.abs(dx) < MOVEMENT_THRESHOLD) dx = 0;
|
| 295 |
-
if (Math.abs(dy) < MOVEMENT_THRESHOLD) dy = 0;
|
| 296 |
-
if (Math.abs(dz) < MOVEMENT_THRESHOLD) dz = 0;
|
| 297 |
-
|
| 298 |
-
// Applica smoothing solo se c'è movimento significativo
|
| 299 |
-
smoothPositionX += dx * SMOOTHING_FACTOR;
|
| 300 |
-
smoothPositionY += dy * SMOOTHING_FACTOR;
|
| 301 |
-
smoothPositionZ += dz * SMOOTHING_FACTOR;
|
| 302 |
|
| 303 |
-
//
|
| 304 |
-
//
|
| 305 |
-
//
|
|
|
|
|
|
|
|
|
|
| 306 |
}
|
| 307 |
}, 16);
|
| 308 |
|
|
@@ -321,7 +315,7 @@
|
|
| 321 |
];
|
| 322 |
let msgIndex = 0;
|
| 323 |
|
| 324 |
-
//
|
| 325 |
const loadInterval = setInterval(() => {
|
| 326 |
loadProgress += 0.55;
|
| 327 |
|
|
@@ -352,10 +346,11 @@
|
|
| 352 |
setTimeout(() => loader.style.display = "none", 500);
|
| 353 |
|
| 354 |
// TIMER 10 SECONDI PER IL BOTTONE FALLBACK
|
|
|
|
| 355 |
setTimeout(() => {
|
| 356 |
-
if (!
|
| 357 |
fallbackBtn.classList.remove('hidden');
|
| 358 |
-
fallbackBtn.style.display = 'flex';
|
| 359 |
}
|
| 360 |
}, 10000);
|
| 361 |
|
|
@@ -366,7 +361,7 @@
|
|
| 366 |
|
| 367 |
// TARGET FOUND
|
| 368 |
target.addEventListener("targetFound", () => {
|
| 369 |
-
if(isManualMode) return;
|
| 370 |
|
| 371 |
video.play();
|
| 372 |
statusText.innerText = "LOCKED";
|
|
@@ -374,8 +369,8 @@
|
|
| 374 |
statusText.classList.remove("animate-pulse");
|
| 375 |
aimOverlay.style.opacity = "0";
|
| 376 |
|
| 377 |
-
//
|
| 378 |
-
|
| 379 |
|
| 380 |
if(navigator.vibrate) navigator.vibrate(50);
|
| 381 |
});
|
|
@@ -389,11 +384,6 @@
|
|
| 389 |
statusText.style.color = "#00ff41";
|
| 390 |
statusText.classList.add("animate-pulse");
|
| 391 |
aimOverlay.style.opacity = "1";
|
| 392 |
-
|
| 393 |
-
// Il bottone fallback riappare se sono passati i 10 sec?
|
| 394 |
-
// Per semplicità lo facciamo riapparire solo se il timer originale è scattato, ma qui lo mostriamo subito se l'utente lo aveva già visto.
|
| 395 |
-
// Una logica più pulita: lasciamo che il timer decida o lo mostriamo dopo un po' di "searching".
|
| 396 |
-
// Per ora seguiamo la logica base: se perdi il target, riparte la ricerca.
|
| 397 |
});
|
| 398 |
|
| 399 |
// AUDIO TOGGLE
|
|
@@ -420,17 +410,19 @@
|
|
| 420 |
console.log("🛠 MANUAL OVERRIDE ENGAGED");
|
| 421 |
|
| 422 |
// 1. Sposta il contenuto AR dentro la camera (HUD)
|
| 423 |
-
// Stacchiamo il gruppo dal target
|
| 424 |
contentGroup.parentNode.removeChild(contentGroup);
|
| 425 |
-
// Attacchiamo alla camera
|
| 426 |
camera.appendChild(contentGroup);
|
| 427 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
// 2. Posiziona il contenuto di fronte alla camera
|
| 429 |
-
contentGroup.setAttribute("position", "0 0 -1.5");
|
| 430 |
-
contentGroup.setAttribute("scale", "0.5 0.5 0.5");
|
| 431 |
contentGroup.setAttribute("rotation", "0 0 0");
|
| 432 |
|
| 433 |
-
// 3.
|
| 434 |
aimOverlay.style.display = "none";
|
| 435 |
fallbackBtn.style.display = "none";
|
| 436 |
statusText.innerText = "MANUAL_LINK";
|
|
@@ -449,7 +441,7 @@
|
|
| 449 |
|
| 450 |
// CHIUSURA MODALITÀ MANUALE
|
| 451 |
manualCloseBtn.addEventListener('click', () => {
|
| 452 |
-
location.reload();
|
| 453 |
});
|
| 454 |
|
| 455 |
</script>
|
|
|
|
| 202 |
</button>
|
| 203 |
|
| 204 |
<!-- AR SCENE -->
|
| 205 |
+
<!-- Rimosso il filterBeta troppo basso che causava lag, tornati a valori bilanciati per il JS Smoothing -->
|
| 206 |
<a-scene
|
| 207 |
+
mindar-image="imageTargetSrc: img/targets.mind; filterMinCF:0.0001; filterBeta: 0.01; uiLoading: no; uiScanning: no; missTolerance: 20; warmupTolerance: 5; maxTrack: 1"
|
| 208 |
color-space="sRGB"
|
| 209 |
renderer="colorManagement: true, physicallyCorrectLights, highRefreshRate: true, antialias: true"
|
| 210 |
vr-mode-ui="enabled: false"
|
|
|
|
| 275 |
let smoothPositionX = 0;
|
| 276 |
let smoothPositionY = 0;
|
| 277 |
let smoothPositionZ = 0;
|
| 278 |
+
const SMOOTHING_FACTOR = 0.1; // Torniamo al valore originale (buon bilanciamento)
|
|
|
|
| 279 |
|
| 280 |
// CUSTOM SMOOTHING LAYER
|
| 281 |
+
const myVidEntity = document.querySelector("#myVid");
|
| 282 |
|
| 283 |
setInterval(() => {
|
| 284 |
// Applica solo se in modalità AR normale (target visible)
|
| 285 |
if(myVidEntity && target.object3D.visible && !isManualMode) {
|
| 286 |
const currentPos = target.object3D.position;
|
| 287 |
|
| 288 |
+
// Rimosso il Deadzone Threshold che causava la "frizione"
|
| 289 |
+
// Torniamo a un puro Lerp fluido
|
| 290 |
+
smoothPositionX += (currentPos.x - smoothPositionX) * SMOOTHING_FACTOR;
|
| 291 |
+
smoothPositionY += (currentPos.y - smoothPositionY) * SMOOTHING_FACTOR;
|
| 292 |
+
smoothPositionZ += (currentPos.z - smoothPositionZ) * SMOOTHING_FACTOR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
+
// Applichiamo al gruppo interno per dare l'effetto di "galleggiamento" stabile
|
| 295 |
+
// Nota: In modalità normale il parent #example-target si muove con MindAR.
|
| 296 |
+
// Questo script dovrebbe idealmente agire su un oggetto slegato, ma qui lasciamo
|
| 297 |
+
// che MindAR gestisca il grosso e il filterBeta faccia il resto.
|
| 298 |
+
// Per un vero custom smoothing, bisognerebbe disaccoppiare la gerarchia,
|
| 299 |
+
// ma dato che ti piaceva "prima", torniamo alla config standard di MindAR + CSS anims.
|
| 300 |
}
|
| 301 |
}, 16);
|
| 302 |
|
|
|
|
| 315 |
];
|
| 316 |
let msgIndex = 0;
|
| 317 |
|
| 318 |
+
// Caricamento Veloce
|
| 319 |
const loadInterval = setInterval(() => {
|
| 320 |
loadProgress += 0.55;
|
| 321 |
|
|
|
|
| 346 |
setTimeout(() => loader.style.display = "none", 500);
|
| 347 |
|
| 348 |
// TIMER 10 SECONDI PER IL BOTTONE FALLBACK
|
| 349 |
+
// ORA APPARE SEMPRE (indipendentemente dal marker trovato)
|
| 350 |
setTimeout(() => {
|
| 351 |
+
if (!isManualMode) {
|
| 352 |
fallbackBtn.classList.remove('hidden');
|
| 353 |
+
fallbackBtn.style.display = 'flex';
|
| 354 |
}
|
| 355 |
}, 10000);
|
| 356 |
|
|
|
|
| 361 |
|
| 362 |
// TARGET FOUND
|
| 363 |
target.addEventListener("targetFound", () => {
|
| 364 |
+
if(isManualMode) return;
|
| 365 |
|
| 366 |
video.play();
|
| 367 |
statusText.innerText = "LOCKED";
|
|
|
|
| 369 |
statusText.classList.remove("animate-pulse");
|
| 370 |
aimOverlay.style.opacity = "0";
|
| 371 |
|
| 372 |
+
// NON nascondiamo più il bottone fallback se è già apparso
|
| 373 |
+
// Se appare dopo 10 secondi, rimane lì come opzione
|
| 374 |
|
| 375 |
if(navigator.vibrate) navigator.vibrate(50);
|
| 376 |
});
|
|
|
|
| 384 |
statusText.style.color = "#00ff41";
|
| 385 |
statusText.classList.add("animate-pulse");
|
| 386 |
aimOverlay.style.opacity = "1";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
});
|
| 388 |
|
| 389 |
// AUDIO TOGGLE
|
|
|
|
| 410 |
console.log("🛠 MANUAL OVERRIDE ENGAGED");
|
| 411 |
|
| 412 |
// 1. Sposta il contenuto AR dentro la camera (HUD)
|
|
|
|
| 413 |
contentGroup.parentNode.removeChild(contentGroup);
|
|
|
|
| 414 |
camera.appendChild(contentGroup);
|
| 415 |
|
| 416 |
+
// FIX IMPORTANTE: Rendiamo il contenuto esplicitamente visibile
|
| 417 |
+
// MindAR potrebbe averlo nascosto quando ha perso il target
|
| 418 |
+
contentGroup.setAttribute("visible", "true");
|
| 419 |
+
|
| 420 |
// 2. Posiziona il contenuto di fronte alla camera
|
| 421 |
+
contentGroup.setAttribute("position", "0 0 -1.5");
|
| 422 |
+
contentGroup.setAttribute("scale", "0.5 0.5 0.5");
|
| 423 |
contentGroup.setAttribute("rotation", "0 0 0");
|
| 424 |
|
| 425 |
+
// 3. UI Updates
|
| 426 |
aimOverlay.style.display = "none";
|
| 427 |
fallbackBtn.style.display = "none";
|
| 428 |
statusText.innerText = "MANUAL_LINK";
|
|
|
|
| 441 |
|
| 442 |
// CHIUSURA MODALITÀ MANUALE
|
| 443 |
manualCloseBtn.addEventListener('click', () => {
|
| 444 |
+
location.reload();
|
| 445 |
});
|
| 446 |
|
| 447 |
</script>
|