Move objects independently inside For Each with Feedback

   1643   8   1
User Avatar
Member
52 posts
Joined: May 2019
Offline
Example HIP file attached.

I have a For Each that doesn't have an input, I'm creating geo with "Multiparam block (tabs)" (parameter interface). Then modifying geo by accessing the current iteration number and concatenating it with multi-param block parameter(s) like so:

ch(strcat("../<PARAMETER_NAME>", detail(-1, "iteration", 0)+1))

Current difficulty: can't move objects separately after 1 iteration. An object after 2nd iteration will move an object from the 1st iteration. I want to move them independently (manually).

Example (desired result): create the first object, and move it. Create a second object, move it independently from the first one, and so on. Make sure that both of them are merged at the end. All of it is inside For Each loop.

Basically, create objects inside For loop and move them independently.

Expected VS current result:


Tried this VEX to try my assumptions(probably missing something fundamental):

vector pos = @P;
int iteration = int(detail(-1, "iteration", 0)); // Get the iteration number. -1 gets it from the Spare input
int numObjects = 2; // Total number of objects to move

int objectId = (@id - 1) % numObjects; // Calculate the object ID based on @id attribute

if (iteration == objectId + 1) // iteration starts from 1
{
if (objectId == 0)
{
// Move the first object in the first iteration
pos.x += ch("../window_placement_x1");
pos.x += ch("../window_placement_y1");
}
else if (objectId == 1)
{
// Move the second object in the second iteration
pos.x += ch("../window_placement_x1");
pos.x += ch("../window_placement_y1");
}
}

@P = pos;


Parameters (just in case):


For each loop (just in case):


GIF example (correct transform):


GIF example (incorrect transform after adding the second frame):


GIF example of how it currently behaves:




If this is not how it is supposed to be, please, guide me in how it should be done.


Thank you for taking the time to have a look 💛
Edited by AnimGraphLab - June 28, 2023 11:51:55

Attachments:
image1.png (228.8 KB)
image2.png (638.5 KB)
image3.png (6.5 MB)
roomgen_forum.hiplc (310.8 KB)
gif1.gif (324.8 KB)
gif2.gif (568.2 KB)
gif3.gif (2.4 MB)

3D Generalist. Transforming 2D images to 3D animations.
Socials: https://linktr.ee/AnimGraphLab [linktr.ee]
User Avatar
Member
1012 posts
Joined: April 2017
Offline
Your example is a bit complex so I might not have understood but, if it gets the ball rollin'...

If you want something different per loop, create another Begin Block set to Fetch Metadata and use the iteration attribute to generate a random seed to do something different each time.

-Olivier
User Avatar
Member
52 posts
Joined: May 2019
Offline
Hey Oliver, thank you for your response!

I actually want to do the opposite of randomization 🙂 I have added another GIF example (the last one) where I've shown the current behavior.

The first frame moves independently from the second frame, but the second frame moves the first frame as well. The current difficulty is I'm not able to move the second frame (or any other after the first frame) without affecting the position of previous frames.

Hope it makes sense.

Just in case, by frames I mean window frames🙂
Edited by AnimGraphLab - June 28, 2023 11:57:31
3D Generalist. Transforming 2D images to 3D animations.
Socials: https://linktr.ee/AnimGraphLab [linktr.ee]
User Avatar
Member
1012 posts
Joined: April 2017
Offline
Oh ok, I get it.

In that case, I think its all about the settings in your For Each. Can you show the settings of your Block Begin and you Block End?

Edit: Also, where is your window placements coming from? It's a node in the for each? What happens at each tab/window you add? It adds detail attributes that get used below?
Edited by olivierth - June 28, 2023 13:40:55
User Avatar
Member
480 posts
Joined: July 2005
Offline
I would put the wrangle at the end just calling placement_xy+itoa(i@id) or something.

Attachments:
roomgen_forum_mod.hipnc (310.0 KB)

User Avatar
Member
52 posts
Joined: May 2019
Offline
Aizatulin
I would put the wrangle at the end just calling placement_xy+itoa(i@id) or something.

Very interesting. This is pretty much what I was trying to figure out and solve. Grateful🙂

Adding additional info below, just in case for future Googlers, or whoever 🙂

I've also added an option to change Z position:

v@P.z += ch("../window_placement_z"+itoa(i@id+1));

As well as added another wrangle to give the option to rotate each object separately:

matrix3 m = ident ();
rotate ( m, radians ( ch("../rotate_y_"+itoa(i@id+1)) ), { 0, 1, 0 } );
@P *= m;


P.S - another issue that was causing unexpected results is Bounds SOP. Whenever a new frame is added, Bound SOP combines 2 objects i.e creates a single bound, instead of 2 separate bounds per object.

So I created a group after the Unreal Material SOP node with a Wrangle:

string groupName = sprintf("bounds_%d", detail(-1,"iteration", 0)+1); // -1 is a for each metadata added to a node spare input
setprimgroup(0, groupName, @primnum, 1);

And then used those groups (5 in total, "hardcoded") inside separate Bound SOP (not dynamic but worked for me, possibly proposition by u/DavidTorno on Reddit answer post [www.reddit.com] with Connectivity SOP would be a solution for that):

Edited by AnimGraphLab - June 30, 2023 12:32:05

Attachments:
2023-02-22-0738.png (579.3 KB)

3D Generalist. Transforming 2D images to 3D animations.
Socials: https://linktr.ee/AnimGraphLab [linktr.ee]
User Avatar
Member
52 posts
Joined: May 2019
Offline
olivierth
Oh ok, I get it.

In that case, I think its all about the settings in your For Each. Can you show the settings of your Block Begin and you Block End?

Edit: Also, where is your window placements coming from? It's a node in the for each? What happens at each tab/window you add? It adds detail attributes that get used below?


Aizatulin answer [www.sidefx.com] worked for my case 🙂

Block Begin:



Block End:



Also, where is your window placements coming from?

Kind of difficult to explain by text 🙂 Basically I get walls -> extract the centroid for each prim -> specify on which wall to place window(s) (only 4 options as only 4 points present: 0,1,2,3) -> copy to point -> change window placement if needed (manual, issue I had) -> add an additional window on the same point and modify its position. Hope it makes sense.



Grateful for your willingness to understand/help 💛
Edited by AnimGraphLab - June 30, 2023 12:24:14

Attachments:
begin block.png (138.4 KB)
end block.png (535.8 KB)
111.png (2.6 MB)

3D Generalist. Transforming 2D images to 3D animations.
Socials: https://linktr.ee/AnimGraphLab [linktr.ee]
User Avatar
Member
480 posts
Joined: July 2005
Offline
If you want to calculate the bounds individually, you can loop over the "ids" for example (like over connected pieces).

@edit: it is better to use id as integer attribute (not float) -> sometimes float may work but some notes expecting integer attribute input and it is more consistent using integer for id.
If you use CopyToPoints, you can also use piece/variant attribute to distinguish between the different ids aswell.
Edited by Aizatulin - July 1, 2023 02:14:28

Attachments:
roomgen_forum_modA.hipnc (316.6 KB)
variant_copy_simple_example.hipnc (105.8 KB)

User Avatar
Member
52 posts
Joined: May 2019
Offline
Aizatulin, thank you so much! Grateful 🙂
3D Generalist. Transforming 2D images to 3D animations.
Socials: https://linktr.ee/AnimGraphLab [linktr.ee]
  • Quick Links