How to do this particular HScript with Vex?

   1704   2   2
User Avatar
Member
3 posts
Joined: Oct. 2016
Offline
Hi!

I needed to automatically animate about 80 tubes to illustrate drilled shafts in the ground, animating the Y-scale of each shaft from 0 to 1 at a fixed speed, but not all shafts at once. I did not want to keyframe all that by hand.



As a Houdini newbie I excitedly jumped into solving it with Vex. A SOP Vex exposed the points while I really just needed quick access to the Y-scale attribute at object-level. I briefly considered an Attribute Wrangle node but I was sorely pressed for time considering that I still had to learn how to code Vex, HScript or whatever was required. Although I had read somewhere that HScript was deprecated, I went for it.



In the Textport I setenv:

playPoint = 140
scaleDuration = 20
spread = 100

I wrote the following HScript for the Y-scale of the first tube before making copies:

{float n = atof(substr($OS,7,3)); float v = 0; p = int($playPoint + ((rand(n) - 0.5) * $spread)); if ($F > p) {v = ($F - p) / $scaleDuration;} if (v < 0) {v = 0;} if (v > 1) {v = 1;} return v;}

HScript description:
  1. get tube geometry node name (“shafty_001”)
  2. strip out digits (“001”) and convert digit string to float
  3. use digit (unique to each auto-numbered tube) to seed the random generator (ranging from 0 to 1)
  4. offset random values between -0.5 and 0.5 to allow start time either side of a point in time
  5. multiply offset with ‘spread’ global variable (frame count for animating all the tubes)
  6. compute scaling steps using my ‘scaleDuration’ global variable (individual tube animation duration)
  7. add to ‘playPoint’ global variable (animation of tubes is now spread around this point in time)
  8. clamp result between 0 and 1 (my code here is probably inefficient)

It works like a charm! The global variables allowed me to very easily time the animation. HScript is suitably fast = real-time viewport playback for all those tubes.

Questions:

(1) Would you do this using SOP Vex? If so, how?

(2) Would you use an Attribute Wrangle? If so, how?

(3) Any other clever / efficient way to solve this?
Edited by Paul Newman - Dec. 3, 2016 06:56:24
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
Setting up dozens of geo nodes with the same content looks not very Houdini-like to me.

One way of scaling tubes up and down is using a copy SOP. Also make sure to have a look at CHOPs for these kind of effects.

Attachments:
drill_shafts.hipnc (63.7 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
3 posts
Joined: Oct. 2016
Offline
Konstantin Magnus
Setting up dozens of geo nodes with the same content looks not very Houdini-like to me.

One way of scaling tubes up and down is using a copy SOP. Also make sure to have a look at CHOPs for these kind of effects.
Thanks for your time to teach me with an example scene!

Coming in cold on a deadline, the main thing is to get something that works ASAP.

I did originally use the copy SOP for non-animating shafts. The idea of animating a point before copying geometry onto it is so cool! That's another Houdini a-ha moment for me!

Cheers!
  • Quick Links