Casting confusion

   1556   4   0
User Avatar
Member
393 posts
Joined: Aug. 2018
Offline
Greetings all,
Could I seek some education on a minor VEX casting matter please:

I was following a tutorial where the following VEX code was entered in the 'force total count' parameter of a SOP Scatter node. The task being to change the random seed every 7 frames and output a value between 20 and 30.

fit01(rand(floor($F*(1/7))), 20, 30)

When I looked at the code I was surprised it worked (coding newbie alert).
My understanding is that "(1/7)" would be an integer calculation - and therefore give 0 as a result. Subsequently the random seed value would remain static at 0. To my surprise, the output value does change every 7 frames as intended.

Testing the above code in a separate point wrangle outputting to a float attribute gives a static output of 0 as I expected. Changing the code to ("1.0/7") to force a float calculation fixes the issue, as expected.

So: why does the original code work in the context of the scatter node parameter, but not in the context of a wrangle?
Or... what am I misunderstanding here : )


With thanks
Edited by Mike_A - Jan. 7, 2023 09:11:03
User Avatar
Member
5100 posts
Joined: Feb. 2012
Online
That's because that's not VEX code but an hscript expression. AFAIK by default all numeric values are evaluated as floats unless you use the int() expression.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
393 posts
Joined: Aug. 2018
Offline
Ah, understood. I realised that '$F' was a HScript variable - but I read somewhere that VEX would interpret that, and wrongly assumed it was a VEX statement.
That leads me on to a secondary question: There are some node parameter fields that are specifically marked as 'VEX expression'. Are all node parameter fields that are not so marked exclusively HScript?
Edited by Mike_A - Jan. 8, 2023 04:24:02
User Avatar
Member
9376 posts
Joined: July 2007
Offline
Mike_A
I realised that '$F' was a HScript function - but I read somewhere that VEX would interpret that, and wrongly assumed it was a VEX statement.
no VEX doesn't understand $F variable it has it's own @Frame binding (which for "convenience" can also now be used instead of $FF in parameters so it may be confusing)
while it's possible to use $F in VEX snippet, it's expanded into the string and injected in the code before it's compiled which happens only on the first frame so $F specifically wouldnt animate, but $FPS or other static variables would expand to the value so it would sort of work, as in the code it would be a hardcoded constant since the expansion happens before before the code is compiled

Mike_A
That leads me on to a secondary question: There are some node parameter fields that are specifically marked as 'VEX expression'. Are all node parameter fields that are not so marked exclusively HScript?
parameters can contain either numerical value or string
such value can be typed in manually or generated using either HScript Expression or Python Expression
for string parameters you can also inject HScript Expression inbetween raw text using ``

VEXpression parameters are just string parameters, with VEX syntax highlighting for conevenience
the string/text you write in there can also as mentioned be generated using HScript or Python Expression and once those expressions are evaluated you will get final string which is hopefully a valid VEX snippet code

this is then referenced by a node inside of that HDA that can evaluate such VEX snippet, usually Snippet VOP or Attribute Wrangle Core SOP
In other words when you are writing VEX in parameters you are literally just writing a string as far as parameters are concerned and could use HScript Expressions in the process, however you would need to be careful to not use any time dependent ones
Edited by tamte - Jan. 7, 2023 22:47:57
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
393 posts
Joined: Aug. 2018
Offline
Thanks Tomas - that's a very helpful explanation.
  • Quick Links