Compare commits

...

2 commits

5 changed files with 83 additions and 55 deletions

View file

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

View file

@ -5,6 +5,7 @@
[ext_resource type="Gradient" uid="uid://b5l44rktieewe" path="res://resources/planet_gradient.tres" id="2_ygjfp"] [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://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="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"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_uxrcv"]
@ -69,7 +70,7 @@ environment = SubResource("Environment_rf2cd")
camera_attributes = SubResource("CameraAttributesPractical_a814b") camera_attributes = SubResource("CameraAttributesPractical_a814b")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo" unique_id=899426195] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo" unique_id=899426195]
transform = Transform3D(0.88874525, -0.29675773, 0.3493804, 0, 0.7621714, 0.6473753, -0.45840138, -0.5753517, 0.6773762, 0, 0, 0) transform = Transform3D(0.99999994, 0, 0, 0, 0.99999994, 0, 0, 0, 0.99999994, 0, 0, 0)
[node name="Icosphere" type="MeshInstance3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo" unique_id=793654005] [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) transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, 0, 0, 0)
@ -89,6 +90,13 @@ fov = 5.0
[node name="CollisionShape3D" type="CollisionShape3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo/StaticBody3D" unique_id=299495076] [node name="CollisionShape3D" type="CollisionShape3D" parent="TabContainer/Planet/SubViewportContainer/SubViewport/ZaWarudo/StaticBody3D" unique_id=299495076]
shape = SubResource("SphereShape3D_rpqi1") 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] [node name="PanelContainer" type="PanelContainer" parent="TabContainer/Planet" unique_id=716838825]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3

View file

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

View file

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

View file

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