Genome
RSS< Twitter< etc

<< Back to FAQ Index

When and How do I Convert Value Data Types?

 

Channel values must match the expected type when passing data to the Output node.

For example, if the Output node is set to Position channel, the value passed to it must be a Vector (float32[3]). If the Output node is set to Selection channel, the value passed to it must be a Float (float32[1] or float32 for short).

float32 means a Floating Point number represented as 32 bits (4 bytes). float32[3] means a Vector with 3 components (typically representing X,Y and Z coordinates, R,G and B colors, U,V and W mapping coordinates etc.), each component using 4 bytes, or 12 bytes combined.

The expected type is listed next to the input socket of the Output node. It is also represented by the Data Type and Arity lists in the Parameters rollout:

Note that in Genome, the data type of the Output channel cannot be changed (in Krakatoa Magma, custom channels can be created and the data type and arity can be customized).

Implicit Conversion

Some Arithmetic operators will perform implicit conversion of the incoming values. For example, the Multiply operator allows a Float to be multiplied by another Float and a Vector to be multiplied by a Float or another Vector. It allows the Multiplication of two Integers, but does not allow the Multiplication of a Float or Vector by an Integer - you will have to explicitly convert an Integer to Float using Convert ToFloat before using it in mixed type operations.

Explicit Conversion

Some operators like Add for example will not perform an implicit conversion - attempting to add a Float to a Vector will produce an error like

Magma Incorrect data type: | ID: 2 | Input Index: 2 | Expected Type: float32[3] | Found Type: Float |

When such an error is displayed, you MUST convert the second input value to the expected type, in this particular case using a Convert ToVector operator.

To perform a conversion from a Float to a Vector, use the Convert > ToVector operator. To convert from Vector to Float, use the Convert Breakout operator.

Conversion Shortcuts

Some operators provide one or more Convert To... buttons in their parameters rollout.

For example, a Float InputValue has a button "Convert To Vector" at the bottom of the rollout which is a shortcut to insert a conversion operator in the existing flow if the node is already connected, or connect a conversion operator behind it if it is not connected yet.