Correct way to get instancer using variants

   1139   13   2
User Avatar
Member
27 posts
Joined: March 2023
Offline
Hello,

I've been trying to get random variants utilized via an instancer however the way I've gotten it working seems like an incorrect/unofficial method.

Plugging multiple of the same "Asset Reference" (same USD file) into a stream and setting to a different variant for each one.
Example image attached.


How do avoid this kind of workflow?
There must be a way to just Asset Reference in an asset once and then randomize the variant being used?


Thanks very much,
amwilkins

Attachments:
variants_instancer.png (197.7 KB)

User Avatar
Staff
4438 posts
Joined: July 2005
Offline
That method is totally correct and official, but maybe not optimal Have you tried using the Explore Variants LOP? You network would be Asset Reference -> Explore Variants -> Instancer (2nd input).
User Avatar
Member
29 posts
Joined: March 2017
Offline
I'm having some troubles with this workflow too.
A simple Pig Head -> Explore Variants -> Instancer (2nd input) throws composition arc warnings.

Primitive is embedded in a composition arc: /explorevariants1/pig/geo_easy_mtl_default
It would be necessary to flatten the stage to access it.


Is there something I'm doing wrong?

Flattening the stage before connecting to the instancer second input works but that's not ideal.

Using a duplicate LOP with reference type set to copy then manually setting each variant seems to work, but that's basically the same manual workflow outlined by am_wilkins above.
User Avatar
Staff
4438 posts
Joined: July 2005
Offline
Try turning off the "Create References" toggle on the Explore Variants node? I believe that will eliminate the reference arc above the individual variants, allowing each variant to be safely copied into the instancer's prototypes folder.
User Avatar
Member
29 posts
Joined: March 2017
Offline
Yeah I tried that but then it just throws a different warning.

Warning Unable to relocate reference: /pig
Warning In </instancer1/Prototypes/explorevariants1/pig/geo_easy_mtl_default>: Unresolved reference prim path @anon:0x2df147ae0:LOP:rootlayer@</pig> introduced by @anon:0x2df149680:LOP@</instancer1/Prototypes/explorevariants1/pig/geo_easy_mtl_default> (recomposing stage on stage @anon:0x2df147ae0:LOP:rootlayer@ <0x14aa17200>)
Edited by pixelninja - March 25, 2024 21:53:52
User Avatar
Member
27 posts
Joined: March 2023
Offline
mtucker
That method is totally correct and official, but maybe not optimal Have you tried using the Explore Variants LOP? You network would be Asset Reference -> Explore Variants -> Instancer (2nd input).

Hi mtucker,

Okay good to know it's correct.
I tried the "Explore Variant" approach and while much neater and it does work—it doesn't vary between the variants.
I tried on "Duplicate Variant" and also "Set Variant" however both methods just instance only one of the variants types rather than alternating between them.


all the best,
amwilkins
User Avatar
Staff
4438 posts
Joined: July 2005
Offline
"it doesn't vary between the variants" - you're going to need to explain this to me
User Avatar
Member
40 posts
Joined: Feb. 2020
Offline
Hi,
You might want to have a look at generating a collection. We generate a collection of the variants we want to scatter. Then in the pointInstancer you put "%myCollection" into "Prototype Primitives slot. We also turn off "Only Copy Specified Prototype Primitives". It will then randomly pick a variant and randomly distribute it on the points.
User Avatar
Member
29 posts
Joined: March 2017
Offline
Ok I still get the "recomposing stage on stage" warning but I've figured out the workflow.

Key things I was missing:
1. Explore variands node needs to be set to mode "Explore Variants" with a spacing of 0
2. The instancer needs to have "Only copy specified prototype primitves" unchecked (this is noted in the docs).

The only downside is that with this method I lose texture display in the viewport.
User Avatar
Member
27 posts
Joined: March 2023
Offline
Hi all,

@mtucker: The goal is just to ensure that the incoming "prototypes" randomize between the variants. While having an intuitive/neat workflow. Cause right now, spamming the same asset ref USD multiple times seems really strange workflow.

@kskovbo: The collection route appears to also work, but still requires asset referencing in the same USD multiple times, correct?



Using the explore variants set to either "Duplicate Variants" or "Set Variants" instances them correctly, however doesn't randomize between variants.
"Explore Variants" complains about "No prototype primitives found".





I also noticed an "Asset Reference" node comes with a "Variant" tab and I thought this would allow me to set the variant on the asset reference, but it doesn't appear to do anything.




all the best,
amwilkins

Attachments:
grass_instancer_collection_01.png (294.8 KB)
grass_instancer_collection_02.png (970.2 KB)
grass_instancer_collection_03.png (923.4 KB)
grass_instancer_collection_04.png (1014.0 KB)
grass_instancer_collection_05.png (76.7 KB)

User Avatar
Member
2 posts
Joined: April 2023
Offline
I might be doing this wrong, but something I have been playing with is using a `for each` loop.
It has an option `For Each Variant in First Input`


and then on a `setvariant` you specify `@ITERATIONVALUE`

but the outcome in the viewport only shows the last variant in the loop, and does not produce 4 unique prims that could then be sent to the instancer.

I also attempted to include a `restructure scene graph` node to output 4 unique prims on each loop, however that did not work either.
Edited by flipsideza - March 28, 2024 11:07:04

Attachments:
for_each.jpg (23.2 KB)
for_each_loop.jpg (18.1 KB)

User Avatar
Staff
4438 posts
Joined: July 2005
Offline
flipsideza
I might be doing this wrong, but something I have been playing with is using a `for each` loop.

The problem here is that you only have one "copy" or the asset in your scene. So in the for each loop, each iteration is setting the variant selection _on that same scene graph location_ to different values. So the last one wins. If you move the asset reference _inside_ the for each loop, and use the ITERATION context option to make a unique asset reference location for each iteration, then you will end up with multiple references to the asset, each with a different variant chosen.

If you take this approach, then you also don't want to feed the asset to the for each first input, because then you'll end up with one too many copies of your asset in the scene (the stage connected to the first input is "passed through"). So you'd want to also connect the asset reference to the _second_ input of the for each LOP, and iterate over variants on the second input. The stage connected to the second input is not made part of the output of the for each LOP.

I've attached a hip file that demonstrates this.

Attachments:
instantiate_variants_with_foreach.hip (103.9 KB)

User Avatar
Staff
4438 posts
Joined: July 2005
Offline
am_wilkins
@mtucker: The goal is just to ensure that the incoming "prototypes" randomize between the variants. While having an intuitive/neat workflow. Cause right now, spamming the same asset ref USD multiple times seems really strange workflow.

I'm not sure what might be going wrong in your setup, but it's certainly possible to make things work as expected (see attached file). The "trickiest" part was realizing that the instancer LOP have to turn off the option to only import the prototype prims... Because the per-variant prims are references to another prim in a different part of the scene graph, you can't _just_ copy the per-variant prims onto the instancer stage.

Attachments:
instance_random_variants.hip (169.1 KB)

User Avatar
Member
2 posts
Joined: April 2023
Offline
mtucker
The problem here is that you only have one "copy" or the asset in your scene.

Ah thats how you do it! Thank you I managed to recreate it my side.

I actually realised over the long weekend that I was not 'creating' multiple assets (like the light example in the help) and realised I needed to move the `Asset Reference` into the loop. I did wonder what I would need to feed into the loop

Thank you for the help
  • Quick Links