Ply 3d file format is a simple compact easy to use 3d format Great for testing and supported by most 3d packages 3 g blender Ply file format the specification information is available here https en wikipedia org wiki PLY_ file_format Following provides a tiny ply parser loader using vanilla javascript function parsePLY data const lines data split n let headerFinished false let vertexCount 0 let vertexProperties let vertexDataStartIndex 0 for let i 0 i lines length i const line lines i trim if line startsWith end_header headerFinished true vertexDataStartIndex i 1 break else if line startsWith element vertex vertexCount parseInt line split 2 else if line startsWith property vertexProperties push line split 2 const vertices if headerFinished for let i vertexDataStartIndex i vertexDataStartIndex vertexCount i const values lines i trim split const vertex for let j 0 j vertexProperties length j vertex vertexProperties j parseFloat values j vertices push vertex return vertices Example usage const plyData ply format ascii 1 0 comment Made with Blender element vertex 8 property float x property float y property float z end_header 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1 1 0 1 1 1 1 0 1 1 const vertices parsePLY plyData console log vertices
2 else if line startsWith property vertexProperties push line split 2 const vertices if headerFinished for let i vertexDataStartIndex i vertexDataStartIndex vertexCount i const values lines i trim split const vertex for let j 0 j vertexProperties length j vertex vertexProperties j parseFloat values j vertices push vertex return vertices Example usage const plyData ply format ascii 1 0 comment Made with Blender element vertex 8 property float x property float y property float z end_header 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1 1 0 1 1 1 1 0 1 1 const vertices parsePLY plyData console log vertices