-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathar0903-event-marker-found-and-lost.html
99 lines (81 loc) · 2.99 KB
/
ar0903-event-marker-found-and-lost.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
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<!-- Correcting zooming issue -->
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<!-- Library untuk VR membangun 3D -->
<script src="./js/aframe/aframe.min.js"></script>
<!-- Library untuk AR yang melakukan pengenalan marker dan menyematkan kamera-->
<script src="./js/arjs/aframe-ar.js"></script>
<title>WebAR: Found & Lost Marker Event</title>
<style>
/* Mengatur posisi elemen pada halaman */
#UI {
position: fixed;
top: 1rem;
left: 1rem;
right: 1rem;
}
/* Styling */
#UI {
font-family: Arial, Helvetica, sans-serif;
font-size: 1.5em;
font-weight: 200;
text-align: center;
color: orange;
background-color: blue;
display: block;
}
.found {
color: red;
background-color: green;
}
.lost {
color: green;
background-color: red;
}
</style>
</head>
<body style="margin : 0px; overflow: hidden;">
<!-- UI Element outside a-scene -->
<div id="UI">Marker information here.</div>
<a-scene embedded vr-mode-ui="enabled: false" arjs="detectionMode: mono_and_matrix; matrixCodeType: 3x3; debugUIEnabled: false;">
<!-- handle hiro marker -->
<a-marker preset="hiro">
<a-box position="0 0.5 0" material="opacity: 0.5;color:cyan;"></a-box>
</a-marker>
<!-- add a simple camera -->
<a-entity camera></a-entity>
</a-scene>
<script>
let ui = document.querySelector("#UI");
// Function to display information
function markerInfo(marker, evt, infoui) {
let posx = marker.object3D.position.x;
let posy = marker.object3D.position.y;
let posz = marker.object3D.position.z;
let message = "marker at x: " + marker.object3D.position.x + ", y: " + marker.object3D.position.x + ", z: " + marker.object3D.position.z;
if (evt) {
infoui.classList.remove("lost");
infoui.classList.add("found");
message = "Found " + message;
} else {
infoui.classList.remove("found");
infoui.classList.add("lost");
message = "Lost " + message;
}
infoui.innerHTML = message;
}
// Detecting single marker
let m = document.querySelector("a-marker");
m.addEventListener("markerFound", (e) => {
markerInfo(m, true, ui);
});
m.addEventListener("markerLost", (e) => {
markerInfo(m, false, ui);
});
</script>
<!-- referensi: https://stackoverflow.com/questions/44799413/how-to-detect-when-a-marker-is-found-in-ar-js -->
</body>
</html>