Skip to content

Commit

Permalink
added cleanup of prims
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelser committed Oct 20, 2023
1 parent 633cd37 commit 1aebec4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/include/UsdUtilTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace cesium::omniverse::UsdUtil {
void setUpUsdUtilTests(long int stage_id);
void cleanUpUsdUtilTests();
}
1 change: 1 addition & 0 deletions tests/src/CesiumOmniverseCppTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CesiumOmniverseCppTestsPlugin final : public ICesiumOmniverseCppTestsInter

void cleanUpAfterTests() noexcept {
// delete any test related prims here
cesium::omniverse::UsdUtil::cleanUpUsdUtilTests();
}
};

Expand Down
49 changes: 38 additions & 11 deletions tests/src/UsdUtilTests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "UsdUtilTests.h"

#include "CesiumUsdSchemas/data.h"
#include "CesiumUsdSchemas/georeference.h"
#include "testUtils.h"

#include "cesium/omniverse/Context.h"
Expand All @@ -14,15 +15,17 @@
#include <pxr/usd/usdGeom/xformable.h>
#include <unistd.h>

// define prim paths globally to cut down on repeated definitions
// name the paths after the function to be tested so they can easily be paired up later
pxr::SdfPath defineCesiumDataPath;
pxr::SdfPath defineCesiumSessionPath;
pxr::SdfPath defineCesiumGeoreferencePath;
pxr::SdfPath defineCesiumTilesetPath;
pxr::SdfPath defineCesiumImageryPath;
pxr::SdfPath defineGlobeAnchorPath;
pxr::SdfPath getOrCreateCesiumDataPath;
pxr::SdfPath getOrCreateCesiumSessionPath;
pxr::SdfPath getOrCreateCesiumGeoreferencePath;
pxr::CesiumData getOrCreateCesiumDataPrim;
pxr::CesiumSession getOrCreateCesiumSessionPrim;
pxr::CesiumGeoreference getOrCreateCesiumGeoreferencePrim;

namespace cesium::omniverse::UsdUtil {
void setUpUsdUtilTests(long int stage_id) {
Expand All @@ -32,7 +35,7 @@ void setUpUsdUtilTests(long int stage_id) {
auto stage = getUsdStage();
auto rootPath = getRootPath();

// name the prims after the function to be tested so they can easily be paired up later
// might as well name the prims after the function as well, to ensure uniqueness and clarity
defineCesiumDataPath = rootPath.AppendChild(pxr::TfToken("defineCesiumData"));
defineCesiumSessionPath = rootPath.AppendChild(pxr::TfToken("defineCesiumSession"));
defineCesiumGeoreferencePath = rootPath.AppendChild(pxr::TfToken("defineCesiumGeoreference"));
Expand All @@ -46,6 +49,30 @@ void setUpUsdUtilTests(long int stage_id) {
defineCesiumTileset(defineCesiumTilesetPath);
defineCesiumImagery(defineCesiumImageryPath);
// defineGlobeAnchor(globeAnchorPath);

getOrCreateCesiumDataPrim = getOrCreateCesiumData();
getOrCreateCesiumSessionPrim = getOrCreateCesiumSession();
getOrCreateCesiumGeoreferencePrim = getOrCreateCesiumGeoreference();
}

void cleanUpUsdUtilTests() {

auto stage = getUsdStage();
auto rootPath = getRootPath();

// might as well name the prims after the function as well, to ensure uniqueness and clarity
stage->RemovePrim(defineCesiumDataPath);
stage->RemovePrim(defineCesiumSessionPath);
stage->RemovePrim(defineCesiumGeoreferencePath);
stage->RemovePrim(defineCesiumImageryPath);
stage->RemovePrim(defineCesiumTilesetPath);
stage->RemovePrim(defineGlobeAnchorPath);

// stage->RemovePrim(globeAnchorPath);

stage->RemovePrim(getOrCreateCesiumDataPrim.GetPath());
stage->RemovePrim(getOrCreateCesiumSessionPrim.GetPath());
stage->RemovePrim(getOrCreateCesiumGeoreferencePrim.GetPath());
}

TEST_SUITE("UsdUtil tests") {
Expand Down Expand Up @@ -128,6 +155,10 @@ TEST_SUITE("UsdUtil tests") {
CHECK(isCesiumTileset(defineCesiumTilesetPath));
CHECK(isCesiumImagery(defineCesiumImageryPath));
// CHECK(hasCesiumGlobeAnchor(globeAnchorPath));

CHECK(isCesiumData(getOrCreateCesiumDataPrim.GetPath()));
CHECK(isCesiumSession(getOrCreateCesiumSessionPrim.GetPath()));
CHECK(isCesiumGeoreference(getOrCreateCesiumGeoreferencePrim.GetPath()));
}

TEST_CASE("Smoke tests") {
Expand All @@ -136,8 +167,10 @@ TEST_SUITE("UsdUtil tests") {
CHECK_NOTHROW(getDynamicTextureProviderAssetPathToken("foo"));
CHECK_NOTHROW(getFabricStageReaderWriter());
CHECK_NOTHROW(getFabricStageReaderWriterId());
CHECK_NOTHROW(getUsdUpAxis());
CHECK(getUsdMetersPerUnit() > 0);

// hasStage();
// List of currently untested functions in UsdUtil:
// usdToGlmVector(const pxr::GfVec3d& vector);
// glmToUsdVector(const glm::dvec3& vector);
// glmToUsdVector(const glm::fvec2& vector);
Expand All @@ -146,8 +179,6 @@ TEST_SUITE("UsdUtil tests") {
// glmToUsdQuat(const glm::dquat& quat);
// glmToUsdMatrixDecomposed(const glm::dmat4& matrix);
// computeUsdWorldToLocalTransform(const pxr::SdfPath& path);
// getUsdUpAxis();
// getUsdMetersPerUnit();
// computeEcefToUsdLocalTransform(const CesiumGeospatial::Cartographic& origin);
// computeEcefToUsdWorldTransformForPrim(
// const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath);
Expand All @@ -161,11 +192,7 @@ TEST_SUITE("UsdUtil tests") {
// const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath, const Viewport& viewport);
// computeWorldExtent(const pxr::GfRange3d& localExtent, const glm::dmat4& localToUsdTransform);
// getEulerAnglesFromQuaternion(const pxr::GfQuatf& quaternion);

// primExists(const pxr::SdfPath& path);

// setGeoreferenceForTileset(const pxr::SdfPath& tilesetPath, const pxr::SdfPath& georeferencePath);

// addOrUpdateTransformOpForAnchor(const pxr::SdfPath& path, const glm::dmat4& transform);
// getCesiumTransformOpValueForPathIfExists(const pxr::SdfPath& path);
// getAnchorGeoreferencePath(const pxr::SdfPath& path);
Expand Down

0 comments on commit 1aebec4

Please sign in to comment.