# Mesh primitive with a variant set and instanceable=true

**URL:** <https://forum.aousd.org/t/mesh-primitive-with-a-variant-set-and-instanceable-true/1174>\
**Category:** Hydra\
**Created:** [January 26, 2024, 3:06pm UTC](https://forum.aousd.org/t/mesh-primitive-with-a-variant-set-and-instanceable-true/1174 "2024-01-26T15:06:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlanier](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/dlanier/32/166_2.png) [@dlanier](https://forum.aousd.org/u/dlanier)\
**Post date:** [January 26, 2024, 3:06pm UTC](https://forum.aousd.org/t/mesh-primitive-with-a-variant-set-and-instanceable-true/1174/1 "2024-01-26T15:06:02Z")

</div>

Hi,

We have a mesh primitive in a Usd scene which has a variant in it. This is with Usd 23.11.  
Say:

```auto
def Mesh "CubeOne" (
            variants = {
                string displacement = "none"
            }
            add variantSets = "displacement"
        )
        {
            float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]
            int[] faceVertexCounts = [4, 4, 4, 4, 4, 4]
            int[] faceVertexIndices = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 1, 0, 1, 7, 5, 3, 6, 0, 2, 4]
            point3f[] points = [(-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, 0.5, -0.5), (0.5, 0.5, -0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5)]
            float[] primvars:__faceindex = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5] (
                interpolation = "faceVarying"
            )
            string primvars:__gprimHandleid = "CubeOne"
            string primvars:__handleid = "CubeOne"
            color3f[] primvars:displayColor = [(0.217638, 0.217638, 0.217638)]
            int primvars:gprimID = 903569
            texCoord2f[] primvars:st = [(0.375, 0), (0.625, 0), (0.625, 0.25), (0.375, 0.25), (0.375, 0.25), (0.625, 0.25), (0.625, 0.5), (0.375, 0.5), (0.375, 0.5), (0.625, 0.5), (0.625, 0.75), (0.375, 0.75), (0.375, 0.75), (0.625, 0.75), (0.625, 1), (0.375, 1), (0.625, 0), (0.875, 0), (0.875, 0.25), (0.625, 0.25), (0.125, 0), (0.375, 0), (0.375, 0.25), (0.125, 0.25)] (
                interpolation = "faceVarying"
            )
            uniform token[] xformOpOrder = ["xformOp:translate"]
            variantSet "displacement" = {
                "moved" {
                    double3 xformOp:translate = (-2, 2, 0.5)

                }
                "none" {
                    double3 xformOp:translate = (-2, 0, 0.5)

                }
            }
        }

```

We look in C++ in a filtering scene index, e.g : MySceneIndex::GetPrim at the prim with :

```auto
auto prim = _GetInputSceneIndex()->GetPrim(primPath);
if(prim.primType == HdPrimTypeTokens->mesh) {
   //Do things.
}

```

The prim is a HdPrimTypeTokens-\>mesh.  
But if we set this prim which has the variant set as instanceable=true. It has no longer the type HdPrimTypeTokens-\>mesh, it seems like an unset prim type.  
This change of prim type doesn’t happen for the meshes that have no variant set in them.  
Is that expected ?

I can detect it’s an instance with :

```auto
bool
_IsUsdNativeInstance(const HdSceneIndexPrim &prim)
{
    UsdImagingUsdPrimInfoSchema primInfoSchema =
        UsdImagingUsdPrimInfoSchema::GetFromParent(prim.dataSource);

    HdPathDataSourceHandle const ds = primInfoSchema.GetNiPrototypePath();
    if (!ds) {
        return false;
    }
    return !ds->GetTypedValue(0.0f).IsEmpty();
}

```

But is that enough ? As we want to deal only with meshes on this code.  
BTW : using \_IsUsdNativeInstance on a mesh prim that has instanceable=true and a variant set returns true and on a mesh prim that has instanceable=true but no variant set, it returns false.

Thank you.  
Regards,  
David Lanier  
Autodesk.

---

<div class="post-metadata">

**Author:** ![tomc](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomc](https://forum.aousd.org/u/tomc)\
**Post date:** [May 16, 2024, 10:21pm UTC](https://forum.aousd.org/t/mesh-primitive-with-a-variant-set-and-instanceable-true/1174/2 "2024-05-16T22:21:15Z")

</div>

Hey David,

Not sure if you’re still having issues with this; if you are, a github issue would be great for tracking. Note, though, that since attributes on the instance prim are attached to the instance and not the prototype, we generally recommend against instancing gprims, and recommend instead instancing a scope or xform above the gprim. Instancing a gprim won’t give many performance benefits.

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![dlanier](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/dlanier/32/166_2.png) [@dlanier](https://forum.aousd.org/u/dlanier)\
**Post date:** [June 4, 2024, 9:39am UTC](https://forum.aousd.org/t/mesh-primitive-with-a-variant-set-and-instanceable-true/1174/3 "2024-06-04T09:39:39Z")

</div>

Hey Tom,  
Thank you for your reply.  
I think it’s ok now, we don’t have any more problems with this.  
Regards,  
David
