BufferAttribute setVector & setColor convenience methods#33348
BufferAttribute setVector & setColor convenience methods#33348Kodub wants to merge 1 commit intomrdoob:devfrom
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
231773f to
ba530c3
Compare
|
If convenience of setting BufferAttribute values here is the primary goal of this change I'll point out that using the spread operator serves this use quite well, in my opinion: const pos = new Vector3();
posAttr.setXYZ( i, ...pos ); |
|
Note that we have similar convenience methods. See #25637. I'd follow the same naming conventions for consistency. |
|
TBH, I'm not in favor of this PR since it bloats the API for no adequately good reason. The spread operator wasn't available in earlier days of three.js but now it's safe to use it and can avoid such verbose APIs. Regarding the math classes, there is e.g. no need for |
|
Note that the spread operator syntax does not work in this case when using TypeScript, since it can't guarantee that the iterator will return enough elements. This syntax works though: Either way, I think it's not entirely clear that the spread operator can be used like this, since the user would have to know that the Vector implements an iterator. But maybe it shouldn't be up to the library to educate users. |
ba530c3 to
bbf484d
Compare

Description
This PR adds new convenience methods to
BufferAttribute&InterleavedBufferAttribute.setVector2()setVector3()setVector4()setColor()These helps simplify setting vectors and colors which seem to be a quite common pattern as most instances of
setXYZare possible to change into these new convenience methods.Before:
After:
Advantages
attribute.setXYZ(0, v.x, v.x, v.z);Discussion points
setXYZFromVector3andsetXYZFromColorRGB. Would these names be preferred to make it clearer that these are convenience methods forsetXYZ?setXYZmethods. The extra function call might introduce a small performance overhead.