Jump to content
Sign in to follow this  
madebygeoff

Randomizing instanced USD variants

Recommended Posts

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, is there a more 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?

Share this post


Link to post
Share on other sites

Thanks, Ryew. He does have a method in that last video using a for-each loop running over all the selected primitives. But it seemed a bit complicated. Was able to chat with Mark Tucker at SideFX who suggested a simpler method.

For anyone else looking, the trick is to make sure in the instancer that you are using "instanceable reference (or inherit or specialize depending on your needs)" instead of the point instancer. And your reference (with variants) needs to be the top level prim that you are feeding in for instanceing.

Then you could write a bit of vex (for instance):

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

Or you can append a set variant LOP and use @prim%3 in the "variant name index" box.

It's a little confusing why @prim doesn't work in the wrangle, but that's how I got it to work.

You take a slight performance hit by not using the point instancer, but it's a useful tradeoff in some situations.

Edited by madebygeoff
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×