Skip to content

Commit 1fd893a

Browse files
committed
Moving Calibration editor to js file
1 parent b6bdae7 commit 1fd893a

File tree

3 files changed

+156
-97
lines changed

3 files changed

+156
-97
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { Calibration } from 'reality-mixer';
2+
3+
const exampleCalibrationJSON = `
4+
{
5+
"schemaVersion": 1,
6+
"camera": {
7+
"width": 1920,
8+
"height": 1080,
9+
"fov": 38,
10+
"position": [0, 1.5, 0],
11+
"orientation": [0, 0, 0, 1]
12+
},
13+
"chromaKey": {
14+
"color": [0, 1, 0],
15+
"similarity": 0.25,
16+
"smoothness": 0
17+
},
18+
"delay": 4
19+
}
20+
`
21+
22+
function CalibrationInput(
23+
onCompleted,
24+
initialCalibrationJSON = exampleCalibrationJSON,
25+
) {
26+
let popupDiv = document.createElement("div");
27+
28+
popupDiv.style = `
29+
position: fixed;
30+
top: 50%;
31+
left: 50%;
32+
transform: translate(-50%, -50%);
33+
background-color: #303841;
34+
border-radius: 4px;
35+
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
36+
color: #EFEFEF;
37+
overflow: hidden;
38+
`
39+
40+
let titleDiv = document.createElement("div");
41+
42+
titleDiv.style = "background-color: #50565E; padding: 8px";
43+
titleDiv.innerText = "Paste or drag and drop your Mixed Reality calibration below:"
44+
45+
let resultDiv = document.createElement("div");
46+
47+
resultDiv.style = "padding: 8px; white-space: pre-wrap; background-color: green;";
48+
49+
let editor = document.createElement("textarea");
50+
51+
editor.style = `
52+
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
53+
border: none;
54+
box-shadow: none;
55+
outline: none;
56+
background-color: #303841;
57+
color: #EFEFEF;
58+
resize: none;
59+
margin: 0px;
60+
`
61+
62+
editor.rows = 20;
63+
editor.cols = 80;
64+
editor.spellcheck = false;
65+
editor.value = initialCalibrationJSON;
66+
67+
function validateCalibration() {
68+
const maybeJson = editor.value;
69+
70+
try {
71+
const json = JSON.parse(maybeJson);
72+
const calibration = Calibration.fromData(json);
73+
74+
resultDiv.style.backgroundColor = "green";
75+
resultDiv.innerHTML = "";
76+
77+
let link = document.createElement("a");
78+
link.innerText = "Click here to continue...";
79+
link.href = "#";
80+
link.style.color = "#EFEFEF";
81+
link.onclick = function() {
82+
onCompleted(popupDiv, calibration);
83+
return false;
84+
}
85+
86+
resultDiv.appendChild(link);
87+
} catch (error) {
88+
resultDiv.innerText = error;
89+
resultDiv.style.backgroundColor = "red";
90+
}
91+
}
92+
93+
editor.oninput = validateCalibration;
94+
validateCalibration();
95+
96+
popupDiv.appendChild(titleDiv);
97+
popupDiv.appendChild(editor);
98+
popupDiv.appendChild(resultDiv);
99+
100+
popupDiv.ondrop = function(e) {
101+
e.preventDefault();
102+
103+
let file = e.dataTransfer.files[0],
104+
reader = new FileReader();
105+
106+
reader.onload = function(event) {
107+
editor.value = event.target.result;
108+
validateCalibration();
109+
};
110+
111+
reader.readAsText(file);
112+
return false;
113+
}
114+
115+
return popupDiv;
116+
}
117+
118+
export { CalibrationInput };

examples/calibration_editor.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Calibration editor</title>
6+
<style>
7+
body { margin: 0; }
8+
</style>
9+
</head>
10+
<body style="background-color:black;">
11+
12+
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
13+
14+
<script type="importmap">
15+
{
16+
"imports": {
17+
"three": "../node_modules/three/build/three.module.js",
18+
"reality-mixer": "../src/mrc.js"
19+
}
20+
}
21+
</script>
22+
23+
<script type="module">
24+
import { CalibrationInput } from './calibration-editor/calibration-editor.js'
25+
26+
function onCalibrationInput(editor, calibration) {
27+
editor.parentNode.removeChild(editor);
28+
console.log(calibration);
29+
// We can then initialize the Mixed Reality Capture with this calibration....
30+
}
31+
32+
const calibrationInput = CalibrationInput(onCalibrationInput);
33+
34+
document.body.appendChild(calibrationInput);
35+
</script>
36+
37+
</body>
38+
</html>

examples/calibration_parser.html

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)