Skip to content

Commit

Permalink
Simplify path management
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 18, 2023
1 parent 0293a2a commit 594eeee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class FabricMaterial {
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo,
uint64_t texcoordIndex);
void setTilesetId(int64_t tilesetId);
bool stageDestroyed();

omni::fabric::Path _materialPath;
Expand All @@ -77,8 +76,9 @@ class FabricMaterial {

omni::fabric::Path _shaderPath;
omni::fabric::Path _baseColorTexturePath;
omni::fabric::Path _imageryLayerResolverPath;
std::vector<omni::fabric::Path> _imageryLayerPaths;

std::vector<omni::fabric::Path> _allPaths;
};

} // namespace cesium::omniverse
56 changes: 16 additions & 40 deletions src/core/src/FabricMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,8 @@ FabricMaterial::~FabricMaterial() {
return;
}

FabricUtil::destroyPrim(_materialPath);
FabricUtil::destroyPrim(_shaderPath);

if (!FabricUtil::isEmpty(_baseColorTexturePath)) {
FabricUtil::destroyPrim(_baseColorTexturePath);
}

if (!FabricUtil::isEmpty(_imageryLayerResolverPath)) {
FabricUtil::destroyPrim(_imageryLayerResolverPath);
}

for (const auto& imageryLayerPath : _imageryLayerPaths) {
FabricUtil::destroyPrim(imageryLayerPath);
for (const auto& path : _allPaths) {
FabricUtil::destroyPrim(path);
}
}

Expand All @@ -93,46 +82,47 @@ const FabricMaterialDefinition& FabricMaterial::getMaterialDefinition() const {
}

void FabricMaterial::initialize() {
auto& fabricResourceManager = FabricResourceManager::getInstance();

const auto& materialPath = _materialPath;
createMaterial(materialPath);
fabricResourceManager.retainPath(materialPath);
_allPaths.push_back(materialPath);

const auto shaderPath = FabricUtil::joinPaths(materialPath, FabricTokens::Shader);
createShader(shaderPath, materialPath);
fabricResourceManager.retainPath(shaderPath);
_shaderPath = shaderPath;
_allPaths.push_back(shaderPath);

if (_materialDefinition.hasBaseColorTexture()) {
const auto baseColorTexturePath = FabricUtil::joinPaths(materialPath, FabricTokens::base_color_texture);
createTexture(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture);
fabricResourceManager.retainPath(baseColorTexturePath);
_baseColorTexturePath = baseColorTexturePath;
_allPaths.push_back(baseColorTexturePath);
}

const auto imageryLayerCount = getImageryLayerCount(_materialDefinition);

if (imageryLayerCount == 1) {
const auto imageryLayerPath = FabricUtil::joinPaths(materialPath, FabricTokens::imagery_layer_n[0]);
createTexture(imageryLayerPath, shaderPath, FabricTokens::inputs_imagery_layers_texture);
fabricResourceManager.retainPath(imageryLayerPath);
_imageryLayerPaths.push_back(imageryLayerPath);
_allPaths.push_back(imageryLayerPath);
} else if (imageryLayerCount > 1) {
const auto imageryLayerResolverPath = FabricUtil::joinPaths(materialPath, FabricTokens::imagery_layer_resolver);
createImageryLayerResolver(
imageryLayerResolverPath, shaderPath, FabricTokens::inputs_imagery_layers_texture, imageryLayerCount);
fabricResourceManager.retainPath(imageryLayerResolverPath);
_imageryLayerResolverPath = imageryLayerResolverPath;
_allPaths.push_back(imageryLayerResolverPath);

_imageryLayerPaths.reserve(imageryLayerCount);
for (uint64_t i = 0; i < imageryLayerCount; i++) {
const auto imageryLayerPath = FabricUtil::joinPaths(materialPath, FabricTokens::imagery_layer_n[i]);
createTexture(imageryLayerPath, imageryLayerResolverPath, FabricTokens::inputs_imagery_layer_n[i]);
fabricResourceManager.retainPath(imageryLayerPath);
_imageryLayerPaths.push_back(imageryLayerPath);
_allPaths.push_back(imageryLayerPath);
}
}

for (const auto& path : _allPaths) {
FabricResourceManager::getInstance().retainPath(path);
}
}

void FabricMaterial::createMaterial(const omni::fabric::Path& materialPath) {
Expand Down Expand Up @@ -335,7 +325,10 @@ void FabricMaterial::setMaterial(int64_t tilesetId, const MaterialInfo& material
auto srw = UsdUtil::getFabricStageReaderWriter();

setShaderValues(_shaderPath, materialInfo);
setTilesetId(tilesetId);

for (const auto& path : _allPaths) {
FabricUtil::setTilesetId(path, tilesetId);
}
}

void FabricMaterial::setBaseColorTexture(
Expand Down Expand Up @@ -387,23 +380,6 @@ void FabricMaterial::clearImageryLayers() {
}
}

void FabricMaterial::setTilesetId(int64_t tilesetId) {
FabricUtil::setTilesetId(_materialPath, tilesetId);
FabricUtil::setTilesetId(_shaderPath, tilesetId);

if (!FabricUtil::isEmpty(_baseColorTexturePath)) {
FabricUtil::setTilesetId(_baseColorTexturePath, tilesetId);
}

if (!FabricUtil::isEmpty(_imageryLayerResolverPath)) {
FabricUtil::setTilesetId(_imageryLayerResolverPath, tilesetId);
}

for (const auto& imageryLayerPath : _imageryLayerPaths) {
FabricUtil::setTilesetId(imageryLayerPath, tilesetId);
}
}

void FabricMaterial::setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo) {
auto srw = UsdUtil::getFabricStageReaderWriter();

Expand Down

0 comments on commit 594eeee

Please sign in to comment.