Showing posts with label foreach. Show all posts
Showing posts with label foreach. 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:

Monday, 21 November 2022

another way to cut or slice objects




Use 2 clip SOPs in a For Each loop. The "detail" function access the iteration number. These little expressions are pasted in the X, Y or Z origin boxes. The first cuts to the top of the division, The second cuts to the bottom of it (technically to the top of the previous iteration - which is what the "-1" is for.

 -8.26+detail("../foreach_count1", "iteration",0)*4

-8.26+(detail("../foreach_count1", "iteration",0)-1)*4

This does not create interior detail - but is good for troublesome geo.

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.

Friday, 21 February 2020

time shifting copy stamps

Needed to time offset an alembic which was being copy-to-points.
The methodology is the same as a previously posted thing, but the copy-to-points node needs to be situated inside the For Each loop



if you squint, you'll see there's an attribrandomize node. I've made an integer attribute called TimeOffset and ..randomised it..
In the timeshift node, I make a spare input and point it to ../PT, which holds said TimeOffset values

The value for the timeshift is : $FF+point(-1, 0, "timeOffset", 0)

so, we take the current frame and add the individual time offset value to it.

Shweet.

Thursday, 18 April 2019

Copying different objects to points

Sometimes you need to copy a bunch of different objects to points. Eg. You have 5 variations of wood splinters and you're emitting them from a snapping plank.
Instead of using the slower copy stamp with random point values, you can use a ForEach loop and a Switch node..and of course a point wrangle.

Connect the objects to the Switch node. In a point wrangle, give each point an (random) integer value (eg "instanceID") ranging from 0 to the number of objects you have.
Make a ForEach network and connect the Point wrangle into the top. Create a null node directly after the start of the Foreach Begin. This will be a "temporary holder" node. It will carry the instanceID value to the Switch node. I've called it PT
The clever bit happens in the Switch node. In the parameter window, click on the cog wheel and add a Spare Input. This will create a new dialog box called Spare Input 0. Type in:

../PT

This will point the spare input to our temporary null & its instanceID value.
In the Select Input dialog box, type

point(-1, 0, "instanceID", 0)

here we are telling the Switch node to get a point attribute from input -1 (which is the spare dialog....which is pointing to the PT temporary null..). The attribute in question is instanceID.. NICE.
A purple arrow going from PT to Switch should have appeared now. This represents that link we've just made.

All that is left to do is to create a Copy To Points node & put the Switch output into the objects input & plug PT into the points input. Finally plug the output of all of that into the Foreach End.

Thursday, 9 November 2017

alternative to copy stamping

Copy Stamping is a bit slow, here's another way of copying things using point attributes.
EG - a bunch of points comprising of cubes, spheres and donuts.


  1. get a bunch of points!
  2. give them an id attribute eg 1,2,3,4..which will represent cube,sphere,donut. The attribute randomise node is quite good for this. There is a setting called Discrete Values which you can tweak with weighting. Eg. 20% value 1, 40%value 2, 40% value 3. Lets call the attribute ID
  3. Create a For-Each-Loop network. Set the mode to "points". By default it is set to process "pieces". Uncheck the use "name" bit. This is to do with the fracturing rigid body workflow.
  4. Connect the cube, sphere and donut to a switch node. In the index box type: point("../foreach1/",0,"ID",0)    this references the current point being processed by the foreach loop and reads it's corresponding ID value.
  5. Inside the foreach loop add a "copy to points" node. Connect the switch node to this.
  6. This should all work now!

Monday, 22 May 2017

voronoi fracture woes & exporting alembics to maya

Voronoi fracturing is often used to create destruction fx. It also creates a lot of dirty geometry, which leads to pain when exporting your geometry to Maya -

"UVs aren't per-vertex or per-polygon per-vertex, skipping"

 This also plays havok with motion blur and any other vertex attributes you might have in play.

Using a For-Each loop, or For-Each subnetwork (if using the subnetwork, attach a Connectivity SOP first, with a "class" attribute, so the For-Each knows what pieces to run over. You type "class" into the Attriubute field of the ForEach Subnetwork parameter box) use Clean SOPs to fix any nasty geo that might have been generated. You'll want to tick most of the boxes - your mileage may vary with the Non-Manifold option.

This probably won't fix the problem still - the fracturing process can make a lot of stray edges - 2 point primitives, which don't play nice.

drop down a Primitive Wrangle and use this code-
i@vertnum = primvertexcount(0,@primnum);

It creates a variable called vertnum that counts how many vertices you have in each primitive.

Follow this wrangle with a blast that has
@vertnum==2
in it's Group box. This will kill any stray edges & hopefully fixes everything!

Tuesday, 16 May 2017

voronoi shatter pieces not staying as a chunk

Sometimes..most of the time, your voronoi shatters that have thickness won't behave correctly. The sides will fall off. Boo.
What you have to do is run all the pieces through a Foreach loop and Fuse the verts back together.

This could go just before your assemble node