hampuseh Posted September 26, 2019 Share Posted September 26, 2019 Greetings! I was wondering if there is a way with a Python script to be able to choose the source geometry library in Houdini (not from disk) and then choose the geometry randomly and copy to the points. To clarify, I have a source of multiple geometries. Geo1, geo2, geo3, etc, which contains a different version of said object. So in this case I have 12 geometry nodes each with a different variation of a oak leaf. I know I can do this with for loop sops and such but I feel that having a script to do this would be quite nice. Quote Link to comment Share on other sites More sharing options...
DonRomano Posted September 26, 2019 Share Posted September 26, 2019 Hey, why not use a copy stamp with a switch node with a variable called copy with this expression : round(fit01(rand($PT), 0, 11)) and then reference stamp("copy1", "copy", 0) in the switch node ? May be much simpler Otherwise check this video : Quote Link to comment Share on other sites More sharing options...
hampuseh Posted September 26, 2019 Author Share Posted September 26, 2019 Thanks for directing me to the video. It would seem that I lack the coding expertise to actually do my own version of the script. The script from the video is doing way more than what I would need. As all I would need is to be able pick the source library via a directory input in the python and then "simply" scatter the objects randomly across the points in which are input to the python node. I will try to work something out during the day. Thanks! Quote Link to comment Share on other sites More sharing options...
toadstorm Posted September 26, 2019 Share Posted September 26, 2019 An easier way would be to use VEX to build up a list of the object paths that you want to randomly copy, then write one of those paths to a point attribute on each point. This might be simpler to do than using Python, since you have the shortcut syntax available to bind attributes... it's a bit cumbersome to do that in Python. Your VEX would look something like this: string paths[] = {"/obj/objects/obj1", "/obj/objects/obj2", "/obj/objects/obj3"}; int randnum = int(rand(@ptnum+ch("seed"))*len(paths)); s@instancepath = "op:"+paths[randnum]; You can then pass the result directly into an Instance SOP. Inserting the "op:" there in front of the path will allow the File SOP inside Instance to reference the correct geometry. Incidentally, this "instancepath" attribute is going to be added to the Copy SOP in H18, so you might want to get yourself used to this sort of workflow. 1 Quote Link to comment Share on other sites More sharing options...
hampuseh Posted September 27, 2019 Author Share Posted September 27, 2019 Ah very nice toadstorm. Yes this made much more sense, I was trying yesterday with Python but couldn't get my head around it really. What I am trying to do now is to make a list automatically of the source library so I don't need to manually type in every single variation of the object. I added a operator path as the source input of the wrangle: string paths[] = {"`chs("source")`/"}; That makes me able to choose any object I desire, but the issue is I am not getting the whole list of available objects in the source. So this will be todays little fiddle! 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.