Skip to content

Commit

Permalink
WIP writing more UsdUtil tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelser committed Oct 17, 2023
1 parent 9137f54 commit 9364c09
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/src/ObjectPoolTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testRandomSequenceOfCmds(MockObjectPool& opl, int numEvents, bool setCap) {
if (maxActiveCount != 0) {
expectedPercentActive = (float)numActive / (float)maxActiveCount;
} else {
expectedPercentActive = 0;
expectedPercentActive = 1;
}
CHECK(opl.computePercentActive() <= expectedPercentActive);
}
Expand Down
50 changes: 49 additions & 1 deletion tests/src/UsdUtilTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,57 @@
#include "cesium/omniverse/UsdUtil.h"

#include <doctest/doctest.h>
#include <glm/ext/matrix_double4x4.hpp>
#include <pxr/usd/usdGeom/cube.h>
#include <pxr/usd/usdGeom/xformCommonAPI.h>
#include <pxr/usd/usdGeom/xformable.h>

namespace cesium::omniverse::UsdUtil {

TEST_SUITE("UsdUtil tests") {
TEST_CASE("Check expected initial state") {
CHECK(cesium::omniverse::UsdUtil::primExists(pxr::SdfPath("/Cesium")));
auto cesiumObjPath = pxr::SdfPath("/Cesium");
CHECK(hasStage());
CHECK(primExists(cesiumObjPath));
// TODO can we check something invisible here too?
CHECK(isPrimVisible(cesiumObjPath));
}

TEST_CASE("Check glm/usd conversion functions") {
glm::dmat4 matrix(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

// Round-trip conversion of usd/glm matrix
CHECK(matrix == usdToGlmMatrix(glmToUsdMatrix(matrix)));
}

TEST_CASE("Tests that require prim creation") {
auto stage = getUsdStage();
auto primPath = getPathUnique(getRootPath(), "CesiumTestPrim");
auto prim = stage->DefinePrim(primPath);

// Intentionally try the same prim name
auto cubePath = getPathUnique(getRootPath(), "CesiumTestPrim");
// Tests getPathUnique actually returns unique paths
CHECK(primPath.GetPrimPath() != cubePath.GetPrimPath());

auto cube = pxr::UsdGeomCube::Define(stage, cubePath);

auto xformApiCube = pxr::UsdGeomXformCommonAPI(cube);
xformApiCube.SetRotate({30, 60, 90});
xformApiCube.SetScale({5, 12, 13});
xformApiCube.SetTranslate({3, 4, 5});

auto xformableCube = pxr::UsdGeomXformable(cube);

pxr::GfMatrix4d cubeXform;
bool xformStackResetNeeded [[maybe_unused]];

xformableCube.GetLocalTransformation(&cubeXform, &xformStackResetNeeded);

CHECK(usdToGlmMatrix(cubeXform) == computeUsdLocalToWorldTransform(cubePath));

// stage->RemovePrim(primPath);
// stage->RemovePrim(cubePath);
}
}
} // namespace cesium::omniverse::UsdUtil

0 comments on commit 9364c09

Please sign in to comment.