fixed projection pixel count, adjustable projection resolution, smaller initial resolution for projection, added button controls
This commit is contained in:
parent
6ca58040c4
commit
901177e2e4
4 changed files with 70 additions and 11 deletions
|
|
@ -101,9 +101,38 @@ theme_override_constants/margin_bottom = 12
|
|||
[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Planet/PanelContainer/MarginContainer" unique_id=654818970]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Generate" type="Button" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer" unique_id=662365522]
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer" unique_id=1125245293]
|
||||
layout_mode = 2
|
||||
text = "Generate"
|
||||
|
||||
[node name="Reset" type="Button" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3" unique_id=662365522]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Reset"
|
||||
|
||||
[node name="Advance" type="Button" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3" unique_id=1446263017]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Advance Once"
|
||||
|
||||
[node name="AutoRun" type="Button" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3" unique_id=58920233]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Auto Run
|
||||
"
|
||||
|
||||
[node name="HBoxContainer4" type="HBoxContainer" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer" unique_id=1084572184]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer4" unique_id=1959611598]
|
||||
layout_mode = 2
|
||||
text = "Projection Resolution:"
|
||||
|
||||
[node name="Resolution" type="LineEdit" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer4" unique_id=1285940001]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "512"
|
||||
max_length = 5
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer" unique_id=1862016318]
|
||||
layout_mode = 2
|
||||
|
|
@ -196,4 +225,7 @@ stretch_mode = 5
|
|||
metadata/_tab_index = 1
|
||||
|
||||
[connection signal="tab_changed" from="TabContainer" to="." method="Tab"]
|
||||
[connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/Generate" to="." method="MakeGo"]
|
||||
[connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3/Reset" to="." method="MakeGo"]
|
||||
[connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3/Advance" to="." method="Advance"]
|
||||
[connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3/AutoRun" to="." method="AutoRun"]
|
||||
[connection signal="text_changed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer4/Resolution" to="." method="ResolutionChange"]
|
||||
|
|
|
|||
19
src/Main.cs
19
src/Main.cs
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue