-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.html
335 lines (300 loc) · 13.3 KB
/
screenshot.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
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
<html>
<!-- Add the use of fonts from FontAwesome -->
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<link rel="stylesheet" href="https://raw.githack.com/l-lin/font-awesome-animation/master/dist/font-awesome-animation.min.css">
<!-- <script src="https://jrdev1.github.io/craf-t/hnl.mobileConsole.js"></script> -->
<!-- <script src="https://code.hnldesign.nl/hnl.mobileConsole.1.3.js?f004ea15"></script> -->
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script>
window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
consoleLog(errorMsg, url, lineNumber);
}
</script>
<!--Merge Images -->
<script src="https://unpkg.com/merge-images"></script>
<!-- we import arjs version without NFT but with marker + location based support -->
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script>
<script src="https://rawgit.com/mayognaise/aframe-gif-shader/master/dist/aframe-gif-shader.min.js"></script>
<script src="https://rawgit.com/mayognaise/aframe-gif-component/master/dist/aframe-gif-component.min.js"></script>
<!-- <script src="https://code.hnldesign.nl/hnl.mobileConsole.1.3.js?f004ea15"></script> -->
<script src="https://unpkg.com/aframe-log-component/dist/aframe-log-component.min.js"></script>
</head>
<body style="margin : 0px; overflow: hidden;">
<a-scene embedded arjs='trackingMethod: best; patternRatio: 0.9; debugUIEnabled: false;' vr-mode-ui="enabled: false">
<a-assets>
<img id="my-gif" src="https://raw.githubusercontent.com/jrDev1/craf-t/master/FathersDayDog600.gif">
</a-assets>
<a-marker id="MainMarker" preset='custom' type='pattern' smooth='true' smoothCount='25' smoothTolerance='6' url='https://raw.githubusercontent.com/jrDev1/craf-t/master/FathersDayDog1.patt' registerevents>
<a-entity id="MainGIF" rotation="-90 0 0" geometry="primitive:plane" material="shader:gif;src: #my-gif; transparent: false; alphaTest: 0.5;">
</a-entity>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
<div style='position: fixed; top: 10px; width:100%; text-align: center; z-index: 1;'>
<!-- <button id="take_screenshot"> Screenshot</button> -->
<a id="take_screenshot" class="faa-float animated btn-floating btn-lg"><i class="fas fa-camera"></i></a>
<a id="menu" class="faa-float animated btn-floating btn-lg "><i class="fas fa-bars "></i></a>
<button id="hideconsole"> Toggle Console</button>
<button id="minus"> Minus</button>
<button id="add"> Add</button>
<a id="download-link"></a>
<p style="color:red;">Test Mode ver 0.1.3</p>
</div>
<textarea id='log' rows=50 cols=60 autofocus readonly></textarea>
<div style='position: fixed; bottom: 105px; width:99%; text-align: center; z-index: 1; '>
<button id='clearbutton' style='position: fixed;left: 94%; display:none;'>Clear
</button>
</div>
<script>
//GET ORIENTATION
var orientation = (screen.orientation || {}).type || screen.mozOrientation || screen.msOrientation;
//CREATE CUSTOM CONSOLE LOG
function consoleLog(log) {
var console = document.getElementById('log');
if (console.value == '') {
console.value += log;
console.focus();
} else {
console.value += '\n' + log;
console.focus();
}
}
document.getElementById("clearbutton").addEventListener("click", (e) => {
var console = document.getElementById('log');
console.value = '';
});
var consoleHidden = true;
function ToggleConsole() {
var console = document.getElementById("log");
var cb = document.getElementById("clearbutton");
if (consoleHidden) {
console.style.display = "block";
cb.style.display = "block";
consoleHidden = false;
} else {
console.style.display = "none";
cb.style.display = "none";
consoleHidden = true;
}
}
document.getElementById("hideconsole").addEventListener("click", ToggleConsole);
//SIZING OF GIF
document.getElementById("minus").addEventListener("click", (e) => {
var width = document.querySelector('#MainGIF').getAttribute('geometry').width;
var height = document.querySelector('#MainGIF').getAttribute('geometry').height;
document.querySelector('#MainGIF').setAttribute('geometry', {
width: width - 0.1
});
document.querySelector('#MainGIF').setAttribute('geometry', {
height: height - 0.1
});
width = width - 0.1;
height = height - 0.1;
consoleLog(width);
});
document.getElementById("add").addEventListener("click", (e) => {
var width = document.querySelector('#MainGIF').getAttribute('geometry').width;
var height = document.querySelector('#MainGIF').getAttribute('geometry').height;
document.querySelector('#MainGIF').setAttribute('geometry', {
width: width + 0.1
});
document.querySelector('#MainGIF').setAttribute('geometry', {
height: height + 0.1
});
width = width + 0.1;
height = height + 0.1;
consoleLog(width);
});
var markerChecked;
//MARKER EVENTS
document.querySelector("a-marker").addEventListener("markerFound", (e) => {
consoleLog("found");
console.log("found");
if (orientation == -90 || orientation == 90) {
// Landscape
consoleLog(window.screen.width + " landscape " + window.screen.height + " orient " + orientation)
} else {
consoleLog(window.screen.width + " portrait " + window.screen.height + " orient " + orientation);
}
markerChecked = true;
document.querySelector('#MainGIF').play();
});
document.querySelector("a-marker").addEventListener("markerLost", (e) => {
consoleLog("lost");
console.log("lost");
if (orientation == -90 || orientation == 90) {
// Landscape
consoleLog(window.screen.width + " landscape " + window.screen.height)
} else {
consoleLog(window.screen.width + " portrait " + window.screen.height);
}
//3 second timer
setTimeout(MarkerCheck, 3000);
markerChecked = false;
document.querySelector('#MainGIF').pause();
console.log("pause");
})
function MarkerCheck() {
console.log("marker checked");
if (markerChecked == false) {
//Restart GIF - Remove and Readd it
document.querySelector('#MainGIF').removeAttribute('material');
document.querySelector('#MainGIF').setAttribute('material', {
shader: "gif",
src: "#my-gif"
});
console.log("Checked");
}
}
function resizeCanvas(origCanvas, width, height) {
let resizedCanvas = document.createElement("canvas");
let resizedContext = resizedCanvas.getContext("2d");
resizedCanvas.height = height;
resizedCanvas.width = width;
consoleLog(width + " dimensions " + height);
if (orientation == -90 || orientation == 90) {
// Landscape
resizedContext.drawImage(origCanvas, 0, 0, width, height);
} else {
// Portrait
var scale = height / width;
var scaledHeight = width * scale;
var scaledWidth = height * scale;
var marginLeft = (width - height);
resizedContext.drawImage(origCanvas, -180, 0, scaledWidth, height);
consoleLog("MARGIN- " + marginLeft + " NORMAL- " + width + " " + height + " SCALED- " + scaledWidth + " " + scaledHeight + " " + scale);
}
return resizedCanvas.toDataURL();
}
document.getElementById("take_screenshot").addEventListener("click", Screenshot);
function Screenshot() {
document.querySelector('#MainGIF').pause();
var aScene = document.querySelector("a-scene").components.screenshot.getCanvas("perspective");
var frame = captureVideoFrame("video", "png");
aScene = resizeCanvas(aScene, frame.width, frame.height);
frame = frame.dataUri;
mergeImages([frame, aScene]).then(b64 => {
var link = document.getElementById("download-link", "png");
link.setAttribute("download", "AR.png");
link.setAttribute("href", b64);
window.open(link.getAttribute("href"));
//link.click();
document.querySelector('#MainGIF').play();
});
}
function captureVideoFrame(video, format, width, height) {
if (typeof video === 'string') {
video = document.querySelector(video);
consoleLog('Video:' + video);
}
format = format || 'jpeg';
if (!video || (format !== 'png' && format !== 'jpeg')) {
return false;
}
var canvas = document.createElement("CANVAS");
canvas.width = width || video.videoWidth;
canvas.height = height || video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0);
var dataUri = canvas.toDataURL('image/' + format);
var data = dataUri.split(',')[1];
var mimeType = dataUri.split(';')[0].slice(5)
var bytes = window.atob(data);
var buf = new ArrayBuffer(bytes.length);
var arr = new Uint8Array(buf);
for (var i = 0; i < bytes.length; i++) {
arr[i] = bytes.charCodeAt(i);
}
var blob = new Blob([arr], {
type: mimeType
});
return {
blob: blob,
dataUri: dataUri,
format: format,
width: canvas.width,
height: canvas.height
};
};
// if (!mobileConsole.status.initialized) {
// mobileConsole.init();
// }
</script>
<style>
#log {
position: fixed;
width: 98%;
height: 120px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
font-size: 16px;
resize: none;
z-index: 1;
bottom: 2%;
left: 1%;
display: none;
}
#take_screenshot {
background-color: red;
border: 2px solid white;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 26px;
margin: 4px 2px;
width: 30px;
border-radius: 50%;
text-shadow: 1px 1px black;
transition-duration: 0.2s;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
#take_screenshot:hover {
background-color: white;
color: red;
border: 2px solid red;
text-shadow: 1px 1px black;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
transform: translateY(2px);
animation-play-state: paused;
}
#take_screenshot:active {
background-color: white;
color: red;
border: 2px solid red;
text-shadow: 1px 1px black;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
transform: translateY(2px);
animation-play-state: play;
}
#menu {
background-color: blue;
border: 2px solid white;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 26px;
margin: 4px 2px;
width: 30px;
border-radius: 50%;
text-shadow: 1px 1px black;
transition-duration: 0.2s;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
#menu:hover {
background-color: white;
color: blue;
border: 2px solid blue;
text-shadow: 1px 1px black;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
transform: translateY(2px);
animation-play-state: paused;
}
</style>
</html>