Stage variables for layer offset

Hello!

I’m trying to prototype a workflow where we can to time offset our caches (references/payloads) based on stage variables. The idea is to have different layers with different offsets values so our caches look different when each of them are sublayered.

I was trying to get int variable expression working in a simple stage like below and I can’t seem to get them working, getting syntax error on the offset variable. Is it even possible to do something like this? Open for any suggestions, thanks in advance :slight_smile:

#usda 1.0
(
    expressionVariables = {
        int64 FRAME = 5
	}
)

def Xform "root"
{
    def "FX5" (
        prepend references = @cache.usda@</cube1> ( offset = `${FRAME}` )
    )
    {
    }
}

Cheers,
Joseph

I don’t believe this is currently possible

See the documentation here USD Variable Expressions — Universal Scene Description 25.02 documentation

Variable expressions can currently be used in:

  • Asset paths (including sublayer, reference, and payload asset paths as well as asset-valued attributes and metadata).
  • Variant selections.

Probably not workable for your use case, but if you have a limited number of frame offsets, I verified that the following works, without error in all cases, as long as FRAME is defined to something . If it’s set to a value that’s outside your range, I set it up to bring in the reference with no offset, but you can do anything you want there.

#usda 1.0
(
    expressionVariables = {
       int FRAME = 5
    }
)

def "MyPrim" (
   prepend references = [ @`if(eq(${FRAME}, 1), "test1.usda")`@(offset = 1),
                          @`if(eq(${FRAME}, 2), "test1.usda")`@(offset = 2),
                          @`if(eq(${FRAME}, 3), "test1.usda")`@(offset = 3),
                          @`if(or(lt(${FRAME}, 1), gt(${FRAME}, 3)), "test1.usda")`@]
)
{
}

For completeness, test1.usda (usdcat --flatten is a quick way to observe how the timeSamples move in response to different FRAME values in the root layer):

#usda 1.0
(
    defaultPrim = "hello"
)

def Xform "hello"
{
    double3 xformOp:translate.timeSamples = {
      0: (1, 2, 3),
      1: (4, 5, 6),
      2: (7, 8, 9),
    }
    uniform token[] xformOpOrder = ["xformOp:translate"]

    def Sphere "small"
    {
        float3[] extent = [(-2, -2, -2), (2, 2, 2)]
        color3f[] primvars:displayColor = [(0, 0, 1)]
        double radius = 2
    }

    def Sphere "big"
    {
        float3[] extent = [(-2, -2, -2), (2, 2, 2)]
        color3f[] primvars:displayColor = [(0, 0, 1)]
        double radius = 20
    }
}