-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbarcode.html
More file actions
149 lines (127 loc) · 6.78 KB
/
barcode.html
File metadata and controls
149 lines (127 loc) · 6.78 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>WebAR: Barcode Value</title>
<script src="./js/aframe/aframe.min.js"></script>
<script src="./js/arjs/aframe-ar.js"></script>
<style>
/* Mengatur posisi elemen pada halaman */
#UI {
position: absolute;
bottom: 3rem;
left: 1rem;
right: 1rem;
}
.UI {
font-family: Arial, Helvetica, sans-serif;
font-size: 1.5em;
font-weight: 200;
text-align: center;
color: orange;
background-color: blue;
display: block;
}
</style>
</head>
<body style="margin : 0px; overflow: hidden;">
<!-- UI Element outside a-scene -->
<div id="UI" class="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) -->
<!-- detectionMode: mono_and_matrix adalah untuk memindai marker matriks | matrixCodeType: 3x3 adalah dimensi matriks yang dipindai -->
<a-scene embedded vr-mode-ui="enabled: false" arjs="detectionMode: mono_and_matrix; matrixCodeType: 3x3; debugUIEnabled: false;">
<!-- handle unknown marker -->
<a-marker type="unknown">
<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-marker>
<!-- handle hiro marker -->
<a-marker preset="hiro">
<a-circle color="blue" 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: orange;" animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
<a-text position="0 0 0.2" value="Hiro" color="orange" 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: orange;" animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
</a-circle>
</a-marker>
<!-- handle kanji marker -->
<a-marker preset="kanji">
<a-circle color="green" 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: yellow;" animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
<a-text position="0 0 0.2" value="⼈" color="yellow" 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: yellow;" animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
</a-circle>
</a-marker>
<!-- add a simple camera -->
<a-entity camera></a-entity>
</a-scene>
<script>
// mengakses DOM UI
let ui = document.querySelector("#UI");
// mengakses DOM scene
let scene = document.querySelector("a-scene");
// Fungsi membuat obyek tulisan pada a-frame
function listBarcode(barcode, scenel) {
for (let i = 0; i < barcode; i++) {
let marker =
`<a-marker type="barcode" value="${i}">
<a-circle color="black" 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: red;"
animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
<a-text
position="0 0 0.2"
value="${i}"
color="red"
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: red;"
animation="property: rotation; to: 360 360 360; loop: true; dur: 10000; easing: linear"></a-box>
</a-circle>
</a-marker>
`;
scenel.insertAdjacentHTML("beforeend", marker);
}
}
function detectMarker(scenel, uiobj) {
// 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 markerID = marker.getAttribute("preset") ? marker.getAttribute("preset") : marker.getAttribute("type") == "barcode" ? marker.getAttribute("type") + " " + marker.getAttribute("value") : marker.getAttribute("type");
let message = "marker " + markerID + " 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 multiple marker
let ms = document.querySelectorAll("a-marker");
for (let i = 0; i < ms.length; i++) {
ms[i].addEventListener("markerFound", (e) => {
markerInfo(ms[i], true, uiobj);
});
ms[i].addEventListener("markerLost", (e) => {
markerInfo(ms[i], false, uiobj);
});
}
}
listBarcode(64, scene);
detectMarker(scene, ui);
</script>
</body>
</html>