Skip to content

Commit

Permalink
Fixing double-rendering of USD prims + autotest
Browse files Browse the repository at this point in the history
  • Loading branch information
vlasovi committed Feb 29, 2024
1 parent 5c4eac3 commit ac82798
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <pxr/base/gf/vec3f.h>
#include <pxr/base/vt/array.h>
#include <pxr/base/vt/value.h>
#include <pxr/imaging/hd/tokens.h>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -90,6 +91,60 @@ void AdskHydraSceneBrowserTestFixture::SetReferenceSceneIndex(
sceneIndex = referenceSceneIndex;
}

void AdskHydraSceneBrowserTestFixture::VerifySceneCorrectness()
{
// Traverse prim hierarchy
QTreeWidgetItemIterator itPrimsTreeWidget = GetIteratorForTree(_primHierarchyWidget);
for (; *itPrimsTreeWidget; itPrimsTreeWidget++) {
QTreeWidgetItem* primQtItem = *itPrimsTreeWidget;
_primHierarchyWidget->setCurrentItem(primQtItem);

// Traverse data source hierarchy
QTreeWidgetItemIterator itDataSourceTreeWidget = GetIteratorForTree(_dataSourceHierarchyWidget);
for (; *itDataSourceTreeWidget; itDataSourceTreeWidget++) {
QTreeWidgetItem* dataSourceQtItem = *itDataSourceTreeWidget;

// Verify representation selector's correctness
if (dataSourceQtItem->text(0) == "reprSelector") {
_dataSourceHierarchyWidget->setCurrentItem(dataSourceQtItem);

int numPointReprs = 0;
int numWireReprs = 0;
int numSurfReprs = 0;

// Count representations in use
_dataSourceValueView->expandAll();
QAbstractItemModel* dataSourceItemModel = _dataSourceValueView->model();
for (int row = 0; row < dataSourceItemModel->rowCount(); ++row) {
QModelIndex valueIndex = dataSourceItemModel->index(row, 0);
QVariant valueData = dataSourceItemModel->data(valueIndex, Qt::DisplayRole);
pxr::TfToken reprName(valueData.toString().toStdString());

if (reprName == pxr::HdReprTokens->hull ||
reprName == pxr::HdReprTokens->smoothHull ||
reprName == pxr::HdReprTokens->refined) {
++numSurfReprs;
} else if (reprName == pxr::HdReprTokens->refinedWire ||
reprName == pxr::HdReprTokens->wire) {
++numWireReprs;
} else if (reprName == pxr::HdReprTokens->refinedWireOnSurf ||
reprName == pxr::HdReprTokens->wireOnSurf) {
++numWireReprs;
++numSurfReprs;
} else if (reprName == pxr::HdReprTokens->points) {
++numPointReprs;
}
}

// Verify that we don't draw the same geometry more than once
EXPECT_LE(numPointReprs, 1);
EXPECT_LE(numWireReprs, 1);
EXPECT_LE(numSurfReprs, 1);
}
}
}
}

void AdskHydraSceneBrowserTestFixture::ComparePrimHierarchy(
bool compareDataSourceHierarchy,
bool compareDataSourceValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class AdskHydraSceneBrowserTestFixture : public ::testing::Test
bool compareDataSourceHierarchy = false,
bool compareDataSourceValues = false);

void VerifySceneCorrectness();

void
CompareDataSourceHierarchy(DataSourceEntry rootDataSourceEntry, bool compareValues = false);

Expand Down
10 changes: 10 additions & 0 deletions lib/adskHydraSceneBrowser/test/adskHydraSceneBrowserTesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ bool RunFullSceneIndexComparisonTest(pxr::HdSceneIndexBasePtr referenceSceneInde
AdskHydraSceneBrowserTestFixture::SetReferenceSceneIndex(referenceSceneIndex);
return RunTestsWithFilter("AdskHydraSceneBrowserTestFixture.FullSceneIndexComparison");
}
bool RunSceneCorrectnessTest(pxr::HdSceneIndexBasePtr referenceSceneIndex)
{
AdskHydraSceneBrowserTestFixture::SetReferenceSceneIndex(referenceSceneIndex);
return RunTestsWithFilter("AdskHydraSceneBrowserTestFixture.VerifySceneCorrectness");
}
} // namespace AdskHydraSceneBrowserTesting

TEST_F(AdskHydraSceneBrowserTestFixture, FullSceneIndexComparison)
Expand All @@ -52,3 +57,8 @@ TEST_F(AdskHydraSceneBrowserTestFixture, FullSceneIndexComparison)
bool compareDataSourceValues = true;
ComparePrimHierarchy(compareDataSourceHierarchy, compareDataSourceValues);
}

TEST_F(AdskHydraSceneBrowserTestFixture, VerifySceneCorrectness)
{
VerifySceneCorrectness();
}
3 changes: 3 additions & 0 deletions lib/adskHydraSceneBrowser/test/adskHydraSceneBrowserTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
namespace AdskHydraSceneBrowserTesting {
HDUITEST_API
bool RunFullSceneIndexComparisonTest(pxr::HdSceneIndexBasePtr referenceSceneIndex);

HDUITEST_API
bool RunSceneCorrectnessTest(pxr::HdSceneIndexBasePtr referenceSceneIndex);
} // namespace AdskHydraSceneBrowserTesting

#endif // ADSK_HYDRA_SCENE_BROWSER_TESTING_H
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ const HdRetainedContainerDataSourceHandle sSelectedDisplayStyleDataSource
HdRetainedContainerDataSource::New(
HdLegacyDisplayStyleSchemaTokens->reprSelector,
HdRetainedTypedSampledDataSource<VtArray<TfToken>>::New(
{ HdReprTokens->refinedWireOnSurf, HdReprTokens->wireOnSurf, TfToken() })));

const HdRetainedContainerDataSourceHandle sUnselectedDisplayStyleDataSource
= HdRetainedContainerDataSource::New(
HdLegacyDisplayStyleSchemaTokens->displayStyle,
HdRetainedContainerDataSource::New(
HdLegacyDisplayStyleSchemaTokens->reprSelector,
HdRetainedTypedSampledDataSource<VtArray<TfToken>>::New(
{ HdReprTokens->refined, HdReprTokens->refined, TfToken() })));
{ HdReprTokens->refinedWireOnSurf, TfToken(), TfToken() })));

const HdDataSourceLocator reprSelectorLocator(
HdLegacyDisplayStyleSchemaTokens->displayStyle,
Expand Down Expand Up @@ -88,10 +80,10 @@ WireframeSelectionHighlightSceneIndex::GetPrim(const SdfPath &primPath) const
// index to convert implicit surfaces (e.g. USD cube / cone / sphere /
// capsule primitive types) to meshes.
if (!isExcluded(primPath) && prim.primType == HdPrimTypeTokens->mesh) {
prim.dataSource = HdOverlayContainerDataSource::New(
{ prim.dataSource, _selection->HasFullySelectedAncestorInclusive(primPath) ?
sSelectedDisplayStyleDataSource :
sUnselectedDisplayStyleDataSource });
if (_selection->HasFullySelectedAncestorInclusive(primPath)) {
prim.dataSource = HdOverlayContainerDataSource::New(
{ prim.dataSource, sSelectedDisplayStyleDataSource });
}
}
return prim;
}
Expand Down
20 changes: 16 additions & 4 deletions plugin/mayaHydraSceneBrowserTest/mayaHydraSceneBrowserTestCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ using namespace MAYAHYDRA_NS;

const MString mayaHydraSceneBrowserTestCmd::name("mayaHydraSceneBrowserTest");

namespace {
void DisplayResult(bool didTestSucceed, const char* testDisplayName)
{
MString testResultString = didTestSucceed ? MString(" test result : PASS") : MString(" test result : FAIL");
MGlobal::displayInfo(testDisplayName + testResultString);
}
} // namespace

MStatus mayaHydraSceneBrowserTestCmd::doIt(const MArgList& args)
{
// Retrieve the scene index
Expand All @@ -44,13 +52,17 @@ MStatus mayaHydraSceneBrowserTestCmd::doIt(const MArgList& args)
// Run comparison test
bool didTestSucceed
= AdskHydraSceneBrowserTesting::RunFullSceneIndexComparisonTest(sceneIndices.front());
bool didAllTestsSucceed = didTestSucceed;
DisplayResult(didTestSucceed, "Hydra Scene Browser comparison");

// Display result
MString testResultString = didTestSucceed ? MString("PASS") : MString("FAIL");
MGlobal::displayInfo("Hydra Scene Browser comparison test result : " + testResultString);
// Run correctness test
didTestSucceed
= AdskHydraSceneBrowserTesting::RunSceneCorrectnessTest(sceneIndices.front());
didAllTestsSucceed |= didTestSucceed;
DisplayResult(didTestSucceed, "Hydra Scene correctness");

// Return result
return didTestSucceed ? MS::kSuccess : MS::kFailure;
return didAllTestsSucceed ? MS::kSuccess : MS::kFailure;
}

MStatus initializePlugin(MObject obj)
Expand Down

0 comments on commit ac82798

Please sign in to comment.