-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
256 lines (252 loc) · 13.2 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content='width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0, user-scalable=no, shrink-to-fit=yes'>
<title>Unity WebGL Player | STGA_Popup</title>
<link rel="stylesheet" href="TemplateData/style.css">
<style>
html{
height: -webkit-fill-available;
}
body {
margin: 0;
padding: 0;
min-height: 100vh;
min-height: -webkit-fill-available;
width: 100vw;
overflow: hidden;
}
.ctaDiv {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #fffa;
z-index: 99;
}
</style>
</head>
<body>
<!--IMAGETARGETS-->
<imagetarget id='BemusHeights_Target' src='targets/BemusHeights_Target.jpg'></imagetarget>
<imagetarget id='BootMonument_Target' src='targets/BootMonument_Target.jpg'></imagetarget>
<imagetarget id='FreemansFarm_Target' src='targets/FreemansFarm_Target.jpg'></imagetarget>
<imagetarget id='HudsonCrossingPark_Target' src='targets/HudsonCrossingPark_Target.jpg'></imagetarget>
<imagetarget id='NielsonHouse_Target' src='targets/NielsonHouse_Target.jpg'></imagetarget>
<imagetarget id='SaratogaMonument_Target' src='targets/SaratogaMonument_Target.jpg'></imagetarget>
<imagetarget id='SaratogaSurrenderSite_Target' src='targets/SaratogaSurrenderSite_Target.jpg'></imagetarget>
<imagetarget id='SchuylerEstate_Target' src='targets/SchuylerEstate_Target.jpg'></imagetarget>
<imagetarget id='CenterLogo_Target' src='targets/CenterLogo_Target.jpg'></imagetarget>
<imagetarget id='Arnold_Target' src='targets/Arnold_Target.jpg'></imagetarget>
<imagetarget id='Baroness_Target' src='targets/Baroness_Target.jpg'></imagetarget>
<imagetarget id='Burgoyne_Target' src='targets/Burgoyne_Target.jpg'></imagetarget>
<imagetarget id='Morgan_Target' src='targets/Morgan_Target.jpg'></imagetarget>
<video id="webcam-video" muted autoplay playsinline style="width:1px;position:absolute"></video>
<div id="startARDiv" class="ctaDiv">
<select id="chooseCamSel" style="display: none;" onchange="SelectCam()"></select>
<p style="text-align: center; width:60vw;">This augmented reality experience requires access to your device's camera</p>
<button id="startARButton" onclick="StartAR()" style="display:none">ALLOW ACCESS</button>
</div>
<div id="screenshotDiv" style="display: none;" class="ctaDiv">
<div style="position:relative; background-color:white; padding:10px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.3), 0 6px 20px 0 rgba(0, 0, 0, 0.25);">
<img id="screenshotImg" src="" alt="screenshot" style="width:80vw; height:80vh">
<button onclick="document.getElementById('screenshotDiv').style.display = 'none';" style="position:absolute; transform:translateY(-100%); right:0; top:0">Close</button>
</div>
</div>
<div id="confirmUrlDiv" style="display: none;" class="ctaDiv">
<div style="position:relative; background-color:white; padding:10px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.3), 0 6px 20px 0 rgba(0, 0, 0, 0.25); width: 80vw; display:flex; flex-direction: column; align-items: center;">
<p id="confirmUrlText" style="text-align: center; width:80%; overflow: hidden; text-overflow: ellipsis;">Are you sure you want to visit url.com?</p>
<div>
<button onclick="window.open(newUrlString, '_blank').focus(); document.getElementById('confirmUrlDiv').style.display = 'none'">VISIT SITE</button>
<button onclick="document.getElementById('confirmUrlDiv').style.display = 'none'">GO BACK</button>
</div>
</div>
</div>
<div id="errorDiv" class="ctaDiv" style="display: none; background:#aaa">
<p id="errorText" style="text-align: center; width:60vw; color:white"></p>
</div>
<div id="unity-container" class="unity-mobile">
<canvas id="unity-canvas" style="width: 100%; height: 100%; background: #0000; z-index: -99"></canvas>
<div id="unity-loading-bar">
<div id="unity-logo" ></div>
<div id="unity-progress-bar-empty">
<div id="unity-progress-bar-full"></div>
</div>
</div>
<canvas id="video-canvas"></canvas>
</div>
<script src="arcamera.js" type="text/javascript"></script>
<script src="itracker.js" type="text/javascript"></script>
<script src="Build/STGA_Booth.loader.js"></script>
<script>
var unityCanvas = document.querySelector("#unity-canvas");
var videoCanvas = document.querySelector("#video-canvas");
window.arCamera = new ARCamera(unityCanvas, videoCanvas);
window.iTracker = new ImageTracker(arCamera);
window.iTracker.initialize()
.then(async ()=>{
console.log("ImageTracker initialized!");
await LoadWebcams();
document.getElementById("startARButton").style.display = "block";
})
.catch(error => {
console.error("Failed to initialize ImageTracker. Are you missing opencv.js? " + error);
ShowError("Failed to initialize the experience.");
});
var container = document.querySelector("#unity-container");
var canvas = document.querySelector("#unity-canvas");
var loadingBar = document.querySelector("#unity-loading-bar");
var progressBarFull = document.querySelector("#unity-progress-bar-full");
function StartAR() {
canvas.style.width = window.innerWidth + "px";
canvas.style.height = window.innerHeight + "px";
document.getElementById("startARDiv").style.display = "none";
createUnityInstance(document.querySelector("#unity-canvas"), {
dataUrl: "Build/STGA_Booth.data",
frameworkUrl: "Build/STGA_Booth.framework.js",
codeUrl: "Build/STGA_Booth.wasm",
streamingAssetsUrl: "StreamingAssets",
companyName: "DefaultCompany",
productName: "STGA_Popup",
productVersion: "0.1",
//webglContextAttributes: { "preserveDrawingBuffer": true },
// matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOM element size.
// devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
},
(progress) => {
progressBarFull.style.width = 100 * progress + "%";
}
).then((unityInstance) => {
window.unityInstance = unityInstance;
RequestWebcam();
loadingBar.style.display = "none";
});
loadingBar.style.display = "block";
}
window.WEBCAM_SETTINGS = {
video: {
facingMode: "environment",
},
audio: false
};
window.requestingForPermissions = false;
async function RequestWebcam(){
window.requestingForPermissions = true;
try{
window.webcamStream = await navigator.mediaDevices.getUserMedia(window.WEBCAM_SETTINGS);
console.log("Webcam access granted");
requestingForPermissions = false;
}
catch (err) {
//user denied camera permission - show error panel
console.error("getUserMedia error - " , err);
ShowError("Failed to start the experience. Camera permission was denied");
window.requestingForPermissions = false;
}
}
async function StartWebcam(){
console.log("StartWebcam")
while (window.requestingForPermissions) {
// Wait until requestingForPermissions becomes true.
console.log("Waiting for permissions...");
await new Promise(resolve => setTimeout(resolve, 100)); // Adjust the delay time as needed.
}
console.log("Got Permissions");
if(window.webcamStream)
{
const video = document.querySelector("#webcam-video");
video.srcObject = webcamStream;
try {
await arCamera.startWebcam(video);
console.log("Webcam started successfully");
window.unityInstance.SendMessage('ARCamera', 'OnStartWebcamSuccess');
}
catch(err){
console.error("Webcam failed to start - ", err);
window.unityInstance.SendMessage('ARCamera', 'OnStartWebcamFail');
}
}
else{
console.error("Webcam failed to start - permission not yet granted");
window.unityInstance.SendMessage('ARCamera', 'OnStartWebcamFail');
}
}
async function LoadWebcams(){
let backCams = [];
let devices = await navigator.mediaDevices.enumerateDevices();
devices.forEach(mediaDevice => {
if (mediaDevice.kind === 'videoinput' && !mediaDevice.label.includes('facing front')) {
backCams.push(mediaDevice);
}
});
var select = document.getElementById("chooseCamSel");
select.style.display = "block";
var count = 0;
//reverse array because some Android phones can't distinguish front and back cams at first load
//and when this happens, most of the time, front cam goes first and back cam goes last
backCams = backCams.reverse();
backCams.forEach(mediaDevice => {
const option = document.createElement('option');
option.value = mediaDevice.deviceId;
let label = `Camera ${count}`;
if (mediaDevice.label) {
label = mediaDevice.label
}
const textNode = document.createTextNode(label);
option.appendChild(textNode);
select.appendChild(option);
count++;
});
iTracker.WEBCAM_NAME = select.options[select.selectedIndex].innerHTML;
}
function SelectCam(){
var select = document.getElementById("chooseCamSel");
window.deviceId = select.value;
window.WEBCAM_SETTINGS.video['deviceId'] = deviceId;
//console.log(window.WEBCAM_SETTINGS);
iTracker.WEBCAM_NAME = select.options[select.selectedIndex].innerHTML;
}
function ShowError(error){
document.getElementById("errorDiv").style.display = "flex";
document.getElementById("errorText").innerHTML = error;
}
function ShowScreenshot(dataUrl){
document.getElementById("screenshotDiv").style.display = "flex";
document.getElementById("screenshotImg").src = dataUrl;
document.getElementById("screenshotImg").style.width = "80vw";
document.getElementById("screenshotImg").style.height = 80 / window.innerWidth * window.innerHeight + "vw";
}
function ShowConfirmUrl(url){
document.getElementById("confirmUrlDiv").style.display = "flex";
window.newUrlString = url;
document.getElementById("confirmUrlText").innerText = "Are you sure you want to visit " + url;
}
window.SpeechBlendWEBGL = {};
window.AudioContext = (function () {
var ACConsructor = window.AudioContext || window.webkitAudioContext;
return function () {
var ac = new ACConsructor();
window.SpeechBlendWEBGL.ac = ac;
window.SpeechBlendWEBGL.a = ac.createAnalyser();
window.SpeechBlendWEBGL.a.smoothingTimeConstant = 0;
window.SpeechBlendWEBGL.fa = new Uint8Array(window.SpeechBlendWEBGL.a.frequencyBinCount);
window.SpeechBlendWEBGL.la = new Uint8Array(window.SpeechBlendWEBGL.a.fftSize);
window.SpeechBlendWEBGL.a.connect(ac.destination);
ac.actualDestination = ac.destination;
Object.defineProperty(ac, 'destination', {
value: window.SpeechBlendWEBGL.a,
writable: false
});
return ac;
}
})();
StartAR();
</script>
</body>
</html>