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:

// Read vector parameter, return value or node
Array vectorAsArray = // param(n), functionReturningVec3(), treenode.value
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:

func(Variant(vecParam));

I feel like I'm missing something obvious here.

FlexSim 17.0.0
dot syntaxvariantvec3
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.

Allister Wilson avatar image Allister Wilson commented ·

Thanks for the clarification.

That's rather unfortunate though, it makes the Vec3 class somewhat pointless for anything non-trivial given the amount of boilerplate code required around it. I'll just stick with separate x / y / z.

1 Like 1 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Allister Wilson commented ·

We're implementing some changes on the 17.2 branch based off the email you sent to [email protected]. We've added an assignment operator and constructor for both Vec3 and Color that takes a Variant.

2 Likes 2 ·
Allister Wilson avatar image Allister Wilson Matthew Gillespie ♦♦ commented ·

Excellent news, thanks for the update.

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Allister Wilson commented ·

Vec3's are nice for setting all three values of an object's location/rotation/size at once:

Object obj = model().find("Queue1");
obj.location = Vec3(0,0,0);

They also have a number of useful methods, especially the project method which replaces all the vectorproject commands:

obj.location.project(obj.up, model())

versus

vectorprojectx(up(obj), xloc(obj), yloc(obj), zloc(obj), model())
vectorprojecty(up(obj), xloc(obj), yloc(obj), zloc(obj), model())
vectorprojectz(up(obj), xloc(obj), yloc(obj), zloc(obj), model())

If you have any suggestions for improvement feel free to make an idea or email [email protected].

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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