void loadPLYDownSample() { if (!isAbsolute) { absFilePath = System.IO.Path.Combine(Application.streamingAssetsPath, fileName); } //zhenyi IntPtr plyIntPtr = PlyLoaderDll.LoadPly(absFilePath); Mesh mesh = new Mesh(); Vector3[] vertices = PlyLoaderDll.GetRVertices(plyIntPtr); Color32[] colors = PlyLoaderDll.GetRColors(plyIntPtr); //int[] indices = PlyLoaderDll.GetRIndexs(plyIntPtr); PlyLoaderDll.UnLoadPly(plyIntPtr); int meshCount = vertices.Length / limitCount + 1; for (int i = 0; i < meshCount; i++) { createMesh(i, Math.Min(limitCount, vertices.Length - i * limitCount), ref vertices, ref colors); } }
// Use this for initialization void Start() { string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, fileName); IntPtr plyIntPtr = PlyLoaderDll.LoadPly(filePath); Mesh mesh = new Mesh(); mesh.vertices = PlyLoaderDll.GetVertices(plyIntPtr); mesh.uv = PlyLoaderDll.GetUvs(plyIntPtr); mesh.normals = PlyLoaderDll.GetNormals(plyIntPtr); mesh.colors32 = PlyLoaderDll.GetColors(plyIntPtr); mesh.SetIndices(PlyLoaderDll.GetIndexs(plyIntPtr), MeshTopology.Triangles, 0, true); mesh.name = "mesh"; GameObject go = new GameObject(); go.name = "meshNew"; MeshFilter mf = go.AddComponent <MeshFilter>(); mf.mesh = mesh; MeshRenderer mr = go.AddComponent <MeshRenderer>(); mr.material = new Material(Shader.Find("Unlit/Texture")); string textureName = PlyLoaderDll.GetTextureName(plyIntPtr); if (textureName.Length > 0) { string texturePath = "file://" + System.IO.Path.Combine(Application.streamingAssetsPath, textureName); WWW www = new WWW(texturePath); while (!www.isDone) { } mr.material.mainTexture = www.texture; } PlyLoaderDll.UnLoadPly(plyIntPtr); }