Ejemplo n.º 1
0
        public override bool Paint(float dt, MadMaps.Common.Painter.IPaintable canvas, MadMaps.Common.Painter.IGridManager gridManager, MadMaps.Common.Painter.Painter.InputState inputState, float minVal, float maxVal, Rect rect, Matrix4x4 TRS)
        {
            var dirty          = false;
            var brushBlendMode = BrushBlendMode;

            if (inputState.Shift)
            {
                if (brushBlendMode != EBrushBlendMode.Subtract)
                {
                    brushBlendMode = EBrushBlendMode.Subtract;
                }
                else
                {
                    brushBlendMode = EBrushBlendMode.Add;
                }
            }

            var scaledRad = gridManager.GetGridSize() * Radius;

            for (var i = -scaledRad; i <= scaledRad; i += gridManager.GetGridSize())
            {
                for (var j = -scaledRad; j <= scaledRad; j += gridManager.GetGridSize())
                {
                    var pos  = inputState.GridPosition + new Vector3(i, 0, j);
                    var cell = gridManager.GetCell(pos);

                    if (rect.size.magnitude > 0 && !rect.Contains(pos.xz()))
                    {
                        canvas.RemoveCell(cell);
                        continue;
                    }

                    var normalisedDist = 1f;
                    if (BrushShape == EBrushShape.Circle)
                    {
                        var circleDist = Vector2.Distance(inputState.GridPosition.xz(), pos.xz());
                        if (circleDist > scaledRad)
                        {
                            continue;
                        }
                        normalisedDist = circleDist / scaledRad;
                    }
                    else
                    {
                        normalisedDist = Mathf.Abs(inputState.GridPosition.x - pos.x) +
                                         Mathf.Abs(inputState.GridPosition.y - pos.y);
                        normalisedDist /= scaledRad;
                    }

                    var falloff = 1f;
                    if (!float.IsNaN(normalisedDist))
                    {
                        falloff = Falloff.Evaluate(normalisedDist);
                    }
                    var val = Strength * falloff;

                    var existingVal = canvas.GetValue(cell);

                    val = BrushUtilities.BlendValues(val, existingVal, brushBlendMode, dt, Flow);
                    val = Mathf.Clamp(val, minVal, maxVal);

                    canvas.SetValue(cell, val);
                    dirty = true;
                }
            }
            return(dirty);
        }
Ejemplo n.º 2
0
        public override bool Paint(float dt, MadMaps.Common.Painter.IPaintable canvas, MadMaps.Common.Painter.IGridManager gridManager, MadMaps.Common.Painter.Painter.InputState inputState, float minVal, float maxVal, Rect rect, Matrix4x4 TRS)
        {
            var dirty = false;

            _openCells.Clear();
            _closedCells.Clear();
            _openCells.Enqueue(gridManager.GetCell(inputState.GridPosition));

            while (_openCells.Count > 0)
            {
                var nextCell = _openCells.Dequeue();
                if (_closedCells.Contains(nextCell) || (rect.size.magnitude > 0 && rect.Contains(gridManager.GetCellCenter(nextCell))))
                {
                    _closedCells.Add(nextCell);
                    continue;
                }
                _closedCells.Add(nextCell);
                var value = canvas.GetValue(nextCell);
                if (value < Range.x || value <= Range.y)
                {
                    continue;
                }
                canvas.SetValue(nextCell, Strength);
                _openCells.Enqueue(gridManager.GetCell(inputState.GridPosition + new Vector3(-1, 0, 0)));
                _openCells.Enqueue(gridManager.GetCell(inputState.GridPosition + new Vector3(1, 0, 0)));
                _openCells.Enqueue(gridManager.GetCell(inputState.GridPosition + new Vector3(0, 0, 1)));
                _openCells.Enqueue(gridManager.GetCell(inputState.GridPosition + new Vector3(0, 0, -1)));
            }

            /*var scaledRad = gridManager.GetGridSize();
             * for (var i = -scaledRad; i <= scaledRad; i += gridManager.GetGridSize())
             * {
             *  for (var j = -scaledRad; j <= scaledRad; j += gridManager.GetGridSize())
             *  {
             *      var pos = inputState.GridPosition + new Vector3(i, 0, j);
             *      var cell = gridManager.GetCell(pos);
             *
             *      if (rect.size.magnitude > 0 && !rect.Contains(pos.xz()))
             *      {
             *          canvas.RemoveCell(cell);
             *          continue;
             *      }
             *
             *      var normalisedDist = 1f;
             *      if (BrushShape == EBrushShape.Circle)
             *      {
             *          var circleDist = Vector2.Distance(inputState.GridPosition.xz(), pos.xz());
             *          if (circleDist > scaledRad)
             *          {
             *              continue;
             *          }
             *          normalisedDist = circleDist/scaledRad;
             *      }
             *      else
             *      {
             *          normalisedDist = Mathf.Abs(inputState.GridPosition.x - pos.x) +
             *                           Mathf.Abs(inputState.GridPosition.y - pos.y);
             *          normalisedDist /= scaledRad;
             *      }
             *
             *      var falloff = 1f;
             *      if (!float.IsNaN(normalisedDist))
             *      {
             *          falloff = Falloff.Evaluate(normalisedDist);
             *      }
             *      var val = Strength*falloff;
             *
             *      var existingVal = canvas.GetValue(cell);
             *
             *      val = BrushUtilities.BlendValues(val, existingVal, brushBlendMode, dt, Flow);
             *      val = Mathf.Clamp(val, minVal, maxVal);
             *
             *      canvas.SetValue(cell, val);
             *      dirty = true;
             *  }
             * }*/
            return(dirty);
        }