hypsographic curve

This commit is contained in:
Aada 2026-03-03 22:05:17 +02:00
parent edffc76e05
commit 9a3be12f0f
7 changed files with 66 additions and 18 deletions

View file

@ -31,9 +31,10 @@ public partial class Main : Control
private int _resolution = 512;
private PlanetHelper _planetHelper;
[Export] private Curve _remapCurve;
public override void _Ready()
{
_planetHelper = new PlanetHelper(_meshInstance, _textureRect);
_planetHelper = new PlanetHelper(_meshInstance, _textureRect, _remapCurve);
UpdateStats();
Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text));
AxialTiltChanged(GetNode<LineEdit>("%AxialTilt").Text);
@ -109,7 +110,8 @@ public partial class Main : Control
UpdateStats();
Vector3 vertexPos = _planetHelper.Mdt.GetVertex(_vertex.Id) * 0.01f;
vertexPos *= _meshInstance.Transform.Basis.Inverse().Orthonormalized();
_pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.1f); // vertexPos * 1.01f;
_pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.03f); // vertexPos * 1.01f;
GetNode<Node3D>("%Pointer").GlobalPosition = _pointerPosition;
}
}
@ -124,12 +126,17 @@ public partial class Main : Control
_planetHelper.AutoRun = true;
}
_planetHelper.Process();
GetNode<Node3D>("%Pointer").GlobalPosition = _pointerPosition;
if (_sunRotating)
{
GetNode<Node3D>("%Sun").Rotation -= GetNode<Node3D>("%Sun").Rotation;
GetNode<Node3D>("%Sun").Rotation += new Vector3(0, (float)Mathf.DegToRad(GetNode<HSlider>("%SunAngle").Value), 0);
}
if (_planetRotating)
{
_meshInstance.Rotation = Vector3.Zero;
_meshInstance.RotateY((float)Mathf.DegToRad(GetNode<HSlider>("%PlanetAngle").Value));
_meshInstance.RotateZ(Mathf.DegToRad(_axialTilt));
}
}
public void UpdateStats()
{
@ -160,7 +167,7 @@ public partial class Main : Control
public void MakeGo()
{
_planetHelper = new PlanetHelper(_meshInstance, _textureRect);
_planetHelper = new PlanetHelper(_meshInstance, _textureRect, _remapCurve);
}
public void Advance()
@ -218,7 +225,7 @@ public partial class Main : Control
{
change = new string(change.Where(c => char.IsDigit(c)).ToArray());
_resolution = Int32.Parse(change);
_resolution = Math.Clamp(_resolution, 64, 2048);
_resolution = Math.Clamp(_resolution, 4, 2048);
}
public void AxialTiltChanged(string value)
@ -242,4 +249,15 @@ public partial class Main : Control
{
_sunRotating = false;
}
private bool _planetRotating = false;
private float _planetRotation = 0f;
public void PlanetAngleStart()
{
_planetRotating = true;
}
public void PlanetAngleStop(bool changed)
{
_planetRotating = false;
}
}

View file

@ -99,12 +99,14 @@ public class PlanetHelper
public MeshDataTool Mdt;
public Oct Octree = new Oct();
public PlanetHelper(MeshInstance3D meshInstance, TextureRect textureRect)
private Curve _remapCurve;
public PlanetHelper(MeshInstance3D meshInstance, TextureRect textureRect, Curve remapCurve)
{
_meshInstance = meshInstance;
_arrayMesh = meshInstance.Mesh as ArrayMesh;
_textureRect = textureRect;
_remapCurve = remapCurve;
_continentalNoise = new FastNoiseLite();
_mountainNoise = new FastNoiseLite();
@ -502,7 +504,7 @@ public class PlanetHelper
height = (height + 0.5f * mult) / (1f + mult);
height += edgeDistance * 0.25f;
height = (height + 0.5f * mult) / (1f + mult);
height += normalRate * 0.35f;
height += normalRate * 0.5f;
height = Mathf.Clamp(height, 0.01f, 0.99f);
ColorVertex(vertexData.Id, Colors.White * height);
vertexData.StageComplete = true;
@ -513,8 +515,12 @@ public class PlanetHelper
{
GD.Print($"Heights - min:'{Vertices.Min(v => v.Height)}' - max:'{Vertices.Max(v => v.Height)}' - average:'{Vertices.Average(v => v.Height)}'");
ScaleValues(Vertices);
foreach (VertexData vertexData in Vertices)
{
vertexData.Height = _remapCurve.Sample(vertexData.Height);
ColorVertex(vertexData.Id, Colors.White * vertexData.Height);
}
float oceanPercentage = Vertices.Count(v => v.Height < 0.5f) / (float)Vertices.Count;
GD.Print($"Ocean Percentage:'{oceanPercentage}'");
CompleteStage();