Capítulo 502 de 859

Chapter 502: UniformArrayNode

Core Idea

Similar to BufferNode this module represents array-like data as uniform buffers. Unlike BufferNode, it can handle more common data types in the array (e.g three.js primitives) and automatically manage buffer padding. It should be the first choice when working with uniforms buffers.

Key Concepts

  • array : Array.<any>: Array holding the buffer data. Unlike BufferNode, the array can hold number primitives as well as three.js objects like …
  • elementType : string: The data type of an array element.
  • isArrayBufferNode : boolean (readonly): This flag can be used for type testing.
  • paddedType : string: The padded type. Uniform buffers must conform to a certain buffer layout so a separate type is computed to ensure correct buffer size.
  • updateType : string: Overwritten since uniform array nodes are updated per render.

Code Examples

const tintColors = uniformArray( [
	new Color( 1, 0, 0 ),
	new Color( 0, 1, 0 ),
	new Color( 0, 0, 1 )
], 'color' );
const redColor = tintColors.element( 0 );
  • What it demonstrates: Typical usage of UniformArrayNode.

Reference Tables

Constructor

Signature
new UniformArrayNode( value : Array.<any>, elementType : string )

Properties

PropertyDescription
.array : Array.<any>Array holding the buffer data. Unlike BufferNode, the array can hold number primitives as well as three.js objects like vectors, matrices or colors.
.elementType : stringThe data type of an array element.
.isArrayBufferNode : boolean (readonly)This flag can be used for type testing.
.paddedType : stringThe padded type. Uniform buffers must conform to a certain buffer layout so a separate type is computed to ensure correct buffer size.
.updateType : stringOverwritten since uniform array nodes are updated per render.

Methods

MethodDescription
.element( indexNode : IndexNode ) : UniformArrayElementNodeOverwrites the default element() method to provide element access based on UniformArrayNode.
.generateNodeType( builder : NodeBuilder ) : stringThis method is overwritten since the node type is inferred from the UniformArrayNode#paddedType.
.getElementType( builder : NodeBuilder ) : stringThe data type of the array elements.
.getPaddedType() : stringReturns the padded type based on the element type.
.setup( builder : NodeBuilder ) : nullImplement the value buffer creation based on the array data.
.update( frame : NodeFrame )The update makes sure to correctly transfer the data from the (complex) objects in the array to the internal, correctly padded value buffer.

Key Takeaways

  1. UniformArrayNode extends: EventDispatcher → Node → InputNode → UniformNode → BufferNode
  2. Most relevant properties: array, elementType, isArrayBufferNode, paddedType.
  3. Key methods: element, generateNodeType, getElementType, getPaddedType.

Connects To