-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: dev
Are you sure you want to change the base?
HYDRA-1286 : Support displacement on GeomSubset wireframe highlights #242
Conversation
@@ -268,45 +298,234 @@ class _RerootingSceneIndexPathArrayDataSource : public HdPathArrayDataSource | |||
HdPathArrayDataSourceHandle const _inputDataSource; | |||
}; | |||
|
|||
// Copied over from USD's rerootingSceneIndex.cpp | |||
class _RerootingSceneIndexContainerDataSource : public HdContainerDataSource |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
//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; | ||
} |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 :-) )
There was a problem hiding this comment.
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])); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
I also moved ConvertHydraToFvpSelection to fvpUtils |
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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 ?
No description provided.