Render WebGL non-contiguous lines as a single object

五迷三道 提交于 2019-12-08 03:02:25

问题


I have multiple WebGL lines to render, and they all have the same rendering style. So for performance, I want to render them all as a single object, in a single draw call.

But the problem is that the lines don't all connect to each other.

See example here: http://jsfiddle.net/b6jgS/6/

As you can see the rings connect, but I don't want them to. Yet I still want to draw them in a single draw call.

The relevant code is this, which simply generates some geometry for some rings:

# Pardon the coffeescript!
ringsGeom =  new THREE.Geometry()
for u in [-2..2]
  for v in [0..100]
    ringsGeom.vertices.push new THREE.Vector3(
      Math.sin(v/100 * 2 * Math.PI)
      Math.cos(v/100 * 2 * Math.PI)
      u
    )


rings = new THREE.Line(
  ringsGeom
  new THREE.LineBasicMaterial(
    color: 0xffff00
    linewidth: 1
  )
)
scene.add rings

How do I have a single object draw multiple discreet disconnected lines?


回答1:


You construct your geometry as an array of pairs of points representing individual line segments, and then create your line like so:

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

For an example, see GridHelper.js.

three.js r.58

P.S. three.js includes the requestAnimationFrame() shim. You do not need to include it yourself.



来源:https://stackoverflow.com/questions/17268228/render-webgl-non-contiguous-lines-as-a-single-object

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