Skip to content

Commit

Permalink
HYDRA-703 : Reuse MayaSceneFlattening test for MeshAdapter transform …
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
debloip-adsk committed Nov 24, 2023
1 parent 6f5d521 commit 204d7d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(TEST_SCRIPT_FILES
# both versions of the test in parallel will conflict.
set(TEST_SCRIPT_FILES_MESH_ADAPTER
testMeshes.py
cpp/testMayaSceneFlattening.py
)

foreach(script ${TEST_SCRIPT_FILES})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <mayaHydraLib/hydraUtils.h>
#include <mayaHydraLib/mayaUtils.h>

#include <pxr/base/tf/envSetting.h>
#include <pxr/base/tf/getenv.h>
#include <pxr/imaging/hd/tokens.h>

#include <maya/MViewport2Renderer.h>
Expand All @@ -28,6 +30,29 @@ PXR_NAMESPACE_USING_DIRECTIVE

using namespace MayaHydra;

namespace {

const std::string kChildCubePrimName = "childCubeShape";

FindPrimPredicate findCubePrimPredicateRenderItem
= [](const HdSceneIndexBasePtr& sceneIndex, const SdfPath& primPath) -> bool {
HdSceneIndexPrim prim = sceneIndex->GetPrim(primPath);
if (prim.primType != HdPrimTypeTokens->mesh) {
return false;
}
bool parentIsCube
= MakeRelativeToParentPath(primPath.GetParentPath()).GetAsString() == kChildCubePrimName;
return parentIsCube;
};

FindPrimPredicate findCubePrimPredicateMeshAdapter
= [](const HdSceneIndexBasePtr& sceneIndex, const SdfPath& primPath) -> bool {
HdSceneIndexPrim prim = sceneIndex->GetPrim(primPath);
return prim.primType == HdPrimTypeTokens->mesh && primPath.GetName() == kChildCubePrimName;
};

} // namespace

TEST(MayaSceneFlattening, childHasFlattenedTransform)
{
// Setup inspector for the first scene index
Expand All @@ -36,16 +61,9 @@ TEST(MayaSceneFlattening, childHasFlattenedTransform)
SceneIndexInspector inspector(sceneIndices.front());

// Retrieve the child cube prim
bool isMeshAdapterEnabled = TfGetenvBool("MAYA_HYDRA_USE_MESH_ADAPTER", false);
FindPrimPredicate findCubePrimPredicate
= [](const HdSceneIndexBasePtr& sceneIndex, const SdfPath& primPath) -> bool {
HdSceneIndexPrim prim = sceneIndex->GetPrim(primPath);
if (prim.primType != HdPrimTypeTokens->mesh) {
return false;
}
bool parentIsCube
= MakeRelativeToParentPath(primPath.GetParentPath()).GetAsString() == "childCubeShape";
return parentIsCube;
};
= isMeshAdapterEnabled ? findCubePrimPredicateMeshAdapter : findCubePrimPredicateRenderItem;
PrimEntriesVector foundPrims = inspector.FindPrims(findCubePrimPredicate, 1);
ASSERT_EQ(foundPrims.size(), static_cast<size_t>(1));
HdSceneIndexPrim cubePrim = foundPrims.front().prim;
Expand Down

0 comments on commit 204d7d1

Please sign in to comment.