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:
- get tube geometry node name (“shafty_001”)
- strip out digits (“001”) and convert digit string to float
- use digit (unique to each auto-numbered tube) to seed the random generator (ranging from 0 to 1)
- offset random values between -0.5 and 0.5 to allow start time either side of a point in time
- multiply offset with ‘spread’ global variable (frame count for animating all the tubes)
- compute scaling steps using my ‘scaleDuration’ global variable (individual tube animation duration)
- add to ‘playPoint’ global variable (animation of tubes is now spread around this point in time)
- 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?