Share indexed point data among multiple prims?

I’m converting geometry from an indexed face set representation to USD. There are multiple objects all indexing into one large vertex array, normal array, and uv array. I would like to place those arrays into a base prim, and put only the index arrays into the individual Mesh objects I am creating.

This structure seems like it will work:

def Xform "xform1"
{
    def Mesh "mesh1" (
        prepend inherits = </xform1/mesh_verts>
    )
    {
        int[] faceVertexCounts = [...]
        int[] faceVertexIndices = [...]
        rel material:binding = </xform1/material1>
        int[] primvars:normals:indices = [...]
        int[] primvars:uvs:indices = [...]
        uniform token subdivisionScheme = "none"
    }

    def Mesh "mesh_verts"
    {
        point3f[] points = [(0.0, 0.5, 0.0), ...]
        normal3f[] primvars:normals = [(0, 0, 1), ...]
        texCoord2f[] primvars:uvs = [(0.2, 0.4), ...]
    }

    def Material "material1"
    { ... }
}

And indeed, I have hand-edited a .usda using this pattern that works. However, I can’t figure out how to create the primvars:normals:indices and primvars:uvs:indices without also adding primvars:normals and primvars:uvs to the individual Mesh objects, and they are preventing those elements from being inherited from the mesh_verts prim.

Using the Python API, how can I create the primvar:* arrays in the mesh_verts prim and the primvar:*:indices arrays in the individual Mesh prims?

Ah, this is kind of an “advanced” construct, and not directly supported in the schema, though arguably it should be. However, you always have access to the full Usd software stack, so you can “manually” create the indices attributes on “mesh1” etc using UsdPrim API:

   normalIndices = prim.CreateAttribute("primvars:normals", Sdf.ValueTypeNames.IntArray)

Once the attributes are created, you’ll be able to use the Primvar and PrimvarsAPI schemas themselves on “mesh1”, I believe.

Also, since “mesh_verts” is not (I think) a Mesh you actually want to be imaged, you probably either want to convert its specifier to an “over” rather than a “def”, or remove the typeName of “Mesh”. Finally, unless you will need to override the source points, normals, etc in a scene that is referencing this asset/file and have it affect all of the meshes, then you can simply use a reference rather than an inherits (inherits are more expensive, because of the extra override power they provide).