fixed projection pixel count, adjustable projection resolution, smaller initial resolution for projection, added button controls

This commit is contained in:
Aada 2026-03-03 07:34:13 +02:00
parent 6ca58040c4
commit 901177e2e4
4 changed files with 70 additions and 11 deletions

View file

@ -24,6 +24,7 @@ public partial class Main : Control
private PlanetHelper.VertexData? _vertex = null;
private PlanetHelper.PlateData? _plate = null;
private int _resolution = 512;
private PlanetHelper _planetHelper;
public override void _Ready()
@ -62,7 +63,7 @@ public partial class Main : Control
{
if (tab == 1)
{
Projector.GatherPoints(_planetHelper);
Projector.GatherPoints(_planetHelper, _resolution);
_textureRect.Texture = Projector.Render(_planetHelper);
}
}
@ -136,4 +137,20 @@ public partial class Main : Control
_planetHelper = new PlanetHelper(_meshInstance, _textureRect);
}
public void Advance()
{
_planetHelper.Advance = true;
}
public void AutoRun()
{
_planetHelper.AutoRun = true;
}
public void ResolutionChange(String change)
{
change = new string(change.Where(c => char.IsDigit(c)).ToArray());
_resolution = Int32.Parse(change);
_resolution = Math.Clamp(_resolution, 64, 8192);
}
}

View file

@ -116,6 +116,15 @@ public class PlanetHelper
Octree.Insert(new Node(i, Mdt.GetVertex(i) * 0.001f));
Mdt.SetVertexColor(i, Colors.Black);
}
if (_meshInstance.GetSurfaceOverrideMaterial(0) is ShaderMaterial shaderMaterial)
{
shaderMaterial.SetShaderParameter("mode", 1);
}
if (_textureRect.Material is ShaderMaterial textureShaderMaterial)
{
textureShaderMaterial.SetShaderParameter("mode", 1);
}
UpdateMesh();
}
public void InitializeGeneration()
@ -211,9 +220,14 @@ public class PlanetHelper
GenerationStage stage = Stage + 1;
Stage = Stage == StopStage ? GenerationStage.Completed : stage;
if (stage == GenerationStage.Completed)
{
AutoRun = false;
_generationStopwatch.Stop();
}
else
{
_generationStopwatch.Restart();
}
GD.Print($"Stage Started: '{Stage.ToString()}'");
_waiting = false;
StageComplete = false;

View file

@ -6,11 +6,8 @@ using System.Threading.Tasks;
public static class Projector
{
public static int[,] Points = new int[1024,512];
private static bool _gathered = false;
public static void GatherPoints(PlanetHelper helper, int resolutionH = 2048, bool regather = false)
public static void GatherPoints(PlanetHelper helper, int resolutionH = 2048)
{
if (!regather && _gathered)
return;
Points = new int[resolutionH,resolutionH / 2];
string filename = $"user://points-{resolutionH}-{resolutionH / 2}.dat";
if (FileAccess.FileExists(filename))
@ -44,13 +41,12 @@ public static class Projector
for (int x = 0; x < Points.GetLength(0); x++)
for (int y = 0; y < Points.GetLength(1); y++)
file.Store32((uint)Points[x,y]);
_gathered = true;
file.Close();
file.Close();
}
public static ImageTexture Render(PlanetHelper helper)
{
var image = Image.CreateEmpty(Points.GetLength(0) + 1, Points.GetLength(1) + 1, false, Image.Format.Rgb8);;
var image = Image.CreateEmpty(Points.GetLength(0), Points.GetLength(1), false, Image.Format.Rgb8);;
for (int x = 0; x < Points.GetLength(0); x++)
{