Creating THREE.Line's with different endpoints using THREE.BufferGeometry

穿精又带淫゛_ 提交于 2020-01-15 05:28:10

问题


I am creating several THREE.Lines using THREE.BufferGeometry. Initially my app had them all starting at the origin and things worked as expected. Now, I would like to be able to start (and end) them at any point.

This fiddle (http://jsfiddle.net/9nVqU/) illustrates (I hope) how changing one end of the line away from the origin causes unexpected results.

I wondered if it was because any given line follows on from the previous one - switching the start/end order didn't change anything though so if that were true, I'd expect it to break.

Maybe I have the arrays set up incorrectly or the attributes that tell THREE.js how to interpret it - I think I need 2 * 3 verts for each line but changes I made to buffer_geometry.attributes = { seemed to make things worse.

FWIW, the actual effect I'm trying to achieve is to selectively turn on and off the lines based on user input. I can do that already by changing the end position but then I lose that value and I don't want to store it elsewhere. I thought that I could move the start point to the end point to switch it off and then move the start point to the origin again to re-enable it. If there is a way to enable/disable lines individually with BufferGeometry, then that would clearly be better.


回答1:


First of all, you would have to do this:

var line = new THREE.Line( buffer_geometry, material );
line.type = THREE.LinePieces;

Second, this is not supported in r.58 , but should be.

As a work-around, you can hack WebGLRenderer.renderBufferDirect() like so:

// render lines

setLineWidth( material.linewidth );

var position = geometryAttributes[ "position" ];

primitives = ( object.type === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
_gl.drawArrays( primitives, 0, position.numItems / 3 );

_this.info.render.calls ++;
_this.info.render.points += position.numItems;

three.js r.58



来源:https://stackoverflow.com/questions/16867293/creating-three-lines-with-different-endpoints-using-three-buffergeometry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!