spite / THREE.MeshLine

Mesh replacement for THREE.Line
MIT License
2.16k stars 380 forks source link

Is it possible to use this with InstacedMesh? #105

Open trusktr opened 4 years ago

trusktr commented 4 years ago

For example either the one from three-instanced-mesh, or the builtin THREE.InstancedMesh? In particular, I would like each line to be instanced, but having different point values. Seems this may not be possible with the current InstancedMesh classes.

spite commented 4 years ago

I´m not sure you understand the idea behind instancing. It's useful to render multiple instances of the same mesh. If you want multiple lines, with different point values, there's really not a lot of advantages. And also, setting up instancing rendering is slightly more costly. Instacing could be used at a low level to render each individual segment of a line, but i don´t think there's a lot to win here.

trusktr commented 4 years ago

I´m not sure you understand the idea behind instancing

I am familiar with instancing.

not a lot of advantages

If it is possible, 1 GPU call for 1000 lines would be better than 1000 GPU calls for 1000 lines.

I don't know three.meshline implementation enough. And I also don't know how feasible it would be to instance lines with such varying characteristics. Seems the shader would need to understand not only which part of a line it is operating on, but which instance it is operating on.

spite commented 4 years ago

If all the lines have the same number of vertices, it could make sense.

Right now, as an alternative, adding some kind of segmentation in a big single geometry rather than instancing could work: if you need to draw a 1000 (different) lines, i would still create one single geometry, and add vertices like: firstOfLine1 ... lastOfLine1, lastOfLine1, firstOfLine2, firstOfLine2, ... lastOfLine2, etc. and set the width to be 0 in the segmentlastOfLine(n-1) to firstOfLine(n). The repeated vertices are there to make the transition look correct.

Just an idea.