Example #1
0
        public void CreatePrintBed(Vector3 displayVolume, Vector2 bedCenter, BedShape bedShape)
        {
            if (MeshViewerWidget.BedCenter == bedCenter &&
                MeshViewerWidget.bedShape == bedShape &&
                MeshViewerWidget.displayVolume == displayVolume)
            {
                return;
            }

            MeshViewerWidget.BedCenter     = bedCenter;
            MeshViewerWidget.bedShape      = bedShape;
            MeshViewerWidget.displayVolume = displayVolume;
            Vector3 displayVolumeToBuild = Vector3.ComponentMax(displayVolume, new Vector3(1, 1, 1));

            double sizeForMarking = Math.Max(displayVolumeToBuild.x, displayVolumeToBuild.y);
            double divisor        = 10;
            int    skip           = 1;

            if (sizeForMarking > 1000)
            {
                divisor = 100;
                skip    = 10;
            }
            else if (sizeForMarking > 300)
            {
                divisor = 50;
                skip    = 5;
            }

            switch (bedShape)
            {
            case BedShape.Rectangular:
                if (displayVolumeToBuild.z > 0)
                {
                    buildVolume = PlatonicSolids.CreateCube(displayVolumeToBuild);
                    foreach (Vertex vertex in buildVolume.Vertices)
                    {
                        vertex.Position = vertex.Position + new Vector3(0, 0, displayVolumeToBuild.z / 2);
                    }
                }
                CreateRectangularBedGridImage(displayVolumeToBuild, bedCenter, divisor, skip);
                printerBed = PlatonicSolids.CreateCube(displayVolumeToBuild.x, displayVolumeToBuild.y, 4);
                {
                    Face face = printerBed.Faces[0];
                    CommonShapes.PlaceTextureOnFace(face, BedImage);
                }
                break;

            case BedShape.Circular:
            {
                if (displayVolumeToBuild.z > 0)
                {
                    buildVolume = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.x / 2, displayVolumeToBuild.y / 2), displayVolumeToBuild.z);
                    foreach (Vertex vertex in buildVolume.Vertices)
                    {
                        vertex.Position = vertex.Position + new Vector3(0, 0, .2);
                    }
                }
                CreateCircularBedGridImage((int)(displayVolumeToBuild.x / divisor), (int)(displayVolumeToBuild.y / divisor), skip);
                printerBed = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.x / 2, displayVolumeToBuild.y / 2), 2);
                {
                    foreach (Face face in printerBed.Faces)
                    {
                        if (face.normal.z > 0)
                        {
                            FaceTextureData faceData = FaceTextureData.Get(face);
                            faceData.Textures.Add(BedImage);
                            foreach (FaceEdge faceEdge in face.FaceEdges())
                            {
                                FaceEdgeTextureUvData edgeUV = FaceEdgeTextureUvData.Get(faceEdge);
                                edgeUV.TextureUV.Add(new Vector2((displayVolumeToBuild.x / 2 + faceEdge.firstVertex.Position.x) / displayVolumeToBuild.x,
                                                                 (displayVolumeToBuild.y / 2 + faceEdge.firstVertex.Position.y) / displayVolumeToBuild.y));
                            }
                        }
                    }
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }

            foreach (Vertex vertex in printerBed.Vertices)
            {
                vertex.Position = vertex.Position - new Vector3(-bedCenter, 2.2);
            }

            if (buildVolume != null)
            {
                foreach (Vertex vertex in buildVolume.Vertices)
                {
                    vertex.Position = vertex.Position - new Vector3(-bedCenter, 2.2);
                }
            }

            Invalidate();
        }
Example #2
0
        public void CreatePrintBed(Vector3 displayVolume, Vector2 bedCenter, BedShape bedShape)
        {
            if (this.bedCenter == bedCenter &&
                this.bedShape == bedShape &&
                this.displayVolume == displayVolume)
            {
                return;
            }

            this.bedCenter     = bedCenter;
            this.bedShape      = bedShape;
            displayVolume      = Vector3.ComponentMax(displayVolume, new Vector3(1, 1, 1));
            this.displayVolume = displayVolume;

            switch (bedShape)
            {
            case BedShape.Rectangular:
                if (displayVolume.z > 0)
                {
                    buildVolume = PlatonicSolids.CreateCube(displayVolume);
                    foreach (Vertex vertex in buildVolume.Vertices)
                    {
                        vertex.Position = vertex.Position + new Vector3(0, 0, displayVolume.z / 2);
                    }
                }
                CreateRectangularBedGridImage((int)(displayVolume.x / 10), (int)(displayVolume.y / 10));
                printerBed = PlatonicSolids.CreateCube(displayVolume.x, displayVolume.y, 4);
                {
                    Face face = printerBed.Faces[0];
                    {
                        FaceTextureData faceData = FaceTextureData.Get(face);
                        faceData.Textures.Add(BedImage);
                        foreach (FaceEdge faceEdge in face.FaceEdges())
                        {
                            FaceEdgeTextureUvData edgeUV = FaceEdgeTextureUvData.Get(faceEdge);
                            edgeUV.TextureUV.Add(new Vector2((displayVolume.x / 2 + faceEdge.firstVertex.Position.x) / displayVolume.x,
                                                             (displayVolume.y / 2 + faceEdge.firstVertex.Position.y) / displayVolume.y));
                        }
                    }
                }
                foreach (Vertex vertex in printerBed.Vertices)
                {
                    vertex.Position = vertex.Position - new Vector3(0, 0, 2.2);
                }
                break;

            case BedShape.Circular:
            {
                if (displayVolume.z > 0)
                {
                    buildVolume = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolume.x / 2, displayVolume.y / 2), displayVolume.z);
                    foreach (Vertex vertex in buildVolume.Vertices)
                    {
                        vertex.Position = vertex.Position + new Vector3(0, 0, .2);
                    }
                }
                CreateCircularBedGridImage((int)(displayVolume.x / 10), (int)(displayVolume.y / 10));
                printerBed = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolume.x / 2, displayVolume.y / 2), 2);
                {
                    foreach (Face face in printerBed.Faces)
                    {
                        if (face.normal.z > 0)
                        {
                            FaceTextureData faceData = FaceTextureData.Get(face);
                            faceData.Textures.Add(BedImage);
                            foreach (FaceEdge faceEdge in face.FaceEdges())
                            {
                                FaceEdgeTextureUvData edgeUV = FaceEdgeTextureUvData.Get(faceEdge);
                                edgeUV.TextureUV.Add(new Vector2((displayVolume.x / 2 + faceEdge.firstVertex.Position.x) / displayVolume.x,
                                                                 (displayVolume.y / 2 + faceEdge.firstVertex.Position.y) / displayVolume.y));
                            }
                        }
                    }
                }

                foreach (Vertex vertex in printerBed.Vertices)
                {
                    vertex.Position = vertex.Position - new Vector3(0, 0, 2.2);
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }

            Invalidate();
        }