-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
229 lines (196 loc) · 7.11 KB
/
index.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html lang="en">
<head>
<title>Calibration Viewer</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab&display=swap" rel="stylesheet">
<style>
body {
margin: 0;
width: 100%;
height: 100%;
background: #11e8bb; /* Old browsers */
background: -moz-linear-gradient(top, #11e8bb 0%, #8200c9 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #11e8bb 0%,#8200c9 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #160016 0%,#160000 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#11e8bb', endColorstr='#8200c9',GradientType=0 ); /* IE6-9 */
}
#banner {
font-family: 'Roboto Slab', serif;
width: 100%;
height: 26px;
color: #df487f;
padding: 15px;
font-size: 18px;
font-weight: 600;
/* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#441627+0,350514+50,4b0d1d+100 */
background: #441627; /* Old browsers */
background: -moz-linear-gradient(top, #441627 0%, #350514 50%, #4b0d1d 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #441627 0%,#350514 50%,#4b0d1d 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #441627 0%,#350514 50%,#4b0d1d 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#441627', endColorstr='#4b0d1d',GradientType=0 ); /* IE6-9 */
}
#container {
display: flex;
align-items: stretch;
}
#canvas {
width: 70%;
}
#source-frame {
width: 30%;
height: 100vh;
background: rgba(0.5, 0.5, 0.5, 0.25);
border-radius: 2px;
}
#source {
box-sizing: border-box;
background:transparent;
border: none;
color: white;
font-family: 'inconsolata', 'monaco', Monospace;
width: 100%;
height: 99vh;
font-size: 12px;
padding: 10px;
}
</style>
</head>
<body>
<div id="banner">
Calibration Viewer
</div>
<div id="container">
<div id="canvas"></div>
<div id="source-frame">
<textarea id="source">
</textarea>
</div>
</div>
<script src="js/three.min.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/stats.min.js"></script>
<script src="js/TrackballControls.js"></script>
<script src="js/SourceParser.js"></script>
<script>
if (WEBGL.isWebGLAvailable() === false) {
document.body.appendChild(WEBGL.getWebGLErrorMessage());
}
var renderer, scene, camera, controls;
/// Keep track of user specified objects. Useful when the user changes
/// object definitions and we need to specifically clear those user
/// specified objects only.
var renderedObjectsFromSource = [];
window.onload = function () {
function onResponse () {
document.getElementById('source').value = this.responseText;
init();
renderScene();
animate();
}
var xhrq = new XMLHttpRequest();
xhrq.addEventListener("load", onResponse);
xhrq.open("GET", "/CalibrationViewer/definitions_source.txt");
xhrq.send();
}
///
/// Parse the contents of the `#source` text-area and populate scene
/// objects
///
function createSceneObjectsFromSource() {
// Helpers
//
const disposeArray = function() { this.array = null; }
function createPointCloudObject(vertices, format) {
console.assert(format === 'xyz');
var pointsGeometry = new THREE.BufferGeometry();
pointsGeometry.addAttribute('position', new THREE.Float32BufferAttribute(vertices.flat(), 3).onUpload(disposeArray));
pointsGeometry.computeBoundingSphere();
return new THREE.Points(pointsGeometry, new THREE.PointsMaterial({ size: 0.05, color: 0x888888 }));
}
// Render defined objects
//
for (let c of renderedObjectsFromSource) {
scene.remove(c);
}
renderedObjectsFromSource = [];
const sourceLines = document.getElementById('source').value;
const definitions = new SourceParser(sourceLines).parse();
const frameObjects = {};
for (const def of definitions) {
if (def instanceof FrameDefinition) {
const frameAxes = new THREE.AxesHelper(0.05);
frameAxes.matrix.set(...def.transform.flat());
frameAxes.matrixAutoUpdate = false;
frameObjects[def.name] = frameAxes;
scene.add(frameAxes);
renderedObjectsFromSource.push(frameAxes);
}
if (def instanceof SceneObjectDefinition) {
if (def.format === 'OBJ') {
const obj = new WavefrontOBJParser(def.data).parse();
const pointsObject = createPointCloudObject(obj.vertices, 'xyz');
pointsObject.parent = frameObjects[def.frame];
scene.add(pointsObject);
renderedObjectsFromSource.push(pointsObject);
}
}
}
}
function init() {
const canvas = document.getElementById('canvas');
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio((window.devicePixelRatio) ? window.devicePixelRatio : 1);
renderer.setSize(canvas.clientWidth, window.innerHeight);
renderer.autoClear = false;
renderer.setClearColor(0x000000, 0.0);
renderer.gammaInput = true;
renderer.gammaOutput = true;
canvas.appendChild(renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(35, canvas.clientWidth / window.innerHeight, 1, 10000);
camera.position.z = 8;
scene.add(camera);
var ambientLight = new THREE.AmbientLight(0xffffff);
scene.add(ambientLight);
// var axes = new THREE.AxesHelper(2);
// scene.add(axes);
var gridHelper = new THREE.GridHelper(50, 50, 0x000000, 0x1b020a);
gridHelper.geometry.rotateX( Math.PI / 2 );
scene.add(gridHelper);
createSceneObjectsFromSource();
controls = new THREE.TrackballControls(camera, renderer.domElement);
controls.minDistance = 2.0;
controls.maxDistance = 2000.0;
controls.dynamicDampingFactor = 0.3;
controls.addEventListener('change', renderScene);
window.addEventListener('resize', onWindowResize, false);
};
function animate() {
requestAnimationFrame(animate);
controls.update();
}
function onWindowResize() {
camera.aspect = canvas.clientWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(canvas.clientWidth, window.innerHeight);
renderScene();
}
function renderScene() {
renderer.clear();
renderer.render(scene, camera);
}
document.addEventListener('keypress', function(e) {
if (e.ctrlKey && (e.charCode == 13)) {
createSceneObjectsFromSource();
renderScene();
}
});
document.getElementById('source').addEventListener('dblclick', function(e) {
createSceneObjectsFromSource();
renderScene();
});
</script>
</body>
</html>