Exemplo n.º 1
0
        /// <summary>
        /// Creates a convex hull given the original vertices of a mesh.
        /// </summary>
        /// <param name="vertices">The original vertices of a mesh</param>
        /// <param name="resultOutcome">The outcome of the process (successfull or unsuccessful)</param>
        /// <param name="PlaneDistanceTolerance">The plane distance tolerance</param>
        /// <returns>The output mesh data of the convex hull</returns>
        public static MeshData GenerateConvexHull(this Vector3[] vertices, out ConvexHullCreationResultOutcome resultOutcome, double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
        {
            MeshData convexMesh = new MeshData();

            List <MIVertex> convexVertices = vertices.Select(point => new MIVertex(point)).ToList();
            var             creation       = ConvexHull.Create(convexVertices, PlaneDistanceTolerance);

            resultOutcome = creation.Outcome;

            var result = creation.Result;

            List <int>      triangles      = new List <int>();
            List <MIVertex> resultVertices = result.Points.ToList();

            foreach (var face in result.Faces)
            {
                triangles.Add(resultVertices.IndexOf(face.Vertices[0]));
                triangles.Add(resultVertices.IndexOf(face.Vertices[1]));
                triangles.Add(resultVertices.IndexOf(face.Vertices[2]));
            }

            convexMesh.vertices  = result.Points.Select(point => point.ToVec()).ToArray();
            convexMesh.triangles = triangles.ToArray();
            //convexMesh.RecalculateNormals();
            //convexMesh.RecalculateBounds();

            return(convexMesh);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a convex hull given the original vertices of a mesh.
        /// </summary>
        /// <param name="vertices">The original vertices of a mesh</param>
        /// <param name="resultOutcome">The outcome of the process (successfull or unsuccessful)</param>
        /// <param name="PlaneDistanceTolerance">The plane distance tolerance</param>
        /// <returns>A mesh that represents the convex hull of the original mesh</returns>
        public static Mesh ToConvexHull(this Vector3[] vertices, out ConvexHullCreationResultOutcome resultOutcome, double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
        {
            Mesh convexMesh = new Mesh();
            var  meshData   = vertices.GenerateConvexHull(out resultOutcome, PlaneDistanceTolerance);

            convexMesh.vertices  = meshData.vertices;
            convexMesh.triangles = meshData.triangles;
            convexMesh.RecalculateNormals();
            convexMesh.RecalculateBounds();

            return(convexMesh);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConvexHullCreationResult{TVertex, TFace}" /> class.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="outcome">The outcome.</param>
 /// <param name="errorMessage">The error message.</param>
 public ConvexHullCreationResult(ConvexHull<TVertex, TFace> result, ConvexHullCreationResultOutcome outcome, string errorMessage = "")
 {
     Result = result;
     Outcome = outcome;
     ErrorMessage = errorMessage;
 }
 public ConvexHullGenerationException(ConvexHullCreationResultOutcome error, string errorMessage)
 {
     ErrorMessage = errorMessage;
     Error        = error;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a convex hull given the original vertices of a mesh.
 /// </summary>
 /// <param name="original">The original mesh</param>
 /// <param name="resultOutcome">The outcome of the process (successfull or unsuccessful)</param>
 /// <param name="PlaneDistanceTolerance">The plane distance tolerance</param>
 /// <returns>The output mesh data of the convex hull</returns>
 public static MeshData GenerateConvexHull(this Mesh original, out ConvexHullCreationResultOutcome resultOutcome, double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
 {
     return(original.vertices.GenerateConvexHull(out resultOutcome, PlaneDistanceTolerance));
 }