-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
aframe-hand-mesh.html
82 lines (65 loc) · 2.81 KB
/
aframe-hand-mesh.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hand Tracking in A-Frame</title>
<script src="js/aframe-master.js"></script>
<script src="js/aframe/hand-tracking-mesh.js"></script>
<script src="js/aframe/hand-tracking-gestures-mesh.js"></script>
<script src="js/aframe/slider.component.js"></script>
<script src="js/aframe/toggle.component.js"></script>
</head>
<body>
<a-scene webxr="optionalFeatures: hand-tracking">
<a-plane position="0 0 -3" rotation="-90 0 0" width="6" height="6" color="#7BC8A4"></a-plane>
<a-entity id="red-slider" position="-0.4 1.1 -0.6" rotation="0 0 90" slider="min: 0; max: 255; value: 220;color: #EF2D5E"></a-entity>
<a-entity id="green-slider" position="-0.2 1.1 -0.6" rotation="0 0 90" slider="min: 0; max: 255; value: 180;color: #329D45"></a-entity>
<a-entity id="blue-slider" position="0 1.1 -0.6" rotation="0 0 90" slider="min: 0; max: 255; value: 50;color: #3263DD"></a-entity>
<a-sphere position="0.3 1.2 -0.6" radius="0.1"></a-sphere>
<a-entity id="toggle" position="0.2 0.9 -0.6" rotation="0 0 0" toggle="active: false"></a-entity>
<a-entity class="hand" hand-tracking-mesh="hand: left" hand-tracking-gestures-mesh></a-entity>
<a-entity class="hand" hand-tracking-mesh="hand: right" hand-tracking-gestures-mesh></a-entity>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
</body>
<script>
let red = 220;
let green = 180;
let blue = 50;
const sphere = document.querySelector("a-sphere");
const redSlider = document.querySelector("#red-slider");
redSlider.addEventListener('change', (evt) => {
var newvalue = Math.round( evt.detail.value);
red = newvalue
updateColor();
});
const greenSlider = document.querySelector("#green-slider");
greenSlider.addEventListener('change', (evt) => {
var newvalue = Math.round( evt.detail.value);
green = newvalue
updateColor();
});
const blueSlider = document.querySelector("#blue-slider");
blueSlider.addEventListener('change', (evt) => {
var newvalue = Math.round( evt.detail.value);
blue = newvalue
updateColor();
});
const toggle = document.querySelector("#toggle");
toggle.addEventListener('change', (evt) => {
sphere.setAttribute("wireframe", evt.detail.active)
});
function updateColor() {
sphere.setAttribute("color", `#${decimalToHex(red) + decimalToHex(green) + decimalToHex(blue)}`);
}
updateColor();
function decimalToHex(d, padding = 2) {
var hex = Number(d).toString(16);
while (hex.length < padding) {
hex = "0" + hex;
}
return hex;
}
</script>
</html>