Skip to content

Commit b6bdae7

Browse files
committed
Improving example
1 parent dde3fe9 commit b6bdae7

File tree

2 files changed

+69
-24
lines changed

2 files changed

+69
-24
lines changed

examples/calibration_parser.html

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,58 @@
55
<title>Calibration parser</title>
66
<style>
77
body { margin: 0; }
8+
9+
.popup {
10+
position: fixed;
11+
top: 50%;
12+
left: 50%;
13+
transform: translate(-50%, -50%);
14+
background-color: #303841;
15+
border-radius: 4px;
16+
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
17+
color: #EFEFEF;
18+
overflow: hidden;
19+
}
20+
21+
.editor {
22+
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
23+
border: none;
24+
box-shadow: none;
25+
outline: none;
26+
background-color: #303841;
27+
color: #EFEFEF;
28+
resize: none;
29+
margin: 0px;
30+
}
831
</style>
932
</head>
1033
<body style="background-color:black;">
1134

35+
<div class="popup">
36+
<div style="background-color: #50565E; padding: 8px">
37+
Paste your Mixed Reality calibration below:
38+
</div>
39+
<textarea id="calibration-editor" rows="20" cols="80" class="editor" spellcheck="false">
40+
{
41+
"schemaVersion": 1,
42+
"camera": {
43+
"width": 1280,
44+
"height": 720,
45+
"fov": 38,
46+
"position": [0, 1.5, 0],
47+
"orientation": [0, 0, 0, 1]
48+
},
49+
"chromaKey": {
50+
"color": [0, 1, 0],
51+
"similarity": 0.25,
52+
"smoothness": 0
53+
},
54+
"delay": 4
55+
}
56+
</textarea>
57+
<div style="padding: 8px; white-space: pre-wrap; background-color: green;" id="result"></div>
58+
</div>
59+
1260
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
1361

1462
<script type="importmap">
@@ -23,29 +71,27 @@
2371
<script type="module">
2472
import * as MRC from 'reality-mixer';
2573

26-
const json = `
27-
{
28-
"schemaVersion": 1,
29-
"camera": {
30-
"width": 1280,
31-
"height": 720,
32-
"fov": 38,
33-
"position": [0, 1.5, 0],
34-
"orientation": [0, 0, 0, 1]
35-
},
36-
"chromaKey": {
37-
"color": [0, 1, 0],
38-
"similarity": 0.25,
39-
"smoothness": 0
40-
},
41-
"delay": 4
42-
}
43-
`;
74+
function validateCalibration() {
75+
let result = document.getElementById("result");
76+
const maybeJson = document.getElementById("calibration-editor").value;
4477

45-
const calibrationData = JSON.parse( json );
78+
try {
79+
const json = JSON.parse(maybeJson);
80+
const calibration = MRC.Calibration.fromData(json);
81+
console.log(calibration);
4682

47-
const calibration = MRC.Calibration.fromData( calibrationData );
48-
console.log(calibration);
83+
result.style.backgroundColor = "green";
84+
result.innerText = "Valid";
85+
} catch (error) {
86+
console.log(error);
87+
result.innerText = error;
88+
result.style.backgroundColor = "red";
89+
}
90+
}
91+
92+
document.getElementById("calibration-editor").oninput = validateCalibration;
93+
validateCalibration();
4994
</script>
95+
5096
</body>
5197
</html>

src/mrc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class Calibration {
5858
// We're not checking if the orientation is a valid unit quaternion
5959

6060
if (!validate(data)) {
61-
console.log(validate.errors);
62-
return null;
63-
}
61+
throw JSON.stringify(validate.errors, null, 2);
62+
}
6463

6564
const cameraCalibration = new CameraCalibration(
6665
data.camera.width,

0 commit comments

Comments
 (0)