Showing posts with label iteration. Show all posts
Showing posts with label iteration. Show all posts

Friday, 6 January 2023

doing things to for each sop loops

 

How to get information about the current loop

Sometimes you need to use the current loop or the current piece number in an expression on one of the nodes in the same loop. You can get this information with a  Block Begin SOP node that uses the Fetch Metadata method.

  1. Set up a looping block using the instructions above.

  2. Select the  Block Begin SOP node, and then in the Parameter Editor click Create Meta Import Node.

    This button adds a second Block Begin SOP node to the side of the existing one. This node is set up to generate an empty geometry with some detail attributes.

    The detail attributes are as follows:

    numiterations

    The expected total number of iterations, taking into account the Max Iterations and Single Pass parameters on the  Block End SOP node of the loop.

    iteration

    The current iteration number, always starting at 0 and increasing by 1 each loop.

    value

    In piecewise loops, this is the current value of the attribute. For example, the piece integer or name string, or if there is no attribute, the current point or primitive number.

    In simple repetition loops, this is a floating point value starting at the Block End SOP’s Start Value and increasing by the specified Increment each loop.

    ivalue

    In simple repetition, this is an integer version of value. This can be useful if the value is naturally an integer (for example, starts at 1 and increments by 2) and/or if values are over 24 million (where floating point numbers lose precision).

  3. To grab the value of these attributes in a node inside the loop, do the following:

Tuesday, 22 February 2022

Getting Point Attributes in CHOPS

Scenario - Had some points that were moving in unison, I wanted to stretch/squash each point's animation individually so they'd move at different rates. 
I made a point attribute for each called "shift" and gave them a random value between a min and max.

Then I made a CHOPNET and imported the geometry with the tx,ty,tz and shift channels.
Next we need a foreach chop node, be sure to specify all the channels in the parameter box.


Now dive into the foreach node and make a Stretch node.

I just wanted to use the shift attribute in the main Length Scale parameter, so I use the "chopi" function which seemed the simplest out of all the chop_ functions available. It evaluates the channel specified in quotes at the index you give it. This index is meant to be along the timeline, I believe - but since our value is a constant you can throw in any number.

chopi("../Foreach_Iteration/shift",10)

The Stretch node goes to the built in output node...make sure that one is being exported.

This should work now...each point's transform animation stretched according to the shift attribute.

Another thing I found whilst trying to figure this out was the Reorder node. It lets you sort the channels according to different rules. So if you use the number suffix, then it will "group" all the same point channels together. shift0, tx0,ty0,tz0, shift1,tx1,ty1,tz1....etc.... Could be useful if you have some sort of nth based logic going in a script or something, although I really think this for each method works much better.

I'm sure there are better ways to get point attributes in CHOPS.....I just can't figure them out haha. Let me know in the comments, if I've remembered to enable them.