Compare commits

..

No commits in common. "a780ef479d4e4aa551c226a6f65caa150ac754d3" and "df46846953948f35cc8a4a3259f5f8ef33240246" have entirely different histories.

5 changed files with 55 additions and 83 deletions

View file

@ -3,20 +3,19 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://n56csi5ekat"
path.s3tc="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"]
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=2
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
@ -24,7 +23,7 @@ compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -38,7 +37,7 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View file

@ -5,7 +5,6 @@
[ext_resource type="Gradient" uid="uid://b5l44rktieewe" path="res://resources/planet_gradient.tres" id="2_ygjfp"]
[ext_resource type="Material" uid="uid://c55st036tapeo" path="res://shaders/planet.tres" id="3_ygjfp"]
[ext_resource type="Material" uid="uid://k3teblrpopsb" path="res://shaders/map.tres" id="4_1wiy7"]
[ext_resource type="Texture2D" uid="uid://n56csi5ekat" path="res://icon.svg" id="5_ygjfp"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_uxrcv"]
@ -70,7 +69,7 @@ environment = SubResource("Environment_rf2cd")
camera_attributes = SubResource("CameraAttributesPractical_a814b")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo" unique_id=899426195]
transform = Transform3D(0.99999994, 0, 0, 0, 0.99999994, 0, 0, 0, 0.99999994, 0, 0, 0)
transform = Transform3D(0.88874525, -0.29675773, 0.3493804, 0, 0.7621714, 0.6473753, -0.45840138, -0.5753517, 0.6773762, 0, 0, 0)
[node name="Icosphere" type="MeshInstance3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo" unique_id=793654005]
transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, 0, 0, 0)
@ -90,13 +89,6 @@ fov = 5.0
[node name="CollisionShape3D" type="CollisionShape3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo/StaticBody3D" unique_id=299495076]
shape = SubResource("SphereShape3D_rpqi1")
[node name="Pointer" type="Sprite3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo" unique_id=1498529325]
unique_name_in_owner = true
transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, 0, 0, 0)
modulate = Color(1, 0, 0, 1)
billboard = 1
texture = ExtResource("5_ygjfp")
[node name="PanelContainer" type="PanelContainer" parent="TabContainer/Planet" unique_id=716838825]
layout_mode = 2
size_flags_horizontal = 3

View file

@ -4,12 +4,11 @@ render_mode unshaded;
uniform int mode = 1;
uniform sampler2D gradient;
varying vec3 world_position;
varying float color;
varying flat float color;
void vertex() {
// Called for every vertex the material is visible on.
world_position = VERTEX;
color = COLOR.r;
VERTEX += VERTEX * COLOR.q * 0.1f;
}
void fragment() {

View file

@ -37,7 +37,6 @@ public partial class Main : Control
Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text));
}
Vector3 _pointerPosition = Vector3.Zero;
private const float RayLength = 1000.0f;
public override void _Input(InputEvent @event)
{
@ -77,27 +76,26 @@ public partial class Main : Control
{
if (Input.IsActionJustPressed("mouse_secondary"))
{
var from = _cameraNode.ProjectRayOrigin(_cameraNode.GetViewport().GetMousePosition());
var to = from + _cameraNode.ProjectRayNormal(_cameraNode.GetViewport().GetMousePosition()) * RayLength;
var from = _cameraNode.ProjectRayOrigin(GetViewport().GetMousePosition());
var to = from + _cameraNode.ProjectRayNormal(GetViewport().GetMousePosition()) * RayLength;
var result = World.GetWorld3D().DirectSpaceState.IntersectRay(PhysicsRayQueryParameters3D.Create(from, to));
if (result.Count > 0)
{
Vector3 pos = result["position"].AsVector3();
GD.Print($"Hit: '{pos}'");
var closest = _planetHelper.Octree.SearchNearest(pos)?.Id;
if (closest != null)
Vector3? pos = result["position"].AsVector3();
if (pos != null)
{
_vertex = _planetHelper.Vertices.Single(v => v.Id == closest);
if (_planetHelper.Plates.Count > 0 && _vertex.PlateId != -1)
_plate = _planetHelper.Plates[_vertex.PlateId];
else
_plate = null;
UpdateStats();
Vector3 vertexPos = _planetHelper.Mdt.GetVertex(_vertex.Id) * 0.01f;
_pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.1f); // vertexPos * 1.01f;
GD.Print($"Hit: '{pos}'");
var closest = _planetHelper.Octree.SearchNearest(pos ?? Vector3.Zero)?.Id;
if (closest != null)
{
_vertex = _planetHelper.Vertices.Single(v => v.Id == closest);
if (_planetHelper.Plates.Count > 0 && _vertex.PlateId != -1)
_plate = _planetHelper.Plates[_vertex.PlateId];
else
_plate = null;
UpdateStats();
}
}
}
}
@ -110,7 +108,6 @@ public partial class Main : Control
_planetHelper.AutoRun = true;
}
_planetHelper.Process();
GetNode<Node3D>("%Pointer").Position = _pointerPosition;
}
public void UpdateStats()
{
@ -199,6 +196,6 @@ 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, 64, 8192);
}
}

View file

@ -4,7 +4,6 @@ using Godot;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using adatonic;
using Node = adatonic.Node;
using Timer = System.Timers.Timer;
@ -24,8 +23,7 @@ public class PlanetHelper
public int CenterVertexId = -1;
public float PlateExpansion { get; set; } = RandF(0.5f, 2f);
public Vector3 MovementAxis { get; set; } = Vector3.Zero;
public float MovementSpeed { get; set; } = RandF(0f, 1f);
public Vector3 Dir { get; set; } = Vector3.Zero;
}
public class VertexData(int Id = 0, int PlateId = 0, List<int> Neighbours = null, bool StageComplete = false)
@ -154,7 +152,7 @@ public class PlanetHelper
ColorVertex(vertex.Id, color);
PlateData plate = new PlateData(i, color, false, [vertex.Id]);
plate.MovementAxis = GetRandomVector3();
plate.Dir = GetRandomTangentialVelocity(Mdt.GetVertex(vertex.Id), RandF(0f, 1f));
Plates.Add(plate);
}
@ -175,13 +173,6 @@ public class PlanetHelper
return verts.Where(v => Mdt.GetVertexColor(v) == Colors.Black).Except([vertexId]);
}
public Vector3 GetRandomVector3()
{
Vector3 vec = Vector3.Up;
vec = vec.Rotated(Vector3.Forward, Mathf.DegToRad(RandF(0, 180f)));
vec = vec.Rotated(Vector3.Up, Mathf.DegToRad(RandF(0, 360f)));
return vec.Normalized();
}
public Vector3 GetRandomTangentialVelocity(Vector3 pointOnSphere, float speed)
{
Vector3 normal = pointOnSphere.Normalized();
@ -401,15 +392,12 @@ public class PlanetHelper
VertexData centerA = Vertices[plateA.CenterVertexId];
VertexData centerB = Vertices[plateB.CenterVertexId];
Vector3 p1, p2;
p1 = Mdt.GetVertex(vertexData.Id);
p2 = Mdt.GetVertex(neighbour);
Vector3 vel1 = ((p1 - p1.Rotated(plateA.MovementAxis, Mathf.DegToRad(1))).Normalized()) * plateA.MovementSpeed;
Vector3 vel2 = ((p2 - p2.Rotated(plateB.MovementAxis, Mathf.DegToRad(1))).Normalized()) * plateB.MovementSpeed;
vertexData.StrainSamples.Add(CalculateStrainMagnitude(p1, p2, vel1, vel2));
p1 = Mdt.GetVertex(vertexData.Id).Cross(Mdt.GetVertex(centerA.Id));
p2 = Mdt.GetVertex(neighbour).Cross(Mdt.GetVertex(centerB.Id));
vertexData.StrainSamples.Add(CalculateStrainMagnitude(p1, p2, plateA.Dir, plateB.Dir));
}
vertexData.StageComplete = true;
var majorStrain = AverageStrainList(vertexData.StrainSamples);
vertexData.StrainSamples = [majorStrain];
switch (majorStrain.Type)
{
case StrainType.Compression:
@ -434,41 +422,41 @@ public class PlanetHelper
}
public void SpreadStress()
{
var availableVerts = Vertices.Where(d => d.StageComplete == false && d.IsEdge && d.StrainSamples.Any()).OrderByDescending(d => Mathf.Abs(d.StrainSamples.Max(s => s.Magnitude))).Take(500).ToList();
var availableVerts = Vertices.Where(d => d.StageComplete == false && d.IsEdge && d.StrainSamples.Any()).OrderBy(d => Mathf.Abs(d.StrainSamples.Max(s => s.Magnitude))).Take(2500).ToList();
foreach (VertexData vertexData in availableVerts)
{
var neighbours = GetNeighboringVertices(vertexData.Id, false).ToList();
var majorStrain = AverageStrainList(vertexData.StrainSamples);
List<StrainAnalysis> localStrains = [];
foreach (int neighbour in neighbours)
{
localStrains.AddRange(Vertices[neighbour].StrainSamples);
}
localStrains.AddRange(vertexData.StrainSamples);
var averageStrain = AverageStrainList(localStrains);
averageStrain.Magnitude *= 0.9f;
averageStrain.NormalRate *= 0.9f;
averageStrain.ShearRate *= 0.9f;
foreach (int neighbour in neighbours)
{
VertexData neighbourVert = Vertices[neighbour];
neighbourVert.IsEdge = true;
neighbourVert.StrainSamples.Add(averageStrain);
var newStrain = new StrainAnalysis();
newStrain.Magnitude = majorStrain.Magnitude * 0.9f;
newStrain.Type = majorStrain.Type;
newStrain.NormalRate = majorStrain.NormalRate * 0.9f;
newStrain.ShearRate = majorStrain.ShearRate * 0.9f;
neighbourVert.StrainSamples.Add(newStrain);
var newAverage = AverageStrainList(neighbourVert.StrainSamples);;
switch (majorStrain.Type)
{
case StrainType.Compression:
ColorVertex(neighbourVert.Id, Colors.Red * averageStrain.Magnitude);
ColorVertex(neighbourVert.Id, Colors.Red * newAverage.Magnitude);
break;
case StrainType.Shear:
ColorVertex(neighbourVert.Id, Colors.Yellow * averageStrain.Magnitude);
ColorVertex(neighbourVert.Id, Colors.Yellow * newAverage.Magnitude);
break;
case StrainType.Tension:
ColorVertex(neighbourVert.Id, Colors.Blue * averageStrain.Magnitude);
ColorVertex(neighbourVert.Id, Colors.Blue * newAverage.Magnitude);
break;
}
}
vertexData.StrainSamples = [AverageStrainList(vertexData.StrainSamples)];
vertexData.StageComplete = true;
if (neighbours.All(n => Vertices[n].IsEdge))
{
vertexData.StageComplete = true;
}
}
if (!availableVerts.Any())
@ -643,11 +631,10 @@ public class PlanetHelper
double bestDiff = double.MaxValue;
int bestMask = 0;
object lobject = new();
int combinations = 1 << n;
var combs = Enumerable.Range(0, combinations / 4).Select(value => value * 4).ToList();
combinations = combs.Count;
Parallel.ForEach(combs, mask =>
for (int mask = 0; mask < combinations; mask++)
{
int oceanArea = 0;
@ -658,15 +645,13 @@ public class PlanetHelper
}
double diff = Math.Abs(oceanArea - targetOcean);
lock (lobject)
if (diff < bestDiff)
{
if (diff < bestDiff)
{
bestDiff = diff;
bestMask = mask;
}
bestDiff = diff;
bestMask = mask;
}
});
}
for (int i = 0; i < n; i++)
{