Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYDRA-1286 : Support displacement on GeomSubset wireframe highlights #242

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from

Conversation

debloip-adsk
Copy link
Collaborator

No description provided.

@@ -268,45 +298,234 @@ class _RerootingSceneIndexPathArrayDataSource : public HdPathArrayDataSource
HdPathArrayDataSourceHandle const _inputDataSource;
};

// Copied over from USD's rerootingSceneIndex.cpp
class _RerootingSceneIndexContainerDataSource : public HdContainerDataSource
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class was previously re-implemented as RepathingContainerDataSource so that it could be externally exposed, but now we need no longer need it to be externally accessible due to the new utility method RepathInstancingDataSources, so we just go back to using the raw version copied over from USD.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand why you are doing a copy of the usd class and not using it directly from usd ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those classes are not exposed, they are located in an anonymous namespace in a .cpp file (see USD's rerootingSceneIndex.cpp, so we can't use them directly. May be worth to make a PR to USD to expose these, I've logged HYDRA-1422 so we can discuss this.

Comment on lines 369 to 425
//We want to set the displayStyle of the selected prim to refinedWireOnSurf only if the displayStyle of the prim is refined (meaning shaded)
HdContainerDataSourceHandle SetWireframeRepr(const HdContainerDataSourceHandle& dataSource, const GfVec4f& color)
{
//Always edit its override wireframe color
auto edited = HdContainerDataSourceEditor(dataSource);
edited.Set(primvarsOverrideWireframeColorLocator,
Fvp::PrimvarDataSource::New(
HdRetainedTypedSampledDataSource<VtVec4fArray>::New(VtVec4fArray{color}),
HdPrimvarSchemaTokens->constant,
HdPrimvarSchemaTokens->color));

//Is the prim in refined displayStyle (meaning shaded) ?
if (HdLegacyDisplayStyleSchema styleSchema =
HdLegacyDisplayStyleSchema::GetFromParent(dataSource)) {

if (HdTokenArrayDataSourceHandle ds =
styleSchema.GetReprSelector()) {
VtArray<TfToken> ar = ds->GetTypedValue(0.0f);
TfToken refinedToken = ar[0];
if(HdReprTokens->refined == refinedToken){
//Is in refined display style, apply the wire on top of shaded reprselector
return HdOverlayContainerDataSource::New({ edited.Finish(), refinedWireDisplayStyleDataSource});
}
}else{
//No reprSelector found, assume it's in the Collection that we have set HdReprTokens->refined
return HdOverlayContainerDataSource::New({ edited.Finish(), refinedWireDisplayStyleDataSource});
}
}

//For the other case, we are only updating the wireframe color assuming we are already drawing lines
return edited.Finish();
}

Fvp::PrimSelection ConvertHydraToFvpSelection(const SdfPath& primPath, const HdSelectionSchema& selectionSchema) {
Fvp::PrimSelection primSelection;
primSelection.primPath = primPath;

auto nestedInstanceIndicesSchema =
#if HD_API_VERSION < 66
const_cast<HdSelectionSchema&>(selectionSchema).GetNestedInstanceIndices();
#else
selectionSchema.GetNestedInstanceIndices();
#endif
for (size_t iNestedInstanceIndices = 0; iNestedInstanceIndices < nestedInstanceIndicesSchema.GetNumElements(); iNestedInstanceIndices++) {
HdInstanceIndicesSchema instanceIndicesSchema = nestedInstanceIndicesSchema.GetElement(iNestedInstanceIndices);
auto instanceIndices = instanceIndicesSchema.GetInstanceIndices()->GetTypedValue(0);
primSelection.nestedInstanceIndices.push_back(
{
instanceIndicesSchema.GetInstancer()->GetTypedValue(0),
instanceIndicesSchema.GetPrototypeIndex()->GetTypedValue(0),
std::vector<int>(instanceIndices.begin(), instanceIndices.end())
}
);
}

return primSelection;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These did not actually change, just reordered.

return primSelection;
}

PXR_NS::HdContainerDataSourceHandle RepathInstancingDataSources(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces RepathingContainerDataSource for usage by the wireframe highlight scene indices

@debloip-adsk debloip-adsk marked this pull request as ready for review January 28, 2025 20:29
@debloip-adsk debloip-adsk self-assigned this Jan 28, 2025
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing tests did not change, just refactored things to allow the displacement test to use a different scene.

Copy link
Collaborator

@lanierd-adsk lanierd-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. A few comments overall.

@@ -268,45 +298,234 @@ class _RerootingSceneIndexPathArrayDataSource : public HdPathArrayDataSource
HdPathArrayDataSourceHandle const _inputDataSource;
};

// Copied over from USD's rerootingSceneIndex.cpp
class _RerootingSceneIndexContainerDataSource : public HdContainerDataSource
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand why you are doing a copy of the usd class and not using it directly from usd ?

namespace FVP_NS_DEF {

TfTokenVector RepathingContainerDataSource::GetNames()
PXR_NS::HdContainerDataSourceHandle ComputeSmoothNormals(const PXR_NS::HdContainerDataSourceHandle& meshPrimDataSource)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to set this in one of the utility class we have so it gets shared by all projects from maya-hydra in case we need it somewhere else. I would also rename the function to addSmoothNormals (I know it's me who named it ComputeSmoothNormals :-) )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, moved it to fvpUtils and updated the name

if (normalsValueDataSource) {
auto normals = normalsValueDataSource->GetTypedValue(0);
for (size_t iNormal = 0; iNormal < normals.size(); iNormal++) {
normals[iNormal] = GfVec3f(xformMatrix.GetInverse().GetTranspose().TransformDir(normals[iNormal]));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please compute the transpose of the inverse in a materix out of the loop and applyTransformDir from it ?
I am not sure this gets optimized correctly by the different compilers we use when being inside the loop.

Copy link
Collaborator Author

@debloip-adsk debloip-adsk Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, moved it out of the loop, thanks

}

//We want to set the displayStyle of the selected prim to refinedWireOnSurf only if the displayStyle of the prim is refined (meaning shaded)
HdContainerDataSourceHandle SetWireframeRepr(const HdContainerDataSourceHandle& dataSource, const GfVec4f& color)
PXR_NS::HdContainerDataSourceHandle ForceDisplacement(const PXR_NS::HdContainerDataSourceHandle& meshPrimDataSource, float displacement)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add this to a utility class as well and call it ApplyDisplacement instead of ForceDisplacement

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both this one and ForceScale, I went to with "Force" to really emphasize that this is not something that should be naturally occurring, and is more of a workaround more than anything. This is also why I don't think we should move these over to common utilities, as we should be using this as little as possible. I've left both of these where they are for now, let me know if you have other thoughts on this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've got your point, let's keep it like that.

std::vector<int>(instanceIndices.begin(), instanceIndices.end())
}
);
PXR_NS::HdContainerDataSourceHandle AddDependency(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be part of the utility functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, moved it to fvpUtils

@@ -756,4 +1029,81 @@ BaseWhSi::CollectInstancingPaths(const PXR_NS::SdfPath& primPath, InstancingPath
}
}

VtValue
BaseWhSi::GetMaterialDisplacementValue(const PXR_NS::HdContainerDataSourceHandle& primDataSource) const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well, I think it should be part of a utility function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it (and GetMaterialPath) to fvpUtils

@debloip-adsk
Copy link
Collaborator Author

I also moved ConvertHydraToFvpSelection to fvpUtils

Copy link
Collaborator

@lanierd-adsk lanierd-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reworking. Only 1 remaining question and we're done.

{
HdContainerDataSourceHandle editedMeshPrimDataSource = meshPrimDataSource;

VtValue displacementValue = GetMaterialDisplacementValue(geomSubsetPrimDataSource, *GetInputSceneIndex());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall there were 2 possible cases for the scale when the parent mesh of the geomsubset has a material and the geomsubset has a material as well :

  • the scale can be on the parent mesh 's material
  • the scale can be on the geomsubset material
    Are these 2 cases handled in your code ? It seems to me, I may be wrong, that if the scale is on the parent mesh 's material, we'll miss it.
    And I am not sure you can have scale on both materials, I think in this case we apply only one if I am correct ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants