Adding points/drawCount for Line2 dynamically

Hi,

I’m trying to solve the problem using a line with width (Line2 currently) and I need to update the line, like driving a car passing several points and leaving the trajectory.

I think for the basic THREE.line case, the problem is easy using drawCount as in Edit fiddle - JSFiddle - Code Playground.

But I’m wondering if this is achievable using Line2.

1 Like

Hi Frank,
Maybe this link can help You.
https://threejs.org/examples/#webgl_lines_fat

Hey,

Thanks for the reply. I’ve tried this Line2 example, but I want to add new points to this line dynamically without create a new Line2 instance.

best,
frank

One solution is to recreate the geometry of the line, not the line itself:

// creating the Line2 instance
var line = new Line2( new LineGeometry( ), material );

// at some later point, updating the line
// by recreating only its geometry
line.geometry = new LineGeometry( );
line.geometry.setPositions( points );

Here is a live demo, see lines 57-58:

https://codepen.io/boytchev/full/YzOYoYO

image

Another alternative, I guess, is to start with a large vertex buffer, but use only a part of it. Thus you will have preallocated space for all future vertices, but will use only the ones that are visible. This will eliminate the need to recreate of the geometry.

1 Like

Hi Frank,

I made a new experiment with fat lines that can be an alternative for You:

https://jrlazz.eu5.org/anim/linha_gorda_2.html

Maybe this new page can help:

https://jrlazz.eu5.org/anim/paintfatA1.html

thank you! Your suggestion solved the problem that had been bothering me for a week! Hope you well !

1 Like