Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 31, 2023
1 parent 02a557e commit efb6c85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/core/include/cesium/omniverse/FabricUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ omni::fabric::Path toFabricPath(const pxr::SdfPath& path);
omni::fabric::Path joinPaths(const omni::fabric::Path& absolutePath, const omni::fabric::Token& relativePath);
std::vector<omni::fabric::Path> getPrimsInMaterialNetwork(const omni::fabric::Path& path);
void copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric::Path& dstMaterialPath);
omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path);
bool materialHasCesiumNodes(const omni::fabric::Path& path);
bool isCesiumNode(const omni::fabric::Token& mdlIdentifier);
omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path);

} // namespace cesium::omniverse::FabricUtil
67 changes: 24 additions & 43 deletions src/core/src/FabricUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,35 +713,10 @@ std::vector<FabricConnection> getConnections(const omni::fabric::Path& path) {
return connections;
}

bool isEmptyToken(
const omni::fabric::Path& path,
const omni::fabric::Token& attributeName,
const omni::fabric::Type& attributeType) {
auto srw = UsdUtil::getFabricStageReaderWriter();
if (attributeType.baseType == omni::fabric::BaseDataType::eToken) {
const auto attributeValue = srw.getAttributeRd<omni::fabric::Token>(path, attributeName);
if (attributeValue == nullptr || (*attributeValue).size() == 0) {
return true;
}
}

return false;
}

bool isOutput(const omni::fabric::Token& attributeName) {
return attributeName == FabricTokens::outputs_out;
}

bool isExtraneousTag(const omni::fabric::Token& attributeName, const omni::fabric::Type& attributeType) {
if (attributeType.baseType == omni::fabric::BaseDataType::eTag) {
if (attributeName != FabricTokens::Shader && attributeName != FabricTokens::Material) {
return true;
}
}

return false;
}

bool isConnection(const omni::fabric::Type& attributeType) {
return attributeType.baseType == omni::fabric::BaseDataType::eConnection;
}
Expand All @@ -759,7 +734,7 @@ std::vector<omni::fabric::TokenC> getAttributesToCopy(const omni::fabric::Path&
const auto& name = names[i];
const auto& type = types[i];

if (!isConnection(type)) {
if (!isOutput(name) && !isConnection(type)) {
attributeNames.emplace_back(omni::fabric::TokenC(name));
}
}
Expand All @@ -785,7 +760,7 @@ std::vector<FabricAttribute> getAttributesToCreate(const omni::fabric::Path& pat
const auto& name = names[i];
const auto& type = types[i];

if (!isConnection(type)) {
if (isOutput(name)) {
attributeNames.emplace_back(FabricAttribute{name, type});
}
}
Expand Down Expand Up @@ -837,14 +812,16 @@ void copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric:

srw.createPrim(dstPath);

// This excludes outputs, empty tokens, extraneous tags, and connections
// This excludes outputs and connections
// The material network will be reconnected later once all the prims have been copied
// The reason for excluding outputs is so that Omniverse doesn't print the warning
// [Warning] [omni.fabric.plugin] Warning: input has no valid data"
const auto attributesToCopy = getAttributesToCopy(srcPath);

isrw->copySpecifiedAttributes(
srw.getId(), srcPath, attributesToCopy.data(), dstPath, attributesToCopy.data(), attributesToCopy.size());

// Add outputs back. The reason we didn't just copy them is because Omniverse prints a warning:
// [Warning] [omni.fabric.plugin] Warning: input has no valid data
// Add the outputs back. This doesn't print a warning.
const auto attributesToCreate = getAttributesToCreate(srcPath);
for (const auto& attribute : attributesToCreate) {
srw.createAttribute(dstPath, attribute.name, attribute.type);
Expand All @@ -867,30 +844,34 @@ void copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric:
}
}

omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path) {
auto srw = UsdUtil::getFabricStageReaderWriter();
if (srw.attributeExists(path, FabricTokens::info_mdl_sourceAsset_subIdentifier)) {
const auto infoMdlSourceAssetSubIdentifierFabric =
srw.getAttributeRd<omni::fabric::Token>(path, FabricTokens::info_mdl_sourceAsset_subIdentifier);
if (infoMdlSourceAssetSubIdentifierFabric != nullptr) {
return *infoMdlSourceAssetSubIdentifierFabric;
}
}
return omni::fabric::Token{};
}

bool materialHasCesiumNodes(const omni::fabric::Path& path) {
auto srw = UsdUtil::getFabricStageReaderWriter();
const auto paths = getPrimsInMaterialNetwork(path);

for (const auto& p : paths) {
const auto mdlIdentifier = getMdlIdentifier(p);
if (mdlIdentifier == FabricTokens::cesium_base_color_texture) {
if (isCesiumNode(mdlIdentifier)) {
return true;
}
}

return false;
}

bool isCesiumNode(const omni::fabric::Token& mdlIdentifier) {
return mdlIdentifier == FabricTokens::cesium_base_color_texture;
}

omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path) {
auto srw = UsdUtil::getFabricStageReaderWriter();
if (srw.attributeExists(path, FabricTokens::info_mdl_sourceAsset_subIdentifier)) {
const auto infoMdlSourceAssetSubIdentifierFabric =
srw.getAttributeRd<omni::fabric::Token>(path, FabricTokens::info_mdl_sourceAsset_subIdentifier);
if (infoMdlSourceAssetSubIdentifierFabric != nullptr) {
return *infoMdlSourceAssetSubIdentifierFabric;
}
}
return omni::fabric::Token{};
}

} // namespace cesium::omniverse::FabricUtil

0 comments on commit efb6c85

Please sign in to comment.