示例#1
0
        public void UpdateControl(SceneViewSelectedRotationAxisType selectedRotationAxis)
        {
            this.SelectedObject = (STLModel3D)ObjectView.SelectedModel;
            if (SelectedObject != null)
            {
                if (this.SelectedObject.LinkedClones.Count > 1 && SceneView.CurrentViewMode == SceneView.ViewMode.ModelRotation)
                {
                    this.Hidden = true;
                    SceneControlToolbarManager.ShowRotationSelectedModelContainsLinkedClonesToolTip();
                }
                else
                {
                    this.Hidden = false;
                    if (selectedRotationAxis != SceneViewSelectedRotationAxisType.Hidden)
                    {
                        this.SelectedRotationAxis = selectedRotationAxis;

                        if (this.SelectedObject != null && !(this.SelectedObject is SupportCone))
                        {
                            //diameter equals front bottom --> back top distance
                            _modelDiameter      = (new Vector3(this.SelectedObject.LeftPoint, this.SelectedObject.FrontPoint, 0) - (new Vector3(this.RightPoint, this.BackPoint, this.TopPoint))).Length;
                            _selectedModelIndex = this.SelectedObject.Index;

                            //initialize triangle array
                            this.Triangles = new TriangleInfoList();

                            //create axis X
                            var rotationAxisXColor = new Byte4Class(240, 255, 0, 0);
                            if (this.SelectedRotationAxis == SceneViewSelectedRotationAxisType.X)
                            {
                                rotationAxisXColor = new Byte4Class(240, 255, 255, 255);
                            }
                            var rotationAxisX = new Torus(_modelDiameter, TORUSOUTSIDERINGDIAMETER, TORUSSEGMENTCOUNT, TORUSSEGMENTBANDCOUNT);
                            foreach (var triangle in rotationAxisX.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = rotationAxisXColor;
                            }


                            //add triangle to stl model
                            rotationAxisX.Rotate(0, 45, 0, Events.RotationEventArgs.TypeAxis.Y, true, false);
                            this.Triangles[0].AddRange(rotationAxisX.Triangles[0]);

                            //create axis Y
                            var rotationAxisY      = new Torus(_modelDiameter, TORUSOUTSIDERINGDIAMETER, TORUSSEGMENTCOUNT, TORUSSEGMENTBANDCOUNT);
                            var rotationAxisYColor = new Byte4Class(241, 0, 255, 0);
                            if (this.SelectedRotationAxis == SceneViewSelectedRotationAxisType.Y)
                            {
                                rotationAxisYColor = new Byte4Class(241, 255, 255, 255);
                            }

                            foreach (var triangle in rotationAxisY.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = rotationAxisYColor;
                            }

                            //add triangle to stl model
                            rotationAxisY.Rotate(45, 0, 0, Events.RotationEventArgs.TypeAxis.X, true, false);
                            this.Triangles[0].AddRange(rotationAxisY.Triangles[0]);

                            //create z rotation axis
                            var rotationAxisZ      = new Torus(_modelDiameter, TORUSOUTSIDERINGDIAMETER, TORUSSEGMENTCOUNT, TORUSSEGMENTBANDCOUNT);
                            var rotationAxisZColor = new Byte4Class(242, 0, 0, 255);
                            if (this.SelectedRotationAxis == SceneViewSelectedRotationAxisType.Z)
                            {
                                rotationAxisZColor = new Byte4Class(242, 255, 255, 255);
                            }
                            foreach (var triangle in rotationAxisZ.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = rotationAxisZColor;
                            }

                            this.Triangles[0].AddRange(rotationAxisZ.Triangles[0]);

                            foreach (var triangle in this.Triangles[0])
                            {
                                triangle.CalcNormal();
                            }

                            //change all triangles center to center of model
                            this.MoveTranslation  = this.SelectedObject.MoveTranslation;
                            this.MoveTranslation += new Vector3Class(0, 0, (this.SelectedObject.TopPoint - this.SelectedObject.BottomPoint) / 2);
                        }
                    }
                    else
                    {
                        //reset bindings
                        this.Triangles = new TriangleInfoList();
                    }

                    if (this.SelectedRotationAxis == SceneViewSelectedRotationAxisType.None)
                    {
                        UpdateSelectedAngleOverlay(this.SelectedObject, RotationEventArgs.TypeAxis.None);
                    }

                    if (this.VBOIndexes == null)
                    {
                        this.BindModel();
                    }
                    else
                    {
                        this.UpdateBinding();
                    }
                }

                this.PreviousSelectedObject = this.SelectedObject;
            }
        }
示例#2
0
        public void UpdateControl(SceneViewSelectedMoveTranslationAxisType selectedMoveTranslationAxis, bool selectedModelChanged)
        {
            if (selectedMoveTranslationAxis != SceneViewSelectedMoveTranslationAxisType.Hidden)
            {
                if (selectedMoveTranslationAxis != SelectedMoveTranslationAxis || this.Triangles == null || this.Triangles.Count == 0 || selectedModelChanged || this.SelectedObject.LinkedClones.Count > 1)
                {
                    this.SelectedMoveTranslationAxis = selectedMoveTranslationAxis;
                    this.SelectedObject = (STLModel3D)ObjectView.SelectedModel;

                    if (SelectedObject != null)
                    {
                        if (SceneView.CurrentViewMode == SceneView.ViewMode.ModelRotation && this.SelectedObject.LinkedClones.Count > 1)
                        {
                            this.Hidden = true;
                            SceneControlToolbarManager.ShowRotationSelectedModelContainsLinkedClonesToolTip();
                        }
                        else
                        {
                            LinkedClone selectedLinkedClone = null;
                            for (var i = 0; i < SelectedObject.LinkedClones.Count; i++)
                            {
                                if (SelectedObject.LinkedClones[i].Selected)
                                {
                                    selectedLinkedClone = SelectedObject.LinkedClones[i];
                                    break;
                                }
                            }

                            var stlModel = SelectedObject;
                            var moveTranslationAxisXColor = new Byte4Class(240, 255, 0, 0);
                            if (this.SelectedMoveTranslationAxis == SceneViewSelectedMoveTranslationAxisType.X)
                            {
                                moveTranslationAxisXColor = new Byte4Class(240, 255, 255, 255);
                            }
                            var centerLeftSide = new Vector3((stlModel.LeftPoint - stlModel.RightPoint) / 2, stlModel.Center.Y, 0);
                            var leftSideCone   = new SceneMoveTranslationGizmoCone(AxisConeHeight - centerLeftSide.X, AxisConeTopHeight, AxisConeTopRadius, AxisConeMiddleRadius, 10, new Vector3Class(), Color.Red);
                            leftSideCone.Rotate(0, -90, 0, Events.RotationEventArgs.TypeAxis.Y, true);
                            foreach (var triangle in leftSideCone.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = moveTranslationAxisXColor;
                            }

                            var centerRightSide = new Vector3((stlModel.RightPoint - stlModel.LeftPoint) / 2, stlModel.Center.Y, 0);
                            var rightSideCone   = new SceneMoveTranslationGizmoCone(AxisConeHeight + centerRightSide.X, AxisConeTopHeight, AxisConeTopRadius, AxisConeMiddleRadius, 10, new Vector3Class(), Color.Red);
                            rightSideCone.Rotate(0, 90, 0, Events.RotationEventArgs.TypeAxis.Y, true);
                            foreach (var triangle in rightSideCone.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = moveTranslationAxisXColor;
                            }

                            //front back
                            var moveTranslationAxisYColor = new Byte4Class(241, 0, 255, 0);
                            if (this.SelectedMoveTranslationAxis == SceneViewSelectedMoveTranslationAxisType.Y)
                            {
                                moveTranslationAxisYColor = new Byte4Class(241, 255, 255, 255);
                            }
                            var centerFrontSide = new Vector3(stlModel.Center.X, (stlModel.FrontPoint - stlModel.BackPoint) / 2, 0);
                            var frontSideCone   = new SceneMoveTranslationGizmoCone(AxisConeHeight + centerFrontSide.Y, AxisConeTopHeight, AxisConeTopRadius, AxisConeMiddleRadius, 10, new Vector3Class(), Color.Green);
                            frontSideCone.Rotate(90, 0, 0, Events.RotationEventArgs.TypeAxis.X, true);
                            foreach (var triangle in frontSideCone.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = moveTranslationAxisYColor;
                            }

                            var centerBackSide = new Vector3(stlModel.Center.X, (stlModel.FrontPoint - stlModel.BackPoint) / 2, 0);
                            var backSideCone   = new SceneMoveTranslationGizmoCone(AxisConeHeight + centerBackSide.Y, AxisConeTopHeight, AxisConeTopRadius, AxisConeMiddleRadius, 10, new Vector3Class(), Color.Green);
                            backSideCone.Rotate(-90, 0, 0, Events.RotationEventArgs.TypeAxis.X, true);
                            foreach (var triangle in backSideCone.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = moveTranslationAxisYColor;
                            }

                            //top bottom
                            var moveTranslationAxisZColor = new Byte4Class(242, 0, 0, 255);
                            if (this.SelectedMoveTranslationAxis == SceneViewSelectedMoveTranslationAxisType.Z)
                            {
                                moveTranslationAxisZColor = new Byte4Class(242, 255, 255, 255);
                            }
                            var topSideCone = new SceneMoveTranslationGizmoCone(AxisConeHeight + ((stlModel.TopPoint - stlModel.BottomPoint) / 2), AxisConeTopHeight, AxisConeTopRadius, AxisConeMiddleRadius, 10, new Vector3Class(), Color.Blue);
                            foreach (var triangle in topSideCone.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = moveTranslationAxisZColor;
                            }

                            var bottomSideCone = new SceneMoveTranslationGizmoCone(AxisConeHeight + ((stlModel.TopPoint - stlModel.BottomPoint) / 2), AxisConeTopHeight, AxisConeTopRadius, AxisConeMiddleRadius, 10, new Vector3Class(), Color.Blue);
                            bottomSideCone.Rotate(180, 0, 0, Events.RotationEventArgs.TypeAxis.X, true);
                            foreach (var triangle in bottomSideCone.Triangles[0])
                            {
                                triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = moveTranslationAxisZColor;
                            }

                            //initialize triangle array
                            this.Triangles = new TriangleInfoList();
                            this.Triangles[0].AddRange(leftSideCone.Triangles[0]);
                            this.Triangles[0].AddRange(rightSideCone.Triangles[0]);
                            this.Triangles[0].AddRange(frontSideCone.Triangles[0]);
                            this.Triangles[0].AddRange(backSideCone.Triangles[0]);

                            if (SelectedObject != null && SelectedObject is SupportCone)
                            {
                                var selectedSupportCone = SelectedObject as SupportCone;
                                var moveTranslation     = new Vector3Class(selectedSupportCone.Center.X, selectedSupportCone.Center.Y, 0);
                                foreach (var triangle in this.Triangles[0])
                                {
                                    triangle.Vectors[0].Position += moveTranslation;
                                    triangle.Vectors[1].Position += moveTranslation;
                                    triangle.Vectors[2].Position += moveTranslation;
                                }

                                this.MoveTranslation = selectedSupportCone.MoveTranslation + new Vector3Class(selectedSupportCone.Model.MoveTranslation.X, selectedSupportCone.Model.MoveTranslation.Y, ((selectedSupportCone.TopPoint - selectedSupportCone.BottomPoint) / 2) + selectedSupportCone.BottomPoint);
                            }
                            else if (selectedLinkedClone != null)
                            {
                                this.Triangles[0].AddRange(topSideCone.Triangles[0]);
                                this.Triangles[0].AddRange(bottomSideCone.Triangles[0]);

                                this.MoveTranslation = selectedLinkedClone.Translation + new Vector3Class(0, 0, ((stlModel.TopPoint - stlModel.BottomPoint) / 2) + stlModel.BottomPoint);
                            }
                            else
                            {
                                this.Triangles[0].AddRange(topSideCone.Triangles[0]);
                                this.Triangles[0].AddRange(bottomSideCone.Triangles[0]);

                                //change all triangles center to center of model
                                if (stlModel.PreviewMoveTranslation.X != 0 || stlModel.PreviewMoveTranslation.Y != 0)
                                {
                                    this.MoveTranslation = stlModel.PreviewMoveTranslation + new Vector3Class(0, 0, (stlModel.TopPoint - stlModel.BottomPoint) / 2);
                                }
                                else
                                {
                                    this.MoveTranslation = stlModel.MoveTranslation + new Vector3Class(0, 0, (stlModel.TopPoint - stlModel.BottomPoint) / 2);
                                }
                            }

                            this.PreviousSelectedObject = SelectedObject;
                        }
                    }
                }
            }
            else
            {
                this.Triangles = new TriangleInfoList();
            }


            if (this.VBOIndexes == null && ObjectView.SelectedModel != null)
            {
                this.BindModel();
            }
            else
            {
                this.UpdateBinding();
            }
        }