Codestyle fixes
This commit is contained in:
@@ -55,11 +55,11 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
private void OnSetupContextMenu(PropertyNameLabel label, ContextMenu menu, CustomEditor linkedEditor)
|
private void OnSetupContextMenu(PropertyNameLabel label, ContextMenu menu, CustomEditor linkedEditor)
|
||||||
{
|
{
|
||||||
menu.ItemsContainer.RemoveChildren();
|
menu.ItemsContainer.RemoveChildren();
|
||||||
|
|
||||||
menu.AddButton("Copy", linkedEditor.Copy);
|
menu.AddButton("Copy", linkedEditor.Copy);
|
||||||
var paste = menu.AddButton("Paste", linkedEditor.Paste);
|
var paste = menu.AddButton("Paste", linkedEditor.Paste);
|
||||||
paste.Enabled = linkedEditor.CanPaste;
|
paste.Enabled = linkedEditor.CanPaste;
|
||||||
|
|
||||||
menu.AddSeparator();
|
menu.AddSeparator();
|
||||||
var moveUpButton = menu.AddButton("Move up", OnMoveUpClicked);
|
var moveUpButton = menu.AddButton("Move up", OnMoveUpClicked);
|
||||||
moveUpButton.Enabled = Index > 0;
|
moveUpButton.Enabled = Index > 0;
|
||||||
@@ -118,7 +118,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
Editor = editor;
|
Editor = editor;
|
||||||
Index = index;
|
Index = index;
|
||||||
Offsets = new Margin(7, 7, 0, 0);
|
Offsets = new Margin(7, 7, 0, 0);
|
||||||
|
|
||||||
MouseButtonRightClicked += OnMouseButtonRightClicked;
|
MouseButtonRightClicked += OnMouseButtonRightClicked;
|
||||||
if (_canReorder)
|
if (_canReorder)
|
||||||
{
|
{
|
||||||
@@ -173,6 +173,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
/// Determines if value of collection can be null.
|
/// Determines if value of collection can be null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool NotNullItems;
|
protected bool NotNullItems;
|
||||||
|
|
||||||
private IntValueBox _sizeBox;
|
private IntValueBox _sizeBox;
|
||||||
private Color _background;
|
private Color _background;
|
||||||
private int _elementsCount;
|
private int _elementsCount;
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all patches that will be affected by the brush
|
/// Gets all patches that will be affected by the brush
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="brush"></param>
|
/// <param name="brush">The brush.</param>
|
||||||
/// <param name="options"></param>
|
/// <param name="options">The options.</param>
|
||||||
/// <param name="gizmo"></param>
|
/// <param name="gizmo">The gizmo.</param>
|
||||||
/// <param name="terrain"></param>
|
/// <param name="terrain">The terrain.</param>
|
||||||
public unsafe virtual List<ApplyParams> GetAffectedPatches(Brush brush, ref Options options, SculptTerrainGizmoMode gizmo, FlaxEngine.Terrain terrain)
|
public virtual unsafe List<ApplyParams> GetAffectedPatches(Brush brush, ref Options options, SculptTerrainGizmoMode gizmo, FlaxEngine.Terrain terrain)
|
||||||
{
|
{
|
||||||
List<ApplyParams> affectedPatches = new();
|
List<ApplyParams> affectedPatches = new();
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
/// <param name="options">The options.</param>
|
/// <param name="options">The options.</param>
|
||||||
/// <param name="gizmo">The gizmo.</param>
|
/// <param name="gizmo">The gizmo.</param>
|
||||||
/// <param name="terrain">The terrain.</param>
|
/// <param name="terrain">The terrain.</param>
|
||||||
public unsafe void Apply(Brush brush, ref Options options, SculptTerrainGizmoMode gizmo, FlaxEngine.Terrain terrain)
|
public void Apply(Brush brush, ref Options options, SculptTerrainGizmoMode gizmo, FlaxEngine.Terrain terrain)
|
||||||
{
|
{
|
||||||
var affectedPatches = GetAffectedPatches(brush, ref options, gizmo, terrain);
|
var affectedPatches = GetAffectedPatches(brush, ref options, gizmo, terrain);
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gizmo"></param>
|
/// <param name="gizmo"></param>
|
||||||
/// <param name="affectedPatches"></param>
|
/// <param name="affectedPatches"></param>
|
||||||
public unsafe virtual void ApplyBrush(SculptTerrainGizmoMode gizmo, List<ApplyParams> affectedPatches)
|
public virtual void ApplyBrush(SculptTerrainGizmoMode gizmo, List<ApplyParams> affectedPatches)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < affectedPatches.Count; i++)
|
for (int i = 0; i < affectedPatches.Count; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEditor.Tools.Terrain.Brushes;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FlaxEditor.Tools.Terrain.Sculpt
|
namespace FlaxEditor.Tools.Terrain.Sculpt
|
||||||
@@ -29,15 +28,9 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
var heightmapSize = affectedPatches[0].HeightmapSize;
|
var heightmapSize = affectedPatches[0].HeightmapSize;
|
||||||
var radius = Mathf.Max(Mathf.CeilToInt(FilterRadius * 0.01f * affectedPatches[0].Brush.Size), 2);
|
var radius = Mathf.Max(Mathf.CeilToInt(FilterRadius * 0.01f * affectedPatches[0].Brush.Size), 2);
|
||||||
|
|
||||||
|
// Calculate bounding coordinates of the total affected area
|
||||||
/////
|
|
||||||
/// Calculate bounding coordinates of the total affected area
|
|
||||||
///
|
|
||||||
|
|
||||||
|
|
||||||
Int2 modifieedAreaMinCoord = Int2.Maximum;
|
Int2 modifieedAreaMinCoord = Int2.Maximum;
|
||||||
Int2 modifiedAreaMaxCoord = Int2.Minimum;
|
Int2 modifiedAreaMaxCoord = Int2.Minimum;
|
||||||
|
|
||||||
for (int i = 0; i < affectedPatches.Count; i++)
|
for (int i = 0; i < affectedPatches.Count; i++)
|
||||||
{
|
{
|
||||||
var patch = affectedPatches[i];
|
var patch = affectedPatches[i];
|
||||||
@@ -46,27 +39,14 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
var br = tl + patch.ModifiedSize;
|
var br = tl + patch.ModifiedSize;
|
||||||
|
|
||||||
if (tl.X <= modifieedAreaMinCoord.X && tl.Y <= modifieedAreaMinCoord.Y)
|
if (tl.X <= modifieedAreaMinCoord.X && tl.Y <= modifieedAreaMinCoord.Y)
|
||||||
{
|
|
||||||
modifieedAreaMinCoord = tl;
|
modifieedAreaMinCoord = tl;
|
||||||
}
|
|
||||||
|
|
||||||
if (br.X >= modifiedAreaMaxCoord.X && br.Y >= modifiedAreaMaxCoord.Y)
|
if (br.X >= modifiedAreaMaxCoord.X && br.Y >= modifiedAreaMaxCoord.Y)
|
||||||
{
|
|
||||||
modifiedAreaMaxCoord = br;
|
modifiedAreaMaxCoord = br;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var totalModifiedSize = modifiedAreaMaxCoord - modifieedAreaMinCoord;
|
var totalModifiedSize = modifiedAreaMaxCoord - modifieedAreaMinCoord;
|
||||||
|
|
||||||
|
// Build map of heights in affected area
|
||||||
/////
|
|
||||||
/// Build map of heights in affected area
|
|
||||||
///
|
|
||||||
|
|
||||||
|
|
||||||
var modifiedHeights = new float[totalModifiedSize.X * totalModifiedSize.Y];
|
var modifiedHeights = new float[totalModifiedSize.X * totalModifiedSize.Y];
|
||||||
|
|
||||||
for (int i = 0; i < affectedPatches.Count; i++)
|
for (int i = 0; i < affectedPatches.Count; i++)
|
||||||
{
|
{
|
||||||
var patch = affectedPatches[i];
|
var patch = affectedPatches[i];
|
||||||
@@ -75,32 +55,26 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
{
|
{
|
||||||
for (int x = 0; x < patch.ModifiedSize.X; x++)
|
for (int x = 0; x < patch.ModifiedSize.X; x++)
|
||||||
{
|
{
|
||||||
// read height from current patch
|
// Read height from current patch
|
||||||
var localCoordX = (x + patch.ModifiedOffset.X);
|
var localCoordX = (x + patch.ModifiedOffset.X);
|
||||||
var localCoordY = (z + patch.ModifiedOffset.Y);
|
var localCoordY = (z + patch.ModifiedOffset.Y);
|
||||||
var coordHeight = patch.SourceHeightMap[(localCoordY * heightmapSize) + localCoordX];
|
var coordHeight = patch.SourceHeightMap[(localCoordY * heightmapSize) + localCoordX];
|
||||||
|
|
||||||
// calculate the absolute coordinate of the terrain point
|
// Calculate the absolute coordinate of the terrain point
|
||||||
var absoluteCurrentPointCoord = patch.PatchCoord * (heightmapSize - 1) + patch.ModifiedOffset + new Int2(x, z);
|
var absoluteCurrentPointCoord = patch.PatchCoord * (heightmapSize - 1) + patch.ModifiedOffset + new Int2(x, z);
|
||||||
var currentPointCoordRelativeToModifiedArea = absoluteCurrentPointCoord - modifieedAreaMinCoord;
|
var currentPointCoordRelativeToModifiedArea = absoluteCurrentPointCoord - modifieedAreaMinCoord;
|
||||||
|
|
||||||
// store height
|
// Store height
|
||||||
var index = (currentPointCoordRelativeToModifiedArea.Y * totalModifiedSize.X) + currentPointCoordRelativeToModifiedArea.X;
|
var index = (currentPointCoordRelativeToModifiedArea.Y * totalModifiedSize.X) + currentPointCoordRelativeToModifiedArea.X;
|
||||||
modifiedHeights[index] = coordHeight;
|
modifiedHeights[index] = coordHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterate through modified points and smooth now that we have height information for all necessary points
|
||||||
/////
|
|
||||||
/// Iterate through modified points and smooth now that we have height information for all necessary points
|
|
||||||
///
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < affectedPatches.Count; i++)
|
for (int i = 0; i < affectedPatches.Count; i++)
|
||||||
{
|
{
|
||||||
var patch = affectedPatches[i];
|
var patch = affectedPatches[i];
|
||||||
|
|
||||||
var brushPosition = patch.Gizmo.CursorPosition;
|
var brushPosition = patch.Gizmo.CursorPosition;
|
||||||
var strength = Mathf.Saturate(patch.Strength);
|
var strength = Mathf.Saturate(patch.Strength);
|
||||||
|
|
||||||
@@ -108,16 +82,16 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
{
|
{
|
||||||
for (int x = 0; x < patch.ModifiedSize.X; x++)
|
for (int x = 0; x < patch.ModifiedSize.X; x++)
|
||||||
{
|
{
|
||||||
// read height from current patch
|
// Read height from current patch
|
||||||
var localCoordX = (x + patch.ModifiedOffset.X);
|
var localCoordX = (x + patch.ModifiedOffset.X);
|
||||||
var localCoordY = (z + patch.ModifiedOffset.Y);
|
var localCoordY = (z + patch.ModifiedOffset.Y);
|
||||||
var coordHeight = patch.SourceHeightMap[(localCoordY * heightmapSize) + localCoordX];
|
var coordHeight = patch.SourceHeightMap[(localCoordY * heightmapSize) + localCoordX];
|
||||||
|
|
||||||
// calculate the absolute coordinate of the terrain point
|
// Calculate the absolute coordinate of the terrain point
|
||||||
var absoluteCurrentPointCoord = patch.PatchCoord * (heightmapSize - 1) + patch.ModifiedOffset + new Int2(x, z);
|
var absoluteCurrentPointCoord = patch.PatchCoord * (heightmapSize - 1) + patch.ModifiedOffset + new Int2(x, z);
|
||||||
var currentPointCoordRelativeToModifiedArea = absoluteCurrentPointCoord - modifieedAreaMinCoord;
|
var currentPointCoordRelativeToModifiedArea = absoluteCurrentPointCoord - modifieedAreaMinCoord;
|
||||||
|
|
||||||
// calculate brush influence at the current position
|
// Calculate brush influence at the current position
|
||||||
var samplePositionLocal = patch.PatchPositionLocal + new Vector3(localCoordX * FlaxEngine.Terrain.UnitsPerVertex, coordHeight, localCoordY * FlaxEngine.Terrain.UnitsPerVertex);
|
var samplePositionLocal = patch.PatchPositionLocal + new Vector3(localCoordX * FlaxEngine.Terrain.UnitsPerVertex, coordHeight, localCoordY * FlaxEngine.Terrain.UnitsPerVertex);
|
||||||
Vector3.Transform(ref samplePositionLocal, ref patch.TerrainWorld, out Vector3 samplePositionWorld);
|
Vector3.Transform(ref samplePositionLocal, ref patch.TerrainWorld, out Vector3 samplePositionWorld);
|
||||||
var paintAmount = patch.Brush.Sample(ref brushPosition, ref samplePositionWorld) * strength;
|
var paintAmount = patch.Brush.Sample(ref brushPosition, ref samplePositionWorld) * strength;
|
||||||
@@ -149,7 +123,6 @@ namespace FlaxEditor.Tools.Terrain.Sculpt
|
|||||||
{
|
{
|
||||||
var coordIndex = (dz * totalModifiedSize.X) + dx;
|
var coordIndex = (dz * totalModifiedSize.X) + dx;
|
||||||
var height = modifiedHeights[coordIndex];
|
var height = modifiedHeights[coordIndex];
|
||||||
|
|
||||||
smoothValue += height;
|
smoothValue += height;
|
||||||
smoothValueSamples++;
|
smoothValueSamples++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user