-
Notifications
You must be signed in to change notification settings - Fork 11
/
ar-event-marker-drawing.html
79 lines (65 loc) · 2.46 KB
/
ar-event-marker-drawing.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
<!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: Marker Drawing</title>
</head>
<body style="margin : 0px; overflow: hidden;">
<a-scene embedded vr-mode-ui="enabled: false" arjs="debugUIEnabled: false;">
<!-- handle hiro marker -->
<a-marker></a-marker>
<a-entity id="penampung"></a-entity>
<!-- add a simple camera -->
<a-entity camera></a-entity>
</a-scene>
<script>
// a-marker
const m = document.querySelector("a-marker");
// a-entity
const penampung = document.querySelector("a-entity#penampung");
// Create object kotak
function buatObyek(obj3d) {
let posx = obj3d.position.x;
let posy = obj3d.position.y + 0.5;
let posz = obj3d.position.z;
let rotx = THREE.Math.radToDeg(obj3d.rotation.x);
let roty = THREE.Math.radToDeg(obj3d.rotation.y);
let rotz = THREE.Math.radToDeg(obj3d.rotation.z);
// template literal to create object
let obyek = `<a-box position="${posx} ${posy} ${posz}+.5" rotation="${rotx} ${roty} ${rotz}" color="red" material="opacity: 0.5; color: red;"></a-box>`;
return obyek;
}
let object3Dinit = {
"position": {
"x": 0,
"y": 0,
"z": 0
},
"rotation": {
"x": 0,
"y": 0,
"z": 0
}
};
let object3D;
m.addEventListener("markerFound", (e) => {
console.log("markerFound");
console.log(m.object3D.position);
object3D = object3Dinit;
m.insertAdjacentHTML("beforeend", buatObyek(object3Dinit));
object3D = m.object3D;
});
m.addEventListener("markerLost", (e) => {
console.log("markerLost");
console.log(m.object3D.position);
penampung.insertAdjacentHTML("beforeend", buatObyek(object3D));
});
</script>
</body>
</html>