123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <!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="http://pointclouds.org/documentation/tutorials/pcd_file_format.php#pcd-file-format" target="_blank" rel="noopener">PCD File format</a>
- <div>PCD loader test by <a href="http://filipecaixeta.com.br" target="_blank" rel="noopener">Filipe Caixeta</a></div>
- <div>+/-: Increase/Decrease point size</div>
- <div>c: Change color</div>
- </div>
- <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';
- var container, stats;
- var camera, controls, scene, renderer;
- init();
- animate();
- function init() {
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0x000000 );
- camera = new THREE.PerspectiveCamera( 15, window.innerWidth / window.innerHeight, 0.01, 40 );
- camera.position.x = 0.4;
- camera.position.z = - 2;
- 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 );
- var loader = new PCDLoader();
- loader.load( './models/pcd/binary/Zaghetto.pcd', function ( points ) {
- scene.add( points );
- var 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.3;
- controls.panSpeed = 0.2;
- controls.staticMoving = true;
- controls.minDistance = 0.3;
- controls.maxDistance = 0.3 * 100;
- stats = new Stats();
- container.appendChild( stats.dom );
- window.addEventListener( 'resize', onWindowResize, false );
- 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 ) {
- var points = scene.getObjectByName( 'Zaghetto.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;
- case 'c':
- points.material.color.setHex( Math.random() * 0xffffff );
- points.material.needsUpdate = true;
- break;
- }
- }
- function animate() {
- requestAnimationFrame( animate );
- controls.update();
- renderer.render( scene, camera );
- stats.update();
- }
- </script>
- </body>
- </html>
|