Working with matrices and arrays in Ventuz C# scripts



Unfortunately there's no direct intuitive way to modify elements of output arrays or matrices in Ventuz3 scripts. The Ventuz3 documentation says you have to assign the output array or matrices at once. But theres a step in between: a temporary array/matrix. And in the case of matrices you additionally need to know that the elements are accessed differently to normal arrays.

But before you start hacking in the code, you have to edit the "custom model" of your freshly generated C# script node. Create the following inputs & outputs

Here's how its done for arrays:

public override void Validate()
//to be flexible create the temp array according to the input arrays length
int[] temp = new int[int_in.Length];

//now assign the modified input values to the temp array
temp[0] = int_in[0] * 2;
temp[1] = int_in[1] - 2;

int_out = temp;
changed = true;

Here's how it's done for matrices:

Output Matrices do have the same restriction as arrays plus they do have a not immediatly obvious way of accessing its elements. Matrices are managed 4x4 counterparts of D3DXMATRIX whose elements, according to the documentation are accessed by fields M11 to M44. The numbers follow an easy rule:


As with arrays you have to use a temporary matrix to modify single elements (or fields as they are called according to SlimDX doc).

//you have to reference SlimDX which is providing easy acces to matrices
using SlimDX;

public override void Validate()
//create a temporary Matrix()
Matrix tempM = new Matrix();
//now assign the modified input values to the temp matrix
tempM.M11 = Matrix_in.M11 * 2;
tempM.M12 = Matrix_in.M12 - 2;

Matrix_out = tempM;

changed = true;


As you've seen it's fairly easy to work with in-/out-put arrays and matrices in Ventuz3 c# scripts. You just have to think around the corner. This method works for Ventuz3 3.08.01. I didn't have a chance to test in Ventuz4 yet but I'll test as soon as possible and update the code if necessary .


MediaScreen GmbH


Ventuz3, C#, matrices, arrays