Jump to content

choose 1-5 random faces between face no.14-18


Recommended Posts

I'm making a procedural tree. I have a couple extrusions going up from my cube before I output the last extrusions output side as a group (branch_extrude).


I would like to pick the number of faces from the side group using a controller (or generate them randomly using stamp later). This isn't a final asset so for now I'm just going with 1-5 branches, (the 4 sides of the cube, and then continuing up). 


The sides of the cube are numbered 15 16 17 18, with the top being number 14. I've accessed these using the 'branch_extrude' group i created from my extrusion which lets me extrude from all the sides no problem. I imagine i could also create a group SOP and extrude 1 of every 2, etc, and I have noticed I can simply enter the face numbers in my extrude group, eg 14, 17. 


What I'd like to do however is select a random number of these faces, between 14 and 18. In half pseudo half houdini language: 

SELECT fit(rand($PT), 0, 1, 1, 5) OF (14, 15, 16, 17, 18) then EXTRUDE. 

Thanks a lot!




Link to comment
Share on other sites

great answer. I used it however, and i can't seem to find the seed and prob operators in the file....  


group :14-18 (pattern 14-18)

group_random: rand($PR+ch("seed"))>(1-ch("prob"))


my understanding of this code is: 

select a random number between 0 and 1 for each primitive number+seed (say, .27 for the number 20). if this is greater than 1 - the ch("prob") value (say .6 or 60%), deselect the face (filter it). so in this case, .27 is not greater than .4, so we would not filter the face. 


however, i figure seed and prob are not set to random floats by default, but i can't find them in the parameter interface... if i use the bit of goblin code you put in a different file however, seed and float channels are not found and i get a warning which doesn't exist in your file, leading me to believe that you

have set these values and the channels are hidden somewhere... 


i created my own controller: 

rand($PR+ch("seed"))>(1-ch("prob")) (with a null with 2 parameters) and this works perfectly. just wondering how yours works still?


also if anyone else is wondering about this, i thought of a way to do it in python which is simple too:

to do this we use:
a = [14, 15, 16, 17, 18]


z = random.rantint (1, len(a))

return a[:z]


i think this works.

Edited by vagrant7
Link to comment
Share on other sites

Yes, your interpretation is correct. These two are spare parameters on the second Group SOP.




Yes, this python code works too. Don't forget to set random's seed or you will get different results each time the node is cooked:

import random
a = [14, 15, 16, 17, 18]

z = random.randint(1, len(a))

return str(a[:z])[1:-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.

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...