objectGroup
A logical group for managing and optimizing per-object uniforms, corresponding to a Uniform Buffer Object (UBO) in WebGPU.
Core Advantages
Its core advantage is performance optimization: it bundles all per-object uniforms into a single data block, significantly reducing API call overhead. It also clearly defines data scope and is automatically managed by the renderer, simplifying development.
Common Uses
Setting different properties (e.g., unique color, wear factor) for multiple objects that share a material.
Passing a unique ID color for each object in object-picking scenarios.
Providing fundamental transformation matrices (like `modelMatrix`), essential for all calculations based on object position, rotation, and scale.
How to adjust
By modifying the value of a Uniform added to this group within a specific object's `onBeforeRender` callback. For example, gradually changing a `dissolveFactor` uniform's value from 0 to 1 can create a dissolve animation for that specific object, while other objects sharing the same material remain unaffected.
Code Examples
1// 1. Declare a per-object uniform
2const intensity = uniform( 1.0 );
3objectGroup.add( intensity );
4
5// 2. Use it in the material
6material.colorNode = color( 0xff0000 ).mul( intensity );
7
8// 3. Set a specific value for an individual object before it renders
9meshA.onBeforeRender = () => {
10 intensity.value = 0.2; // Make this object darker
11};