You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
3.0 KiB
121 lines
3.0 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - PCD</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">
|
|
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
|
|
<a href="https://pointclouds.org/documentation/tutorials/pcd_file_format.html" target="_blank" rel="noopener">PCD File format</a>
|
|
<div>+/-: Increase/Decrease point size</div>
|
|
<div>c: Change color</div>
|
|
</div>
|
|
|
|
<!-- Import maps polyfill -->
|
|
<!-- Remove this when import maps will be widely supported -->
|
|
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
|
|
|
|
<script type="importmap">
|
|
{
|
|
"imports": {
|
|
"three": "../build/three.module.js",
|
|
"three/addons/": "./jsm/"
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<script type="module">
|
|
|
|
import * as THREE from 'three';
|
|
|
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
import { PCDLoader } from 'three/addons/loaders/PCDLoader.js';
|
|
|
|
let camera, scene, renderer;
|
|
|
|
init();
|
|
render();
|
|
|
|
function init() {
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
document.body.appendChild( renderer.domElement );
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 0.01, 40 );
|
|
camera.position.set( 0, 0, 1 );
|
|
scene.add( camera );
|
|
|
|
const controls = new OrbitControls( camera, renderer.domElement );
|
|
controls.addEventListener( 'change', render ); // use if there is no animation loop
|
|
controls.minDistance = 0.5;
|
|
controls.maxDistance = 10;
|
|
|
|
//scene.add( new THREE.AxesHelper( 1 ) );
|
|
|
|
const loader = new PCDLoader();
|
|
loader.load( './models/pcd/binary/Zaghetto.pcd', function ( points ) {
|
|
|
|
points.geometry.center();
|
|
points.geometry.rotateX( Math.PI );
|
|
points.name = 'Zaghetto.pcd';
|
|
scene.add( points );
|
|
|
|
render();
|
|
|
|
} );
|
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
|
window.addEventListener( 'keypress', keyboard );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function keyboard( ev ) {
|
|
|
|
const points = scene.getObjectByName( 'Zaghetto.pcd' );
|
|
|
|
switch ( ev.key || String.fromCharCode( ev.keyCode || ev.charCode ) ) {
|
|
|
|
case '+':
|
|
points.material.size *= 1.2;
|
|
break;
|
|
|
|
case '-':
|
|
points.material.size /= 1.2;
|
|
break;
|
|
|
|
case 'c':
|
|
points.material.color.setHex( Math.random() * 0xffffff );
|
|
break;
|
|
|
|
}
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|