spite / THREE.MeshLine

Mesh replacement for THREE.Line
MIT License
2.14k stars 381 forks source link

Updating line start and end point #51

Open zoneblaze opened 6 years ago

zoneblaze commented 6 years ago

Hi there, I'm new to 3JS, I managed to draw a simple straight line ok with MeshLine, next I need the start point and endpoint to animate in different directions.

geometry.vertices.push(new THREE.Vector3( 0, 0, 0)); geometry.vertices.push(new THREE.Vector3( 30, -30, -130 ));

I tried e.g "geometry.vertices[0].x += 1" on render udate with "this.geometry.verticesNeedUpdate = true"

But nothing happens, am I missing a trick or is it not possible to change a line shape once it has been initialized?

spite commented 6 years ago

Check https://github.com/spite/THREE.MeshLine/blob/master/demo/js/main-spinner.js#L223, you have to call .setGeometry again when you change your vertices. THREE.MeshLine needs to run some operations on your geometry.

ffpetrovic commented 6 years ago

I need to change the points at runtime. Which means I'm calling .setGeometry every render cycle. Any performance downsides on that part?

Also, a question, can the geometry that is used later, be larger than the initial geometry set on the MeshLine? Meaning, can it later have more vertices?

Hari-KrishnanV commented 6 years ago

Is it possible to change the existing vertices? If possible, how can I add, remove or modify the vertices?

trusktr commented 4 years ago

you have to call .setGeometry again when you change your vertices

I'm calling .setGeometry every render cycle. Any performance downsides on that part?

@ffpetrovic Yes, MeshLine creates a new internal positions array every time (with this.positions = [] then fill sit up again), instead of reusing the same array, so the previous arrays will all need to be garbage collected.

can the geometry that is used later, be larger than the initial geometry set on the MeshLine? Meaning, can it later have more vertices?

Yes, because look at the code here:

https://github.com/spite/THREE.MeshLine/blob/565dc97b36c742120936555c3b0eeb9653202e03/src/THREE.MeshLine.js#L37-L57

As you can see there (click on it to see the code that isn't visible above), it assigns a new array to this.positions, then copies all the Geometry's vertices into the array (wasteful, but works).

Is it possible to change the existing vertices? If possible, how can I add, remove or modify the vertices?

@Hari-KrishnanV Yes, read the comments above. ^


@spite It'd be great if it would re-use the same array, or even better, just iterate on the geometry's own vertices without using more memory.