forked from RuthDanielaAguirre/GameJam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference.html
More file actions
128 lines (106 loc) · 3.51 KB
/
reference.html
File metadata and controls
128 lines (106 loc) · 3.51 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
<html>
<head>
<script type="module">
import * as THREE from 'three';
import { MindARThree } from "../../src/face-target/three.js";
const frontCameraDeviceSelect = document.querySelector("#frontCameraDeviceSelect");
const backCameraDeviceSelect = document.querySelector("#backCameraDeviceSelect");
let mindarThree = null;
const setup = () => {
const userDeviceId = frontCameraDeviceSelect.value? frontCameraDeviceSelect.value: undefined;
const environmentDeviceId = backCameraDeviceSelect.value? backCameraDeviceSelect.value: undefined;
console.log("setup:", userDeviceId, environmentDeviceId);
mindarThree = new MindARThree({
container: document.querySelector("#container"),
filterMinCF: 0.001,
filterBeta: 10,
userDeviceId,
environmentDeviceId,
});
const anchor = mindarThree.addAnchor(1);
//const geometry = new THREE.SphereGeometry( 0.1, 32, 16 );
const geometry = new THREE.SphereGeometry(0.5, 10, 10); // radius=0.5 = half face width
const material = new THREE.MeshBasicMaterial({ color: 0x00ffff, transparent: true, opacity: 0.5 });
const sphere = new THREE.Mesh(geometry, material);
anchor.group.add(sphere);
}
const start = async () => {
if (!mindarThree) {
setup();
}
const { renderer, scene, camera } = mindarThree;
await mindarThree.start();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
}
const startButton = document.querySelector("#startButton");
startButton.addEventListener("click", () => {
start();
});
stopButton.addEventListener("click", () => {
mindarThree.stop();
mindarThree.renderer.setAnimationLoop(null);
});
const switchButton = document.querySelector("#switchButton");
switchButton.addEventListener("click", () => {
mindarThree.switchCamera();
});
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
console.log('device', device);
if (device.kind === 'videoinput') {
const option = document.createElement('option');
option.text = device.label || 'camera ' + (frontCameraDeviceSelect.length);
option.value = device.deviceId;
const option2 = document.createElement('option');
option2.text = device.label || 'camera ' + (backCameraDeviceSelect.length);
option2.value = device.deviceId;
frontCameraDeviceSelect.appendChild(option);
backCameraDeviceSelect.appendChild(option2);
}
console.log(device.kind + ": " + device.label +
" id = " + device.deviceId);
});
})
.catch(function(err) {
console.log(err.name + ": " + err.message);
});
</script>
<style>
body {
margin: 0;
}
#container {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
}
#control {
position: fixed;
top: 0;
left: 0;
z-index: 2;
}
</style>
</head>
<body>
<div id="control">
<button id="startButton">Start</button>
<button id="stopButton">Stop</button>
<button id="switchButton">Switch</button>
Front Camera
<select id="frontCameraDeviceSelect">
<option value="">Default</option>
</select>
Back Camera
<select id="backCameraDeviceSelect">
<option value="">Default</option>
</select>
</div>
<div id="container">
</div>
</body>
</html>