diff --git a/addons/portal_gizmos/gizmo.gd b/addons/portal_gizmos/gizmo.gd new file mode 100644 index 0000000..ef3648b --- /dev/null +++ b/addons/portal_gizmos/gizmo.gd @@ -0,0 +1,42 @@ +extends EditorNode3DGizmoPlugin + +func _init(): + print("[gizmo] _init") + create_material("main", Color(1,0,1), false, true, false) + + +func _get_gizmo_name() -> String: + return "PortalGizmo" + + +func _has_gizmo(for_node_3d: Node3D) -> bool: + var result: bool = for_node_3d is Portal + if result: print("[gizmo] _has_gizmo: " + for_node_3d.name) + return result + + +func _redraw(gizmo): + var node3d = gizmo.get_node_3d() as Portal + print("[gizmo] _redraw: " + node3d.name) + + gizmo.clear() # Always clear the gizmo + + if node3d not in EditorInterface.get_selection().get_selected_nodes(): + return # If not selected, don't draw anything + + + var lines = PackedVector3Array() + + lines.push_back(Vector3(0, 0, 0)) + + if node3d.exit_portal != null: + lines.push_back(node3d.to_local(node3d.exit_portal.global_position)) + else: + lines.push_back(Vector3(5, 5, 5)) + + #var handles = PackedVector3Array() + #handles.push_back(Vector3(0, 1, 0)) + #handles.push_back(Vector3(0, 2, 0)) + + gizmo.add_lines(lines, get_material("main", gizmo), false) + #gizmo.add_handles(handles, get_material("handles", gizmo), []) diff --git a/addons/portal_gizmos/gizmo.gd.uid b/addons/portal_gizmos/gizmo.gd.uid new file mode 100644 index 0000000..bb45a5e --- /dev/null +++ b/addons/portal_gizmos/gizmo.gd.uid @@ -0,0 +1 @@ +uid://b8vlwx31bxx4b diff --git a/addons/portal_gizmos/plugin.cfg b/addons/portal_gizmos/plugin.cfg new file mode 100644 index 0000000..715ae73 --- /dev/null +++ b/addons/portal_gizmos/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Portal Gizmos" +description="Plugin providing 3D Gizmos for portals" +author="Vojtech Struhar" +version="0.1" +script="portal_gizmos.gd" diff --git a/addons/portal_gizmos/portal_gizmos.gd b/addons/portal_gizmos/portal_gizmos.gd new file mode 100644 index 0000000..5376a8a --- /dev/null +++ b/addons/portal_gizmos/portal_gizmos.gd @@ -0,0 +1,13 @@ +@tool +extends EditorPlugin + +const GIZMO_PACKED = preload("gizmo.gd") +var gizmo = GIZMO_PACKED.new() + +func _enter_tree() -> void: + print("[portal_gizmos] Enter") + add_node_3d_gizmo_plugin(gizmo) + +func _exit_tree() -> void: + print("[portal_gizmos] Exit") + remove_node_3d_gizmo_plugin(gizmo) diff --git a/addons/portal_gizmos/portal_gizmos.gd.uid b/addons/portal_gizmos/portal_gizmos.gd.uid new file mode 100644 index 0000000..6dc7a79 --- /dev/null +++ b/addons/portal_gizmos/portal_gizmos.gd.uid @@ -0,0 +1 @@ +uid://c61kmx68labq0 diff --git a/project.godot b/project.godot index 9bf0227..09ef8c2 100644 --- a/project.godot +++ b/project.godot @@ -20,6 +20,10 @@ config/icon="res://icon.svg" window/size/viewport_width=1920 window/size/viewport_height=1080 +[editor_plugins] + +enabled=PackedStringArray("res://addons/portal_gizmos/plugin.cfg") + [input] move_left={