spite / THREE.MeshLine

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

Fast advance() function for dynamic lines with demo #25

Closed Jared-Sprague closed 7 years ago

Jared-Sprague commented 7 years ago

Hey @spite! We started using this library to add dynamic trails to moving objects, and quickly learned that calling setGeometry() everytime the line changes, is very in efficient and slow as it completely rebuilds the line. And 4 of the arrays that it build are static based on the length of the line and never change. @mwcz and I created the advance() function advances the line by one position by modifying the buffer attribute typed arrays directly for Next, Current, and Previous positions. This is so much faster than calling setGeometry() for 1 new position. See the included demo that adds trails to the flocking birds demo.

spite commented 7 years ago

Nice work!

I've reviewed the PR and i have a few changes and fixes for both the advance() and the boids demo. Do you mind if i merge our PR and then change it on the master branch?

mwcz commented 7 years ago

Sounds good to me! @Jared-Sprague? By the way, thank you @spite for making this!

Jared-Sprague commented 7 years ago

Sounds good thanks!

spite commented 7 years ago

Ok. That should be it. Merged and updated.

The most relevant changes should be:

For the lib:

For the demo:

I think that's all, I hope I haven't broken anything.

Again, thanks for the work!

Jared-Sprague commented 7 years ago

@spite Ah i love the changes! Especially the memcopy so clever!

One question, will you uplaod the trails demo and link to it from the readme?

spite commented 7 years ago

Yes, of course, with full credits! I can host it on my domain, or link to your online version.

Jared-Sprague commented 7 years ago

I think it makes the most sense to put it in the same location as the other demos. I actually haven't uploaded it anywhere. Thanks!

Jared-Sprague commented 7 years ago

@spite of course I'm happy to host the tail demo if you want!

spite commented 7 years ago

Sorry, I've been AFK until now. I've hosted it with the other demos, no worries. All done!

Jared-Sprague commented 7 years ago

@spite thanks you rock! and thanks for the mention!