Пример #1
0
        /// <summary>
        /// Make boolean difference between two meshes using the CarveSharp library.
        /// </summary>
        /// <param name="mA">Mesh to subtract from.</param>
        /// <param name="mB">Mesh to subtract.</param>
        /// <returns>Mesh difference between MeshA and MeshB.</returns>
        public static Mesh Carve(Mesh mA, Mesh mB, CarveSharp.CarveSharp.CSGOperations Operation)
        {
            if (mA == null || mB == null)
            {
                return(null);
            }
            mA.Weld(Math.PI);
            mB.Weld(Math.PI);

            //MeshA.Faces.ConvertQuadsToTriangles();
            //MeshB.Faces.ConvertQuadsToTriangles();

            var cmA = mA.MeshToCarve();
            var cmB = mB.MeshToCarve();

            var tmp = CarveSharp.CarveSharp.PerformCSG(cmA, cmB, Operation);

            return(tmp.CarveToMesh());
        }
Пример #2
0
        /// <summary>
        /// Make boolean difference between a mesh and a
        /// collection of meshes using the CarveSharp library.
        /// </summary>
        /// <param name="MeshA">Mesh to subtract from.</param>
        /// <param name="Meshes">Meshes to subtract.</param>
        /// <returns>Mesh difference.</returns>
        public static Mesh Carve(Mesh MeshA, IEnumerable <Mesh> Meshes, CarveSharp.CarveSharp.CSGOperations Operation)
        {
            MeshA.Weld(3.14);
            MeshA.Faces.ConvertQuadsToTriangles();
            var tmp = MeshA.MeshToCarve();

            foreach (Mesh m in Meshes)
            {
                if (m == null)
                {
                    continue;
                }
                m.Weld(3.14);
                m.Faces.ConvertQuadsToTriangles();
                var mm = m.MeshToCarve();
                tmp = CarveSharp.CarveSharp.PerformCSG(tmp, mm, Operation);
            }

            return(tmp.CarveToMesh());
        }
Пример #3
0
        /// <summary>
        /// Make boolean difference between two collections
        /// of meshes using the CarveSharp library.
        /// </summary>
        /// <param name="MeshesA">Meshes A.</param>
        /// <param name="MeshesB">Meshes B.</param>
        /// <param name="Operation">Carve operation to perform.</param>
        /// <returns>Mesh difference.</returns>
        public static List <Mesh> Carve(IEnumerable <Mesh> MeshesA, IEnumerable <Mesh> MeshesB, CarveSharp.CarveSharp.CSGOperations Operation)
        {
            List <Mesh> OutMeshes = new List <Mesh>();

            foreach (Mesh mA in MeshesA)
            {
                if (mA == null)
                {
                    continue;
                }
                mA.Weld(3.14);
                //mA.Faces.ConvertQuadsToTriangles();
                CarveMesh temp = mA.MeshToCarve();

                foreach (Mesh m in MeshesB)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    m.Weld(3.14);
                    //m.Faces.ConvertQuadsToTriangles();
                    var cm = m.MeshToCarve();
                    temp = CarveSharp.CarveSharp.PerformCSG(temp, cm, Operation);
                }

                if (temp != null)
                {
                    OutMeshes.Add(temp.CarveToMesh());
                }
            }
            return(OutMeshes);
        }