Beispiel #1
0
        private void tbWizard_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (e.TabPage == this.tbPreview)
            {
                this.magsAIPreview1.GLControl = this.magsAIOrientationTabPanel1.GLControl;
                ToolbarActionsManager.Update(MainFormToolStripActionType.btnSelectPressed, this.magsAIPreview1.GLControl, null);

                this.magsAIPreview1.GLControl.Render();

                foreach (var model in ObjectView.Objects3D)
                {
                    if (model is STLModel3D && !(model is GroundPane))
                    {
                        var stlModel = model as STLModel3D;

                        if (this.magsAIOrientationTabPanel1.OrientationType == MagsAIOrientationTabPanel.TypeOfOrientation.SelectedTriangles)
                        {
                            //calc new model normal
                            var autorotationNormal = stlModel.Triangles.CalcSelectedOrientationTrianglesNormal();

                            float zAngle; float yAngle;
                            VectorHelper.CalcRotationAnglesYZFromVector(autorotationNormal, false, out zAngle, out yAngle);

                            //rotate model
                            stlModel.Rotate(0, 0, stlModel.RotationAngleZ - zAngle, RotationEventArgs.TypeAxis.Z);
                            stlModel.UpdateDefaultCenter();
                            stlModel.Rotate(0, stlModel.RotationAngleY - yAngle, 0, RotationEventArgs.TypeAxis.Y);
                            stlModel.UpdateDefaultCenter();
                            stlModel.UpdateBoundries();
                        }
                        else
                        {
                            stlModel.Triangles.ClearSelectedOrientationTriangles();
                        }

                        if (this.magsAIMaterialTabPanel1.LiftModelOnSupport)
                        {
                            stlModel.MoveTranslationZ = 5f;
                            stlModel.LiftModelOnSupport();
                        }
                    }
                }
            }
            else if (e.TabPage == this.tbMagsAIOrientation)
            {
                //ToolStripActionsManager.Update(MainFormToolStripActionType.btnLayFlatPressed, frmStudioMain.SceneControl);
            }
        }
        private void Update(Vector3Class startPoint, Vector3Class endPoint)
        {
            this.StartPoint = startPoint;
            this.EndPoint   = endPoint;

            float yAngle = 0f;
            float zAngle = 0f;

            VectorHelper.CalcRotationAnglesYZFromVector(endPoint - startPoint, false, out zAngle, out yAngle);

            var diffVector  = endPoint - startPoint;
            var diffVector2 = diffVector;

            diffVector2.Z = 0;
            yAngle        = VectorHelper.CalcAngleBetweenVectorPoints(new Vector2(diffVector2.Length, 0), new Vector2(0, 0), new Vector2(diffVector2.Length, diffVector.Z));
            var totalHeight = (endPoint - startPoint).Length;

            if (this.Triangles == null)
            {
                this.Triangles = new TriangleInfoList();
            }
            this.Triangles[0].Clear();

            this.Triangles = new TriangleInfoList();

            var capPointsCount = 26;
            var capPoints      = VectorHelper.CreateCircle(0, this.Radius, capPointsCount, true);

            var rotationMatrix = Matrix4.CreateRotationY(OpenTK.MathHelper.DegreesToRadians(yAngle));

            for (var capPointIndex = 0; capPointIndex < capPointsCount; capPointIndex++)
            {
                var rotatedVector     = Vector3Class.Transform(capPoints[capPointIndex], rotationMatrix);
                var rotationXYScaling = capPoints[capPointIndex].X / rotatedVector.X;
                capPoints[capPointIndex] = new Vector3Class(capPoints[capPointIndex].X, capPoints[capPointIndex].Y, rotatedVector.Z * rotationXYScaling);
            }

            for (var capPointIndex = 0; capPointIndex < capPointsCount; capPointIndex++)
            {
                var capTriangle = new Triangle();
                capTriangle.Vectors[0].Position = capPoints[capPointIndex];
                capTriangle.Vectors[1].Position = capPoints[capPointIndex == capPointsCount - 1 ? 0 : capPointIndex + 1];
                //capTriangle.Vectors[2].Position = startPoint;
                capTriangle.CalcNormal();
                this.Triangles[0].Add(capTriangle);
            }

            //bottom capPoints
            for (var capPointIndex = 0; capPointIndex < capPointsCount; capPointIndex++)
            {
                var bottomCapTriangle = (Triangle)this.Triangles[0][capPointIndex].Clone();
                bottomCapTriangle.Flip();
                this.Triangles[0].Add(bottomCapTriangle);
            }

            //move top cap to total height
            for (var capPointIndex = 0; capPointIndex < capPointsCount; capPointIndex++)
            {
                this.Triangles[0][capPointIndex].Vectors[0].Position.Z += totalHeight;
                this.Triangles[0][capPointIndex].Vectors[1].Position.Z += totalHeight;
                this.Triangles[0][capPointIndex].Vectors[2].Position.Z += totalHeight;
            }

            //create cylinder triangles
            for (var capPointIndex = 0; capPointIndex < capPointsCount; capPointIndex++)
            {
                var leftTriangle = new Triangle();
                leftTriangle.Vectors[0].Position = this.Triangles[0][capPointIndex].Vectors[0].Position;
                leftTriangle.Vectors[1].Position = this.Triangles[0][capPointIndex + capPointsCount].Vectors[0].Position;
                leftTriangle.Vectors[2].Position = this.Triangles[0][capPointIndex + capPointsCount].Vectors[2].Position;
                leftTriangle.CalcNormal();
                this.Triangles[0].Add(leftTriangle);

                var rightTriangle = new Triangle();
                rightTriangle.Vectors[0].Position = this.Triangles[0][capPointIndex].Vectors[0].Position;
                rightTriangle.Vectors[1].Position = this.Triangles[0][capPointIndex + capPointsCount].Vectors[2].Position;
                rightTriangle.Vectors[2].Position = this.Triangles[0][capPointIndex].Vectors[1].Position;
                rightTriangle.CalcNormal();
                this.Triangles[0].Add(rightTriangle);
            }

            this.UpdateBoundries();
            this.Rotate(0, 90 - yAngle, 0, Events.RotationEventArgs.TypeAxis.Y, updateFaceColor: false);
            this.Rotate(0, 0, zAngle, Events.RotationEventArgs.TypeAxis.Z, updateFaceColor: false);
            foreach (var triangle in this.Triangles[0])
            {
                triangle.Vectors[0].Position += startPoint;
                triangle.Vectors[1].Position += startPoint;
                triangle.Vectors[2].Position += startPoint;
            }

            this.UpdateBoundries();
        }
Beispiel #3
0
        internal SupportConeV2(float topHeight, float topRadius, float middleRadius, float bottomHeight, float bottomRadius, int slicesCount, TriangleIntersection modelIntersection, Color color, STLModel3D stlModel = null, bool groundSupport = true, bool useSupportPenetration = false, STLModel3D surfaceTriangles = null, TypeSupportCone supportConeType = TypeSupportCone.Normal, float bottomWidthCorrection = 0f,
                               float aSegmentRadius = float.MinValue, float aSegmentHeight = float.MinValue, float bSegmentRadius = float.MinValue, float bSegmentHeight = float.MinValue, float cSegmentRadius = float.MinValue, float dSegmentRadius = float.MinValue, float dSegmentHeight = float.MinValue, bool calcSliceContours = true)
        {
            this._color = color;

            this.SupportConeVersion = TypeSupportConeVersion.Version2;

            this.ModelIntersection = modelIntersection;

            this.ASegmentHeight = aSegmentHeight;
            this.ASegmentRadius = aSegmentRadius;
            this.BSegmentHeight = bSegmentHeight;
            this.BSegmentRadius = bSegmentRadius;
            this.CSegmentRadius = cSegmentRadius;
            this.DSegmentHeight = dSegmentHeight;
            this.DSegmentRadius = dSegmentRadius;

            //supportcone properties
            this.TopRadius    = topRadius;
            this.TopHeight    = topHeight;
            this.MiddleRadius = middleRadius;
            this.BottomHeight = bottomHeight;
            this.BottomRadius = bottomRadius;

            this.MiddleRadius = bSegmentRadius;
            middleRadius      = bSegmentRadius;

            //determine rotation angle
            float angleY;
            float angleZ;

            VectorHelper.CalcRotationAnglesYZFromVector(modelIntersection.Normal, false, out angleZ, out angleY);

            var aSegmentRotationY = 0f;

            this._rotationAngleY = angleY;
            this._rotationAngleZ = angleZ;

            if (angleZ < 0)
            {
                this._rotationAngleZ = 360 + angleZ;
            }

            if (this.RotationAngleY > 180 && this.RotationAngleY < 270f)
            {
                this._rotationAngleY = 225 - (((270f - this.RotationAngleY) / 90f) * 45f);
                aSegmentRotationY    = 270 - (270f - angleY);
            }
            else if (this.RotationAngleY > 90 && this.RotationAngleY < 180)
            {
                this._rotationAngleY = 180 - (((180 - this.RotationAngleY) / 90f) * 45f);
                aSegmentRotationY    = 180 - (180 - angleY);
            }

            //create segments
            this.ASegment = new Sphere(aSegmentRadius, new Vector3(),
                                       Sphere.eSubdivisions.Two,
                                       new Sphere.eDir[] { Sphere.eDir.All },
                                       modelIntersection.IntersectionPoint,
                                       new Structs.Byte4Class(this.Color.A, color.R, color.G, color.B)
                                       );

            this.RefPointCSegment = new Vector3Class(0, 0, aSegmentHeight + bSegmentHeight + cSegmentRadius);
            var refPointRotationVector = this.Rotate(this.RotationAngleY, this.RotationAngleZ, this.RefPointCSegment);

            this.RefPointCSegment = refPointRotationVector + modelIntersection.IntersectionPoint;
            var refPointCSegmentXY = new Vector3Class(this.RefPointCSegment.X, this.RefPointCSegment.Y, 0);

            refPointRotationVector.Normalize();



            var middleHeight = this.RefPointCSegment.Z - cSegmentRadius - dSegmentHeight - topHeight - bottomHeight;

            //add bottom caps to b-seqment
            this.BSegment = Cone.Create(bSegmentRadius, aSegmentRadius - 0.1f, (aSegmentRadius / 2) + bSegmentHeight + cSegmentRadius, slicesCount, new Vector3Class());

            //rotate B segment using normal
            this.BSegment.Rotate(this.RotationAngleY, this.RotationAngleZ);
            this.BSegment.Translate(modelIntersection.IntersectionPoint);
            this.BSegmentCap = new ConeCap(this.RefPointCSegment, this.BSegment.BottomPoints, false);

            //merge a and b-segments
            //var aSegmentBottomPoints = this.ASegment.BottomPoints;
            var bSegmentTopPoints = this.BSegment.TopPoints;


            //middle circle
            this.CSegment = (new Sphere(cSegmentRadius * 1.1f,
                                        new Vector3(),
                                        Sphere.eSubdivisions.Two,
                                        new Sphere.eDir[] { Sphere.eDir.All },
                                        this.RefPointCSegment,
                                        new Structs.Byte4Class(this.Color.A, color.R, color.G, color.B)));

            if (middleHeight >= 0f)
            {
                this.DSegment = Cone.Create(dSegmentRadius, topRadius, dSegmentHeight + cSegmentRadius, slicesCount, this.RefPointCSegment - new Vector3Class(0, 0, (dSegmentHeight + cSegmentRadius)));

                this.TopSupportCone    = Cone.Create(topRadius, middleRadius, topHeight, slicesCount, this.RefPointCSegment - new Vector3Class(0, 0, dSegmentHeight + cSegmentRadius + topHeight));
                this.MiddleSupportCone = Cone.Create(middleRadius, middleRadius + (middleHeight * bottomWidthCorrection / 100f), middleHeight, slicesCount, refPointCSegmentXY + new Vector3Class(0, 0, bottomHeight));
            }
            else
            {
                this.DSegment          = new Cone();
                this.TopSupportCone    = new Cone();
                this.MiddleSupportCone = Cone.Create(middleRadius, middleRadius, (this.RefPointCSegment.Z - this.BottomHeight), slicesCount, refPointCSegmentXY + new Vector3Class(0, 0, this.BottomHeight));
            }

            this.BottomSupportCone = Cone.Create(middleRadius + (middleHeight * (bottomWidthCorrection / 100f)), bottomRadius + (middleHeight * (bottomWidthCorrection / 100f)), bottomHeight, slicesCount, refPointCSegmentXY);
            var capPoints      = VectorHelper.CreateCircle(0, bottomRadius + (middleHeight * bottomWidthCorrection / 100f), slicesCount, false);
            var supportConeCap = base.CreateCap(capPoints, new Vector3Class(), new Vector3Class(), false);

            foreach (var supportConeCapPoint in supportConeCap[0])
            {
                supportConeCapPoint.Vectors[0].Position += refPointCSegmentXY;
                supportConeCapPoint.Vectors[1].Position += refPointCSegmentXY;
                supportConeCapPoint.Vectors[2].Position += refPointCSegmentXY;
            }
            this.BottomSupportCone[0].AddRange(supportConeCap[0]);

            this.Triangles = new TriangleInfoList();
            this.Triangles[0].AddRange(this.TotalTriangles);

            foreach (var triangle in this.Triangles[0])
            {
                triangle.CalcMinMaxX();
                triangle.CalcMinMaxY();
                triangle.CalcMinMaxZ();
                triangle.CalcCenter();
                triangle.UpdateColor(this.ColorAsByte4, true);
            }

            this.UpdateBoundries();

            if (this.VBOIndexes == null || this.VBOIndexes.Length == 0)
            {
                this.BindModel();
                this.UpdateBinding();
            }
        }
        private void btnGenerateSupport_Click(object sender, EventArgs e)
        {
            this.btnGenerateSupport.Enabled = false;
            var selectedModel = ObjectView.SelectedModel;

            selectedModel.SupportBasement = false;

            //calc new model normal
            var autorotationNormal = selectedModel.Triangles.CalcSelectedOrientationTrianglesNormal();

            float zAngle; float yAngle;

            VectorHelper.CalcRotationAnglesYZFromVector(autorotationNormal, false, out zAngle, out yAngle);

            //rotate model
            if (!float.IsNaN(zAngle) && zAngle != 0)
            {
                selectedModel.Rotate(0, 0, selectedModel.RotationAngleZ - zAngle, RotationEventArgs.TypeAxis.Z);
                selectedModel.UpdateDefaultCenter();
            }

            if (!float.IsNaN(yAngle) && yAngle != 0)
            {
                selectedModel.Rotate(0, selectedModel.RotationAngleY - yAngle, 0, RotationEventArgs.TypeAxis.Y);
                selectedModel.UpdateDefaultCenter();
            }

            selectedModel.UpdateBoundries();
            selectedModel.MoveTranslationZ = 5f;
            selectedModel.LiftModelOnSupport();
            selectedModel.UpdateBinding();
            selectedModel.Triangles.UpdateSelectedOrientationTriangles(selectedModel);

            //   frmStudioMain.SceneControl.Enabled = false;
            Task.Run(() => {
                try { Core.Engines.MagsAI.MagsAIEngine.Calculate(selectedModel, PrintJobManager.CurrentPrintJobSettings.Material, PrintJobManager.SelectedPrinter); }
                catch {
                }
            }).ContinueWith(s =>
            {
                frmStudioMain.SceneControl.EnableRendering();
                if (UserProfileManager.UserProfile.Settings_Use_Support_Basement)
                {
                    selectedModel.SupportBasement = true;
                }

                if (this.btnGenerateSupport.InvokeRequired)
                {
                    this.btnGenerateSupport.Invoke(new MethodInvoker(

                                                       delegate
                    {
                        this.btnGenerateSupport.Enabled = true;
                    }
                                                       ));
                }
                else
                {
                    this.btnGenerateSupport.Enabled = true;
                }
            }).ContinueWith(t => {
                MAGSAICompleted?.Invoke(null, null);
            }, CancellationToken.None, TaskContinuationOptions.None,
                            TaskScheduler.FromCurrentSynchronizationContext());
        }