projection to png saving
This commit is contained in:
parent
aefc76c178
commit
2ace157573
3 changed files with 112 additions and 34 deletions
45
src/Main.cs
45
src/Main.cs
|
|
@ -2,6 +2,7 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -21,6 +22,8 @@ public partial class Main : Control
|
|||
[Export] private MeshInstance3D _meshInstance;
|
||||
[Export] private Node3D World;
|
||||
[Export] private TextureRect _textureRect;
|
||||
|
||||
[Export] private Gradient _gradient;
|
||||
|
||||
private PlanetHelper.VertexData? _vertex = null;
|
||||
private PlanetHelper.PlateData? _plate = null;
|
||||
|
|
@ -31,6 +34,7 @@ public partial class Main : Control
|
|||
{
|
||||
_planetHelper = new PlanetHelper(_meshInstance, _textureRect);
|
||||
UpdateStats();
|
||||
Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text));
|
||||
}
|
||||
|
||||
private const float RayLength = 1000.0f;
|
||||
|
|
@ -147,6 +151,47 @@ public partial class Main : Control
|
|||
_planetHelper.AutoRun = true;
|
||||
}
|
||||
|
||||
public void SaveImageValue()
|
||||
{
|
||||
Image img = Projector.RenderImage(_planetHelper);
|
||||
DirectoryInfo d = new DirectoryInfo(ProjectSettings.GlobalizePath("user://"));
|
||||
FileInfo[] files = d.GetFiles("Projection-*.png");
|
||||
int max = 0;
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
int number = int.Parse(file.Name.Split('-')[1]);
|
||||
max = Math.Max(max, number);
|
||||
}
|
||||
max += 1;
|
||||
img.SavePng(ProjectSettings.GlobalizePath($"user://ProjectionValue-{max}-{Projector.Points.GetLength(0)}.png"));
|
||||
}
|
||||
public void SaveImageColor()
|
||||
{
|
||||
Image img = Projector.RenderImage(_planetHelper);
|
||||
Vector2 size = img.GetSize();
|
||||
for (int x = 0; x < size.X; x++)
|
||||
{
|
||||
for (int y = 0; y < size.Y; y++)
|
||||
{
|
||||
img.SetPixel(x,y, _gradient.Sample(img.GetPixel(x,y).R));
|
||||
}
|
||||
}
|
||||
DirectoryInfo d = new DirectoryInfo(ProjectSettings.GlobalizePath("user://"));
|
||||
FileInfo[] files = d.GetFiles("ProjectionColor-*.png");
|
||||
int max = 0;
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
int number = int.Parse(file.Name.Split('-')[1]);
|
||||
max = Math.Max(max, number);
|
||||
}
|
||||
max += 1;
|
||||
img.SavePng(ProjectSettings.GlobalizePath($"user://Projection-{max}-{Projector.Points.GetLength(0)}.png"));
|
||||
}
|
||||
|
||||
public void OpenFolder()
|
||||
{
|
||||
OS.ShellShowInFileManager(ProjectSettings.GlobalizePath("user://"));
|
||||
}
|
||||
public void ResolutionChange(String change)
|
||||
{
|
||||
change = new string(change.Where(c => char.IsDigit(c)).ToArray());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue