Пример #1
0
        /// <summary>
        /// For every T Junction add a vertex to the mesh edge that needs one.
        /// </summary>
        /// <param name="mesh"></param>
        public static void RepairTJunctions(this Mesh mesh)
        {
            var nonManifoldEdges = mesh.GetNonManifoldEdges();

            foreach (MeshEdge edge in nonManifoldEdges)
            {
                IVertex start  = edge.VertexOnEnd[0];
                IVertex end    = edge.VertexOnEnd[1];
                Vector3 normal = (end.Position - start.Position).GetNormal();

                // Get all the vertices that lay on this edge
                foreach (var vertex in mesh.Vertices)
                {
                    // test if it falls on the edge
                    // split the edge at them
                    IVertex  createdVertex;
                    MeshEdge createdMeshEdge;
                    mesh.SplitMeshEdge(edge, out createdVertex, out createdMeshEdge);
                    createdVertex.Position = vertex.Position;
                    createdVertex.Normal   = vertex.Normal;
                    mesh.MergeVertices(vertex, createdVertex);
                }
            }

            throw new NotImplementedException();

            // and merge the mesh edges that are now manifold
            //mesh.MergeMeshEdges(CancellationToken.None);
        }
Пример #2
0
        public static bool IsManifold(this Mesh mesh)
        {
            var nonManifoldEdges = mesh.GetNonManifoldEdges();

            if (nonManifoldEdges.Count == 0)
            {
                return(true);
            }

            // Every non-manifold edge must have matching non-manifold edge(s) that it lines up with.
            // If this is true the model is still functionally manifold.

            return(false);
        }
        private static ImageBuffer BuildImageFromSTL(Mesh loadedMesh, string stlHashCode, Point2D size)
        {
            if(loadedMesh != null)
            {
                ImageBuffer tempImage = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());
                Graphics2D partGraphics2D = tempImage.NewGraphics2D();
                partGraphics2D.Clear(new RGBA_Bytes());

                AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox();
                double maxSize = Math.Max(aabb.XSize, aabb.YSize);
                double scale = size.x / (maxSize * 1.2);
                RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh,
                    new Vector2((size.x / scale - bounds2D.Width) / 2 - bounds2D.Left,
                        (size.y / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
                    scale, RGBA_Bytes.White);

                List<MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges();
                if (nonManifoldEdges.Count > 0)
                {
                    if (File.Exists("RunUnitTests.txt"))
                    {
                        partGraphics2D.Circle(size.x / 4, size.x / 4, size.x / 8, RGBA_Bytes.Red);
                    }
                }

                // and save it to disk
                string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath;
                string folderToSavePrintsTo = Path.Combine(applicationUserDataPath, "data", "temp", "thumbnails");
                string tgaFileName = Path.Combine(folderToSavePrintsTo, "{0}_{1}x{2}.tga".FormatWith(stlHashCode, size.x, size.y));

                if (!Directory.Exists(folderToSavePrintsTo))
                {
                    Directory.CreateDirectory(folderToSavePrintsTo);
                }
                ImageTgaIO.SaveImageData(tgaFileName, tempImage);

                // and give it back
                return tempImage;
            }

            return null;
        }