Jump to content

while loop in Houdini


freaq

Recommended Posts

I need to do a system where houdini is trying a fit, and if there is intersection between specific parts of the mesh, try again.

basically generating a potetial position (point with a normal for an instance)

 

I have a method for detecting the intersection, but I need a way to if intersection is detected try again until no intersection is detected.

effectively a while loop with a foreach sop or sopsolver or something.

 

anyone have any ideas or examples??

 

thansk :)

Link to comment
Share on other sites

As a matter of fact, I did something very similar to that last week :),

what you can try to do is a foreach node and set it to "for each number"

The number range then becomes the maximum amount of tries.

You can then use the stop expression to make the the loop stop, when you achieved the desired result

To do the latter, I usually set a detail attribute inside and check the "each" node (so the next iteration)

if the detail changed, if so it is safe to break out of the loop ;)

 

If you want to use a true while loop that may be also be possible, if you can fit everything in a wrangle.

 

Hope that helps ;)

Link to comment
Share on other sites

so I'm trying this solution, but when I use the stop condition instead of getting 1 point

(I if I execute 20 times get 6 positive hits so if this would work I should just get one.)

 

I get the shell of the building back, instead of an instance point.

so I'm doing something wrong:

 

in the stop condition I'm using this expression:

detail("../foreach2/each1","stop",0)

Edited by freaq
Link to comment
Share on other sites

I guess you have you disabled "Merge Results" as well, right?

If you want just the output points, I guess you will have to group,

delete and merge the separate paths in the for loop.

 

It gets a bit more complicated, but in general,

you need to make sure the output of the forloop is the same as the input

(+ the extra output points)

if you delete these points, and add them at the output again

you should be able to separate the points at the end (outside the forloop)

 

I am not entirely sure if this is your problem,

but I would need some more information to go on,

if what described above doesn't help.

Link to comment
Share on other sites

got a reply from SESI for people who might be facing a similar issue:

 

The devs tell me:

"It is a while, not a do-while.

 

 We setup the variables for an iteration.

 We then evaluate that parameter.

 That will cause the chain to cook since your test node is at the bottom.

 Then, if it evaluates to one, we quit, without even starting the iteration.

 

 I think what you want is for it to stop the *next* iteration, not the one in which the attribute changed on.

 

 Simplest approach may be to:

 1) have an attrib wrangle over detail; if the stop condition != 0, increment it.

 2) Then have your test setting it to 1 if your stop condition is met.

 3) Finally, your detail() will check for > 1.

 

 This way when it first hits 1 it latches...

 

 Though, writing it, I realize you need a separate Each in Feedback mode to get this to work. So it is going to be a lot more complicated.

 

 I think we need an option to have it stop *after* the iteration rather than before to make this clean, so I'm making this an RFE."

 

Cheers,

 

Silvina

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...