検索 - User list
Full Version: specific variants on specific instance points
Root » Solaris and Karma » specific variants on specific instance points
pgu
Hey,

So, I have :

- an object composed with some variants
- a point cloud containing an “inst” attribute storing a specific variant name for each point.

I'd like to set a specific variant on my object on a specific point, according to that “inst” attribute. Also, I'd like keeping it procedural as much as possible.

This is what I've got for now :



I followed the example Matt Estela (and Mark Tucker) kindly provided in his extremely helpful website [www.tokeru.com] and could make it work for my first “wish”. So all good on that part.

The problem is that I use a stageManager node in order to rename manually my prims just before sending that to the instancer. But this is not a procedural way to tackle this. I mean… it works for that little example, but I'd like to make it work for something much bigger and complex… . So, is there a more robust way to do this ?

In order to replace the stage manager, I was thinking of maybe having a python snippet that could get the variant name and rename the prims accordingly. But I'm not skilled enough to find my way in the USD documentation and do that myself… Also maybe there is a smart way of doing this with some lop nodes and magical expressions ?

So, if you have an idea, I'd love to hear it

Cheers
mtucker
We are working on an “Explore Variants” LOP for Houdini 18.5 for this exact purpose (among others). It's an HDA built on nodes that exist in 18.0, so we may be able to backport it once we've solidified the design a bit more.
pgu
Hey Mark,

That's really cool to hear !

In the meantime, could you point me out some paths that I could follow through so I can “unstick” myself from this problem ?

Cheers
mtucker
You can control the naming in the Duplicate LOP. You could put an expression in the Duplicate Name parameter to look at the variant names, for example. Renaming prims after the fact in USD is always something to be avoided if possible.
pgu
Hey Mark,

I did try to find an attribute @variants @variant or anything in the help [www.sidefx.com] but couldn't find any clues.

Regarding the expressions, is there any link where I could find some examples or help about how to set them up ? They look like proper to the USD api and whenever I check the USD api documentation, I'm litteraly like a chicken in front of a screwdriver (meaning I don't understand what I see) Haha

Cheers
mtucker
Yeah, the USD Python API is the way to get at this information. And I totally hear you on the lack of documentation for those APIs. I am beginning to suspect we (SideFX) wants and needs that documentation more than Pixar does, so it may fall in our laps to do it… But usually I find if I know what I'm looking for I can figure it out with a combination of the python shell auto-complete feature and the C++ documentation for the various USD classes.
pgu
Thanks Mark, I'll try my luck and get back here with a solution if I find one

Cheers
pgu
Hey,

I finally got it to work (thanks to all the people involved ^^)

I went the python way and over commented it in case some people get an interest out of it.

node = hou.pwd()
stage = node.editableStage()

# Add code to modify the stage.
# Use drop down menu to select examples.

from pxr import Usd, Kind

# variant set name that will be unfolded
variantSet = "model"

# bring any prim into the mix if it has a variantSet
mainPrim = [prim for prim in stage.TraverseAll() if prim.HasVariantSets()]
if not mainPrim:
    exit()
# take only the first prim that "fits the description"
mainPrim = mainPrim[0]

# get all the variants in the specified variantSet of the mainPrim
variants = mainPrim.GetVariantSet(variantSet).GetVariantNames()

# get the name of the mainPrim
toDup = mainPrim.GetName()

# for each variant detected
for variant in variants:
    # create a new prim named after an existing variant
    prim = stage.DefinePrim("/{0}".format(variant), "Xform")
    # do an internal reference from mainPrim to the new prim
    prim.GetPrim().GetReferences().AddInternalReference("/{0}".format(toDup))
    # set the corresponding variant of the new prim
    prim.GetVariantSet(variantSet).SetVariantSelection(variant)
    # set the kind to component
    Usd.ModelAPI(prim).SetKind(Kind.Tokens.component)

Cheers
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB