Made planet shader 3d, added sprite to selected point, fixed collision stress calculation
This commit is contained in:
parent
930ed42150
commit
451df075e0
5 changed files with 82 additions and 54 deletions
|
|
@ -3,19 +3,20 @@
|
|||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://n56csi5ekat"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
path.s3tc="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
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]
|
||||
|
||||
compress/mode=0
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
|
|
@ -23,7 +24,7 @@ compress/rdo_quality_loss=0.0
|
|||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
|
|
@ -37,7 +38,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=1
|
||||
detect_3d/compress_to=0
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
[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"]
|
||||
|
||||
|
|
@ -69,7 +70,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.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]
|
||||
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]
|
||||
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
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ render_mode unshaded;
|
|||
uniform int mode = 1;
|
||||
uniform sampler2D gradient;
|
||||
varying vec3 world_position;
|
||||
varying flat float color;
|
||||
varying 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() {
|
||||
|
|
|
|||
33
src/Main.cs
33
src/Main.cs
|
|
@ -37,6 +37,7 @@ 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)
|
||||
{
|
||||
|
|
@ -76,26 +77,27 @@ public partial class Main : Control
|
|||
{
|
||||
if (Input.IsActionJustPressed("mouse_secondary"))
|
||||
{
|
||||
var from = _cameraNode.ProjectRayOrigin(GetViewport().GetMousePosition());
|
||||
var to = from + _cameraNode.ProjectRayNormal(GetViewport().GetMousePosition()) * RayLength;
|
||||
var from = _cameraNode.ProjectRayOrigin(_cameraNode.GetViewport().GetMousePosition());
|
||||
var to = from + _cameraNode.ProjectRayNormal(_cameraNode.GetViewport().GetMousePosition()) * RayLength;
|
||||
var result = World.GetWorld3D().DirectSpaceState.IntersectRay(PhysicsRayQueryParameters3D.Create(from, to));
|
||||
if (result.Count > 0)
|
||||
{
|
||||
Vector3? pos = result["position"].AsVector3();
|
||||
if (pos != null)
|
||||
Vector3 pos = result["position"].AsVector3();
|
||||
|
||||
GD.Print($"Hit: '{pos}'");
|
||||
var closest = _planetHelper.Octree.SearchNearest(pos)?.Id;
|
||||
if (closest != null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
_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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,6 +110,7 @@ public partial class Main : Control
|
|||
_planetHelper.AutoRun = true;
|
||||
}
|
||||
_planetHelper.Process();
|
||||
GetNode<Node3D>("%Pointer").Position = _pointerPosition;
|
||||
}
|
||||
public void UpdateStats()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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;
|
||||
|
|
@ -23,7 +24,8 @@ public class PlanetHelper
|
|||
|
||||
public int CenterVertexId = -1;
|
||||
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)
|
||||
|
|
@ -152,7 +154,7 @@ public class PlanetHelper
|
|||
ColorVertex(vertex.Id, color);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +174,14 @@ public class PlanetHelper
|
|||
return verts.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)
|
||||
{
|
||||
Vector3 normal = pointOnSphere.Normalized();
|
||||
|
|
@ -392,12 +401,15 @@ public class PlanetHelper
|
|||
VertexData centerA = Vertices[plateA.CenterVertexId];
|
||||
VertexData centerB = Vertices[plateB.CenterVertexId];
|
||||
Vector3 p1, p2;
|
||||
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));
|
||||
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));
|
||||
}
|
||||
vertexData.StageComplete = true;
|
||||
var majorStrain = AverageStrainList(vertexData.StrainSamples);
|
||||
vertexData.StrainSamples = [majorStrain];
|
||||
switch (majorStrain.Type)
|
||||
{
|
||||
case StrainType.Compression:
|
||||
|
|
@ -422,41 +434,41 @@ public class PlanetHelper
|
|||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
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);;
|
||||
neighbourVert.StrainSamples.Add(averageStrain);
|
||||
switch (majorStrain.Type)
|
||||
{
|
||||
case StrainType.Compression:
|
||||
ColorVertex(neighbourVert.Id, Colors.Red * newAverage.Magnitude);
|
||||
ColorVertex(neighbourVert.Id, Colors.Red * averageStrain.Magnitude);
|
||||
break;
|
||||
case StrainType.Shear:
|
||||
ColorVertex(neighbourVert.Id, Colors.Yellow * newAverage.Magnitude);
|
||||
ColorVertex(neighbourVert.Id, Colors.Yellow * averageStrain.Magnitude);
|
||||
break;
|
||||
case StrainType.Tension:
|
||||
ColorVertex(neighbourVert.Id, Colors.Blue * newAverage.Magnitude);
|
||||
ColorVertex(neighbourVert.Id, Colors.Blue * averageStrain.Magnitude);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (neighbours.All(n => Vertices[n].IsEdge))
|
||||
{
|
||||
vertexData.StageComplete = true;
|
||||
}
|
||||
vertexData.StrainSamples = [AverageStrainList(vertexData.StrainSamples)];
|
||||
vertexData.StageComplete = true;
|
||||
}
|
||||
|
||||
if (!availableVerts.Any())
|
||||
|
|
@ -631,10 +643,11 @@ public class PlanetHelper
|
|||
|
||||
double bestDiff = double.MaxValue;
|
||||
int bestMask = 0;
|
||||
|
||||
object lobject = new();
|
||||
int combinations = 1 << n;
|
||||
|
||||
for (int mask = 0; mask < combinations; mask++)
|
||||
var combs = Enumerable.Range(0, combinations / 4).Select(value => value * 4).ToList();
|
||||
combinations = combs.Count;
|
||||
Parallel.ForEach(combs, mask =>
|
||||
{
|
||||
int oceanArea = 0;
|
||||
|
||||
|
|
@ -645,13 +658,15 @@ public class PlanetHelper
|
|||
}
|
||||
|
||||
double diff = Math.Abs(oceanArea - targetOcean);
|
||||
|
||||
if (diff < bestDiff)
|
||||
lock (lobject)
|
||||
{
|
||||
bestDiff = diff;
|
||||
bestMask = mask;
|
||||
if (diff < bestDiff)
|
||||
{
|
||||
bestDiff = diff;
|
||||
bestMask = mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue