Ordering in the Primitives parameter is ignored?

   762   2   2
User Avatar
Member
333 posts
Joined: April 2018
Offline
So it seems that the order of the primitives specified in the Primitives parameter has no bearing, and a Vexpression will always use the ordering from the Scene Graph Tree?

So, if I have this scene structure:

/
-Obj1
-Obj2
-Obj3

but in the Primitives parameter write them in reverse order as
/Obj3 /Obj2 /Obj1
, @elemnum will still use the ordering from the SGT?

If this is the case, then is there a way to override this ordering, and have the Vexpression use the list as it is defined in the Primitives parameter?
User Avatar
Staff
4176 posts
Joined: Sept. 2007
Offline
I don't think this is possible with VEX, since it's just traversing the stage the way USD presents it? And with VEX being a SIMD-like kernel you can't guarantee ordering when you start threading code...

If you need something to run serially, then I'd use Python; though I guess you could do a manual loop in VEX to make it loop over primitives in a specific order, but that sounds messy compared to Python.
I'm o.d.d.
User Avatar
Member
333 posts
Joined: April 2018
Offline
Thank you for clarifying. Some more detail - I'm reading textures from a folder into a string array using Python. I write that array to a primvar, and then use a Vexpression on an Assign Material LOP to override the 'File' parameter on a USD UV Texture VOP.

It works fine, except that I cannot control the ordering of the texture assignment.

Here's the Python code:
node = hou.pwd()
stage = node.editableStage()

import os
from pxr import Sdf, Usd, UsdGeom

# read the texture path from the parameter in the UI
userpath = hou.parm('./tp').eval()

# if no custom path is set, use $HIP/tex as the default
if userpath == "":
    texpath = os.path.dirname(hou.hipFile.path()) + '/tex'
else:
    texpath = userpath

files = []

# create an array of acceptable file extensions
# only files with these extensions will get added to the files array
ext = (".jpg", ".png", ".bmp", ".hdr", ".exr")

# get list of file names
for names in os.listdir(texpath):
    if names.lower().endswith(tuple(ext)):
        texname = texpath + '/' + names
        files.append(texname)
        
# usd things
asset = stage.GetPrimAtPath('/')
primvarsapi = UsdGeom.PrimvarsAPI(asset)

# create the primvar
primvar = primvarsapi.CreatePrimvar('texpaths', Sdf.ValueTypeNames.StringArray)

# write the file list to the primvar
primvar.Set(files)


Here is the Vexpression:



And here it is in action:



If you see my folder structure, you'll see that they don't match the objects from left to right. I thought I could fix that with the Primitives parameter, but that doesn't work, and I can't see an easy way to fix this without renaming the images to match (which is clunky), or doing manual assignments in the Vexpression, which is also clunky.

Perhaps another way to do the overrides? I only know this way currently.

Thanks again.
  • Quick Links