protected override void OnNodeMouse3DMove(object sender, RoutedEventArgs e)
        {
            DraggableGeometryWoSnapModel3D model = sender as DraggableGeometryWoSnapModel3D;

            if (this.isCaptured && model != null)
            {
                model.DragX = this.DragX;
                model.DragY = this.DragY;
                model.DragZ = this.DragZ;
                if (this.Use_OSnapPoint)
                {
                    model.OnMouse3DMoveDelayed(this.OSnapPoint);
                }

                UpdatePosOnly();
                UpdateTransforms(sender);
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // ========================================== TRANSFORMATION METHODS ====================================== //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        // --------------------------------------------- ENDPOINT handles ----------------------------------------- //

        #region Endpoint_Handles

        protected override void OnNodeMouse3DDown(object sender, RoutedEventArgs e)
        {
            var args = e as Mouse3DEventArgs;

            if (args == null)
            {
                return;
            }
            if (args.Viewport == null)
            {
                return;
            }

            this.isCaptured = true;
            Application.Current.MainWindow.Cursor = Cursors.SizeAll;

            // prepare for SNAP
            this.pos_current    = new List <Vector3>(this.pos);
            this.endH_currentTV = new List <Vector3>(this.edgeHandles.Select(x => x.Transform.ToMatrix().TranslationVector).ToArray());

            // update the modifying lines
            int n = this.pos.Count();

            for (int i = 0; i < n; i++)
            {
                if (sender == this.endHandles[i])
                {
                    this.posML_old = pos[i];
                    Matrix ML_t   = Matrix.Translation(this.posML_old);
                    Matrix ML_new = Matrix.Scaling(0f) * ML_t;
                    this.modifyLines.Transform = new MatrixTransform3D(ML_new.ToMatrix3D());

                    DraggableGeometryWoSnapModel3D dgm = sender as DraggableGeometryWoSnapModel3D;
                    if (dgm != null)
                    {
                        dgm.OnMouseDownOverride(pos[i].ToPoint3D());
                    }
                }
            }
            this.modifyLines.Visibility = Visibility.Visible;
        }
예제 #3
0
        protected virtual void UpdateOnCoordsChange()
        {
            // initialize coordinates
            Coords2Pos();

            if (pos == null)
            {
                return;
            }

            this.Children.Clear();

            // initialise handle lists
            int n = pos.Count;

            endHandles      = new List <DraggableGeometryWoSnapModel3D>(n);
            midpointHandles = new List <MeshGeometryModel3D>(n);
            edgeHandles     = new List <MeshGeometryModel3D>(n);

            endH_indInChildren  = new List <int>(n);
            midPH_indInChildren = new List <int>(n);
            edgeH_indInChildren = new List <int>(n);

            // determine scaling factor of grips
            BoundingBox bb         = BoundingBox.FromPoints(pos.ToArray());
            float       avgDistCam = Vector3.Distance(Vector3.Lerp(bb.Maximum, bb.Minimum, 0.5f), this.CamPos.ToVector3());

            this.scaleCamPos = Math.Max(1f, avgDistCam);

            for (int i = 0; i < n; i++)
            {
                // this.scaleCamPos = Vector3.Distance(pos[i], this.CamPos.ToVector3());
                // ENDPOINT handles
                Matrix3D T = Matrix3D.Identity;
                T.Scale(new Vector3D(this.scaleCamPos, this.scaleCamPos, this.scaleCamPos));
                T.Translate(pos[i].ToVector3D());
                var m1 = new DraggableGeometryWoSnapModel3D()
                {
                    Visibility = Visibility.Visible,
                    Material   = this.SelMaterial,
                    Geometry   = NodeGeometry,
                    Transform  = new MatrixTransform3D(T),
                };
                m1.MouseDown3D += OnNodeMouse3DDown;
                m1.MouseMove3D += OnNodeMouse3DMove;
                m1.MouseUp3D   += OnNodeMouse3DUp;
                this.endHandles.Add(m1);
                this.Children.Add(m1);
                this.endH_indInChildren.Add(this.Children.Count - 1);

                // MIDPOINT handles
                Matrix3D M = Matrix3D.Identity;
                M.Scale(new Vector3D(this.scaleCamPos, this.scaleCamPos, this.scaleCamPos));
                M.Translate(Vector3.Lerp(pos[i], pos[(i + 1) % n], 0.5f).ToVector3D());
                var m2 = new MeshGeometryModel3D()
                {
                    Geometry         = MidEdgeGeometry,
                    Material         = this.SelMaterial,
                    Visibility       = Visibility.Visible,
                    IsHitTestVisible = true,
                    Transform        = new MatrixTransform3D(M),
                };
                m2.MouseDown3D += OnMidNodeMouse3DDown;
                m2.MouseMove3D += OnMidNodeMouse3DMove;
                m2.MouseUp3D   += OnMidNodeMouse3DUp;
                this.midpointHandles.Add(m2);
                this.Children.Add(m2);
                this.midPH_indInChildren.Add(this.Children.Count - 1);

                // EDGE handles
                Matrix L  = calcTransf(pos[i], pos[(i + 1) % n], this.scaleCamPos * EDGE_GRIP_SIZE);
                var    m3 = new MeshGeometryModel3D()
                {
                    Geometry         = EdgeGeometry,
                    Material         = this.materialLines,
                    Visibility       = Visibility.Visible,
                    IsHitTestVisible = true,
                    Transform        = new MatrixTransform3D(L.ToMatrix3D()),
                };
                m3.MouseDown3D += OnEdgeMouse3DDown;
                m3.MouseMove3D += OnEdgeMouse3DMove;
                m3.MouseUp3D   += OnEdgeMouse3DUp;
                this.edgeHandles.Add(m3);
                this.Children.Add(m3);
                this.edgeH_indInChildren.Add(this.Children.Count - 1);
            }

            // lines showing Modification along axes (hidden for the moment)
            this.modifyLines = new LineGeometryModel3D()
            {
                Geometry         = LineGeometry,
                Color            = SharpDX.Color.White,
                Thickness        = 0.5,
                Visibility       = Visibility.Hidden,
                IsHitTestVisible = false,
            };
            this.Children.Add(modifyLines);
            this.posML_old = Vector3.Zero;

            // adjust for open / closed polyline
            OnIsPolyLineClosedProperty_IsFalse();

            // !!!!!!! REATTACH TO THE RENDER HOST !!!!!!!
            if (this.renderHost != null)
            {
                Attach(this.renderHost);
            }
        }