--- /dev/null
+#usda 1.0
+(
+ upAxis = "Y"
+ '''This file is used to demonstrate how expression variables can be passed to usdrecord
+ on the command-line. It will set them on the stage's session layer, allowing them to
+ be used in asset-valued attribute resolution.
+
+ In this file, the variable ${TEXTURE} is used to indicate a texture filename.'''
+)
+
+def Mesh "card" (
+ prepend apiSchemas = ["MaterialBindingAPI"]
+)
+{
+ rel material:binding = </PreviewMaterial>
+
+ point3f[] points = [
+ (0, 0, 0),
+ (1, 0, 0),
+ (0, 1, 0),
+ (1, 1, 0),
+ ]
+ float2[] primvars:st (interpolation = "vertex")
+ float2[] primvars:st = [
+ (0, 0),
+ (1, 0),
+ (0, 1),
+ (1, 1)
+ ]
+ int[] faceVertexIndices = [
+ 0, 1, 3, 2
+ ]
+ int[] faceVertexCounts = [
+ 4
+ ]
+ uniform token subdivisionScheme = "none"
+}
+
+def Material "PreviewMaterial"
+{
+ add token outputs:surface.connect = </PreviewMaterial/PreviewSurface.outputs:surface>
+
+ def Shader "PreviewSurface"
+ {
+ token info:id = "UsdPreviewSurface"
+ color3f inputs:emissiveColor.connect = </PreviewMaterial/ColorAndOpacityTexture.outputs:rgb>
+ token outputs:surface
+ }
+
+ def Shader "UV"
+ {
+ token info:id = "UsdPrimvarReader_float2"
+ string inputs:varname = "st"
+ float2 outputs:result
+ }
+
+ def Shader "ColorAndOpacityTexture"
+ {
+ token info:id = "UsdUVTexture"
+ asset inputs:file = @`"${TEXTURE}.tex"`@
+ float2 inputs:st.connect = </PreviewMaterial/UV.outputs:result>
+ color3f outputs:rgb
+ }
+}
#
from pxr import Usd
+from pxr import Sdf
from pxr import UsdAppUtils
from pxr import Tf
'more than one extra purpose, either use commas with no spaces or '
'quote the argument and separate purposes by commas and/or spaces.'))
+ parser.add_argument('--vars', action='store', type=str, nargs='*',
+ dest='expressionVariables', metavar='NAME=VALUE',
+ help=(
+ 'Specify expression variables and their values to override in '
+ 'a session layer. Currently, only string-valued variables '
+ 'are supported.'))
+
# Note: The argument passed via the command line (disableGpu) is inverted
# from the variable in which it is stored (gpuEnabled).
parser.add_argument('--disableGpu', action='store_false',
purposes = args.purposes.replace(',', ' ').split()
+ # Prepare a session layer with requested expressionVariables
+ sessionLayer = Sdf.Layer.CreateAnonymous("usdrecord-session.usda",
+ {Sdf.FileFormat.Tokens.TargetArg: Usd.UsdFileFormat.Tokens.Target})
+ if args.expressionVariables:
+ exprVars = sessionLayer.expressionVariables
+ for entry in args.expressionVariables:
+ name, val = entry.split('=')
+ exprVars[name] = val
+ sessionLayer.expressionVariables = exprVars
+
+ # Load the root layer.
+ rootLayer = Sdf.Layer.FindOrOpen(args.usdFilePath)
+ if not rootLayer:
+ _Err('Could not open layer: %s' % args.usdFilePath)
+ return 1
+
# Open the USD stage, using a population mask if paths were given.
if args.populationMask:
populationMaskPaths = args.populationMask.replace(',', ' ').split()
for maskPath in populationMaskPaths:
populationMask.Add(maskPath)
- usdStage = Usd.Stage.OpenMasked(args.usdFilePath, populationMask)
+ usdStage = Usd.Stage.OpenMasked(rootLayer, sessionLayer, populationMask)
else:
- usdStage = Usd.Stage.Open(args.usdFilePath)
+ usdStage = Usd.Stage.Open(rootLayer, sessionLayer)
if not usdStage:
_Err('Could not open USD stage: %s' % args.usdFilePath)