Esempio n. 1
0
        private void MeshAnalysis1(List <Vector3> triangles)
        {
            List <Vector3> vertices = new List <Vector3>();
            List <int>     faces    = new List <int>();

            GeoUtils.MeshVertexPrimitiveType(triangles, ref vertices, ref faces);
            MeshAnalysis2(vertices, faces);
        }
 /// <summary>
 ///  三角面数组 每个子List为一个三角面
 /// </summary>
 /// <param name="triangleLst"></param>
 /// <param name="vert"></param>
 /// <returns></returns>
 public static List<List<int>> Decompose(List<List<Vector2>> triangleLst, ref List<Vector2> vert)
 {
     List<Vector2> tries = new List<Vector2>();
     GeoUtils.FlatList(triangleLst, ref tries);
     List<int> indices = new List<int>();
     GeoUtils.MeshVertexPrimitiveType(tries, ref vert, ref indices);    
     return HMDecompose(vert, indices);
 }
 public static List<List<int>> Decompose(EarPolygon poly, ref List<Vector2> vert)
 {
     EarClipping.Clip(poly);
     List<Vector2> triangles = new List<Vector2>();
     GeoUtils.FlatList(poly.mResults, ref triangles);
     List<int> indices = new List<int>();
     GeoUtils.MeshVertexPrimitiveType(triangles, ref vert, ref indices);
     return HMDecompose(vert, indices);
 }
Esempio n. 4
0
        public static void RemoveInvalidPoint(ref List <Vector3> vertices, ref List <int> faces)
        {
            List <Vector3> allValid = new List <Vector3>();

            for (int i = 0; i < faces.Count; ++i)
            {
                allValid.Add(vertices[faces[i]]);
                allValid.Add(vertices[faces[i + 1]]);
                allValid.Add(vertices[faces[i + 2]]);
            }
            vertices.Clear();
            faces.Clear();
            GeoUtils.MeshVertexPrimitiveType(allValid, ref vertices, ref faces);
        }
Esempio n. 5
0
 private void OnGUI()
 {
     if (GUILayout.Button("MeshCreate"))
     {
         mTriangleObjects.Clear();
         List <Vector3> drawTriangles = new List <Vector3>();
         BuildTriangles(ref mTriangleObjects, ref drawTriangles);
         List <Vector3> vertices = new List <Vector3>();
         List <int>     indices  = new List <int>();
         GeoUtils.MeshVertexPrimitiveType(drawTriangles, ref vertices, ref indices);
         Mesh mesh = new Mesh();
         mesh.SetVertices(vertices);
         mesh.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0);
         mMeshFilter.mesh = mesh;
         float start = Time.realtimeSinceStartup;
         mBVH = new BVH(mTriangleObjects);
         float end1 = Time.realtimeSinceStartup;
         Debug.Log(string.Format("time initialized: {0}", end1 - start));
     }
     if (GUILayout.Button("RayTest"))
     {
         List <BVHRay> rayList = new List <BVHRay>();
         BuildRay(ref rayList, ref mTriangleObjects);
         float end1 = Time.realtimeSinceStartup;
         BVHIntersectionInfo insect = new BVHIntersectionInfo();
         int insectC = 0;
         int missC   = 0;
         for (int i = 0; i < 200; ++i)
         {
             foreach (BVHRay ray in rayList)
             {
                 bool isInsect = mBVH.GetIntersection(ray, ref insect, false);
                 int  test     = isInsect ? insectC++ : missC++;
                 if (isInsect)
                 {
                     Debug.DrawLine(ray.mOrigin, insect.mHitPoint, Color.blue, 2000);
                 }
             }
         }
         float end2 = Time.realtimeSinceStartup;
         Debug.Log(string.Format("time slapped: {0}, insect: {1}, miss: {2}", end2 - end1, insectC, missC));
     }
 }
 /// <summary>
 /// 简单多边形或者三角面点数组
 /// </summary>
 /// <param name="tries"></param>
 /// <param name="isPolygon">是否为简单多边形</param>
 /// <param name="vert"></param>
 /// <returns></returns>
 public static List<List<int>> Decompose(List<Vector2> tries, bool isPolygon, ref List<Vector2> vert) 
 {
     if (isPolygon)
     {
         EarPolygon poly = new EarPolygon();
         foreach (Vector2 v in tries)
         {
             poly.AddPoint(v.x, v.y);
         }
         EarClipping.Clip(poly);
         List<Vector2> triangles = new List<Vector2>();
         GeoUtils.FlatList(poly.mResults, ref triangles);
         List<int> indices = new List<int>();
         GeoUtils.MeshVertexPrimitiveType(triangles, ref vert, ref indices);
         return HMDecompose(vert, indices);
     }
     else
     {
         List<int> indices = new List<int>();
         GeoUtils.MeshVertexPrimitiveType(tries, ref vert, ref indices);
         return HMDecompose(vert, indices);
     }
 }