看完了Geometry和BufferGeometry,主体应该基本上了解了,趁热打铁,看完拓展性的InstancedBufferGeometry和InterleavedBuffer吧。


InstancedBufferGeometry

文档里对这个的描述就一句话:

An instanced version of BufferGeometry.

源码也异常的简单。

就是对BufferGeometry进行了一个包装,然后加了一个 maxInstancedCount 属性。

根本不知道instance在哪里了,之后内部有用到看一下吧。
(也有可能这个instance,是对象层面的instance,而不是WebGL绘制时候的instance,这个等用到的时候看吧)

InstancedBufferAttribute

相比于BufferAttribute,只多了一个 meshPerAttribute 的属性,也暂时不知道用处。

InterlevedBuffer

“Interleaved” means that multiple attributes, possibly of different types, (e.g., position, normal, uv, color) are packed into a single array buffer.

这个场景的确在WebGL中经常用到。

因为是放在一个数组里边,因此存储的时候也比较简单,就一个array,然后通过stride和offset来存取数据。

其它的倒没有什么,具体的array里边数据怎么放,是传进来数组的事情了。

InterlevedBufferAttribute

存储上述InterlevedBuffer的attribute
有个很重要,就是offset属性,也就是说,虽然是一个array,但不是一个buffer就占满了,而是通过offset,放到指定的位置

剩下的方法好像也就没有什么特殊的了,读写之类的,根据stride和offset来就是了

不过这里有个问题,在例子(/examples/#webgl_buffergeometry_points_interleaved)中:

  1. var interleavedBuffer32 = new THREE.InterleavedBuffer( interleavedFloat32Buffer, 4 );
  2. var interleavedBuffer8 = new THREE.InterleavedBuffer( interleavedUint8Buffer, 16 );
  3. geometry.setAttribute( 'position', new THREE.InterleavedBufferAttribute( interleavedBuffer32, 3, 0, false ) );
  4. geometry.setAttribute( 'color', new THREE.InterleavedBufferAttribute( interleavedBuffer8, 3, 12, true ) );

是两个interlevedBuffer,然后两个InterleavedBufferAttribute,那么,这个interleved的意义在哪里,是在后续操作会合并在一起么。

InstancedInterleavedBuffer

和上边的相同,也之多了一个不知道干嘛用的attribute,剩下的都相同。


大概就是这样,没发现什么有营养的东西,疑惑倒是不少。
不过geometry的部分差不多看完了,下一步看看core里边杂七杂八的东西吧,这样也算结束了一个比较核心的部分。