question

Allister Wilson avatar image
1 Like"
Allister Wilson asked Allister Wilson commented

Vec3 as parameter, return value and node data

How do you pass these around and store them as node data?

The best I could come up with for reading them is:

  1. // Read vector parameter, return value or node
  2. Array vectorAsArray = // param(n), functionReturningVec3(), treenode.value
  3. Vec3 vector = Vec3(vectorAsArray[1].as(double), vectorAsArray[2], vectorAsArray[3]);

To pass them as a function parameter I had to explicitly construct a variant:

  1. func(Variant(vecParam));

I feel like I'm missing something obvious here.

FlexSim 17.0.0
dot syntaxvec3variant
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
3 Likes"
Matthew Gillespie answered Allister Wilson commented

Function parameters, return values, and the data stored on a node are all Variants, so you need to convert the Vec3 into a Variant.

For a return value you can just return the Vec3 and it will automatically be converted into an Array. For the other two cases, you can use vec.as(Array) to convert the Vec3 into an Array Variant.

Turning an Array into a Vec3 requires you to construct a new Vec3 (as you did above) and set each component individually.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.