예제 #1
0
        private void CreateBase(List <MeshGroup> meshesList, List <Matrix4X4> meshTransforms, List <PlatingMeshGroupData> platingDataList)
        {
            if (meshesList.Count > 0)
            {
                AxisAlignedBoundingBox bounds = meshesList[0].GetAxisAlignedBoundingBox(meshTransforms[0]);
                for (int i = 1; i < meshesList.Count; i++)
                {
                    bounds = AxisAlignedBoundingBox.Union(bounds, meshesList[i].GetAxisAlignedBoundingBox(meshTransforms[i]));
                }

                double          roundingScale = 20;
                RectangleDouble baseRect      = new RectangleDouble(bounds.minXYZ.x, bounds.minXYZ.y, bounds.maxXYZ.x, bounds.maxXYZ.y);
                baseRect.Inflate(2);
                baseRect *= roundingScale;
                RoundedRect baseRoundedRect = new RoundedRect(baseRect, 1 * roundingScale);

                Mesh baseMeshResult = VertexSourceToMesh.Extrude(baseRoundedRect, unscaledBaseHeight / 2 * roundingScale * sizeScrollBar.Value * heightScrollBar.Value);

                baseMeshResult.Transform(Matrix4X4.CreateScale(1 / roundingScale));

                meshesList.Add(new MeshGroup(baseMeshResult));
                platingDataList.Add(new PlatingMeshGroupData());
                meshTransforms.Add(Matrix4X4.CreateTranslation(0, 0, 0));
                PlatingHelper.CreateITraceableForMeshGroup(platingDataList, meshesList, meshesList.Count - 1, null);
            }
        }
        private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
        {
            int            newIndex = asynchMeshGroups.Count;
            StyledTypeFace typeFace = printer.TypeFaceStyle;

            for (int i = 0; i < currentText.Length; i++)
            {
                string          letter        = currentText[i].ToString();
                TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

                if (CharacterHasMesh(letterPrinter, letter))
                {
                    Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);

                    asynchMeshGroups.Add(new MeshGroup(textMesh));

                    PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

                    newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
                    asynchPlatingDatas.Add(newMeshInfo);
                    asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, null);
                    ScaleRotateTranslate moved = asynchMeshGroupTransforms[newIndex];
                    moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));
                    asynchMeshGroupTransforms[newIndex] = moved;

                    newIndex++;
                }

                processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
            }
        }
예제 #3
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                var path = new VertexStorage();
                path.MoveTo(Width / 2, 0);

                for (int i = 1; i < Sides; i++)
                {
                    var angle = MathHelper.Tau * i / 2 / (Sides - 1);
                    path.LineTo(Math.Cos(angle) * Width / 2, Math.Sin(angle) * Width / 2);
                }

                var mesh = VertexSourceToMesh.Extrude(path, Depth);
                mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                Mesh = mesh;

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
예제 #4
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var sides = Sides.ClampIfNotCalculated(this, 3, 180, ref valuesChanged);
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(Width.Value(this) / 2, 0);

                    for (int i = 1; i < sides; i++)
                    {
                        var angle = MathHelper.Tau * i / 2 / (sides - 1);
                        path.LineTo(Math.Cos(angle) * Width.Value(this) / 2, Math.Sin(angle) * Width.Value(this) / 2);
                    }

                    var mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
                    mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                    Mesh = mesh;
                }
            }

            Invalidate(InvalidateType.DisplayValues);

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
예제 #5
0
        private void insertTextBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            asynchMeshGroups.Clear();
            asynchMeshGroupTransforms.Clear();
            asynchPlatingDatas.Clear();

            string          currentText  = (string)e.Argument;
            TypeFacePrinter printer      = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
            Vector2         size         = printer.GetSize(currentText);
            double          centerOffset = -size.x / 2;

            double ratioPerMeshGroup = 1.0 / currentText.Length;
            double currentRatioDone  = 0;

            for (int i = 0; i < currentText.Length; i++)
            {
                int newIndex = asynchMeshGroups.Count;

                TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
                Mesh            textMesh      = VertexSourceToMesh.Extrude(letterPrinter, 10 + (i % 2));

                if (textMesh.Faces.Count > 0)
                {
                    asynchMeshGroups.Add(new MeshGroup(textMesh));

                    PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

                    newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
                    asynchPlatingDatas.Add(newMeshInfo);
                    asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
                    {
                        continueProcessing = true;
                        int nextPercent    = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
                        backgroundWorker.ReportProgress(nextPercent);
                    });

                    currentRatioDone += ratioPerMeshGroup;

                    PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, newIndex);
                }

                backgroundWorker.ReportProgress((i + 1) * 95 / currentText.Length);
            }

            SetWordSpacing(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
            SetWordSize(asynchMeshGroups, asynchMeshGroupTransforms);
            SetWordHeight(asynchMeshGroups, asynchMeshGroupTransforms);

            if (createUnderline.Checked)
            {
                CreateUnderline(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
            }

            backgroundWorker.ReportProgress(95);
        }
예제 #6
0
        public void GenerateBase(Polygons polygonShape, double bottomWithoutBase)
        {
            if (polygonShape != null &&
                polygonShape.Select(p => p.Count).Sum() > 3)
            {
                Polygons polysToOffset = new Polygons();

                switch (BaseType)
                {
                case BaseTypes.Rectangle:
                    polysToOffset.Add(GetBoundingPolygon(polygonShape));
                    break;

                case BaseTypes.Circle:
                    polysToOffset.Add(GetBoundingCircle(polygonShape));
                    break;

                case BaseTypes.Outline:
                    PolyTree polyTreeForBase = GetPolyTree(polygonShape);
                    foreach (PolyNode polyToOffset in polyTreeForBase.Childs)
                    {
                        polysToOffset.Add(polyToOffset.Contour);
                    }
                    break;
                }

                if (polysToOffset.Count > 0)
                {
                    Polygons basePolygons;

                    if (BaseType == BaseTypes.Outline &&
                        InfillAmount > 0)
                    {
                        basePolygons = Offset(polysToOffset, (BaseSize + InfillAmount) * scalingForClipper);
                        basePolygons = Offset(basePolygons, -InfillAmount * scalingForClipper);
                    }
                    else
                    {
                        basePolygons = Offset(polysToOffset, BaseSize * scalingForClipper);
                    }

                    basePolygons = ClipperLib.Clipper.CleanPolygons(basePolygons, 10);

                    VertexStorage rawVectorShape = basePolygons.PolygonToPathStorage();
                    var           vectorShape    = new VertexSourceApplyTransform(rawVectorShape, Affine.NewScaling(1.0 / scalingForClipper));

                    var baseObject = new Object3D()
                    {
                        Mesh = VertexSourceToMesh.Extrude(vectorShape, zHeight: ExtrusionHeight)
                    };
                    Children.Add(baseObject);
                    baseObject.Mesh.Translate(new Vector3(0, 0, -ExtrusionHeight + bottomWithoutBase));
                }
                else
                {
                    // clear the mesh
                    Mesh = null;
                }
            }
        }
        protected IObject3D CreateReach(double reach, double innerDiameter)
        {
            var finWidth  = 4.0;
            var finLength = innerDiameter;

            var pattern = new VertexStorage();

            pattern.MoveTo(0, 0);
            pattern.LineTo(finLength / 2, 0);
            pattern.LineTo(finLength / 2, reach - finLength / 8);
            pattern.LineTo(finLength / 2 - finLength / 8, reach);
            pattern.LineTo(-finLength / 2 + finLength / 8, reach);
            pattern.LineTo(-finLength / 2, reach - finLength / 8);
            pattern.LineTo(-finLength / 2, 0);

            var fin1 = new Object3D()
            {
                Mesh = VertexSourceToMesh.Extrude(pattern, finWidth)
            };

            fin1 = new TranslateObject3D(fin1, 0, 0, -finWidth / 2);
            //fin1.ChamferEdge(Face.Top | Face.Back, finLength / 8);
            //fin1.ChamferEdge(Face.Top | Face.Front, finLength / 8);
            fin1 = new RotateObject3D(fin1, -MathHelper.Tau / 4);
            var fin2 = new SetCenterObject3D(new RotateObject3D(fin1, 0, 0, MathHelper.Tau / 4), fin1.GetCenter());

            return(new Object3D().SetChildren(new List <IObject3D>()
            {
                fin1, fin2
            }));
        }
예제 #8
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            var rebuildLock = RebuildLock();

            bool valuesChanged = false;

            var height = Height.Value(this);

#if DEBUG
            var bevelSteps = BevelSteps.ClampIfNotCalculated(this, 1, 32, ref valuesChanged);
            var bevelStart = BevelStart.ClampIfNotCalculated(this, 0, height, ref valuesChanged);
            var aabb       = this.GetAxisAlignedBoundingBox();
            var bevelInset = BevelInset.ClampIfNotCalculated(this, 0, Math.Min(aabb.XSize / 2, aabb.YSize / 2), ref valuesChanged);
#endif

            // now create a long running task to do the extrusion
            return(ApplicationController.Instance.Tasks.Execute(
                       "Linear Extrude".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var vertexSource = this.VertexSource;
                List <(double height, double inset)> bevel = null;
#if DEBUG
                if (BevelTop)
                {
                    bevel = new List <(double height, double inset)>();
                    for (int i = 0; i < bevelSteps; i++)
                    {
                        var heightRatio = i / (double)bevelSteps;
                        height = heightRatio * (height - bevelStart) + bevelStart;
                        var insetRatio = (i + 1) / (double)bevelSteps;
                        var inset = Easing.Sinusoidal.In(insetRatio) * -bevelInset;
                        bevel.Add((height, inset));
                    }
                }
#endif

                Mesh = VertexSourceToMesh.Extrude(this.VertexSource, height, bevel);
                if (Mesh.Vertices.Count == 0)
                {
                    Mesh = null;
                }

                UiThread.RunOnIdle(() =>
                {
                    rebuildLock.Dispose();
                    if (valuesChanged)
                    {
                        Invalidate(InvalidateType.DisplayValues);
                    }
                    Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
                });

                return Task.CompletedTask;
            }));
        }
예제 #9
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            return(Task.Run(() =>
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    bool valuesChanged = false;
                    var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
                    var nameToWrite = NameToWrite.Value(this);
                    if (string.IsNullOrWhiteSpace(nameToWrite))
                    {
                        Mesh = PlatonicSolids.CreateCube(20, 10, height);
                    }
                    else
                    {
                        Mesh = null;
                        this.Children.Modify(list =>
                        {
                            list.Clear();

                            var offest = 0.0;
                            double pointsToMm = 0.352778;

                            foreach (var letter in nameToWrite.ToCharArray())
                            {
                                var style = new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), PointSize.Value(this));
                                var letterPrinter = new TypeFacePrinter(letter.ToString(), style)
                                {
                                    ResolutionScale = 10
                                };
                                var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                                list.Add(new Object3D()
                                {
                                    Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height.Value(this)),
                                    Matrix = Matrix4X4.CreateTranslation(offest, 0, 0),
                                    Name = letter.ToString()
                                });

                                offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                            }
                        });
                    }
                }

                UiThread.RunOnIdle(() =>
                {
                    rebuildLock.Dispose();
                    Invalidate(InvalidateType.DisplayValues);
                    Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                });
            }));
        }
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            bool valuesChanged = false;

            if (BevelTop)
            {
                BevelSteps = agg_basics.Clamp(BevelSteps, 1, 32, ref valuesChanged);
                BevelStart = agg_basics.Clamp(BevelStart, 0, Height, ref valuesChanged);
                var aabb = this.GetAxisAlignedBoundingBox();
                BevelInset = agg_basics.Clamp(BevelInset, 0, Math.Min(aabb.XSize / 2, aabb.YSize / 2), ref valuesChanged);
            }

            var rebuildLock = RebuildLock();

            // now create a long running task to process the image
            return(ApplicationController.Instance.Tasks.Execute(
                       "Linear Extrude".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var vertexSource = this.VertexSource;
                List <(double height, double inset)> bevel = null;
                if (BevelTop)
                {
                    bevel = new List <(double height, double inset)>();
                    for (int i = 0; i < BevelSteps; i++)
                    {
                        var heightRatio = i / (double)BevelSteps;
                        var height = heightRatio * (Height - BevelStart) + BevelStart;
                        var insetRatio = (i + 1) / (double)BevelSteps;
                        var inset = Easing.Sinusoidal.In(insetRatio) * -BevelInset;
                        bevel.Add((height, inset));
                    }
                }

                Mesh = VertexSourceToMesh.Extrude(this.VertexSource, Height, bevel);
                if (Mesh.Vertices.Count == 0)
                {
                    Mesh = null;
                }

                rebuildLock.Dispose();

                if (valuesChanged)
                {
                    Invalidate(InvalidateType.DisplayValues);
                }

                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
                return Task.CompletedTask;
            }));
        }
예제 #11
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            return(ApplicationController.Instance.Tasks.Execute(
                       "Generating Text Meshes".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (string.IsNullOrWhiteSpace(NameToWrite))
                    {
                        Mesh = PlatonicSolids.CreateCube(20, 10, Height);
                    }
                    else
                    {
                        Mesh = null;
                        this.Children.Modify(list =>
                        {
                            list.Clear();

                            var offest = 0.0;
                            double pointsToMm = 0.352778;

                            foreach (var letter in this.NameToWrite.ToCharArray())
                            {
                                var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), this.PointSize))
                                {
                                    ResolutionScale = 10
                                };
                                var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                                list.Add(new Object3D()
                                {
                                    Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height),
                                    Matrix = Matrix4X4.CreateTranslation(offest, 0, 0),
                                    Name = letter.ToString()
                                });

                                offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                            }
                        });
                    }
                }

                rebuildLock.Dispose();
                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                return Task.CompletedTask;
            }));
        }
예제 #12
0
        private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
        {
            int            newIndex = asyncMeshGroups.Count;
            StyledTypeFace typeFace = printer.TypeFaceStyle;

            for (int i = 0; i < currentText.Length; i++)
            {
                string          letter        = currentText[i].ToString();
                TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

                if (CharacterHasMesh(letterPrinter, letter))
                {
#if true
                    Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
#else
                    Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
                    // this is the code to make rounded tops
                    // convert the letterPrinter to clipper polygons
                    List <List <IntPoint> > insetPoly = VertexSourceToPolygon.CreatePolygons(letterPrinter);
                    // inset them
                    ClipperOffset clipper = new ClipperOffset();
                    clipper.AddPaths(insetPoly, JoinType.jtMiter, EndType.etClosedPolygon);
                    List <List <IntPoint> > solution = new List <List <IntPoint> >();
                    clipper.Execute(solution, 5.0);
                    // convert them back into a vertex source
                    // merge both the inset and original vertex sources together
                    // convert the new vertex source into a mesh (trianglulate them)
                    // offset the inner loop in z
                    // create the polygons from the inner loop to a center point so that there is the rest of an approximation of the bubble
                    // make the mesh for the bottom
                    // add the top and bottom together
                    // done
#endif

                    asyncMeshGroups.Add(new MeshGroup(textMesh));

                    PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

                    newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
                    asyncPlatingDatas.Add(newMeshInfo);
                    asyncMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, newIndex, null);
                    ScaleRotateTranslate moved = asyncMeshGroupTransforms[newIndex];
                    moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));
                    asyncMeshGroupTransforms[newIndex] = moved;

                    newIndex++;
                }

                processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
            }
        }
예제 #13
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            var roundSegments = RoundSegments.ClampIfNotCalculated(this, 2, 90, ref valuesChanged);

            Invalidate(InvalidateType.DisplayValues);

            using (RebuildLock())
            {
                var height = Height.Value(this);
                var width  = Width.Value(this);
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(width, 0);

                    var range = 360 / 4.0;
                    switch (Round)
                    {
                    case RoundTypes.Up:
                        for (int i = 1; i < roundSegments - 1; i++)
                        {
                            var angle = range / (roundSegments - 1) * i;
                            var rad   = MathHelper.DegreesToRadians(angle);
                            path.LineTo(Math.Cos(rad) * width, Math.Sin(rad) * height);
                        }
                        break;

                    case RoundTypes.Down:
                        for (int i = 1; i < roundSegments - 1; i++)
                        {
                            var angle = range / (roundSegments - 1) * i;
                            var rad   = MathHelper.DegreesToRadians(angle);
                            path.LineTo(width - Math.Sin(rad) * width, height - Math.Cos(rad) * height);
                        }
                        break;
                    }

                    path.LineTo(0, height);

                    Mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
                    Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));

            return(Task.CompletedTask);
        }
예제 #14
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            if (windowService == null)
            {
                throw new ArgumentNullException("windowService");
            }

            if (objectProvider == null)
            {
                throw new ArgumentNullException("objectProvider");
            }

            if (objectProvider.GetObject() is List <List <IntPoint> > polygons)
            {
                var vertexStorage = PlatingHelper.PolygonToVertexStorage(polygons);

                var polygonsMesh = VertexSourceToMesh.Extrude(vertexStorage, zHeight: 30);

                // Position
                var aabb = polygonsMesh.GetAxisAlignedBoundingBox();
                polygonsMesh.Transform(Matrix4X4.CreateTranslation(-aabb.Center));
                polygonsMesh.Transform(Matrix4X4.CreateScale(1.6 / aabb.XSize));

                var systemWindow = new SystemWindow(800, 600);
                var lighting     = new LightingData();

                //Debugger.Launch();
                systemWindow.AfterDraw += (s, e) =>
                {
                    var screenSpaceBounds = systemWindow.TransformToScreenSpace(systemWindow.LocalBounds);

                    WorldView world = new WorldView(screenSpaceBounds.Width, screenSpaceBounds.Height);
                    //world.Translate(new Vector3(0, 0, 0));
                    //world.Rotate(Quaternion.FromEulerAngles(new Vector3(rotateX, 0, 0)));

                    GLHelper.SetGlContext(world, screenSpaceBounds, lighting);
                    GLHelper.Render(polygonsMesh, Color.White);
                    GLHelper.UnsetGlContext();
                };

                using (var displayForm = new OpenGLSystemWindow()
                {
                    AggSystemWindow = systemWindow
                })
                {
                    //System.Diagnostics.Debugger.Launch();
                    windowService.ShowDialog(displayForm);
                }
            }
        }
예제 #15
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            using (RebuildLock())
            {
                var vertexSource = this.VertexSource;
                Mesh = VertexSourceToMesh.Extrude(this.VertexSource, Height);
                if (Mesh.Vertices.Count == 0)
                {
                    Mesh = null;
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
        public VertexStorageObject3D(VertexStorage vertexStorage)
        {
            this.vertexStorage = vertexStorage;

            this.Children.Modify(children =>
            {
                int i = 0;
                foreach (var v in vertexStorage.Vertices())
                {
                    if (!v.IsMoveTo && !v.IsLineTo)
                    {
                        continue;
                    }

                    var localVertex = v;

                    var localIndex = i++;

                    var item = new Object3D()
                    {
                        Mesh   = CreateCylinder(1, 1),
                        Matrix = Matrix4X4.CreateTranslation(v.position.X, v.position.Y, 0),
                        Color  = Color.Green
                    };

                    item.Invalidated += (s, e) =>
                    {
                        System.Diagnostics.Debugger.Break();
                        //vertexStorage.modify_vertex(localIndex, item.Matrix.Position.X, localVertex.position.Y = item.Matrix.Position.Y);
                    };

                    children.Add(item);
                }

                children.Add(generatedMesh = new Object3D()
                {
                    Mesh  = VertexSourceToMesh.Extrude(vertexStorage, 0.5),
                    Color = new Color("#93CEFF99")
                });
            });

            this.Invalidated += (s, e) =>
            {
                // Recompute path from content
                generatedMesh.Mesh = VertexSourceToMesh.Extrude(vertexStorage, 0.5);
                //VertexSourceToMesh.Revolve(vertexStorage));
            };
        }
예제 #17
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            return(ApplicationController.Instance.Tasks.Execute(
                       "Mirror".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify((List <IObject3D> list) =>
                    {
                        list.Clear();

                        var offest = 0.0;
                        double pointsToMm = 0.352778;
                        foreach (var letter in NameToWrite.ToCharArray())
                        {
                            var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize))
                            {
                                ResolutionScale = 10
                            };
                            var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
                            IObject3D letterObject = new Object3D()
                            {
                                Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, Height)
                            };

                            letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
                            list.Add(letterObject);

                            offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                        }
                    });
                }

                rebuildLock.Dispose();
                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                return Task.CompletedTask;
            }));
        }
예제 #18
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                this.Children.Modify((list) =>
                {
                    list.Clear();

                    var offest        = 0.0;
                    double pointsToMm = 0.352778;
                    foreach (var letter in NameToWrite.ToCharArray())
                    {
                        var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize))
                        {
                            ResolutionScale = 10
                        };
                        var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
                        IObject3D letterObject   = new Object3D()
                        {
                            Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, Height)
                        };

                        letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
                        list.Add(letterObject);

                        offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                    }
                });


                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Content));
        }
예제 #19
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            RoundSegments = agg_basics.Clamp(RoundSegments, 3, 360 / 4 - 2, ref valuesChanged);

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(Width, 0);

                    if (Round)
                    {
                        var range = 360 / 4.0;
                        for (int i = 1; i < RoundSegments - 1; i++)
                        {
                            var angle = range / (RoundSegments - 1) * i;
                            var rad   = MathHelper.DegreesToRadians(angle);
                            path.LineTo(Width - Math.Sin(rad) * Width, Height - Math.Cos(rad) * Height);
                        }
                    }

                    path.LineTo(0, Height);

                    Mesh = VertexSourceToMesh.Extrude(path, Depth);
                    Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));

            return(Task.CompletedTask);
        }
예제 #20
0
        override public Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(Width, 0);
                    path.LineTo(Width / 2, Height);

                    var mesh = VertexSourceToMesh.Extrude(path, Depth);
                    mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
                    Mesh = mesh;
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            // now create a long running task to process the image
            return(ApplicationController.Instance.Tasks.Execute(
                       "Linear Extrude".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var vertexSource = this.VertexSource;
                List <(double height, double inset)> bevel = null;
                if (BevelTop)
                {
                    bevel = new List <(double height, double inset)>();
                    for (int i = 0; i < BevelSteps; i++)
                    {
                        var heightRatio = i / BevelSteps;
                        var height = heightRatio * (Height - BevelHeight) + BevelHeight;
                        var insetRatio = (i + 1) / BevelSteps;
                        var inset = insetRatio * -BevelInset;
                        bevel.Add((height, inset));
                    }
                }

                Mesh = VertexSourceToMesh.Extrude(this.VertexSource, Height, bevel);
                if (Mesh.Vertices.Count == 0)
                {
                    Mesh = null;
                }

                rebuildLock.Dispose();
                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
                return Task.CompletedTask;
            }));
        }
예제 #22
0
        public override Task Rebuild()
        {
            IObject3D cancerRibbonStl = Object3D.Load("Cancer_Ribbon.stl", CancellationToken.None);

            cancerRibbonStl = new RotateObject3D(cancerRibbonStl, MathHelper.DegreesToRadians(90));

            var letterPrinter = new TypeFacePrinter(NameToWrite.ToUpper(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), 12));

            IObject3D nameMesh = new Object3D()
            {
                Mesh = VertexSourceToMesh.Extrude(letterPrinter, 5)
            };

            AxisAlignedBoundingBox textBounds = nameMesh.GetAxisAlignedBoundingBox();
            var textArea = new Vector2(25, 6);

            double scale = Math.Min(textArea.X / textBounds.XSize, textArea.Y / textBounds.YSize);

            nameMesh = new ScaleObject3D_3(nameMesh, scale, scale, 2 / textBounds.ZSize);
            nameMesh = new AlignObject3D(nameMesh, FaceAlign.Bottom | FaceAlign.Front, cancerRibbonStl, FaceAlign.Top | FaceAlign.Front, 0, 0, -1);
            nameMesh = new SetCenterObject3D(nameMesh, cancerRibbonStl.GetCenter(), true, false, false);

            nameMesh = new RotateObject3D(nameMesh, 0, 0, MathHelper.DegreesToRadians(50));
            nameMesh = new TranslateObject3D(nameMesh, -37, -14, -1);

            // output two meshes for card holder and text
            this.Children.Modify(list =>
            {
                list.Clear();
                list.Add(cancerRibbonStl);
                list.Add(nameMesh);
            });

            this.Mesh = null;
            this.Invalidate(InvalidateType.Children);
            return(Task.CompletedTask);
        }
예제 #23
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            // now create a long running task to process the image
            return(ApplicationController.Instance.Tasks.Execute(
                       "Linear Extrude".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var vertexSource = this.VertexSource;
                Mesh = VertexSourceToMesh.Extrude(this.VertexSource, Height);
                if (Mesh.Vertices.Count == 0)
                {
                    Mesh = null;
                }

                rebuildLock.Dispose();
                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
                return Task.CompletedTask;
            }));
        }
        public static (Mesh bed, Mesh volume) CreatePrintBedAndVolume(PrinterConfig printer)
        {
            Mesh printerBed  = null;
            Mesh buildVolume = null;

            Vector3 displayVolumeToBuild = Vector3.ComponentMax(printer.Bed.ViewerVolume, new Vector3(1, 1, 1));

            ImageBuffer bedplateImage = CreatePrintBedImage(printer);

            switch (printer.Bed.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);
                    }
                    var bspTree = FaceBspTree.Create(buildVolume);
                    buildVolume.FaceBspTree = bspTree;
                }

                printerBed = PlatonicSolids.CreateCube(displayVolumeToBuild.X, displayVolumeToBuild.Y, 1.8);
                {
                    Face face = printerBed.Faces[0];
                    MeshHelper.PlaceTextureOnFace(face, bedplateImage);
                }
                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);
                    }
                }

                printerBed = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.X / 2, displayVolumeToBuild.Y / 2), 1.8);
                {
                    foreach (Face face in printerBed.Faces)
                    {
                        if (face.Normal.Z > 0)
                        {
                            face.SetTexture(0, bedplateImage);
                            foreach (FaceEdge faceEdge in face.FaceEdges())
                            {
                                faceEdge.SetUv(0, 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();
            }

            var zTop = printerBed.GetAxisAlignedBoundingBox().maxXYZ.Z;

            foreach (Vertex vertex in printerBed.Vertices)
            {
                vertex.Position = vertex.Position - new Vector3(-printer.Bed.BedCenter, zTop + .02);
            }

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

            return(printerBed, buildVolume);
        }
예제 #25
0
        override public Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                    });

                    var brailleText = TextToEncode;
                    if (UseGrade2)
                    {
                        brailleText = BrailleGrade2.ConvertString(brailleText);
                    }

                    double    pointSize  = 18.5;
                    double    pointsToMm = 0.352778;
                    IObject3D textObject = new Object3D();
                    var       offest     = 0.0;

                    TypeFacePrinter textPrinter;
                    if (RenderAsBraille)
                    {
                        textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(typeFace, pointSize));
                    }
                    else
                    {
                        textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
                    }

                    foreach (var letter in brailleText.ToCharArray())
                    {
                        IObject3D       letterObject;
                        TypeFacePrinter letterPrinter;
                        if (RenderAsBraille)
                        {
                            letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(typeFace, pointSize));
                            var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                            // add all the spheres to letterObject
                            letterObject = new Object3D();

                            var vertexCount  = 0;
                            var positionSum  = Vector2.Zero;
                            var lastPosition = Vector2.Zero;
                            // find each dot outline and get it's center and place a sphere there
                            foreach (var vertex in scalledLetterPrinter.Vertices())
                            {
                                switch (vertex.command)
                                {
                                case Agg.ShapePath.FlagsAndCommand.Stop:
                                case Agg.ShapePath.FlagsAndCommand.EndPoly:
                                case Agg.ShapePath.FlagsAndCommand.FlagClose:
                                case Agg.ShapePath.FlagsAndCommand.MoveTo:
                                    if (vertexCount > 0)
                                    {
                                        var    center = positionSum / vertexCount;
                                        double radius = 1.44 / 2;                                                // (center - lastPosition).Length;
                                        var    sphere = new HalfSphereObject3D(radius * 2, 15)
                                        {
                                            Color = Color.LightBlue
                                        };
                                        sphere.Translate(center.X, center.Y);
                                        letterObject.Children.Add(sphere);
                                    }
                                    vertexCount = 0;
                                    positionSum = Vector2.Zero;
                                    break;

                                case Agg.ShapePath.FlagsAndCommand.Curve3:
                                case Agg.ShapePath.FlagsAndCommand.Curve4:
                                case Agg.ShapePath.FlagsAndCommand.LineTo:
                                    vertexCount++;
                                    lastPosition = vertex.position;
                                    positionSum += lastPosition;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
                            var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
                            letterObject = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(scalledLetterPrinter, 1),
                                Color = Color.LightBlue
                            };
                        }

                        letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
                        textObject.Children.Add(letterObject);

                        offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                    }

                    // add a plate under the dots
                    var padding = .9 * pointSize * pointsToMm / 2;
                    var size    = textPrinter.LocalBounds * pointsToMm;

                    // make the base
                    var basePath = new VertexStorage();
                    basePath.MoveTo(0, 0);
                    basePath.LineTo(size.Width + padding, 0);
                    basePath.LineTo(size.Width + padding, size.Height + padding);
                    basePath.LineTo(padding, size.Height + padding);
                    basePath.LineTo(0, size.Height);

                    IObject3D basePlate = new Object3D()
                    {
                        Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight)
                    };

                    basePlate = new AlignObject3D(basePlate, FaceAlign.Top, textObject, FaceAlign.Bottom, 0, 0, .01);
                    basePlate = new AlignObject3D(basePlate, FaceAlign.Left | FaceAlign.Front,
                                                  size.Left - padding / 2,
                                                  size.Bottom - padding / 2);
                    this.Children.Add(basePlate);

                    basePlate.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);

                    // add an optional chain hook
                    if (AddHook)
                    {
                        // x 10 to make it smoother
                        double        edgeWidth      = 3;
                        double        height         = basePlate.ZSize();
                        IVertexSource leftSideObject = new RoundedRect(0, 0, height / 2, height, 0)
                        {
                            ResolutionScale = 10
                        };

                        IVertexSource cicleObject = new Ellipse(0, 0, height / 2, height / 2)
                        {
                            ResolutionScale = 10
                        };

                        cicleObject = new Align2D(cicleObject, Side2D.Left | Side2D.Bottom, leftSideObject, Side2D.Left | Side2D.Bottom, -.01);
                        IVertexSource holeObject = new Ellipse(0, 0, height / 2 - edgeWidth, height / 2 - edgeWidth)
                        {
                            ResolutionScale = 10
                        };
                        holeObject = new SetCenter2D(holeObject, cicleObject.GetBounds().Center);

                        IVertexSource hookPath = leftSideObject.Plus(cicleObject);
                        hookPath = hookPath.Minus(holeObject);

                        IObject3D chainHook = new Object3D()
                        {
                            Mesh   = VertexSourceToMesh.Extrude(hookPath, BaseHeight),
                            Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
                        };

                        chainHook = new AlignObject3D(chainHook, FaceAlign.Left | FaceAlign.Bottom | FaceAlign.Back, basePlate, FaceAlign.Right | FaceAlign.Bottom | FaceAlign.Back, -.01);

                        this.Children.Add(chainHook);
                    }

                    // add the object that is the dots
                    this.Children.Add(textObject);
                    textObject.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
            return(Task.CompletedTask);
        }
예제 #26
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, 1.8);
                {
                    Face face = printerBed.Faces[0];
                    MeshHelper.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)
                        {
                            face.SetTexture(0, BedImage);
                            foreach (FaceEdge faceEdge in face.FaceEdges())
                            {
                                faceEdge.SetUv(0, 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();
        }
예제 #27
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();
        }
예제 #28
0
        public override Task Rebuild()
        {
            var allPaths = SvgParser.GetPaths(this.SvgPath);

            var selectedItems = new HashSet <SvgParser.SvgNodeInfo>(allPaths);

            try
            {
                this.Children.Modify(children =>
                {
                    children.Clear();

                    var svgContent = new List <IObject3D>();

                    int i = 0;
                    foreach (var item in selectedItems)
                    {
                        IVertexSource vertexSource = null;

                        if (item is SvgParser.SvgPolygonInfo polygon)
                        {
                            var storage = new VertexStorage();

                            storage.MoveTo(polygon.Points[0]);

                            for (var j = 1; j < polygon.Points.Count; j++)
                            {
                                storage.LineTo(polygon.Points[j]);
                            }

                            // close
                            storage.LineTo(polygon.Points[0]);

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgPolyLineInfo polyline)
                        {
                            var storage = new VertexStorage();
                            storage.MoveTo(polyline.Points[0]);

                            for (var j = 1; j < polyline.Points.Count; j++)
                            {
                                storage.LineTo(polyline.Points[j]);
                            }

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgLineInfo line)
                        {
                            var storage = new VertexStorage();
                            storage.MoveTo(line.Points[0]);
                            storage.LineTo(line.Points[1]);

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgPathInfo path)
                        {
                            vertexSource = new VertexStorage(path.DString);
                        }
                        else
                        {
                            // Skip unknown type
                            continue;
                        }

                        var flattened = new FlattenCurves(vertexSource)
                        {
                            ResolutionScale = 6
                        };

                        var itemZ = 3 + item.Z + (0.1 * i++);

                        if (item.Fill is SvgColourServer fill)
                        {
                            var fillColor = fill.Colour.GetAggColor();

                            var object3D = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(flattened, itemZ),
                                Color = fillColor,
                                // Flip
                                //Matrix = Matrix4X4.Identity * Matrix4X4.CreateScale(1, -1, 1)
                            };

                            svgContent.Add(object3D);
                        }

                        if (item.Stroke is SvgColourServer stroke)
                        {
                            var aggStroke = new Stroke(flattened, item.StrokeWidth)
                            {
                                LineCap  = LineCap.Round,
                                LineJoin = LineJoin.Round
                            };

                            //							aggStroke.l

                            var strokeObject = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(aggStroke, itemZ),
                                Color = stroke.Colour.GetAggColor()
                            };

                            svgContent.Add(strokeObject);
                        }
                    }

                    var mirror = new MirrorObject3D()
                    {
                        MirrorOn = MirrorObject3D.MirrorAxis.Y_Axis
                    };

                    mirror.Children.Modify(list =>
                    {
                        list.AddRange(svgContent);
                    });

                    mirror.Rebuild();

                    mirror.Matrix = Matrix4X4.CreateScale(0.15);

                    children.Add(mirror);
                });
            }
            catch { }

            return(base.Rebuild());
        }
예제 #29
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();
        }
예제 #30
0
        public override async Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                    });

                    var brailleLetter = new BrailleObject3D()
                    {
                        TextToEncode = Letter.ToString(),
                        BaseHeight   = BaseHeight,
                    };
                    await brailleLetter.Rebuild();

                    this.Children.Add(brailleLetter);

                    var textObject = new TextObject3D()
                    {
                        PointSize   = 46,
                        Color       = Color.LightBlue,
                        NameToWrite = Letter.ToString(),
                        Height      = BaseHeight
                    };

                    await textObject.Rebuild();

                    IObject3D letterObject = new RotateObject3D_2(textObject, Vector3.UnitX, -90);
                    await letterObject.Rebuild();

                    var scaleRatio = Math.Max(letterObject.XSize() / 17, letterObject.ZSize() / 17);
                    if (scaleRatio > 1)
                    {
                        letterObject = new ScaleObject3D(letterObject, 1.0 / scaleRatio, 1, 1.0 / scaleRatio);
                    }
                    letterObject = new AlignObject3D(letterObject, FaceAlign.Bottom | FaceAlign.Front, brailleLetter, FaceAlign.Top | FaceAlign.Front, 0, 0, 3.5);
                    letterObject = new SetCenterObject3D(letterObject, brailleLetter.GetCenter(), true, false, false);
                    this.Children.Add(letterObject);

                    var basePath = new RoundedRect(0, 0, 22, 34, 3)
                    {
                        ResolutionScale = 10
                    };

                    IObject3D basePlate = new Object3D()
                    {
                        Mesh   = VertexSourceToMesh.Extrude(basePath, BaseHeight),
                        Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
                    };

                    basePlate = new AlignObject3D(basePlate, FaceAlign.Bottom | FaceAlign.Back, brailleLetter, FaceAlign.Bottom | FaceAlign.Back);
                    basePlate = new SetCenterObject3D(basePlate, brailleLetter.GetCenter(), true, false, false);
                    this.Children.Add(basePlate);

                    IObject3D underline = await CubeObject3D.Create(basePlate.XSize(), .2, 1);

                    underline = new AlignObject3D(underline, FaceAlign.Bottom, brailleLetter, FaceAlign.Top);
                    underline = new AlignObject3D(underline, FaceAlign.Back | FaceAlign.Left, basePlate, FaceAlign.Front | FaceAlign.Left, 0, .01);
                    this.Children.Add(underline);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
        }