• 3D
  • drawing 3d lines (graphs)

I want to draw a lot of 3d lines, at least 100+, maybe 1000+. Something like a 3d matrix of small dynamic graphs (or 3D surfaces) being dynamically updated from a file or some external source (maybe socket? or mem sharing?).

I'm new to the engine and games engines in general. Can someone describe general efficient approach to such task? Maybe there is some tutorial? Do I need shaders?

Assuming hardware is at least: some strong multicore CPU with 32+ GB RAM, GPU at least gtx 970.

For a quick solution try this code (put it in it's own script). Some things don't work like line thickness but I've been using it a lot to test things in my game.

extends ImmediateGeometry

# class member variables go here, for example:
var m = SpatialMaterial.new()
var points = PoolVector3Array()
export(Color) var color = Color(1,1,1)


func _ready():
	#Turn off shadows
	self.set_cast_shadows_setting(0)
	
	#set_material()
	

func set_material():
	m.set_line_width(3)
	m.set_point_size(3)
	m.set_flag(SpatialMaterial.FLAG_UNSHADED, true)
	m.set_flag(SpatialMaterial.FLAG_USE_POINT_SIZE, true)
	
	m.set_albedo(color)
	
	#m.set_fixed_flag(FixedMaterial.FLAG_USE_COLOR_ARRAY, true)
	
	set_material_override(m)

func set_material_color(color):	
	m.set_line_width(3)
	m.set_point_size(3)
	m.set_flag(SpatialMaterial.FLAG_UNSHADED, true)
	m.set_flag(SpatialMaterial.FLAG_USE_POINT_SIZE, true)
	
	m.set_albedo(color)
	set_material_override(m)



func draw_line(points):
	set_material()
	begin(Mesh.PRIMITIVE_LINE_STRIP, null)
	for i in points:
		add_vertex(i)
	end()


func draw_line_color(points, size, color_par):
	#set_material_color(color)	
	clear()
	color = color_par
	set_material()
	
	if (size != null):
		##set width
		m.set_line_width(size)
		m.set_point_size(size)
	
	begin(Mesh.PRIMITIVE_LINE_STRIP, null)
	for i in points:
		#set_color(color)
		add_vertex(i)
	end()

To use it:

var drawLineFile = load("gdScriptLocation")

func someFunction():
	var pencil = drawLineFile.new()
	# this for me drew x and z axis 
	pencil.draw_line_color([Vector3(0,1000,0),Vector3(1000,1000,0)],3,Color(1.0,0.0,0.0))
	someNode.add_child(pencil)

I have not used it myself, but there is also a Line3D addon on GitHub that apparently replicates the majority of the Line2D functionality but in 3D that may be helpful to use/use-as-a-reference.

Thanks for the advice. I managed to draw a 3D line. Now playing with params, trying to figure out how to set thickness and other stuff.