Skip to content

Commit

Permalink
Merge branch 'recovery-branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
addmix committed Dec 27, 2023
2 parents a1bb493 + 56bc45e commit f5dd0b6
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 8 deletions.
2 changes: 2 additions & 0 deletions globals/math_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 99 additions & 0 deletions nodes/3d/point_3d/point_3d.gd
Original file line number Diff line number Diff line change
@@ -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))
20 changes: 20 additions & 0 deletions nodes/3d/point_3d/point_3d.gdshader
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 12 additions & 4 deletions nodes/3d/vector_3d/vector_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -101,3 +107,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))
11 changes: 9 additions & 2 deletions nodes/3d/vector_3d/vector_3d.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 6 additions & 2 deletions plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit f5dd0b6

Please sign in to comment.