-
Notifications
You must be signed in to change notification settings - Fork 11
/
ar0603-ar-nft.html
111 lines (93 loc) · 3.94 KB
/
ar0603-ar-nft.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
<!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">
<title>WebAR: Image Tracking (NFT)</title>
<!-- Library untuk VR membangun 3D -->
<script src="./js/aframe/aframe.min.js"></script>
<!-- Library untuk AR yang melakukan pengenalan NFT dan menyematkan kamera-->
<script src="./js/arjs/aframe-ar-nft.js"></script>
<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;">
<div id="UI">Marker information here.</div>
<!-- embedded vr-mode-ui="enabled: false" adalah untuk menonaktifkan tombol VR (stereocospic view) -->
<!-- debugUIEnabled: false adalah untuk menonaktifkan UI untuk debugging (true hanya untuk troubleshooting) -->
<a-scene vr-mode-ui="enabled: false;" renderer="logarithmicDepthBuffer: true;" embedded
arjs="trackingMethod: best; sourceType: webcam;debugUIEnabled: false;">
<!-- camera -->
<!-- camera: berguna untuk meletakkan layer dunia nyata yang ditangkap menggunakan kamera -->
<a-entity camera></a-entity>
<!-- we use cors proxy to avoid cross-origin problems -->
<a-nft type="nft" url="marker/markerbarcode1/1" smooth="true" smoothCount="10" smoothTolerance=".01"
smoothThreshold="5">
<a-circle color="purple" radius="1" rotation="-90 0 0">
<a-box position="1 1 0" depth="0.3" height="0.3" width="0.3" rotation="0 0 0" material="color: white;"
animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
<a-text position="0 0 0.2" value="?" color="white" align="center" width="30">
</a-text>
<a-box position="-1 -1 0" depth="0.3" height="0.3" width="0.3" rotation="0 0 0" material="color: white;"
animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
</a-circle>
</a-entity>
</a-nft>
</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-nft");
m.addEventListener("markerFound", (e) => {
markerInfo(m, true, ui);
});
m.addEventListener("markerLost", (e) => {
markerInfo(m, false, ui);
});
</script>
</body>
</html>