forked from sapan-ostic/Iterative_Closest_Point
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyntcloud_plot.html
239 lines (216 loc) · 8.35 KB
/
pyntcloud_plot.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
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<head>
<title>PyntCloud</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #cccccc;
font-family: Monospace;
font-size: 13px;
text-align: center;
background-color: #050505;
margin: 0px;
overflow: hidden;
}
#logo_container {
position: absolute;
top: 0px;
width: 100%;
}
#PyntCloudLogo {
height: 100px;
}
#screenshot {
position: absolute;
background-color: rgb(245, 139, 69);
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
<button id="screenshot">SCREENSHOT </button>
<div>
<img id="PyntCloudLogo" src="pyntcloud_plot_assets/pyntcloud_logo.png">
</div>
<div id="container">
</div>
<script src="pyntcloud_plot_assets/three.min.js"></script>
<script src="pyntcloud_plot_assets/OrbitControls.js"></script>
<script src="pyntcloud_plot_assets/stats.min.js"></script>
<script src="pyntcloud_plot_assets/jquery.min.js"></script>
<script src="pyntcloud_plot_assets/PLYLoader.js"></script>
<script src="pyntcloud_plot_assets/dat.gui.min.js"></script>
<script>
var container;
var camera, scene, renderer, controls;
var points;
var loader;
//
// Config File Loader
//
let fileLoader = new THREE.FileLoader();
let filename = 'pyntcloud_plot';
fileLoader.load(filename + ".config.json", result => {
let config = JSON.parse(result);
console.log("Loaded " + filename + ".config.json", config);
init(config);
animate(config);
})
//========================= INIT ==============================================//
function init(config) {
let camera_position = config.camera_position;
let look_at = config.look_at;
//
// SCENE
//
scene = new THREE.Scene();
//
// Lines
//
drawLines(scene, config.polylines_points, config.polylines_colors)
//
// CAMERA
//
camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.x = camera_position[0];
camera.position.y = camera_position[1];
camera.position.z = camera_position[2];
camera.up = new THREE.Vector3(0, 0, 1);
//
// GUI
//
var parameters =
{
size: config.point_size,
opacity: config.point_opacity,
wireframe: true,
};
const gui = new dat.GUI();
//
// LOADER
//
var material;
var figure;
loader = new THREE.PLYLoader();
loader.load(config.filename + '.ply', (geometry) => {
if (geometry.index){
material = new THREE.MeshBasicMaterial({
side: THREE.DoubleSide,
vertexColors: THREE.VertexColors,
transparent: true,
opacity: config.point_opacity,
wireframe: true,
});
figure = new THREE.Mesh(geometry, material);
var figureMaterial = gui.add( parameters, 'wireframe' ).name('Wireframe').listen();
figureMaterial.onChange((value) => {
figure.material.wireframe = value;
});
}
else {
material = new THREE.PointsMaterial({
size: config.point_size,
vertexColors: THREE.VertexColors,
transparent: true,
opacity: config.point_opacity,
});
figure = new THREE.Points(geometry, material);
var figureSize = gui.add(parameters, 'size').min(0.001).max(1).step(0.001).name("Point Size").listen();
figureSize.onChange((value) => {
figure.material.size = value;
});
}
var figureOpacity = gui.add(parameters, 'opacity').min(0.1).max(1).step(0.1).name('Opacity').listen();
figureOpacity.onChange((value) => {
figure.material.opacity = value;
});
scene.add(figure);
//var helper = new THREE.VertexNormalsHelper( figure, 0.5, 0x00ff00, 1 );
//scene.add(helper);
});
var light = new THREE.AmbientLight( 0xFFFFFF, 1 ); // soft white light
scene.add( light );
//
// RENDERER
//
renderer = new THREE.WebGLRenderer({
antialias: false,
preserveDrawingBuffer: true
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
//
// SCREENSHOT
//
$("#screenshot").click(function() {
window.open(renderer.domElement.toDataURL("image/png"), "Final");
return false;
});
//
// ORBIT CONTROLS
//
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.target.copy(new THREE.Vector3(look_at[0], look_at[1], look_at[2]));
camera.lookAt(new THREE.Vector3(look_at[0], look_at[1], look_at[2]));
//
// ADD CONTAINER TO DOM
//
container = document.getElementById('container');
container.appendChild(renderer.domElement);
//
// RESIZE LISTENER
//
window.addEventListener('resize', onWindowResize, false);
}
//========================= RESIZE ==============================================//
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
//========================= ANIMATE ==============================================//
function animate(config) {
requestAnimationFrame(animate);
render();
}
//========================= RENDER ==============================================//
function render() {
renderer.render(scene, camera);
}
//======================== Line Drawing Utils ===================================//
function zip() {
var args = [].slice.call(arguments);
var shortest = args.length==0 ? [] : args.reduce(function(a,b){
return a.length<b.length ? a : b
});
return shortest.map(function(_,i){
return args.map(function(array){return array[i]})
});
}
function makeThreeLine(linePoints, lineColor) {
let material = new THREE.LineBasicMaterial({ color: parseInt(lineColor, 16) });
let geometry = new THREE.Geometry();
linePoints.forEach(x => {
// ... is "spread syntax", same as a "splat" in Python.
geometry.vertices.push(new THREE.Vector3(...x));
})
return new THREE.Line(geometry, material);
}
function drawLines(scene, lines, colors) {
if (lines.length !== colors.length) {
throw Error("lines and colors must be the same length");
}
zip(lines, colors).forEach(lc => scene.add(makeThreeLine(lc[0], lc[1])))
}
</script>
</body>
</html>