karen Posted April 15, 2023 Share Posted April 15, 2023 In attached hip file, I'm trying to randomise the primitive sort for each copied sphere. I've checked "output group prefix" and "copy number attribute" for later use by the sort node, but I'd like one sort node to do all the work of assigning different seeds to different spheres. Is it possible? change_sort_seed_for_each_copy.hiplc Quote Link to comment Share on other sites More sharing options...
Alain2131 Posted April 15, 2023 Share Posted April 15, 2023 (edited) You are on the right path. You need the seed to change for each sphere. The question is, what is different on each spheres ? You said it, copynum. Sadly, you cannot simply put in copynum into the seed and expect it to work - the parameters are cooked only once, meaning they cannot have different values for different parts of the geometry. So, if one geometry cannot have different parameter values for it, how about multiple geometries ? The solution is to use the for each node. There is a mode where it takes in an attribute, and splits the geometry in batches where the attribute matches. So all copynum of value 0 will be in one batch, value 1 in the next batch, and so on. All the nodes contained within the for each will be cooked as many times as there are batches (iterations). NOTE Luckily, the copynum attribute is on the primitives. If it was on the points, you would have lost the primitives inside the for each. As a workaround, you'd have had to promote copynum from points to primitives. Not applicable here, but a good thing to know. Then, since we have "multiple geometries" (thanks to the different batches), the nodes in the for each loop will cook once for each of these batches, allowing to change any parameters as we see fit between each iterations. We have two choices here. 1. Use the copynum attribute. This will work because we KNOW it is different for each iteration, and the parameter will pick up a different value on each iteration. 2. Use the iteration number. The for each loop keeps track of which iteration it is on, and we can refer to it. There's not really a better solution, use what you like. You can even make your own attribute as a seed, to be able to tweak it to your liking, if you need. For 1), you'll want to use the prim() expression. It requires the geometry to look into (0 being the connected input), which primitive to fetch the attribute (since the attributes often differs and because the parameters can only have one value, we have to choose which one to take. In our case, the value is the same on all primitives WITHIN THE LOOP, so we can take the first primitive, 0), which attribute to fetch (copynum), and which index to fetch (for vectors and arrays, for integers and floats just use 0). For 2), you'll want to use the detail() expression. Specify which geometry to fetch the attribute from (foreach_begin1_metadata1 is the node which stores the iteration value), which attribute to fetch (iteration), and again which index (it's an integer, so we just specify 0). change_sort_seed_for_each_copy_solution_1.hipnc Edited April 16, 2023 by Alain2131 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.