UsdImagingStageSceneIndex Chain and Flattening Scene Index

Hi,

I use the exact same scene index chain that is used in USDView or in maya usd which is : https://github.com/Autodesk/maya-usd/blob/dc1c13a3f8012b2a99a45e46fb30250fd4b82487/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp#L195

So there is part of this scene index chain is a UsdImagingStageSceneIndex.
I’d like to add more scene indices to this chain to be able to add a parent prim to all the prims from the stage and control its transform and visibility.
But I noticed that if I add only a flattening scene index to the end of this chain, it breaks all transforms from prims.
Is there a way to work around this ?
The way I add the flattening scene index is by :

HdFlatteningSceneIndex::New(lastSceneIndex, UsdImagingFlattenedDataSourceProviders());//Flatten

Thank you.
Regards,

The purpose of the flattening scene index is to flatten certain attributes as that is the way the data is expected to be consumed by current render delegates. One of these attributes is the transform - the flattening scene index is responsible for flattening the transform matrix on a prim by concatenating the transforms up the parent hierarchy. If you want to work together with the flattening scene index, you have to make sure that you take it into consideration when you design your own scene indices. For example, if you add a scene index after the flattening scene index in the chain, and that scene index manipulates transforms in some way, you may have to intercept the call to retrieve the data for HdXformSchema->xform and dynamically compute a new flattened transform in your own scene index (or defer back to the parent index if you don’t have any new computation to perform). If you have complete control over your scene index hierarchy, you can always add your scene index prior to the flattening one, such that you manipulate the source xform op data and the flattening scene index will compute the correct transform from that.

Thanks for your reply.
It was a double transform problem, I needed to flatten only once the transform and not in both flatten scene indices in the same chain.
Regards,
David

Note that you can customize which attributes are flattened by the flattening scene index.

In general, our intention is that the flattening scene index is idempotent (meaning you can apply it twice and it doesn’t change the output, and hopefully doesn’t add much overhead). I think this was not true of transforms in versions from this spring, but it should be true in 23.11.

Anyway, glad you figured it out! :slight_smile:

Thanks for your reply Tom. Yes, I was expecting that adding twice the flattening scene index wouldn’t hurt but it was applying twice the transforms, and also a problem for the visibility attribute. We are still with usd 23.08. I am glad to hear that will change in 23.11.
I am removing flattening of transforms and visibility for the usd stage scene indices chain and doing it in the 2nd flattening scene index like this

//Add a flattening scene index to the merging scene index, flatten only transform and visibility, meaning that transform and visibility should not have been already flatten previously !
static HdContainerDataSourceHandle const flattenedTransformAndVisibilityDataSourceHandle =
        HdRetainedContainerDataSource::New(
            HdVisibilitySchema::GetSchemaToken(),
            HdMakeDataSourceContainingFlattenedDataSourceProvider::Make<HdFlattenedVisibilityDataSourceProvider>(),
            HdXformSchema::GetSchemaToken(),
            HdMakeDataSourceContainingFlattenedDataSourceProvider::Make<HdFlattenedXformDataSourceProvider>()
        );

_inOutData._lastSceneIndexChain = HdFlatteningSceneIndex::New(mergingSceneIndex, flattenedTransformAndVisibilityDataSourceHandle);//Flatten

Regards,
David