How to use EditorSpatialGizmo to make a custom gizmo

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ywaby

Hey ywaby. I can see you are here too.
I was actually looking into this as well. Whatcha going to do with a custom gizmo?

SIsilicon | 2018-06-14 03:42

I has got it in project water_pack. and reference withgodot csg src
addon main.py

tool
extends EditorPlugin
...
func create_spatial_gizmo(for_spatial):
	if for_spatial is buoyancy_3d:
		var buoyancy_points = buoyancy_gizmo.new(for_spatial)
		return buoyancy_points

buoyancy_gizmo.py

tool
extends EditorSpatialGizmo
var mat
var node
func _init(node):
    self.node = node
    set_spatial_node(node)
    node.buoyancy_points.connect("data_changed", self, "redraw")
    mat = SpatialMaterial.new()
    mat.flags_unshaded = true
    mat.flags_transparent = true
    mat.flags_no_depth_test = true
    mat.albedo_color = Color(0.277, 0.54, 0.74, 1)

func hightline_selected_point():
    pass

func redraw():
    clear()
    var lines = []
    var handles = []
    var buoyancy_points = node.buoyancy_points.data
    if !buoyancy_points.empty():
        for point in buoyancy_points:
            handles.append(point.pos)
            lines.append(point.pos)
            lines.append(point.pos + point.vector)
        add_handles(handles)
        add_lines(lines, mat, false)

ywaby | 2018-06-28 13:51

You make code show up by adding a minimum of four spaces before the code. And keeping it one line below other text.

One space

Two space

Three spaces

Four

SIsilicon | 2018-06-28 14:16

:bust_in_silhouette: Reply From: SIsilicon

Well I did make a more functional spatial gizmo in my fork of your project. Remember?