Randomizing instanced variants

   2921   4   0
User Avatar
Member
63 posts
Joined: July 2018
Offline
New to solaris and usd, but I've gone through the basic overviews and tutorials. Trying to understand better how to manipulate different levels of data in LOPs.

So let's say I've got an asset referenced in with 4 geometry variants and 4 material variants (so a total of 16 variants).

When I go to instance, instead of creating 16 different prims for each unique variant and instancing them as a collection, what's the most efficient way to randomize the instances.

Is there a way I can instance a single prim and randomize the variants after (or with) the instancer? Or do I have to establish all the possible variants ahead of the instancer?
madebygeoff.com
User Avatar
Staff
4454 posts
Joined: July 2005
Offline
If you are using "instanceable references" (instead of a point instancer), and your variants exist on the top level primitive (at the same level where you are settnig the instanceable flag), you can just set the variant choices on each instance. In USD the primitive that is marked "instanceable" is still (somewhat) editable. It is only the "instance proxy" primitives inside that cannot be modified.
User Avatar
Member
63 posts
Joined: July 2018
Offline
Thank you Mark! Very helpful. From there I was able to randomize either with a wrangle or the set variants LOP.

However, I noticed that in the wrangle I had to randomize the variant index by @elemnum:

string variants_mtl[] = usd_variants(0, "/instancer1/Instance0", "mtl");
int random = @elemnum%3;
usd_setvariantselection(0, @primpath, "mtl", variants_mtl[random]);

Whereas in the LOP, I had to use @prim in the variant name index:

@prim%3

I'm guessing that has to do with VEX vs. Expressions, but are those attributes listed somewhere? I found the USD VEX page, but it took a bunch of trial and error to figure out @prim.
madebygeoff.com
User Avatar
Staff
4454 posts
Joined: July 2005
Offline
Different LOP nodes support different local variables, but each node should document available variables in its help (as Set Variant does: https://www.sidefx.com/docs/houdini/nodes/lop/setvariant.html). As for VEX, I think it would be reasonable to expect to be allowed to use @prim as an equivalent to @elemnum (when iterating over primitives). Please submit an RFE if you think that would make things easier to learn/use.
User Avatar
Member
63 posts
Joined: July 2018
Offline
Answer: read the manual
madebygeoff.com
  • Quick Links