Exemplo n.º 1
0
 public override void ToolDeselected(bool preventHistory)
 {
     _state        = SketchState.None;
     _currentFace  = _cloneFace = null;
     _intersection = null;
     _base         = null;
     _depth        = 0;
     _volumePlane  = null;
 }
Exemplo n.º 2
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            //
            switch (_state)
            {
            case SketchState.None:
                // nothin
                break;

            case SketchState.Ready:
                if (e.Button != MouseButtons.Left)
                {
                    break;
                }
                _base = new Polygon(_currentFace.Plane, 1);
                _base.Transform(new UnitTranslate(_intersection - _base.Vertices[0]));
                _state = SketchState.DrawingBase;
                break;

            case SketchState.DrawingBase:
                if (e.Button == MouseButtons.Right)
                {
                    // Cancel
                    _state = SketchState.None;
                    _base  = null;
                }
                else if (e.Button == MouseButtons.Left)
                {
                    ExpandBase(_intersection);
                    _volumePlane = new Plane(_base.Vertices[1], _base.Vertices[2], _base.Vertices[2] + _base.Plane.Normal);
                    _state       = SketchState.DrawingVolume;
                }
                break;

            case SketchState.DrawingVolume:
                if (e.Button == MouseButtons.Right)
                {
                    _state       = SketchState.DrawingBase;
                    _volumePlane = null;
                }
                else if (e.Button == MouseButtons.Left)
                {
                    var diff = _intersection - _base.Vertices[2];
                    var sign = _base.Plane.OnPlane(_intersection) < 0 ? -1 : 1;
                    _depth = diff.VectorMagnitude() * sign;
                    CreateBrush(_base, _depth);
                    _base        = null;
                    _volumePlane = null;
                    _state       = SketchState.None;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 3
0
        private void UpdateCurrentFace(Viewport3D viewport, ViewportEvent e)
        {
            var ray = viewport.CastRayFromScreen(e.X, e.Y);

            // The face doesn't change when drawing, just update the intersection
            if (_state == SketchState.DrawingBase || _state == SketchState.DrawingVolume)
            {
                _intersection = (_state == SketchState.DrawingBase ? _currentFace.Plane : _volumePlane).GetIntersectionPoint(ray, true, true);
                return;
            }

            var isect = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray)
                        .OfType <Solid>()
                        .SelectMany(x => x.Faces)
                        .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                        .Where(x => x.Intersection != null)
                        .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                        .FirstOrDefault();

            if (isect != null)
            {
                if (_currentFace != isect.Item)
                {
                    _cloneFace = isect.Item.Clone();
                    _cloneFace.Transform(new UnitTranslate(isect.Item.Plane.Normal * 0.1m), TransformFlags.None);
                }

                _currentFace  = isect.Item;
                _intersection = isect.Intersection;
                _state        = SketchState.Ready;
            }
            else
            {
                _cloneFace    = null;
                _currentFace  = null;
                _intersection = null;
                _state        = SketchState.None;
            }
        }
Exemplo n.º 4
0
        private void UpdateCurrentFace(Viewport3D viewport, ViewportEvent e)
        {
            var ray = viewport.CastRayFromScreen(e.X, e.Y);

            // The face doesn't change when drawing, just update the intersection
            if (_state == SketchState.DrawingBase || _state == SketchState.DrawingVolume)
            {
                _intersection = (_state == SketchState.DrawingBase ? _currentFace.Plane : _volumePlane).GetIntersectionPoint(ray, true, true);
                return;
            }

            var isect = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray)
                .OfType<Solid>()
                .SelectMany(x => x.Faces)
                .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .FirstOrDefault();

            if (isect != null)
            {
                if (_currentFace != isect.Item)
                {
                    _cloneFace = isect.Item.Clone();
                    _cloneFace.Transform(new UnitTranslate(isect.Item.Plane.Normal * 0.1m), TransformFlags.None);
                }

                _currentFace = isect.Item;
                _intersection = isect.Intersection;
                _state = SketchState.Ready;
            }
            else
            {
                _cloneFace = null;
                _currentFace = null;
                _intersection = null;
                _state = SketchState.None;
            }
        }
Exemplo n.º 5
0
 public override void ToolSelected(bool preventHistory)
 {
     _state = SketchState.None;
     _currentFace = _cloneFace = null;
     _intersection = null;
     _drawing = null;
     _volumePlane = null;
 }
Exemplo n.º 6
0
 public override void MouseDown(ViewportBase viewport, ViewportEvent e)
 {
     //
     switch (_state)
     {
         case SketchState.None:
             // nothin
             break;
         case SketchState.Ready:
             if (e.Button != MouseButtons.Left) break;
             _drawing = new Box(_intersection, _intersection);
             _state = SketchState.DrawingBase;
             break;
         case SketchState.DrawingBase:
             if (e.Button == MouseButtons.Right)
             {
                 // Cancel
                 _state = SketchState.None;
                 _drawing = null;
             }
             else if (e.Button == MouseButtons.Left)
             {
                 _drawing = new Box(_drawing.Start, _intersection);
                 _volumePlane = new Plane(new Coordinate(_drawing.End.X, _drawing.Start.Y, _drawing.Start.Z), _drawing.End, _drawing.End + _currentFace.Plane.Normal);
                 _state = SketchState.DrawingVolume;
             }
             break;
         case SketchState.DrawingVolume:
             if (e.Button == MouseButtons.Right)
             {
                 _state = SketchState.DrawingBase;
                 _volumePlane = null;
             }
             else if (e.Button == MouseButtons.Left)
             {
                 CreateBrush(new Box(new[] {_drawing.Start, _drawing.End}));
                 _drawing = null;
                 _volumePlane = null;
                 _state = SketchState.None;
             }
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Exemplo n.º 7
0
 public override void MouseDown(ViewportBase viewport, ViewportEvent e)
 {
     //
     switch (_state)
     {
         case SketchState.None:
             // nothin
             break;
         case SketchState.Ready:
             if (e.Button != MouseButtons.Left) break;
             _base = new Polygon(_currentFace.Plane, 1);
             _base.Transform(new UnitTranslate(_intersection - _base.Vertices[0]));
             _state = SketchState.DrawingBase;
             break;
         case SketchState.DrawingBase:
             if (e.Button == MouseButtons.Right)
             {
                 // Cancel
                 _state = SketchState.None;
                 _base = null;
             }
             else if (e.Button == MouseButtons.Left)
             {
                 ExpandBase(_intersection);
                 _volumePlane = new Plane(_base.Vertices[1], _base.Vertices[2], _base.Vertices[2] + _base.Plane.Normal);
                 _state = SketchState.DrawingVolume;
             }
             break;
         case SketchState.DrawingVolume:
             if (e.Button == MouseButtons.Right)
             {
                 _state = SketchState.DrawingBase;
                 _volumePlane = null;
             }
             else if (e.Button == MouseButtons.Left)
             {
                 var diff = _intersection - _base.Vertices[2];
                 var sign = _base.Plane.OnPlane(_intersection) < 0 ? -1 : 1;
                 _depth = diff.VectorMagnitude() * sign;
                 CreateBrush(_base, _depth);
                 _base = null;
                 _volumePlane = null;
                 _state = SketchState.None;
             }
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }