-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2c9f08
commit d7896d8
Showing
10 changed files
with
243 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
@tool | ||
class_name DebugArrowMesh extends MeshInstance3D | ||
|
||
@export var size: float = 1 | ||
@export var fat: float = 1 | ||
@export var color: Color = Color.WHITE_SMOKE | ||
|
||
var arrowmesh: MeshInstance3D | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
arrowmesh = fancyArrow( size , color ) | ||
add_child( arrowmesh ) | ||
|
||
# Create a material based on the color ( you can put transparency ) | ||
func getArrowMaterial() -> Material: | ||
var material := StandardMaterial3D.new() | ||
material.set_specular(0.5) | ||
material.set_metallic(0.5) | ||
material.set_transparency( material.TRANSPARENCY_ALPHA ) | ||
material.set_albedo(color) | ||
return material | ||
|
||
# convert blender coordenates to godot cords | ||
# observe that to get the correct face : get the triangle main point, and go ant-hour | ||
func vb(x:float,y:float,z:float) -> Vector3: | ||
return Vector3(x,z,y) | ||
|
||
# add a strip triangle with material to the mesh | ||
func addStrip( m: ImmediateMesh, v1: Vector3, v2: Vector3, v3: Vector3 , mat: Material ): | ||
m.surface_begin(Mesh.PRIMITIVE_TRIANGLE_STRIP, mat) | ||
m.surface_add_vertex(v1) | ||
m.surface_add_vertex(v2) | ||
m.surface_add_vertex(v3) | ||
m.surface_end() | ||
|
||
# draw the fancy arrow | ||
func fancyArrow( size: float, color = Color.RED) -> MeshInstance3D: | ||
var mesh_instance := MeshInstance3D.new() | ||
var immediate_mesh := ImmediateMesh.new() | ||
var material := getArrowMaterial() | ||
|
||
mesh_instance.mesh = immediate_mesh | ||
mesh_instance.set_cast_shadows_setting( mesh_instance.SHADOW_CASTING_SETTING_OFF ) | ||
|
||
addStrip(immediate_mesh,vb(0,0,0),vb(0.05,-1.9,-0.025),vb(-0.05,-1.9,-0.025),material) | ||
addStrip(immediate_mesh,vb(0,0,0),vb(-0.05,-1.9,-0.025),vb(-0.05,-1.9,0.025),material) | ||
addStrip(immediate_mesh,vb(0,0,0),vb(-0.05,-1.9,0.025),vb(0.05,-1.9,0.025),material) | ||
addStrip(immediate_mesh,vb(0,0,0),vb(0.05,-1.9,0.025),vb(0.05,-1.9,-0.025),material) | ||
|
||
addStrip(immediate_mesh,vb(0.1,-1.9,0),vb(0.05,-1.9,-0.025),vb(0.05,-1.9,0.025),material) | ||
addStrip(immediate_mesh,vb(-0.1,-1.9,0),vb(-0.05,-1.9,0.025),vb(-0.05,-1.9,-0.025),material) | ||
|
||
addStrip(immediate_mesh,vb(0,-2,0),vb(-0.1,-1.9,0),vb(-0.05,-1.9,-0.025),material) | ||
addStrip(immediate_mesh,vb(0,-2,0),vb(-0.05,-1.9,-0.025),vb(0.05,-1.9,-0.025),material) | ||
addStrip(immediate_mesh,vb(0,-2,0),vb(0.05,-1.9,-0.025),vb(0.1,-1.9,0),material) | ||
|
||
addStrip(immediate_mesh,vb(0,-2,0),vb(-0.05,-1.9,0.025),vb(-0.1,-1.9,0),material) | ||
addStrip(immediate_mesh,vb(0,-2,0),vb(0.05,-1.9,0.025),vb(-0.05,-1.9,0.025),material) | ||
addStrip(immediate_mesh,vb(0,-2,0),vb(0.1,-1.9,0),vb(0.05,-1.9,0.025),material) | ||
|
||
material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED | ||
material.albedo_color = color | ||
|
||
mesh_instance.transform.origin = Vector3(0,0,0) | ||
set_scale( Vector3(fat,fat,size/2) ) | ||
|
||
return mesh_instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
@tool | ||
class_name PlaneGate3D extends Area3D | ||
|
||
signal gate_entered(body: Node) | ||
signal gate_exited(body: Node) | ||
|
||
@export var size: Vector2 = Vector2(100, 50): set = set_size | ||
@export var tolerence: float = 1.0: set = set_tolerance | ||
@export_category("Debugging") | ||
@export var show_debug_shape: bool = true: set = _set_show_debug_shape | ||
|
||
var is_editor: bool = Engine.is_editor_hint() | ||
var collider: CollisionShape3D = CollisionShape3D.new() | ||
var debug_mesh := MeshInstance3D.new() | ||
var debug_arrow := DebugArrowMesh.new() | ||
var debug_material := StandardMaterial3D.new() | ||
|
||
func _init(): | ||
create_nodes() | ||
|
||
func _ready(): | ||
set_size(size) | ||
connect("body_exited", _on_body_exited) | ||
|
||
if is_editor: | ||
add_child(debug_mesh) | ||
add_child(debug_arrow) | ||
debug_material.cull_mode = BaseMaterial3D.CULL_DISABLED | ||
debug_material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA | ||
debug_material.albedo_color = Color(Color.RED, 0.5) | ||
debug_material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED | ||
debug_draw() | ||
|
||
func _on_body_exited(body: Node): | ||
var direction = (body.transform.origin - transform.origin).normalized() | ||
var forward_vector = -transform.basis.z.normalized() | ||
var dot = direction.dot(forward_vector) | ||
if dot > 0: | ||
emit_signal("gate_entered", body) | ||
else: | ||
emit_signal("gate_exited", body) | ||
|
||
func _set_show_debug_shape(new_value: bool): | ||
show_debug_shape = new_value | ||
debug_draw() | ||
|
||
func debug_draw(): | ||
debug_mesh.mesh = null | ||
if !show_debug_shape: return | ||
var immediate_mesh = ImmediateMesh.new() | ||
immediate_mesh.surface_begin(Mesh.PRIMITIVE_TRIANGLES, debug_material) | ||
|
||
var x = size.x / 2 | ||
var y = size.y / 2 | ||
# Define the vertices of the plane | ||
var v1 = Vector3(-x, -y, 0.0) # Bottom left | ||
var v2 = Vector3(x, -y, 0.0) # Bottom right | ||
var v3 = Vector3(x, y, 0.0) # Top right | ||
var v4 = Vector3(-x, y, 0.0) # Top left | ||
|
||
# Normal pointing up | ||
var normal = Vector3(0.0, 1.0, 0.0) | ||
|
||
# Draw the first triangle (v1, v2, v3) | ||
immediate_mesh.surface_add_vertex(v1) | ||
immediate_mesh.surface_set_normal(normal) | ||
immediate_mesh.surface_add_vertex(v2) | ||
immediate_mesh.surface_set_normal(normal) | ||
immediate_mesh.surface_add_vertex(v3) | ||
immediate_mesh.surface_set_normal(normal) | ||
|
||
# Draw the second triangle (v1, v3, v4) | ||
immediate_mesh.surface_add_vertex(v1) | ||
immediate_mesh.surface_set_normal(normal) | ||
immediate_mesh.surface_add_vertex(v3) | ||
immediate_mesh.surface_set_normal(normal) | ||
immediate_mesh.surface_add_vertex(v4) | ||
immediate_mesh.surface_set_normal(normal) | ||
|
||
# End drawing | ||
immediate_mesh.surface_end() | ||
debug_mesh.mesh = immediate_mesh | ||
|
||
func set_tolerance(new_tolerance: float): | ||
tolerence = new_tolerance | ||
set_size(size) | ||
|
||
func set_size(new_size: Vector2): | ||
size = new_size | ||
if collider: | ||
collider.shape.size = Vector3(size.x, size.y, tolerence) | ||
if is_editor: | ||
debug_draw() | ||
else: | ||
create_nodes() | ||
|
||
func create_nodes(): | ||
collider.shape = BoxShape3D.new() | ||
add_child(collider) | ||
set_size(size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.