Copy to points and variants

   4915   6   0
User Avatar
Member
240 posts
Joined: March 2015
Online
Hi, I'm using a copy-to-points and variants setup but would like "unique" variants. I've attached a hip file showing a rough example of what I'm trying to do. I've used colours as a visual aid but the actual project uses different geometry, not colours.

I have 12 variants and 12 "Clusters" and would like to choose 5 variants for each "Cluster" by using a seed.

Cluster 1 has repeated variant #7 which I don't want.
Cluster 2 has "unique" variants. (none are repeated)

Cluster 2 only works because that particular seed just happens to work. Rather than try random seeds to find working ones, I'd like to make sure there are no repeats, no matter what seed is used.

One option would be to use a working seed and shift each variant by 1,2,3 etc but I can't quite figure it out.

I'd appreciate any suggestions.

Rob

Attachments:
Variants.hiplc (263.6 KB)

User Avatar
Member
2658 posts
Joined: June 2008
Offline
Python can help in that case because it is easy to check if a value is in a list or not.

The HUGE CAVEAT, of course, is don't submit more points than you have variants or you will generate an infinite loop. The while will never be able to exit. So don't do that.

import random

geo = hou.pwd().geometry()

# Create the point attribute value, giving it a default value and store the returned hou.Attrib object.
rnd_variant = geo.addAttrib(hou.attribType.Point, "variant", 0)

sample_set = [0,1,2,3,4,5,6,7,8,9,10,11]
result_set = []
for point in geo.points():
    n = False
    while(n==False):
        value = random.sample(sample_set, 1)
        if value not in result_set:
            result_set.append(value)
            n = True
            
for index,point in enumerate(geo.points()):
    value = result_set[index]
    point.setAttribValue(rnd_variant, value)
Edited by Enivob - Feb. 21, 2022 10:33:37

Attachments:
ap_python_variants.hiplc (290.0 KB)
Untitled-1.jpg (214.1 KB)

Using Houdini Indie 20.5
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
User Avatar
Member
240 posts
Joined: March 2015
Online
Thanks Enivob, I appreciate your help. I have no clue about Python so I wouldn't have figured that out.
User Avatar
Member
9421 posts
Joined: July 2007
Offline
Didn't check the file, but you should be able to use Sort SOP and randomize point numbers and Enumerate SOP to create variant attrib from those point numbers

Randomized point numbers never repeat, it's like a shuffle
Edited by tamte - Feb. 21, 2022 12:17:52
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
240 posts
Joined: March 2015
Online
tamte
Didn't check the file, but you should be able to use Sort SOP and randomize point numbers and Enumerate SOP to create variant attrib from those point numbers

Randomized point numbers never repeat, it's like a shuffle

I'm probably not understanding or doing it correctly because that results in only variants 0 to 4 being used on each cluster.

ie. if I have 5 points and 12 variants to choose from...
5 points = variants 0,1,2,3,4 whereas I needed 5 points = variants 3,6,8,9,10 etc.
User Avatar
Member
9421 posts
Joined: July 2007
Offline
in that case it would be easiest like this

- make sure your variants are already packed (so 1 point with variant attribute per variant)
- Sort SOP shuffle your variants
- Attrib Copy SOP the variant to your scatter points (this will pick first N shuffled variant numbers in case there is more variats, or it will cycle if there is less variants)
- profit

Attachments:
packed_variants_unnique_random.hiplc (253.2 KB)

Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
240 posts
Joined: March 2015
Online
Thanks Tamte, that's something I can understand and use for future scenarios.
  • Quick Links