Created
June 24, 2015 06:20
-
-
Save kaorun55/6690b60e0b134dad908d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mesh ReadPly(string path) | |
| { | |
| Mesh mesh = new Mesh(); | |
| using ( var reader = new StreamReader(path) ) { | |
| var line = reader.ReadLine(); | |
| if ( line != "ply" ) { | |
| return null; | |
| } | |
| line = reader.ReadLine(); | |
| if ( line != "format ascii 1.0" ) { | |
| return null; | |
| } | |
| line = reader.ReadLine(); | |
| if ( line != "comment file created by Kinect Face" ) { | |
| return null; | |
| } | |
| line = reader.ReadLine(); | |
| if ( line != "element vertex 1347" ) { | |
| return null; | |
| } | |
| // property float x | |
| //property float y | |
| //property float z | |
| //property uchar red | |
| //property uchar green | |
| //property uchar blue | |
| line = reader.ReadLine(); | |
| line = reader.ReadLine(); | |
| line = reader.ReadLine(); | |
| line = reader.ReadLine(); | |
| line = reader.ReadLine(); | |
| line = reader.ReadLine(); | |
| line = reader.ReadLine(); | |
| if ( line != "element face 2630" ) { | |
| return null; | |
| } | |
| line = reader.ReadLine(); | |
| if ( line != "property list uchar int vertex_index" ) { | |
| return null; | |
| } | |
| line = reader.ReadLine(); | |
| if ( line != "end_header" ) { | |
| return null; | |
| } | |
| const int vertexCount = 1347; | |
| var vertices = new Vector3[vertexCount]; | |
| var colors32 = new Color32[vertexCount]; | |
| Debug.Log("Read Vertex"); | |
| for ( int i = 0; i < vertexCount; i++ ) { | |
| line = reader.ReadLine(); | |
| var param = line.Split( new char[] { ' ' } ); | |
| if ( param.Length != 6 ) { | |
| return null; | |
| } | |
| vertices[i].x = float.Parse( param[0] ); | |
| vertices[i].y = float.Parse( param[1] ); | |
| vertices[i].z = float.Parse( param[2] ); | |
| colors32[i].r = byte.Parse( param[3] ); | |
| colors32[i].g = byte.Parse( param[4] ); | |
| colors32[i].b = byte.Parse( param[5] ); | |
| } | |
| mesh.vertices = vertices; | |
| mesh.colors32 = colors32; | |
| mesh.triangles = FaceData.Triangles(); | |
| mesh.RecalculateNormals(); | |
| mesh.RecalculateBounds(); | |
| } | |
| return mesh; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment