Skip to content

How to efficiently set Xflow input with TypedArrays

lachsen edited this page Nov 4, 2013 · 2 revisions

It is possible to use the setScriptValue method of ValueElements (e.g. <float3>, <int> etc.) to override the data with a typed array.

Example:

var valueElement = document.getElementByTagName("float3")[0];
// set data of value element
valueElement.setScriptValue(someTypedArray);
// clear the override value:
valueElement.textContent = "1 0 2";

When using setScriptValue, the content of the DOM element is replaced with the text [value set by script].

Example:

<!-- ValueElement before using setScriptValue -->
<float3 name="diffuseColor" >1 1 0</float3>
<!-- ValueElement after using setScript Value -->
<float3 name="diffuseColor" >[value set by script]</float3>

Depending on the type of ValueElement different TypedArrays are supported.

Here a table:

ValueElement TypedArray
float Float32Array
float2 Float32Array
float3 Float32Array
float4 Float32Array
float4x4 Float32Array
int Int32Array
int4 Int32Array
bool Int8Array
texture Currently not supported
Clone this wiki locally