I have a couple of questions regarding the design and goals of BufferGeometry
.
- It is well known that a
BufferGeometry
can be reused by multipleObject3D
of the same kind. For instance, aBufferGeometry
can be shared by twoMesh
.
But can a BufferGeometry
be reused by the two objects of different kinds, say a Mesh
and a Line
? And if so, does it require an indexed geometry with drawcalls
?
- Can a
BufferAttribute
be reused in multipleBufferGeometry
. For instance, is it legal to create a bunch geometries sharing a singleposition
buffer, but each having its owncolor
buffer?
If the BufferAttribute
wrapper can’t be shared, can the typed array .array
be shared?
- Are per-element attributes going to be supported in
BufferGeometry
? For instance, color-per-face. Of course, the color-per-face array would need to be unroll into a per-vertex temporary array during thecreateBuffer
orupdateBuffer
phase of the renderer anytime an update is needed.
No(ish) I found the draws are not happy when you cross the types (e.g. gl.LINES and gl.TRIANGLES) against the same buffer, and the drawcall actually returns an error about binding issues – however I didn’t scientifically confirm this was the reason; sometime you get weird errors 🙂 but see 2b) which is a quick work around.
Yes, easily and the shared data will be uploaded to gpu once and shared between all the objects.
Yes, is more “when” rather than “can’t” due to different draw types, though this will double load the data to gpu.
There are also the more exotic options of:
InterleavedBufferAttribute where multiple
BufferAttribute
share the same.array
via InterleavedBuffer so that vertex data can be positioned in proximity:Which allows you to achieve some of the best practices for mobile:
You can mix
InterleavedBufferAttribute
with regularBufferAttribute
or DynamicBufferAttribute when your use cases for the buffers is different, for example one of them gets updated but the other is fixed. (see best practices link above):Don’t know answer to this; but related to complete the
BufferAttribute
picture there is also InstancedBufferAttribute to use with InstancedBufferGeometry; which allows you repeat the mesh, but with different per mesh attributes.Some examples of the exotic types are:
Buffergeometry Instancing
Buffergeometry Instancing – Billboards
Buffergeometry Instancing – Dynamic updates
Buffergeometry Instancing – Interleaved + Dynamic Updates
Yes if you are not going to update it and are not worried what will happen on context loss; but you should also probably be using DynamicBufferAttribute rather than BufferAttribute if you are updating as it preps the gpu with hints that this will happen better.
HTH and maybe @mrdoob can provide more info on 3) as it sounds like the haunting MeshFaceMaterial shadow…