How can I clear the GeometryInstane vertex buffer?

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

Hi,

I’m using the Navmesh Demo as a template to create 3D lines. The code below generates 3D lines at random locations.

Problem: using the clear() method for the GeometryInstance node (renamed ‘draw’ here) does not clear the vertex buffer of the node. I know this because running the scene creates an increasing amount of randomly positioned lines.

How can I clear this buffer without having to assign the pointer to the node as null?

extends Spatial

var im

func _ready():
    	var material = SpatialMaterial.new()
    	
    	set_process(true)
    
    	im = get_node("draw")
    	im.set_material_override(material)
        pass
    
func _process(delta):
    	im.begin(Mesh.PRIMITIVE_LINE_STRIP, null)
    	im.clear()
    	
           #create 2 points per line
    	for n in range(2):
    		var point = Vector3(randf()*10-5, randf()*10-5, randf()*10)
    		im.add_vertex(point)
    	im.end()
    	pass

Are you actually talking about ImmediateGeometry? GeometryInstance does not have clear function.

    im.begin(Mesh.PRIMITIVE_LINE_STRIP, null)
    im.clear()

Did you try clearing before begin?

Zylann | 2019-02-12 18:34