.drawMode
(f.e. gl.TRIANGLE_STRIP
) were removed in r112.
However, the solutions that have since been put in place are not ideal:
BufferGeometryUtils.toTrianglesDrawMode
allows emulating TRIANGLE_STRIP
mode but (besides the fact that it mutates the incoming geometry which is questionable) it produces a new geometry with significantly different meaning such that the BufferGeometry
APIs must be used entirely differently.
For example, before converting to triangle strip mode, this code is correct:
geometry.setDrawRange(numberOfPositionsToDraw)
That code sets the number of positions (for the position
attribute) that we wish to draw.
However, if we change to triangle strip mode,
const newGeometry = BufferGeometryUtils.toTrianglesDrawMode(geometry, THREE.TriangleStripDrawMode)
not only is render behavior of the original geometry
side-effected (added indices), but this code will now be totally incorrect:
newGeometry.setDrawRange(numberOfPositionsToDraw)
There is no mention about this in the docs anywhere. The problem is that once we’ve switched to a indexed geometry (that’s how the TRIANGLE_STRIP
emulation works), the draw range must be the number of indices to draw, no longer the number of positions to draw, which is definitely not obvious.
To correct the problem, the user will have to look at source code, and finally figure out they need to write this instead:
newGeometry.setDrawRange((numberOfPositionsToDraw - 1) * 3)
or if they’re making a series of quads, not triangles, then
newGeometry.setDrawRange((numberOfPositionsToDraw - 2) * 3)
This is totally non-obvious.
Essentially, what setDrawRange
now requires is the number of triangles to draw (between positions) multiplied by 3
for the fact each triangle has three numbers for indices.
I really think that modes should be restored, in a way similar to what was mentioned in the drawMode
removal PR:
const geometry = new TriangleStripGeometry()
geometry.setAttribute('positions', array)
// this is intuitive, indices are abstracted away from the user
geometry.setDrawRange(numberOfPositionsToDraw)
where TriangleStripGeometry.setDrawRange
does the automatic mapping from point count to triangle index count.
Perhaps BufferGeometry.setDrawRange
would remain as is, so people who know what it is doing will be able to do custom indexing, but otherwise people that just need a strip are left with a lot of complication.
With this approach, we can remove BufferGeometryUtils.toTrianglesDrawMode
. The concept is really meant to be a class, IMO (aligning with all else in Three.js), and we’ll also then get rid of unexpected side-effects.