TSL: How to update elements in array

  1. When declaring array in TSL, do I need to write:
const arr = array(...);

OR

const arr = array(...).toVar();
  1. Once I declared my array, if I need to update an element later how should I do ? I guess we use array.elementAssign() but I’m not sure on how to use this method
    Thanks !

The toVar() is optional but I would recommend it if you are referring to arr more than once. It can also improve the readability of the transpiled code if you use toVar() with the name parameter.
E.g. the below code will name the variable boneMatrices in WGSL or GLSL.

const arr = array(...).toVar( 'boneMatrices' );

It should be:

arr.element( 0 ).assign( value );

value must be a node type e.g. float().

The method elementAssign() does not exist.

2 Likes

thanks !
I mentionned elementAssign because Typescript gave me this definition

(property) elementAssign: (indexNode: NodeRepresentation<Node>) => ShaderNodeObject<ArrayNode>

when writing

array(...).elementAssign()