Pasterz
Pasterz

Reputation: 11

Loading PLY files without faces - Three.js

I'm working on a Web Service which main funcionality resolves around displaying binary .ply files. To open and visualize the point cloud I'm using PLYLoader from Three.js. I used it to present example files from the internet and it worked. But when I'm trying to attach my .ply file it doesn't. I'm using Three.js because I need my display to be optimal, my files are at least 70mb.

Example .ply file here: https://onedrive.live.com/redir?resid=7DDB287362EDFD5A!761&authkey=!AOHxkZk-6etH--0&ithint=file%2cply

I noticed that the .ply files that i have are a bit different from .ply files i displayed before. In my files there are no faces only points.

So basically my question is "Is it possible to display point cloud using Three.js? or should I use other library? If this is possible can someone help me with configuring my code to work properly?

Here it is my script in which I'm supporting .ply files:

        var cameraControls;
        var container = document.getElementById("three");
        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera( 75, container.offsetWidth / container.offsetHeight, 0.1, 1000 );
        var renderer = new THREE.WebGLRenderer();
        renderer.setSize( container.offsetWidth, container.offsetHeight );
        document.getElementById("three").appendChild( renderer.domElement );
        cameraControls = new THREE.OrbitControls( camera, renderer.domElement );
        cameraControls.target.set( 0, 0, 0 );
        cameraControls.addEventListener( 'change', render );
        var geometry = new THREE.BoxGeometry( 3, 3, 3 );
        var material = new THREE.MeshPhongMaterial( { color: 0x00ff00 } );
        var cube = new THREE.Mesh( geometry, material );
        var loader = new THREE.PLYLoader();
            loader.load( 'resources/cube.ply', function ( geometry ) {

                geometry.computeFaceNormals();

                var material = new THREE.MeshStandardMaterial( { color: 0x0055ff } );
                var mesh = new THREE.Mesh( geometry, material );

                mesh.position.y = - 0.25;
                mesh.rotation.x = - Math.PI / 2;
                mesh.scale.multiplyScalar( 1 );

                mesh.castShadow = true;
                mesh.receiveShadow = true;

                scene.add( mesh );

            } );
        var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
        var light = new THREE.AmbientLight( 0x404040 ); // soft white light
        scene.add( light );
        directionalLight.position.set( 0, 1, 0 );
        scene.add( directionalLight );
        camera.position.z = 5;
        function render() {
            requestAnimationFrame( render );
            renderer.render( scene, camera );
        }
        render();

Upvotes: 1

Views: 3149

Answers (2)

Remy Mellet
Remy Mellet

Reputation: 1795

Use PointMaterials and Points

  const loader = new PLYLoader();
  loader.load('00000012.ply', function (geometry) {
    var material = new THREE.PointsMaterial( { size: 0.005 } );
    material.vertexColors = true //if has colors
    var mesh = new THREE.Points(geometry, material)
    scene.add(mesh)
  } );

Upvotes: 0

Zain
Zain

Reputation: 53

Use THREE.MeshNormalMaterial. It loads the textures with MeshNormalMaterial for some odd reason

Upvotes: 0

Related Questions