Using three.js + plyloader

2.6k views Asked by At

I'm trying to load a ply file using the plyloader of three.js. I have successfully loaded the ply only if it has both vertices (x y z) and faces (format: 3 index0 index1 index2). Is there a way to use it without faces? Any ideas on a quick way to create faces with three.js given only xyz points? My original file contains xyz coordinates. I used CloudCompare to generate a mesh and saved it as ply file which has xyz points and faces. Thanks.

This code is from plyloader:

if ( vertexCount != 0 && faceCount != 0 ) {
                    // Vertex                        
                    // assume x y z
                    var patternVertex = /([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;
                    for ( var i = 0; i < vertexCount; i++) {
                            if ( ( result = patternVertex.exec( body ) ) != null ) {
                                    geometry.vertices.push( new THREE.Vector3( parseFloat( result[ 1 ] ), parseFloat( result[ 3 ] ), parseFloat( result[ 5 ] ) ) );
                            } else {
                                    console.error('Vertex error: vertex count mismatch.');
                                    return geometry;
                            }
                    }

                    // Face
                    // assume 3 index0 index1 index2
                    var patternFace = /3[\s]+([-+]?[0-9]+)[\s]+([-+]?[0-9]+)[\s]+([-+]?[0-9]+)/g;
                    for (var i = 0; i < faceCount; i++) {
                            if ( ( result = patternFace.exec( body ) ) != null ) {
                                    geometry.faces.push( new THREE.Face3( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) ) );
                            } else {
                                    console.error('Face error: vertex count mismatch.');
                                    return geometry;
                            }
                    }

            } 
0

There are 0 answers