-
Notifications
You must be signed in to change notification settings - Fork 1
/
recording_2020-10-07_14-47-51_demo.html
144 lines (101 loc) · 3.58 KB
/
recording_2020-10-07_14-47-51_demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Point cloud visualization</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="info">
<div>recording_2020-10-07_14-47-51</div>
<!-- <div>+/-: Increase/Decrease point size</div> -->
</div>
<section id="loading-screen">
<div id="loader"></div>
</section>
<script type="module">
import * as THREE from './build/three.module.js';
import Stats from './jsm/libs/stats.module.js';
import { TrackballControls } from './jsm/controls/TrackballControls.js';
import { PCDLoader } from './jsm/loaders/PCDLoader.js';
let container, stats;
let camera, controls, scene, renderer;
init();
animate();
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.x = 0;
camera.position.y = 0;
camera.position.z = 500;
camera.up.set(0, 0, 1);
scene.add( camera );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// Loading Manager
const loadingManager = new THREE.LoadingManager( () => {
const loadingScreen = document.getElementById( 'loading-screen' );
loadingScreen.classList.add( 'fade-out' );
loadingScreen.addEventListener( 'transitionend', onTransitionEnd );
} );
const loader = new PCDLoader(loadingManager);
loader.load( './jsm/models/recording_2020-10-07_14-47-51.pcd', function ( points)
{
scene.add( points );
points.material.vertexColors = THREE.VertexColors;
points.material.size *= 40;
const center = points.geometry.boundingSphere.center;
controls.target.set( center.x, center.y, center.z );
controls.update();
} );
container = document.createElement( 'div' );
document.body.appendChild( container );
container.appendChild( renderer.domElement );
controls = new TrackballControls( camera, renderer.domElement );
controls.rotateSpeed = 2.0;
controls.zoomSpeed = 0.8;
controls.panSpeed = 0.8;
controls.staticMoving = true;
controls.minDistance = 10;
controls.maxDistance = 500;
stats = new Stats();
container.appendChild( stats.dom );
window.addEventListener( 'resize', onWindowResize );
window.addEventListener( 'keypress', keyboard );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
controls.handleResize();
}
function keyboard( ev ) {
const points = scene.getObjectByName( 'recording_2020-10-07_14-47-51.pcd' );
switch ( ev.key || String.fromCharCode( ev.keyCode || ev.charCode ) ) {
case '+':
points.material.size *= 1.2;
points.material.needsUpdate = true;
break;
case '-':
points.material.size /= 1.2;
points.material.needsUpdate = true;
break;
}
}
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
stats.update();
}
function onTransitionEnd( event ) {
const element = event.target;
element.remove();
}
</script>
</body>
</html>