Search code examples
three.jspoint-cloudslidar

Not able to plot pcd file from PCDLoader in 3js


I am trying to plot pcd file following the example mentioned here. WIth the given pcd I am able to plot but the pcd I have I am not able to plot. I cross checked the format and there were no errors as well in browser. Here is my pcd file. I am not getting whats going wrong.


Solution

  • I have tested your PCD file on my computer and it renders find. However, just replacing the PCD file in the mentioned example won't work since the spatial distribution of the data set is totally different. Hence you need a different camera and control setting. You should be able to see the point cloud with the following basic code:

    var camera, container, scene, renderer;
    
    init();
    animate();
    
    function init() {
    
        scene = new THREE.Scene();
    
        camera = new THREE.PerspectiveCamera( 15, window.innerWidth / window.innerHeight, 0.1, 1000 );
        camera.position.z = 700;
    
        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 THREE.PCDLoader();
        loader.load( './models/pcd/binary/test.pcd', function ( points ) {
    
            points.material.size = 5;
    
            scene.add( points );
    
        } );
            container = document.createElement( 'div' );
            document.body.appendChild( container );
            container.appendChild( renderer.domElement );
    
            window.addEventListener( 'resize', onWindowResize, false );
    
    }
    
    function onWindowResize() {
    
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
    
        renderer.setSize( window.innerWidth, window.innerHeight );
    
    }
    
    function animate() {
    
        requestAnimationFrame( animate );
    
        renderer.render( scene, camera );
    
    }