Пример #1
0
        void CreateMeasureCube(Vector2 startPoint, string text, double width, double height)
        {
            //outerbox
            var cubeModel = new STLModel3D(TypeObject.None, false);
            //cubeModel = (new Cube(12.8f, 8f, 5f)).AsSTLModel3D(Managers.MaterialManager.DefaultMaterial);

            var outerPath         = new Polygon(new PolygonPoint(-(width / 2), -(height / 2)), new PolygonPoint((width / 2), -(height / 2)), new PolygonPoint((width / 2), (height / 2)), new PolygonPoint(-(width / 2), (height / 2)));
            var textAsPolygonSet  = new PolygonSet();
            var letterPolygonsTop = FontTessellationEngine.ConvertStringToTrianglesWithOuterPath(text, FontStyle.Bold, outerPath, out textAsPolygonSet);

            outerPath = new Polygon(new PolygonPoint(-(width / 2), -(height / 2)), new PolygonPoint((width / 2), -(height / 2)), new PolygonPoint((width / 2), (height / 2)), new PolygonPoint(-(width / 2), (height / 2)));
            var letterPolygonsBottom = FontTessellationEngine.ConvertStringToTrianglesWithOuterPath(text, FontStyle.Bold, outerPath, out textAsPolygonSet);

            foreach (var t in letterPolygonsBottom[0])
            {
                t.Flip();
            }

            cubeModel.Triangles = letterPolygonsTop;
            foreach (var t in letterPolygonsTop[0])
            {
                t.Vectors[0].Position += new Vector3Class(0, 0, 5);
                t.Vectors[1].Position += new Vector3Class(0, 0, 5);
                t.Vectors[2].Position += new Vector3Class(0, 0, 5);
            }

            cubeModel.Triangles[0].AddRange(letterPolygonsBottom[0]);

            cubeModel._scaleFactorX = cubeModel._scaleFactorY = cubeModel._scaleFactorZ = 1;
            cubeModel.Scale(0.1f, 0.1f, 1f, Events.ScaleEventArgs.TypeAxis.ALL, true, true);

            CreateExtrudeTriangles(cubeModel, outerPath.Points);
            foreach (var polygon in outerPath.Holes)
            {
                CreateExtrudeTriangles(cubeModel, polygon.Points, true);

                foreach (var holePolygon in polygon.Holes)
                {
                    CreateExtrudeTriangles(cubeModel, holePolygon.Points, true);
                }
            }

            //center triangle
            cubeModel.UpdateBoundries();
            cubeModel.UpdateDefaultCenter();
            cubeModel.Triangles.UpdateWithMoveTranslation(new Vector3Class(startPoint.X, startPoint.Y, 0) - new Vector3Class(cubeModel.LeftPoint, cubeModel.BackPoint, -0.2f));

            //orient model properly
            cubeModel.HorizontalMirror(false, true);
            cubeModel.Rotate(0, 0, 180, Events.RotationEventArgs.TypeAxis.Z);
            cubeModel.UpdateTrianglesMinMaxZ();

            this.Triangles[0].AddRange(cubeModel.Triangles[0]);
        }
Пример #2
0
        internal static void Calculate(STLModel3D model)
        {
            model.UpdateBoundries();

            //properties of right part of trapezoid
            var sideBCAngleOffset = 0f;
            var sideBCAngle       = 90d;
            var sideBDHeight      = Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputC;

            if (Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputA != 70 || Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputB != 120 ||
                Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputC != 70 || Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputD != 120)
            {
                sideBCAngleOffset = (float)(Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputC, 2) - Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputF, 2) + Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputD, 2)) / (2 * Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputD);
                sideBCAngle       = MathHelper.RadiansToDegrees(Math.Acos(-sideBCAngleOffset / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputF));
                sideBDHeight      = (float)Math.Sqrt(Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputC, 2) - Math.Pow(sideBCAngleOffset, 2));
            }

            //properties of left part of trapezoid
            var sideABAngleOffset = 0f;
            var sideABAngle       = 90d;
            var sideABHeight      = Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputA;

            if (Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputA != 70 || Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputB != 120 ||
                Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputC != 70 || Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputD != 120)
            {
                sideABAngleOffset = (float)(Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputA, 2) - Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputE, 2) + Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputB, 2)) / (2 * Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputB);
                sideABAngle       = MathHelper.RadiansToDegrees(Math.Acos(-sideABAngleOffset / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputE));
                sideABHeight      = (float)Math.Sqrt(Math.Pow(Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputA, 2) - Math.Pow(sideABAngleOffset, 2));
            }
            model.UpdateBoundries();
            var moveYFactor = -model.FrontPoint;

            for (var arrayIndex = 0; arrayIndex < model.Triangles.Count; arrayIndex++)
            {
                for (var triangleIndex = 0; triangleIndex < model.Triangles[arrayIndex].Count; triangleIndex++)
                {
                    model.Triangles[arrayIndex][triangleIndex].Vectors[0].Position += new Vector3(0, moveYFactor, 0);
                    model.Triangles[arrayIndex][triangleIndex].Vectors[1].Position += new Vector3(0, moveYFactor, 0);
                    model.Triangles[arrayIndex][triangleIndex].Vectors[2].Position += new Vector3(0, moveYFactor, 0);
                }
            }

            model.UpdateBoundries();

            var modelWidth = model.RightPoint - model.LeftPoint;

            float sideDHeightDifference = (float)(sideABHeight - sideBDHeight);

            if (sideDHeightDifference < 0)
            {
                sideDHeightDifference = -sideDHeightDifference;
            }
            if (sideABAngle <= 90)    //angle A forward /
            {
                var leftSideMaxCorrection = new Vector3((sideABAngleOffset), ((float)(sideABHeight - sideBDHeight)), 0);
                if (sideABHeight >= sideBDHeight)                                       //highest point at right side
                {
                    leftSideMaxCorrection = new Vector3(leftSideMaxCorrection.X, 0, 0); //NO Y correction
                }

                //change model vectors
                for (var arrayIndex = 0; arrayIndex < model.Triangles.Count; arrayIndex++)
                {
                    for (var triangleIndex = 0; triangleIndex < model.Triangles[arrayIndex].Count; triangleIndex++)
                    {
                        for (var vectorIndex = 0; vectorIndex < 3; vectorIndex++)
                        {
                            var orgPoint = model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position;
                            if (orgPoint.X <= 0)
                            {
                                var vectorOffSetPercentageX = orgPoint.Y / (float)sideABHeight;
                                var vectorOffSetPercentageY = 1 - (-orgPoint.X / (modelWidth / 2));

                                var vectorOffSetPercentageYOffset = vectorOffSetPercentageY * (sideDHeightDifference / 2);

                                var correctionVectorY = (vectorOffSetPercentageX * vectorOffSetPercentageYOffset);
                                correctionVectorY = sideABAngle >= sideBDHeight ? -correctionVectorY : correctionVectorY;
                                var correctionVector = new Vector3(leftSideMaxCorrection.X * vectorOffSetPercentageX, correctionVectorY, 0);
                                model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position += correctionVector;
                            }
                        }
                    }
                }
            }
            else if (sideABAngle > 90)    //angle A backward
            {
                var leftSideMaxCorrection = new Vector3(sideABAngleOffset, sideDHeightDifference, 0);
                if (sideABHeight >= sideBDHeight)                                       //highest point at right side
                {
                    leftSideMaxCorrection = new Vector3(leftSideMaxCorrection.X, 0, 0); //NO Y correction
                }

                //change model vectors
                for (var arrayIndex = 0; arrayIndex < model.Triangles.Count; arrayIndex++)
                {
                    for (var triangleIndex = 0; triangleIndex < model.Triangles[arrayIndex].Count; triangleIndex++)
                    {
                        for (var vectorIndex = 0; vectorIndex < 3; vectorIndex++)
                        {
                            var orgPoint = model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position;
                            if (orgPoint.X <= 0)
                            {
                                var vectorOffSetPercentageX = orgPoint.Y / sideABHeight;
                                var vectorOffSetPercentageY = 1 - (-orgPoint.X / (modelWidth / 2));

                                var vectorOffSetPercentageYOffset = vectorOffSetPercentageY * (sideDHeightDifference / 2);
                                var correctionVectorY             = (vectorOffSetPercentageX * vectorOffSetPercentageYOffset);
                                correctionVectorY = sideABAngle >= sideBDHeight ? correctionVectorY : -correctionVectorY;
                                var correctionVector = new Vector3(leftSideMaxCorrection.X * vectorOffSetPercentageX, correctionVectorY, 0);

                                model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position += correctionVector;
                            }
                        }
                    }
                }
            }

            if (sideBCAngle <= 90)    //angle C forward \
            {
                var rightSideMaxCorrection = new Vector3(-sideBCAngleOffset, sideDHeightDifference, 0);

                if (sideABHeight < sideBDHeight)                                          //highest point at right side
                {
                    rightSideMaxCorrection = new Vector3(rightSideMaxCorrection.X, 0, 0); //NO Y correction
                }

                //change model vectors
                for (var arrayIndex = 0; arrayIndex < model.Triangles.Count; arrayIndex++)
                {
                    for (var triangleIndex = 0; triangleIndex < model.Triangles[arrayIndex].Count; triangleIndex++)
                    {
                        for (var vectorIndex = 0; vectorIndex < 3; vectorIndex++)
                        {
                            //var vectorOffSetPercentage = 0f;
                            var orgPoint = model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position;

                            if (orgPoint.X > 0)
                            {
                                var vectorOffSetPercentageX = orgPoint.Y / (float)sideBDHeight;
                                var vectorOffSetPercentageY = ((modelWidth / 2) + orgPoint.X) / modelWidth;
                                var correctionVectorX       = vectorOffSetPercentageX * rightSideMaxCorrection.X;
                                var correctionVectorY       = (vectorOffSetPercentageY * vectorOffSetPercentageX * sideDHeightDifference);
                                correctionVectorY = sideABHeight < correctionVectorY ? -correctionVectorY : correctionVectorY;
                                model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position += new Vector3(-correctionVectorX, correctionVectorY, 0);
                            }
                        }
                    }
                }
            }
            if (sideBCAngle > 90)    //angle C backward /
            {
                var rightSideMaxCorrection = new Vector3(-sideBCAngleOffset, sideDHeightDifference, 0);

                if (sideABHeight < sideBDHeight)                                          //highest point at right side
                {
                    rightSideMaxCorrection = new Vector3(rightSideMaxCorrection.X, 0, 0); //NO Y correction
                }

                //change model vectors
                for (var arrayIndex = 0; arrayIndex < model.Triangles.Count; arrayIndex++)
                {
                    for (var triangleIndex = 0; triangleIndex < model.Triangles[arrayIndex].Count; triangleIndex++)
                    {
                        for (var vectorIndex = 0; vectorIndex < 3; vectorIndex++)
                        {
                            var orgPoint = model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position;
                            if (orgPoint.X > 0)
                            {
                                var vectorOffSetPercentageX = orgPoint.Y / (float)sideBDHeight;
                                var vectorOffSetPercentageY = ((modelWidth / 2) + orgPoint.X) / modelWidth;
                                var correctionVectorX       = vectorOffSetPercentageX * rightSideMaxCorrection.X;
                                var correctionVectorY       = (vectorOffSetPercentageY * vectorOffSetPercentageX * sideDHeightDifference);
                                correctionVectorY = sideABHeight < correctionVectorY ? correctionVectorY : -correctionVectorY;
                                model.Triangles[arrayIndex][triangleIndex].Vectors[vectorIndex].Position += new Vector3(-correctionVectorX, correctionVectorY, 0);
                            }
                        }
                    }
                }
            }

            model.Scale(144 / Managers.PrinterManager.DefaultPrinter.TrapeziumCorrectionInputB, 1, 1, Events.ScaleEventArgs.TypeAxis.X);
            model.Scale(1, 90f / Math.Max(sideABHeight, sideBDHeight), 1, Events.ScaleEventArgs.TypeAxis.Y);
            model.UpdateDefaultCenter();

            //var rotate model with angle of side D

            if (model.SupportStructure != null)
            {
                foreach (var supportCone in model.SupportStructure)
                {
                    ModelCorrections.Trapezoid.Calculate(supportCone);
                }
            }

            if (model.Triangles.HorizontalSurfaces != null && model.Triangles.HorizontalSurfaces.SupportStructure != null)
            {
                foreach (var supportCone in model.Triangles.HorizontalSurfaces.SupportStructure)
                {
                    ModelCorrections.Trapezoid.Calculate(supportCone);
                }
            }

            if (model.Triangles.FlatSurfaces != null && model.Triangles.FlatSurfaces.SupportStructure != null)
            {
                foreach (var supportCone in model.Triangles.FlatSurfaces.SupportStructure)
                {
                    ModelCorrections.Trapezoid.Calculate(supportCone);
                }
            }

            if (model.SupportBasementStructure != null)
            {
                ModelCorrections.Trapezoid.Calculate(model.SupportBasementStructure);
            }
        }