From ee4a1f09bddd31f8ea2bdc5969f5763f0a7eb899 Mon Sep 17 00:00:00 2001 From: addmix <38119387+addmix@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:18:09 -0700 Subject: [PATCH 1/4] Added AABB to Vector3D --- nodes/3d/vector_3d/vector_3d.gd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nodes/3d/vector_3d/vector_3d.gd b/nodes/3d/vector_3d/vector_3d.gd index ba3ac03..f58a728 100644 --- a/nodes/3d/vector_3d/vector_3d.gd +++ b/nodes/3d/vector_3d/vector_3d.gd @@ -101,3 +101,5 @@ func _init(_color : Color = Color(), _width : float = 0.1) -> void: st.generate_normals() mesh = st.commit() + + custom_aabb = AABB(Vector3.ZERO, Vector3(100, 100, 100)) From 074bbe3077ecb36db96e076c279ef3a9c1d119d3 Mon Sep 17 00:00:00 2001 From: addmix <38119387+addmix@users.noreply.github.com> Date: Tue, 26 Dec 2023 19:01:45 -0700 Subject: [PATCH 2/4] Added `MathUtils.log_with_base()` --- globals/math_utils.gd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/globals/math_utils.gd b/globals/math_utils.gd index 694c926..a3b6749 100644 --- a/globals/math_utils.gd +++ b/globals/math_utils.gd @@ -45,6 +45,8 @@ static func polynomial_smin(a : float, b : float, k : float =0.1) -> float: static func sigmoid(x : float, e : float = E) -> float: return pow(e, x) / pow(e, x) + 1.0 +static func log_with_base(value : float, base : float) -> float: + return log(value) / log(base) #matrix math stuff, very inefficient stuff From b0df10c1ca870a57a65921c6fbac68a53d43a834 Mon Sep 17 00:00:00 2001 From: addmix <38119387+addmix@users.noreply.github.com> Date: Tue, 26 Dec 2023 22:23:12 -0700 Subject: [PATCH 3/4] Added checker pattern to Vector3D --- nodes/3d/vector_3d/vector_3d.gd | 14 ++++++++++---- nodes/3d/vector_3d/vector_3d.gdshader | 11 +++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/nodes/3d/vector_3d/vector_3d.gd b/nodes/3d/vector_3d/vector_3d.gd index f58a728..e4cf20f 100644 --- a/nodes/3d/vector_3d/vector_3d.gd +++ b/nodes/3d/vector_3d/vector_3d.gd @@ -17,14 +17,18 @@ class_name Vector3D if is_equal_approx(dot_squared, length_squared): up = Vector3(1, 0, 0) transform = transform.looking_at(value, up) +@export var color := Color(1, 1, 1): + set(x): + color = x + material.set_shader_parameter("_color", color) @export var width := 0.1: set(x): width = x material.set_shader_parameter("_width", width) -@export var color := Color(1, 1, 1): +@export var checker := false: set(x): - color = x - material.set_shader_parameter("_color", color) + checker = x + material.set_shader_parameter("checker_pattern", checker) var material := ShaderMaterial.new() @@ -55,11 +59,13 @@ Vector3(0, 1, 0)] #index 5 top point #534 #541 -func _init(_color : Color = Color(), _width : float = 0.1) -> void: +func _init(_color : Color = Color(), _width : float = 0.1, _checker : bool = false) -> void: material.shader = preload("./vector_3d.gdshader") material.render_priority = 100 + color = _color width = _width + checker = _checker var st := SurfaceTool.new() diff --git a/nodes/3d/vector_3d/vector_3d.gdshader b/nodes/3d/vector_3d/vector_3d.gdshader index ecded17..33db361 100644 --- a/nodes/3d/vector_3d/vector_3d.gdshader +++ b/nodes/3d/vector_3d/vector_3d.gdshader @@ -4,12 +4,19 @@ render_mode unshaded, depth_test_disabled; uniform float _length = 0.0; uniform float _width = 1.0; uniform vec3 _color = vec3(0, 0, 0); +uniform bool checker_pattern = false; void vertex() { VERTEX = VERTEX * _width; + COLOR = vec4(VERTEX, 0); VERTEX -= float(VERTEX.z < 0.0) * vec3(0, 0, _length); } void fragment() { - ALBEDO = _color; -} + vec3 output_color = _color; + if (checker_pattern) { + ALBEDO = _color * sign(COLOR.r) * sign(COLOR.g) * sign(COLOR.b); + } else { + ALBEDO = _color; + } +} \ No newline at end of file From 56bc45ef47a11ad1edf7c43385046514dfc1ee9e Mon Sep 17 00:00:00 2001 From: addmix <38119387+addmix@users.noreply.github.com> Date: Tue, 26 Dec 2023 22:23:22 -0700 Subject: [PATCH 4/4] Added Point3D --- nodes/3d/point_3d/point_3d.gd | 99 +++++++++++++++++++++++++++++ nodes/3d/point_3d/point_3d.gdshader | 20 ++++++ plugin.gd | 8 ++- 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 nodes/3d/point_3d/point_3d.gd create mode 100644 nodes/3d/point_3d/point_3d.gdshader diff --git a/nodes/3d/point_3d/point_3d.gd b/nodes/3d/point_3d/point_3d.gd new file mode 100644 index 0000000..baa8373 --- /dev/null +++ b/nodes/3d/point_3d/point_3d.gd @@ -0,0 +1,99 @@ +@tool +extends MeshInstance3D +class_name Point3D + +@export var color := Color(1, 1, 1): + set(x): + color = x + material.set_shader_parameter("_color", color) +@export var width := 0.1: + set(x): + width = x + material.set_shader_parameter("_width", width) +@export var checker := true: + set(x): + checker = x + material.set_shader_parameter("checker_pattern", checker) + +var material := ShaderMaterial.new() + +var _mesh : Array[Vector3] = [Vector3(0, -1, 0), Vector3(-1, 0, 0), Vector3(0, 1, 0), Vector3(1, 0, 0)] +var _verticies : Array[Vector3] = [Vector3(0, -1, 0), #index 0 bottom point +#go clockwise from -z position +Vector3(0, 0, -1), Vector3(1, 0, 0), Vector3(0, 0, 1), Vector3(-1, 0, 0), #index 1-4 side poitns +#top +Vector3(0, 1, 0)] #index 5 top point + +# 5 +# +# 1 +# 4 2 +# 3 +# +# 0 + +#bottom triangle order +#021 +#032 +#043 +#014 + +#top triangle order +#512 +#523 +#534 +#541 + + + +func _init(_color : Color = Color(), _width : float = 0.1, _checker : bool = true) -> void: + material.shader = preload("./point_3d.gdshader") + material.render_priority = 100 + + color = _color + width = _width + checker = _checker + + var st := SurfaceTool.new() + + st.begin(Mesh.PRIMITIVE_TRIANGLES) + st.set_material(material) + #bottom 4 triangles + #northeast + st.add_vertex(_verticies[0]) + st.add_vertex(_verticies[2]) + st.add_vertex(_verticies[1]) + #southeast + st.add_vertex(_verticies[0]) + st.add_vertex(_verticies[3]) + st.add_vertex(_verticies[2]) + #southwest + st.add_vertex(_verticies[0]) + st.add_vertex(_verticies[4]) + st.add_vertex(_verticies[3]) + + st.add_vertex(_verticies[0]) + st.add_vertex(_verticies[1]) + st.add_vertex(_verticies[4]) + + #top 4 triangles + st.add_vertex(_verticies[5]) + st.add_vertex(_verticies[1]) + st.add_vertex(_verticies[2]) + + st.add_vertex(_verticies[5]) + st.add_vertex(_verticies[2]) + st.add_vertex(_verticies[3]) + + st.add_vertex(_verticies[5]) + st.add_vertex(_verticies[3]) + st.add_vertex(_verticies[4]) + + st.add_vertex(_verticies[5]) + st.add_vertex(_verticies[4]) + st.add_vertex(_verticies[1]) + + st.generate_normals() + mesh = st.commit() + + custom_aabb = AABB(Vector3.ZERO, Vector3(100, 100, 100)) diff --git a/nodes/3d/point_3d/point_3d.gdshader b/nodes/3d/point_3d/point_3d.gdshader new file mode 100644 index 0000000..b1e26d1 --- /dev/null +++ b/nodes/3d/point_3d/point_3d.gdshader @@ -0,0 +1,20 @@ +shader_type spatial; +render_mode unshaded, depth_test_disabled; + +uniform float _width = 1.0; +uniform vec3 _color : source_color = vec3(0, 0, 0); +uniform bool checker_pattern = false; + +void vertex() { + VERTEX = VERTEX * _width; + COLOR = vec4(VERTEX, 0); +} + +void fragment() { + vec3 output_color = _color; + if (checker_pattern) { + ALBEDO = _color * sign(COLOR.r) * sign(COLOR.g) * sign(COLOR.b); + } else { + ALBEDO = _color; + } +} \ No newline at end of file diff --git a/plugin.gd b/plugin.gd index 74c5456..f0c0161 100644 --- a/plugin.gd +++ b/plugin.gd @@ -33,10 +33,9 @@ func _enter_tree() -> void: #nodes/3d + add_custom_type("Point3D", "MeshInstance3D", preload("./nodes/3d/point_3d/point_3d.gd"), node3d_icon) add_custom_type("Vector3D", "MeshInstance3D", preload("./nodes/3d/vector_3d/vector_3d.gd"), node3d_icon) add_custom_type("FloatingOrigin", "Node3D", preload("./nodes/3d/floating_origin.gd"), node3d_icon) - - add_custom_type("Thruster", "Marker3D", preload("./nodes/3d/thruster.gd"), node3d_icon) #nodes/3d/physics @@ -52,7 +51,12 @@ func _exit_tree() -> void: remove_custom_type("StateMachine") remove_custom_type("State") + remove_custom_type("Point3D") remove_custom_type("Vector3D") + remove_custom_type("FloatingOrigin") + remove_custom_type("Thruster") + + remove_custom_type("Area3DPreferredObjectPicker") if has_node("/root/PluginList"): remove_autoload_singleton("PluginList")