How to use Loop Subgraphs in PCG?

Hi there!

I have a bunch of points (in hundreds or thousands) created by a Sampler (Spline or Surface). They have a random Density value. I want to offset the position of each one of them by the value of Density specific to that point. It should be rather easy, right? I can not figure that out.

My test setup is looking like this:


I sample something to create a bunch of points.
I use Loop Subgraph (in Loop Pins option I type: In)
Inside the Subgraph:
I use Attribute Select node to select Density.
I multiply 1000 by density value and I use it as a vector.
I pin In from Input in Transform Points node and I use my vector to Override Offset Min and Max.

I would expect that Subgraph Loop will repeat that operation for each point:
Get a point, offset its position by 1000 multiplied by its density value.
So in result I would see black points (those with Density = 0 ) would not move at all, white points (those with Density value = 1 ) would move by 1000 and everything in between would move proportionally.

Unfortunately all points move by the same value. It is Density value, but one value is used to calculate all points.

What am I doing wrong? How can I fix it? How can I achieve my goal here?

Please help.

Don’t know if you still need an answer but will post the solution for future reference.

Found the answer at 21:30 on this video: https://www.youtube.com/watch?v=Rknnu16mrOw
By Michael Royalty on YouTube.
Video is Definitely worth a watch as this is just a copy of that solution.

I’m not quite sure how the system works but before feeding any data into a loop subgraph it needs to be partitioned which tells the loop what to iterate over . To do this you can employ the attribute partition node. Here’s the basic version I made when I was trying to get the system working (Image A):

NOTE: only allowed 1 image so will place all on 1 and then label with letters

(Almost verbatim from the video)

  1. Assign the Index attribute to a new attribute called Index using the copy attribute node.
    (Image B)

  2. Feed the points data into the Attribute Partition and set the Attribute to Index ( the bit in red is the key to the partition, Each is an item which the loop will iterate over).
    (Image C)

  3. Now you can feed the ‘set’ into the loop subgraph and it will act on everything inside each subset, when using index each subset contains it’s own individual point so it’ll just act on that point (I just copied yours).
    (Image D)

And done!

(Image E)

I see why it is this way because I can imagine some incredibly useful applications with the sets based on groups of attributes but I was stumped for how it work for a good while . I Probably would have remained that way without the video and a little assistance from YouTube transcript to find the right bit! Hope this helps you or anyone else trying to use the Loop Subgraph node!

4 Likes