2

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;
                            }
                    }

            } 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tiffany
  • 151
  • 2
  • 7
  • 1
    If you are missing the face data you can generate them by http://stackoverflow.com/questions/4882993/mesh-generation-from-points-with-x-y-and-z-co-ordinate and CloudCompare is one of them. What do you mean "use the plyloader without faces"? What do you want to display, points ? – gaitat Jan 22 '14 at 17:10
  • I see. Thanks for the suggestion. :) I'm trying to create a rapid prototype by using three.js with a ply data set (xyz coordinates). plyloader was a method I found to help me after I generated a mesh with faces through CloudCompare. I don't want to use CloudCompare to generate a mesh. I want to skip that step. I want to display points and a mesh; ultimately textured mesh (maybe too ambitious?). Are there other methods that can help me or do I have to generate the mesh manually using different algorithms like Delaunay? I've also heard of marching cube and poisson. – Tiffany Jan 23 '14 at 00:08
  • Yes you can use any of the algorithms you suggested (plus the ones in the above stackoverfloaw answer) to generate a mesh from a point cloud. With just having a point cloud you cannot display a mesh. You need the connectivity info of the faces and thats what these algorithms provide. – gaitat Jan 23 '14 at 15:58

0 Answers0