Ejemplo n.º 1
0
        public void SetPower(int power)
        {
            Power = power;
            var size = Resolution + 1;

            Points = new DisplacementPoint[size, size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    //TODO: approximate new point values instead of zeroing
                    Points[i, j] = new DisplacementPoint(this, i, j);
                }
            }
            UpdateBoundingBox();
        }
Ejemplo n.º 2
0
 public void SetPower(int power)
 {
     Power = power;
     var size = Resolution + 1;
     Points = new DisplacementPoint[size, size];
     for (int i = 0; i < size; i++)
     {
         for (int j = 0; j < size; j++)
         {
             //TODO: approximate new point values instead of zeroing
             Points[i, j] = new DisplacementPoint(this, i, j);
         }
     }
     UpdateBoundingBox();
 }
Ejemplo n.º 3
0
 private Coordinate GetNormal(Viewport3D vp, DisplacementPoint point, GeometryControl.Axis axis)
 {
     switch (axis)
     {
         case GeometryControl.Axis.XAxis:
             return Coordinate.UnitX;
         case GeometryControl.Axis.YAxis:
             return Coordinate.UnitY;
         case GeometryControl.Axis.ZAxis:
             return Coordinate.UnitZ;
         case GeometryControl.Axis.FaceNormal:
             return point.Parent.Plane.Normal;
         case GeometryControl.Axis.PointNormal:
             return point.Displacement.Normal;
         case GeometryControl.Axis.TowardsViewport:
             var v = vp.Camera.LookAt;
             return new Coordinate((decimal) v.X, (decimal) v.Y, (decimal) v.Z).Normalise();
         default:
             throw new ArgumentOutOfRangeException("axis");
     }
 }
Ejemplo n.º 4
0
        private void ApplyEffect(decimal distance, Coordinate normal,
            DisplacementPoint point, GeometryControl.Effect effect, GeometryControl.Brush brush,
            decimal spatialRadius, int pointSize, Easing softEdgeFunc)
        {
            var disps = new List<Displacement>();
            //CollectJoinedDisplacements(disps, point.Parent, Selection.GetSelectedFaces().OfType<Displacement>().ToList());
            disps.AddRange(Document.Selection.GetSelectedFaces().OfType<Displacement>());
            var list = new List<Tuple<DisplacementPoint, decimal>>();

            if (brush == GeometryControl.Brush.Point)
            {
                // If we're in point brush mode, select the points by location in the displacement grid
                list.Add(Tuple.Create(_currentPoint, 1m));
                var ratio = 1m / pointSize;
                var cx = _currentPoint.XIndex;
                var cy = _currentPoint.YIndex;
                for (var i = 1; i < pointSize; i++)
                {
                    var edge = 1 - softEdgeFunc.Evaluate(ratio * i);// softEdge ? 1 - (ratio * i) : 1;

                    var points = new List<DisplacementPoint>();
                    for (var j = -i; j <= i; j++)
                    {
                        // Get the points in a box around the point, distance i
                       // points.Add(disp.GetPoint(cx - i, cy + j));
                       // points.Add(disp.GetPoint(cx + i, cy + j));
                       // if (j == -i || j == i) continue;
                       // points.Add(disp.GetPoint(cx + j, cy - i));
                       // points.Add(disp.GetPoint(cx + j, cy + i));
                    }

                    list.AddRange(points.Where(x => x != null).Select(x => Tuple.Create(x, edge)));
                }
            }
            else if (brush == GeometryControl.Brush.Spatial)
            {
                // For spatial brush mode, select the points by distance from the current point
                var points = disps.SelectMany(x => x.GetPoints())
                    .Select(x => new
                                     {
                                         Point = x,
                                         Distance = (x.Location - _currentPoint.Location).VectorMagnitude()
                                     })
                    .Where(x => x.Distance <= spatialRadius);
                // list.AddRange(points.Select(x => Tuple.Create(x.Point, softEdge ? (spatialRadius - x.Distance) / spatialRadius : 1)));
                list.AddRange(points.Select(x => Tuple.Create(x.Point, 1 - softEdgeFunc.Evaluate(1 - (spatialRadius - x.Distance) / spatialRadius))));
            }

            if (!list.Any()) return;

            switch (effect)
            {
                case GeometryControl.Effect.RelativeDistance:
                    list.ForEach(
                        x => x.Item1.CurrentPosition.Location +=
                             normal * (distance * x.Item2));
                    break;
                case GeometryControl.Effect.AbsoluteDistance:
                    list.ForEach(
                        x => x.Item1.CurrentPosition.Location =
                             x.Item1.InitialPosition + (x.Item1.Parent.Plane.Normal * distance));
                    break;
                case GeometryControl.Effect.SmoothPoints:
                    var avg = list.Select(x => x.Item1.Location).Aggregate(Coordinate.Zero, (x, y) => x + y) / list.Count;
                    foreach (var pt in list)
                    {
                        var dist = (pt.Item1.Location - avg).Dot(normal);
                        var mult = -Math.Sign(dist) * Math.Min(Math.Abs(dist), Math.Abs(distance));
                        pt.Item1.CurrentPosition.Location += mult * pt.Item2 * normal;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException("effect");
            }
        }
Ejemplo n.º 5
0
        public override void UpdateFrame(ViewportBase viewport, FrameInfo frame)
        {
            var vp = viewport as Viewport3D;
            if (vp == null) return;

            if (_moveCount > 0)
            {
                PaintCurrentPoint(vp, _moveCount);
                _moveCount = 0;
            }

            // Check the current intersecting point
            var ray = vp.CastRayFromScreen(_mousePos.X, _mousePos.Y);
            var selectedFaces = Document.Selection.GetSelectedFaces().OfType<Displacement>();
            var closestPoints = selectedFaces.Select(x => x.GetClosestDisplacementPoint(ray));
            _currentPoint = closestPoints
                .OrderBy(x => (x.Location - ray.ClosestPoint(x.Location)).VectorMagnitude())
                .FirstOrDefault();

            if (_needsRedraw)
            {
                // update display lists?
                _needsRedraw = false;
            }
        }
Ejemplo n.º 6
0
 public override void ToolDeselected(bool preventHistory)
 {
     _currentPoint = null;
 }
Ejemplo n.º 7
0
 public override void ToolDeselected()
 {
     _currentPoint = null;
 }