MatteoScript commited on
Commit
cdca82e
·
verified ·
1 Parent(s): 0c9bcec

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +45 -25
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
6
- <title>AR Video 9:16 + Mirino Verticale</title>
7
 
8
  <script src="https://aframe.io/releases/1.4.2/aframe.min.js"></script>
9
  <script src="https://cdn.jsdelivr.net/npm/mind-ar@1.2.2/dist/mindar-image.prod.js"></script>
@@ -11,39 +11,36 @@
11
 
12
  <style>
13
  body { margin: 0; overflow: hidden; background-color: black; }
 
14
  #vid { position: absolute; top: 0; left: 0; opacity: 0; z-index: -1; pointer-events: none; }
15
 
16
- /* --- STILE DEL MIRINO (Aggiornato per 9:16) --- */
17
-
18
  #viewfinder-container {
19
  position: fixed;
20
  top: 50%;
21
  left: 50%;
22
  transform: translate(-50%, -50%);
23
 
24
- /* Larghezza relativa */
25
- width: 50vw;
26
- /* Altezza calcolata per mantenere il rapporto ~9:16 rispetto alla larghezza */
27
- height: 89vw;
28
 
29
- /* Limiti massimi in pixel per schermi grandi (desktop/tablet) */
30
- /* Se la larghezza max è 270px, l'altezza sarà circa 480px (270 * 1.77) */
31
- max-width: 270px;
32
- max-height: 480px;
33
 
34
  z-index: 10;
35
- pointer-events: none; /* Lascia passare i click */
 
36
  }
37
 
38
- /* Stile comune per i 4 angoli */
39
  .corner {
40
  position: absolute;
41
- width: 40px;
42
- height: 40px;
43
- border-color: rgba(255, 255, 255, 0.8);
44
  border-style: solid;
45
  border-width: 0;
46
- box-shadow: 0 0 10px rgba(0,0,0,0.5); /* Aggiunta ombra per visibilità su sfondi chiari */
47
  }
48
 
49
  /* Posizionamento angoli */
@@ -71,14 +68,14 @@
71
  device-orientation-permission-ui="enabled: false">
72
 
73
  <a-assets>
74
- <video id="vid" src="./video.mp4" loop muted playsinline webkit-playsinline crossorigin="anonymous"></video>
75
  </a-assets>
76
 
77
  <a-camera position="0 0 0" look-controls="enabled: false"></a-camera>
78
 
79
  <a-entity id="example-target" mindar-image-target="targetIndex: 0">
80
  <a-entity id="ar-video-plane"
81
- geometry="primitive: plane; width: 1; height: 1.78"
82
  material="src: #vid; shader: flat; transparent: true; opacity: 1"
83
  position="0 0 0">
84
  </a-entity>
@@ -88,27 +85,50 @@
88
  <script>
89
  const video = document.querySelector("#vid");
90
  const target = document.querySelector("#example-target");
91
- // Opzionale: riferimento al mirino se volessi nasconderlo quando trova il target
92
  const viewfinder = document.querySelector("#viewfinder-container");
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  target.addEventListener("targetFound", () => {
95
- console.log("Target trovato: Play video");
96
  video.play();
97
- // Effetto visivo: il mirino diventa più trasparente quando trova il target
98
  viewfinder.style.opacity = 0.2;
99
  });
100
 
101
  target.addEventListener("targetLost", () => {
102
- console.log("Target perso: Pause video");
103
  video.pause();
104
- // Il mirino torna ben visibile
105
  viewfinder.style.opacity = 1;
106
  });
107
 
 
108
  document.body.addEventListener('click', () => {
109
  if(video.muted) {
110
  video.muted = false;
111
- console.log("Audio attivato");
 
 
112
  }
113
  });
114
  </script>
 
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
6
+ <title>AR Video - Auto Aspect Ratio</title>
7
 
8
  <script src="https://aframe.io/releases/1.4.2/aframe.min.js"></script>
9
  <script src="https://cdn.jsdelivr.net/npm/mind-ar@1.2.2/dist/mindar-image.prod.js"></script>
 
11
 
12
  <style>
13
  body { margin: 0; overflow: hidden; background-color: black; }
14
+ /* Il video è nascosto, serve solo come texture */
15
  #vid { position: absolute; top: 0; left: 0; opacity: 0; z-index: -1; pointer-events: none; }
16
 
17
+ /* --- STILE DEL MIRINO DINAMICO --- */
 
18
  #viewfinder-container {
19
  position: fixed;
20
  top: 50%;
21
  left: 50%;
22
  transform: translate(-50%, -50%);
23
 
24
+ /* Larghezza di base */
25
+ width: 60vw;
26
+ max-width: 300px;
 
27
 
28
+ /* L'altezza verrà calcolata automaticamente via JS in base al video */
29
+ aspect-ratio: 9/16; /* Fallback iniziale */
 
 
30
 
31
  z-index: 10;
32
+ pointer-events: none;
33
+ transition: opacity 0.3s ease;
34
  }
35
 
 
36
  .corner {
37
  position: absolute;
38
+ width: 30px;
39
+ height: 30px;
40
+ border-color: rgba(255, 255, 255, 0.9);
41
  border-style: solid;
42
  border-width: 0;
43
+ box-shadow: 0 0 8px rgba(0,0,0,0.3);
44
  }
45
 
46
  /* Posizionamento angoli */
 
68
  device-orientation-permission-ui="enabled: false">
69
 
70
  <a-assets>
71
+ <video id="vid" src="video (2) (1).mp4" loop muted playsinline webkit-playsinline crossorigin="anonymous"></video>
72
  </a-assets>
73
 
74
  <a-camera position="0 0 0" look-controls="enabled: false"></a-camera>
75
 
76
  <a-entity id="example-target" mindar-image-target="targetIndex: 0">
77
  <a-entity id="ar-video-plane"
78
+ geometry="primitive: plane; width: 1; height: 1"
79
  material="src: #vid; shader: flat; transparent: true; opacity: 1"
80
  position="0 0 0">
81
  </a-entity>
 
85
  <script>
86
  const video = document.querySelector("#vid");
87
  const target = document.querySelector("#example-target");
88
+ const plane = document.querySelector("#ar-video-plane");
89
  const viewfinder = document.querySelector("#viewfinder-container");
90
 
91
+ // --- FUNZIONE CRUCIALE: Adatta il formato al video ---
92
+ video.addEventListener('loadedmetadata', () => {
93
+ const vWidth = video.videoWidth;
94
+ const vHeight = video.videoHeight;
95
+
96
+ // Calcola il rapporto (es. se video è 1080x1350, ratio è 1.25)
97
+ const ratio = vHeight / vWidth;
98
+
99
+ console.log(`Video caricato: ${vWidth}x${vHeight}. Ratio: ${ratio}`);
100
+
101
+ // 1. Aggiorna il piano AR (Mantiene larghezza 1, adatta altezza)
102
+ plane.setAttribute("geometry", {
103
+ primitive: "plane",
104
+ width: 1,
105
+ height: ratio
106
+ });
107
+
108
+ // 2. Aggiorna il mirino CSS per riflettere la forma del video
109
+ viewfinder.style.aspectRatio = `${vWidth} / ${vHeight}`;
110
+ });
111
+
112
+ // --- Gestione Play/Pause ---
113
  target.addEventListener("targetFound", () => {
114
+ console.log("Target trovato");
115
  video.play();
 
116
  viewfinder.style.opacity = 0.2;
117
  });
118
 
119
  target.addEventListener("targetLost", () => {
120
+ console.log("Target perso");
121
  video.pause();
 
122
  viewfinder.style.opacity = 1;
123
  });
124
 
125
+ // --- Gestione Audio al tocco ---
126
  document.body.addEventListener('click', () => {
127
  if(video.muted) {
128
  video.muted = false;
129
+ // A volte serve resettare il tempo per sincronizzare l'audio se era partito muto
130
+ // video.currentTime = 0;
131
+ console.log("Unmute");
132
  }
133
  });
134
  </script>