Skip to content

BufferAttribute setVector & setColor convenience methods#33348

Open
Kodub wants to merge 3 commits intomrdoob:devfrom
Kodub:feature/buffer-attribute-set-vector
Open

BufferAttribute setVector & setColor convenience methods#33348
Kodub wants to merge 3 commits intomrdoob:devfrom
Kodub:feature/buffer-attribute-set-vector

Conversation

@Kodub
Copy link
Copy Markdown
Contributor

@Kodub Kodub commented Apr 7, 2026

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 setXYZ are possible to change into these new convenience methods.

Before:

const v = new THREE.Vector3(1, 2, 3);
attribute.setXYZ(0, v.x, v.y, v.z);

const c = new THREE.Color(0.1, 0.2, 0.3);
attribute.setXYZ(1, c.r, c.g, c.b);

After:

const v = new THREE.Vector3(1, 2, 3);
attribute.setVector3(0, v);

const c = new THREE.Color(0.1, 0.2, 0.3);
attribute.setColor(1, c);

Advantages

  • Shorter code
  • Helps prevent hard to spot mistakes. For example: attribute.setXYZ(0, v.x, v.x, v.z);

Discussion points

  • Other possible names are setXYZFromVector3 and setXYZFromColorRGB. Would these names be preferred to make it clearer that these are convenience methods for setXYZ?
  • Right now these methods simply call their respective setXYZ methods. The extra function call might introduce a small performance overhead.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 360.57
85.58
360.57
85.58
+0 B
+0 B
WebGPU 635.48
176.41
635.48
176.41
+0 B
+0 B
WebGPU Nodes 633.6
176.11
633.6
176.11
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 492.95
120.2
493.07
120.21
+120 B
+7 B
WebGPU 707.66
191.31
707.96
191.31
+294 B
+3 B
WebGPU Nodes 656.88
178.57
657.18
178.61
+294 B
+41 B

@Kodub Kodub force-pushed the feature/buffer-attribute-set-vector branch from 231773f to ba530c3 Compare April 7, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant