protected override void DrawSceneGizmos(MadMaps.Common.Painter.IGridManager gridManager, MadMaps.Common.Painter.Painter.InputState inputState, Rect rect, Matrix4x4 TRS) { Radius = Mathf.Clamp(Radius, 0, 32); //var scaledRad = gridManager.GetGridSize()*Radius; var translatedPlanePos = TRS.MultiplyPoint(inputState.PlanePosition); var translatedGridPos = TRS.MultiplyPoint(inputState.GridPosition); var planeUp = TRS.GetRotation() * Vector3.up; var planeForward = TRS.GetRotation() * Vector3.forward; var planeRot = Quaternion.LookRotation(planeUp, planeForward); Handles.color = Color.white * 0.5f; if (BrushShape == EBrushShape.Circle) { Handles.CircleHandleCap(-1, translatedPlanePos, planeRot, gridManager.GetGridSize() * Radius, EventType.Repaint); } else { Handles.RectangleHandleCap(-1, translatedGridPos, planeRot, gridManager.GetGridSize() * Radius, EventType.Repaint); } Handles.color = Color.white; if (BrushShape == EBrushShape.Circle) { Handles.CircleHandleCap(-1, translatedGridPos, planeRot, gridManager.GetGridSize() * Mathf.Max(.5f, Radius), EventType.Repaint); } else { Handles.RectangleHandleCap(-1, translatedGridPos, planeRot, gridManager.GetGridSize() * Mathf.Max(.5f, Radius), EventType.Repaint); } }
public void DrawGizmos(MadMaps.Common.Painter.IGridManager gridManager, MadMaps.Common.Painter.Painter.InputState inputState, Rect rect, Matrix4x4 TRS) { if (!inputState.MouseBlocked) { DrawSceneGizmos(gridManager, inputState, rect, TRS); } }
protected override void DrawSceneGizmos(MadMaps.Common.Painter.IGridManager gridManager, MadMaps.Common.Painter.Painter.InputState inputState, Rect rect, Matrix4x4 TRS) { /*var translatedPlanePos = TRS.MultiplyPoint(inputState.PlanePosition); * var translatedGridPos = TRS.MultiplyPoint(inputState.GridPosition); * var planeUp = TRS.GetRotation()*Vector3.up; * var planeForward = TRS.GetRotation()*Vector3.forward; * var planeRot = Quaternion.LookRotation(planeUp, planeForward); * * Handles.color = Color.white*0.5f; * if (BrushShape == EBrushShape.Circle) * { * Handles.CircleHandleCap(-1, translatedPlanePos, planeRot, * gridManager.GetGridSize()*Radius, EventType.Repaint); * } * else * { * Handles.RectangleHandleCap(-1, translatedGridPos, planeRot, * gridManager.GetGridSize()*Radius, EventType.Repaint); * } * Handles.color = Color.white; * if (BrushShape == EBrushShape.Circle) * { * Handles.CircleHandleCap(-1, translatedGridPos, planeRot, * gridManager.GetGridSize()*Mathf.Max(.5f, Radius), EventType.Repaint); * } * else * { * Handles.RectangleHandleCap(-1, translatedGridPos, planeRot, * gridManager.GetGridSize()*Mathf.Max(.5f, Radius), EventType.Repaint); * }*/ }
public Painter(MadMaps.Common.Painter.IPaintable canvas, MadMaps.Common.Painter.IGridManager gridManager) { Canvas = canvas; GridManager = gridManager; _lastUpdate = EditorApplication.timeSinceStartup; }
protected abstract void DrawSceneGizmos(MadMaps.Common.Painter.IGridManager gridManager, MadMaps.Common.Painter.Painter.InputState inputState, Rect rect, Matrix4x4 TRS);
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); }
public override bool Paint(float dt, IPaintable canvas, IGridManager gridManager, Painter.InputState inputState, float minVal, float maxVal, Rect rect, Matrix4x4 TRS) { var dirty = false; 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); var sum = 0f; for (var iter = 0; iter < Iterations; ++iter) { for (var u = -1; u <= 1; ++u) { for (var v = -1; v <= 1; ++v) { var neighbourPos = inputState.GridPosition + new Vector3(i + u * gridManager.GetGridSize(), 0, j + v * gridManager.GetGridSize()); var neighbourCell = gridManager.GetCell(neighbourPos); sum += canvas.GetValue(neighbourCell); } } } val = Mathf.Lerp(sum / 9, val, Strength * Flow * dt); val = Mathf.Clamp(val, minVal, maxVal); canvas.SetValue(cell, val); dirty = true; } } return(dirty); }
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); }