]> git.za3k.com Git - the_dome.git/commitdiff
Initial commit, fun geodesic random testing
authorZachary Vance <za3k@za3k.com>
Tue, 25 Jun 2024 02:15:11 +0000 (22:15 -0400)
committerZachary Vance <za3k@za3k.com>
Tue, 25 Jun 2024 02:15:11 +0000 (22:15 -0400)
12 files changed:
.gitattributes [new file with mode: 0644]
.gitignore [new file with mode: 0644]
DrawLine3D.gd [new file with mode: 0644]
geodesic_dome.gd [new file with mode: 0644]
geodesic_dome.tscn [new file with mode: 0644]
ico_vertex.gd [new file with mode: 0644]
ico_vertex.tscn [new file with mode: 0644]
icon.svg [new file with mode: 0644]
icon.svg.import [new file with mode: 0644]
project.godot [new file with mode: 0644]
world.gd [new file with mode: 0644]
world.tscn [new file with mode: 0644]

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..8ad74f7
--- /dev/null
@@ -0,0 +1,2 @@
+# Normalize EOL for all files that Git considers text files.
+* text=auto eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..4709183
--- /dev/null
@@ -0,0 +1,2 @@
+# Godot 4+ specific ignores
+.godot/
diff --git a/DrawLine3D.gd b/DrawLine3D.gd
new file mode 100644 (file)
index 0000000..0225363
--- /dev/null
@@ -0,0 +1,97 @@
+extends Node2D
+
+class Line:
+       var Start
+       var End
+       var LineColor
+       var time
+       
+       func _init(Start, End, LineColor, time):
+               self.Start = Start
+               self.End = End
+               self.LineColor = LineColor
+               self.time = time
+
+var Lines = []
+var RemovedLine = false
+
+func _process(delta):
+       for i in range(len(Lines)):
+               Lines[i].time -= delta
+       
+       if(len(Lines) > 0 || RemovedLine):
+               queue_redraw() #Calls _draw
+               RemovedLine = false
+
+func _draw():
+       var Cam = get_viewport().get_camera_3d()
+       for i in range(len(Lines)):
+               var ScreenPointStart = Cam.unproject_position(Lines[i].Start)
+               var ScreenPointEnd = Cam.unproject_position(Lines[i].End)
+               
+               #Dont draw line if either start or end is considered behind the camera
+               #this causes the line to not be drawn sometimes but avoids a bug where the
+               #line is drawn incorrectly
+               if(Cam.is_position_behind(Lines[i].Start) ||
+                       Cam.is_position_behind(Lines[i].End)):
+                       continue
+               
+               draw_line(ScreenPointStart, ScreenPointEnd, Lines[i].LineColor)
+       
+       #Remove lines that have timed out
+       var i = Lines.size() - 1
+       while (i >= 0):
+               if(Lines[i].time < 0.0):
+                       Lines.remove_at(i)
+                       RemovedLine = true
+               i -= 1
+
+func DrawLine(Start, End, LineColor, time = 0.0):
+       Lines.append(Line.new(Start, End, LineColor, time))
+
+func DrawRay(Start, Ray, LineColor, time = 0.0):
+       Lines.append(Line.new(Start, Start + Ray, LineColor, time))
+
+func DrawCube(Center, HalfExtents, LineColor, time = 0.0):
+       #Start at the 'top left'
+       var LinePointStart = Center
+       LinePointStart.x -= HalfExtents
+       LinePointStart.y += HalfExtents
+       LinePointStart.z -= HalfExtents
+       
+       #Draw top square
+       var LinePointEnd = LinePointStart + Vector3(0, 0, HalfExtents * 2.0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       LinePointStart = LinePointEnd
+       LinePointEnd = LinePointStart + Vector3(HalfExtents * 2.0, 0, 0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       LinePointStart = LinePointEnd
+       LinePointEnd = LinePointStart + Vector3(0, 0, -HalfExtents * 2.0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       LinePointStart = LinePointEnd
+       LinePointEnd = LinePointStart + Vector3(-HalfExtents * 2.0, 0, 0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       
+       #Draw bottom square
+       LinePointStart = LinePointEnd + Vector3(0, -HalfExtents * 2.0, 0)
+       LinePointEnd = LinePointStart + Vector3(0, 0, HalfExtents * 2.0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       LinePointStart = LinePointEnd
+       LinePointEnd = LinePointStart + Vector3(HalfExtents * 2.0, 0, 0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       LinePointStart = LinePointEnd
+       LinePointEnd = LinePointStart + Vector3(0, 0, -HalfExtents * 2.0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       LinePointStart = LinePointEnd
+       LinePointEnd = LinePointStart + Vector3(-HalfExtents * 2.0, 0, 0)
+       DrawLine(LinePointStart, LinePointEnd, LineColor, time);
+       
+       #Draw vertical lines
+       LinePointStart = LinePointEnd
+       DrawRay(LinePointStart, Vector3(0, HalfExtents * 2.0, 0), LineColor, time)
+       LinePointStart += Vector3(0, 0, HalfExtents * 2.0)
+       DrawRay(LinePointStart, Vector3(0, HalfExtents * 2.0, 0), LineColor, time)
+       LinePointStart += Vector3(HalfExtents * 2.0, 0, 0)
+       DrawRay(LinePointStart, Vector3(0, HalfExtents * 2.0, 0), LineColor, time)
+       LinePointStart += Vector3(0, 0, -HalfExtents * 2.0)
+       DrawRay(LinePointStart, Vector3(0, HalfExtents * 2.0, 0), LineColor, time)
diff --git a/geodesic_dome.gd b/geodesic_dome.gd
new file mode 100644 (file)
index 0000000..b6c3ffa
--- /dev/null
@@ -0,0 +1,24 @@
+extends Node3D
+
+@export var vertex_scene: PackedScene
+
+func random_position():
+       return Vector3(
+               randf_range(-2,2),
+               randf_range(-2,2),
+               randf_range(-2,2)
+       )
+
+func add_vertex(p : Vector3):
+       var vertex = vertex_scene.instantiate()
+       vertex.position = p
+       add_child(vertex)
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+       for i in range(11):
+               add_vertex(random_position())           
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+       pass
diff --git a/geodesic_dome.tscn b/geodesic_dome.tscn
new file mode 100644 (file)
index 0000000..56f1092
--- /dev/null
@@ -0,0 +1,21 @@
+[gd_scene load_steps=4 format=3 uid="uid://cr06eruxv1iyp"]
+
+[ext_resource type="Script" path="res://geodesic_dome.gd" id="1_ewsyw"]
+[ext_resource type="PackedScene" uid="uid://bn7wa6in76pce" path="res://ico_vertex.tscn" id="2_loxxg"]
+
+[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_dw2k7"]
+transparency = 1
+cull_mode = 2
+albedo_color = Color(1, 1, 1, 0.254902)
+
+[node name="GeodesicDome" type="Node3D"]
+script = ExtResource("1_ewsyw")
+vertex_scene = ExtResource("2_loxxg")
+
+[node name="UnitSphere" type="CSGSphere3D" parent="."]
+radius = 0.9
+material = SubResource("StandardMaterial3D_dw2k7")
+
+[node name="TopVertex" parent="." instance=ExtResource("2_loxxg")]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
+fixed = true
diff --git a/ico_vertex.gd b/ico_vertex.gd
new file mode 100644 (file)
index 0000000..9406e98
--- /dev/null
@@ -0,0 +1,34 @@
+class_name IsoVertex extends RigidBody3D
+
+@export var fixed : bool = false
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+       pass # Replace with function body.
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+       get_tree().call_group("vertex", "maybe_draw_line", self)
+
+func maybe_draw_line(other : IsoVertex):
+       if self == other: return
+       var v1 := self.position
+       var v2 := other.position
+       var midpoint = (v1 + v2) / 2
+       if midpoint.length() > 0.75: # If it doesn't pass through the 'middle'
+               get_tree().current_scene.draw_line(v1, v2)
+
+func push_away_from(other : IsoVertex, delta : float):
+       if self == other: return
+       if fixed: return
+       var displacement = self.position - other.position
+       var forceDirection = displacement.normalized()
+       var forceStrength = 10 / displacement.length_squared() # Some function of
+       apply_force(forceDirection * forceStrength * delta)
+
+func _physics_process(delta):
+       # Step 1, get a list of all other vertices
+       # Step 2, apply force to each
+       get_tree().call_group("vertex", "push_away_from", self, delta)
+       # Step 3, normalize current position
+       position = position.normalized()
diff --git a/ico_vertex.tscn b/ico_vertex.tscn
new file mode 100644 (file)
index 0000000..56455d4
--- /dev/null
@@ -0,0 +1,16 @@
+[gd_scene load_steps=3 format=3 uid="uid://bn7wa6in76pce"]
+
+[ext_resource type="Script" path="res://ico_vertex.gd" id="1_31hj6"]
+
+[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_2qrn4"]
+albedo_color = Color(0.495227, 0.615034, 0.939684, 1)
+
+[node name="IsoVertex" type="RigidBody3D" groups=["vertex"]]
+collision_layer = 0
+collision_mask = 0
+gravity_scale = 0.0
+script = ExtResource("1_31hj6")
+
+[node name="Dot" type="CSGSphere3D" parent="."]
+radius = 0.05
+material = SubResource("StandardMaterial3D_2qrn4")
diff --git a/icon.svg b/icon.svg
new file mode 100644 (file)
index 0000000..3fe4f4a
--- /dev/null
+++ b/icon.svg
@@ -0,0 +1 @@
+<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z" fill="#478cbf"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>
diff --git a/icon.svg.import b/icon.svg.import
new file mode 100644 (file)
index 0000000..70be774
--- /dev/null
@@ -0,0 +1,37 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bwn5xbopjnidj"
+path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.svg"
+dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+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
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/project.godot b/project.godot
new file mode 100644 (file)
index 0000000..858ed5e
--- /dev/null
@@ -0,0 +1,20 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+;   [section] ; section goes between []
+;   param=value ; assign values to parameters
+
+config_version=5
+
+[application]
+
+config/name="The Dome"
+run/main_scene="res://world.tscn"
+config/features=PackedStringArray("4.2", "Forward Plus")
+config/icon="res://icon.svg"
+
+[autoload]
+
+DrawLine3d="*res://DrawLine3D.gd"
diff --git a/world.gd b/world.gd
new file mode 100644 (file)
index 0000000..8183573
--- /dev/null
+++ b/world.gd
@@ -0,0 +1,14 @@
+extends Node3D
+
+var LineDrawer = preload("res://DrawLine3D.gd").new()
+
+func draw_line(v1 : Vector3, v2 : Vector3):
+       LineDrawer.DrawLine(v1, v2, Color.BROWN, 0.1)
+
+# Called when the node enters the scene tree for the first time.
+func _ready(): 
+       add_child(LineDrawer)
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+       pass
diff --git a/world.tscn b/world.tscn
new file mode 100644 (file)
index 0000000..645362c
--- /dev/null
@@ -0,0 +1,17 @@
+[gd_scene load_steps=3 format=3 uid="uid://cotgytv6xac3l"]
+
+[ext_resource type="PackedScene" uid="uid://cr06eruxv1iyp" path="res://geodesic_dome.tscn" id="1_j3sin"]
+[ext_resource type="Script" path="res://world.gd" id="1_lxwr8"]
+
+[node name="World" type="Node3D"]
+script = ExtResource("1_lxwr8")
+
+[node name="CameraPivot" type="Node3D" parent="."]
+transform = Transform3D(1, 0, 0, 0, 0.846797, 0.531916, 0, -0.531916, 0.846797, 0.0169442, 1.0738, 1.64421)
+
+[node name="Camera3D" type="Camera3D" parent="CameraPivot"]
+
+[node name="GeodesicDome" parent="." instance=ExtResource("1_j3sin")]
+
+[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
+transform = Transform3D(1, 0, 0, 0, -0.258819, 0.965926, 0, -0.965926, -0.258819, 0, 2.14709, 3)