0

Refreshing Viewport

Anonymous 5 years ago 0
This discussion was imported from CodePlex

murray_b wrote at 2012-04-23 05:33:

Hi Objo

I am having issues with drawing of a line on the viewport.

I am drawing by mousedown and mousemove. With the mousemove reseting the second point in the line LineVisual3D.

What I am not getting is the line being drawn on the viewport. Even once I stop the drawing (using MouseUp) it is not until I rotate the viewport that the line is drawn on the viewport.

I am sure I am missing something simple here but I can't work out what it is. Any ideas what I might be doing wrong to not have the viewport automatically refreshing. Is there a method I can call to force the redraw?

thanks


Murray

  private void HViewPortMouseDown(object sender, MouseButtonEventArgs e)
        {
            // first see if they have selected an item only allow selection of drillholes
            var helix = (HelixViewport3D) sender;
            Point position = e.GetPosition(helix);
            Visual3D obj = helix.FindNearestVisual(position);
            if (obj != null)
            {
                // First create a new line

                _measureline = new LinesVisual3D {Color = Colors.White};
                _measureline.DepthOffset = 0.001;
                _measureLinePoint2 = new Point3D();

                Point3D? findNearestPoint = helix.FindNearestPoint(position);

                if (findNearestPoint != null)
                {
                    _measureline.Points.Add((Point3D) findNearestPoint);
                    _measureLinePoint2 = (Point3D) findNearestPoint;
                    _measureline.Points.Add(_measureLinePoint2);

                    Children.Add(_measureline);
                    RaisePropertyChanged("_measureline");
                    _measuring = true;
                    MouseMove += HViewPortMouseMove;
                }
            }
        }

        private void HViewPortMouseMove(object sender, MouseEventArgs e)
        {
            if (_measuring)
            {
                var helix = (HelixViewport3D) sender;
                Point position = e.GetPosition(helix);
                Point3D? obj = helix.FindNearestPoint(position);
                _measureline.Points.Remove(_measureLinePoint2);
                if (obj != null) _measureLinePoint2 = (Point3D) obj;
                _measureline.Points.Add(_measureLinePoint2);


                RaisePropertyChanged("_measureline");
                RaisePropertyChanged("Objects");
            }
        }

        private void HViewPortMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (_measuring)
            {
                //   Objects.Remove(_measureline);
                _measuring = false;
            }
        }


murray_b wrote at 2012-04-23 05:55:

Ok

So I have discovered this is a bug with LinesVisual3d.

Because If I change the code to use a PipeVisual3d it works fine.

Regards

Murray


objo wrote at 2012-04-25 07:05:

Notice that the LinesVisual3D.Points property is an IList (not implementing INotifyCollectionChanged). This means the visual will not be redrawn until you change the property (replace the points collection) or change the camera (since this is a visual in screen space). 

PipeVisual3D is updated every time you change the Point1 or Point2 properties.


xpix wrote at 2014-02-14 12:28:

Hello,

i guess i have the same Problem. I want to use the LinesVisual3d and not the pipes. At this time, i have a one Question. How can i reset the camera without move to start position? As i right understand, to redraw the LinesVisual3d i have to move the camera a little bit. Or can i use a special event or methode to redraw the screen and the camera pos is still?

Here my short code:
        public void refreshCamera(){
            camera.UpDirection = new Vector3D(camera.UpDirection.X, camera.UpDirection.Y, camera.UpDirection.Z);
            camera.Position = new Point3D(camera.Position.X, camera.Position.Y, camera.Position.Z);
            camera.LookDirection = new Vector3D(camera.LookDirection.X - 0.001, camera.LookDirection.Y, camera.LookDirection.Z);
            camera.LookAt(new Point3D(0, 0, 0), 1);

            viewport.ResetCamera();
        }
Please help :)

objo wrote at 2014-02-19 21:03:

This may be a defect. It should be possible to change the points on the line and redraw without changing camera position. Please create an example and add an issue!