- Edited
I've been experimenting with @Calinou's suggestion of using 3D meshes to compensate no line thickness in GLES2, and I've managed to get some good results using CubeMeshes and a MultiMesh.
Problem is the function Transform.looking_at
isn't working in some cases. In my case, it failed when trying to draw three lines that represent the axes of the 3D space in my editor. You can see the problem in the image below: the Y-axis line should be upright, and the reason it's not is because it failed to rotate and I'm getting this error:
set_look_at: Condition "v_x.length() == 0" is true
(here in godot's source code).
The two points for that line are a = (8, 0, 8)
and b = (8, 3, 8)
. I'm positioning the line at the center between them before using Transform.looking_at
. My code looks like this:
func line(a:Vector3, b:Vector3, color:Color, thickness:float) -> void:
var idx = mm.visible_instance_count # 'mm' is the MultiMesh
_add_instance_and_check_buffer_size()
var transform := mm.get_instance_transform(idx)
transform.origin = (a+b)/2
transform = transform.looking_at(b, Vector3.UP)
transform.basis.x *= _width_factor*thickness # set the width of the "line"
transform.basis.y *= _width_factor*thickness
transform.basis.z *= a.distance_to(b) # set the length of the "line"
mm.set_instance_transform(idx, transform)
mm.set_instance_color(idx, color)