Jump to content

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?

Link to comment
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
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.

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