foreach loop to populate a switch with file ?

   3930   7   1
User Avatar
Member
48 posts
Joined: Aug. 2017
Offline
Hi, I just started with houdini recently, and I would like to know if it possible to create the following network

this is my attempt at doing it, but I'm not sure how to make it work at all (and if it possible), using stamp(“..”, “FORLOOP”, 1) don't seem to produce a number for my path, and i'm not sure of how I have to connect the file to the switch :



The idea is that I have an FBX file containing around 60 mesh, all prefixed with Moss_X (with X being a number), and I would like to basically load all of these mesh and populate the switch node, in order to easily use it with a copy and scatter node that will randomly use each of the available mesh.

is that possible to do ? I would like to avoid doing a python script as it remove a bit of the procedurality of my process !

Thanks a lot !
Edited by SciTheSqrl - Aug. 21, 2017 14:07:06
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Hello and welcome.
stamp(“..”, “FORLOOP”, 1) expression is not working anymore with new for loop.
You should do this:
select foreach_begin1 node and press Create Meta Import Node.
Now you see a new node called: foreach_begin1_metadata1
go to file1 node and replace stamp(“..”, “FORLOOP”, 1) with detail(“../foreach_begin1_metadata1”, “iteration”, 0)
Now you should see something…
User Avatar
Member
48 posts
Joined: Aug. 2017
Offline
Thanks Nima, it worked with a meta node and detail().

I still don't know how I can use my switch node now, if I connect the ouput of the file to the switch, it seem to be considered a single input.

however, I actually found a better way to do what I wanted, directly using stamp() inside the filepath did the trick !



I would still be interested to know if it was possible to do it using the loop ?

Also, do using the stamp() inside the file node would trigger a reload of the file for every call of the copy node ? would having 10k particle in the scatter trigger the reload of the file 10k time ?

Thanks for the help !
Edited by SciTheSqrl - Aug. 21, 2017 17:32:11
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
copy stamping is deprecated since Houdini 16.
You should connect all 60 objects to your switch node if you wanna use it.
Doing this manually can be boring you can write Python script to do this for you but your network becomes messy…
Another approach is to use a delete node inside your for loop and randomly delete all objects expect one in each iteration.
I also used Compiled Blocks to increase the speed.
Take a look at HIP file to see what I'm taking about.

Attachments:
Object Selection in Forloop.hip (258.1 KB)

User Avatar
Member
48 posts
Joined: Aug. 2017
Offline
Thanks a lot nima ! I could understand a lot more about these loop, and using your delete network, I could use a foreach loop to load every single moss mesh inside my fbx without relying on more than a single file node !

I'm also very amazed by your compiled scattering network, using a copy to point node instead of a copy stamp make it at least 10 to 20 time faster ! not to mention it also don't crash when I go above 50k point … (7sec for 200k point yay!)

200k instanced object of every mesh contained in the fbx!
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
I'm delighted.
With the help of Display As option in assemble node you can choose another representation for your packed objects.
This cause to avoid lagging in scene view at higher number of instances.
User Avatar
Member
48 posts
Joined: Aug. 2017
Offline
Thanks about the Display As, it help a lot.

There is a last problem hopefully should be easily fixed, how can I use the point id in the random of the delete instead of the iteration ? I have setup something to make the scattering more efficient, but now, everytime I move my camera, it reinstanciate everything with different mesh (the iteration must be unordered ?),.

Thanks again !
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
You have to use iteration attribute because this is only attribute that changes from one iteration to the another.
You can create a attribute randomize node to create id attribute and use that in delete node.
If you just use point id you will get obvious repetition.
  • Quick Links