Is there a rule about hyphens in primvar names in Universal Scene Description

62 Views Asked by At

I'm reading a .USDA file (exported by blender) via USD.NET and and when looking at loading texture data I have an image texture defined within a material like this:

            def Shader "Image_Texture"
            {
                uniform token info:id = "UsdUVTexture"
                asset inputs:file = @./textures/BodyBase.png@
                token inputs:sourceColorSpace = "sRGB"
                float2 inputs:st.connect = </_materials/Material_001/preview/uvmap.outputs:result>
                float3 outputs:rgb
            }

            def Shader "uvmap"
            {
                uniform token info:id = "UsdPrimvarReader_float2"
                token inputs:varname = "Cube_001-mesh-map-0"
                float2 outputs:result
            }

and I read the variable name for st from uvmap as "Cube_001-mesh-map-0". However in the mesh data, I have:

texCoord2f[] primvars:Cube_001_mesh_map_0 = [...] (
                interpolation = "faceVarying"
            )

i.e. there are no hyphens in the primvar name. Is this a convention that I should be accounting for, as in is it safe to just always convert hyphens to underscores when trying to look up primvars?

The following code won't find the primvar if parameterPath uses the hyphenated version:

UsdGeomPrimvar? GetPrimvar(UsdPrim meshPrim, string parameterPath)
{
    UsdGeomPrimvarsAPI api = new UsdGeomPrimvarsAPI(meshPrim);
    TfToken testToken = new TfToken(parameterPath);
    UsdGeomPrimvar primVar = api.GetPrimvar(testToken);
    if (primVar.IsDefined())
        return primVar;
    return null;
}
1

There are 1 best solutions below

0
On

For me it doesn't work also if I had hyphens, I had to modify my variable to work.

It is not written anywhere in the documentation but I assumed we should not add hyphen or any other special character that I found such as : spacing, dot, #, \r, \t, \n, [, ], ~, -, :, + ... and I guess many other more