diff --git a/.clang-tidy b/.clang-tidy index 7a8f2df26..a750fcf01 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,4 @@ --- -Checks: "-*,bugprone-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-bugprone-exception-escape" +Checks: "-*,bugprone-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-bugprone-exception-escape,-modernize-pass-by-value" WarningsAsErrors: "*" FormatStyle: none diff --git a/apps/cesium.omniverse.dev.kit b/apps/cesium.omniverse.dev.kit index 981f498bc..fbd3cfc0d 100644 --- a/apps/cesium.omniverse.dev.kit +++ b/apps/cesium.omniverse.dev.kit @@ -6,6 +6,7 @@ app = true [dependencies] # Include basic configuration (that brings most of basic extensions) "omni.app.dev" = {} +"omni.kit.window.material_graph" = {} "cesium.omniverse" = {} "cesium.powertools" = {} #"omni.example.ui" = {} @@ -17,6 +18,15 @@ app.useFabricSceneDelegate = true app.usdrt.scene_delegate.enableProxyCubes = false app.usdrt.scene_delegate.geometryStreaming.enabled = false app.fastShutdown = true +# Both searchPaths settings must be set in order for material graph to find cesium mdl exports +renderer.mdl.searchPaths.custom = "${app}/../exts/cesium.omniverse/mdl" +materialConfig.searchPaths.custom = ["${app}/../exts/cesium.omniverse/mdl"] +materialConfig.materialGraph.userAllowList = ["cesium.mdl"] [settings.app.exts] -folders.'++' = ["${app}/../exts"] # Make extensions from this repo available. +folders.'++' = [ + "${app}", # Find other applications in this folder + "${app}/exts", # Find extensions in this folder + "${app}/../exts", # Find cesium.omniverse and cesium.usd.schemas + "${app}/../extern/nvidia/app/extscache" # Find omni.kit.window.material_graph +] diff --git a/apps/cesium.omniverse.dev.python.debug.kit b/apps/cesium.omniverse.dev.python.debug.kit index 02af2a0ad..c64a3caa2 100644 --- a/apps/cesium.omniverse.dev.python.debug.kit +++ b/apps/cesium.omniverse.dev.python.debug.kit @@ -10,9 +10,3 @@ app = true [settings] app.window.title = "Cesium For Omniverse Python Debugging App" - -[settings.app.exts] -folders.'++' = [ - "${app}", - "${app}/../exts" -] diff --git a/apps/cesium.omniverse.dev.trace.kit b/apps/cesium.omniverse.dev.trace.kit index da770c3bb..743bac538 100644 --- a/apps/cesium.omniverse.dev.trace.kit +++ b/apps/cesium.omniverse.dev.trace.kit @@ -9,9 +9,3 @@ app = true [settings] app.window.title = "Cesium For Omniverse Performance Tracing App" app.fastShutdown = false - -[settings.app.exts] -folders.'++' = [ - "${app}", - "${app}/../exts" -] diff --git a/apps/cesium.performance.kit b/apps/cesium.performance.kit index 5b469500d..5a60d3f4a 100644 --- a/apps/cesium.performance.kit +++ b/apps/cesium.performance.kit @@ -9,10 +9,3 @@ app = true [settings] app.window.title = "Cesium For Omniverse Performance Testing App" - -[settings.app.exts] -folders.'++' = [ - "${app}", - "${app}/exts", - "${app}/../exts" -] diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 295fb450d..4fbb0d7bc 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -48,6 +48,14 @@ if(exit_code AND NOT exit_code EQUAL 0) endif() # cmake-format: on +# Add a symlink to USD Composer (create) so that we can use its extensions (e.g. omni.kit.window.material_graph) in our internal applications +# Don't check for errors because we can still proceed with the build +if(UNIX) + execute_process(COMMAND bash "${PROJECT_SOURCE_DIR}/extern/nvidia/link_app.sh --app create") +elseif(WIN32) + execute_process(COMMAND cmd /C "${PROJECT_SOURCE_DIR}/extern/nvidia/link_app.bat --app create") +endif() + if(WIN32) set(NVIDIA_PLATFORM_NAME "windows-x86_64") elseif(UNIX AND NOT APPLE) diff --git a/exts/cesium.omniverse/mdl/cesium.mdl b/exts/cesium.omniverse/mdl/cesium.mdl new file mode 100644 index 000000000..e3bdbe16a --- /dev/null +++ b/exts/cesium.omniverse/mdl/cesium.mdl @@ -0,0 +1,16 @@ +mdl 1.8; + +import ::anno::*; +import ::state::*; +import ::tex::*; + +using ::gltf::pbr import *; + +module [[ + anno::version( 1, 0, 0), + anno::display_name("Cesium MDL functions") +]]; + +// For internal use only. See note in FabricMaterial.cpp +export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup(); +export material cesium_material(*) [[ anno::hidden() ]] = gltf_material(); diff --git a/src/core/include/cesium/omniverse/Context.h b/src/core/include/cesium/omniverse/Context.h index ef3d9e9ed..3564ca6c6 100644 --- a/src/core/include/cesium/omniverse/Context.h +++ b/src/core/include/cesium/omniverse/Context.h @@ -111,8 +111,9 @@ class Context { uint64_t tokenEventId, uint64_t assetEventId); - std::filesystem::path getCesiumExtensionLocation() const; - std::filesystem::path getCertificatePath() const; + const std::filesystem::path& getCesiumExtensionLocation() const; + const std::filesystem::path& getCertificatePath() const; + const pxr::TfToken& getCesiumMdlPathToken() const; bool creditsAvailable() const; std::vector> getCredits() const; @@ -162,6 +163,7 @@ class Context { std::filesystem::path _cesiumExtensionLocation; std::filesystem::path _certificatePath; + pxr::TfToken _cesiumMdlPathToken; glm::dmat4 _ecefToUsdTransform; }; diff --git a/src/core/include/cesium/omniverse/FabricGeometry.h b/src/core/include/cesium/omniverse/FabricGeometry.h index 84006d4f8..4dea4b247 100644 --- a/src/core/include/cesium/omniverse/FabricGeometry.h +++ b/src/core/include/cesium/omniverse/FabricGeometry.h @@ -13,12 +13,10 @@ struct Model; namespace cesium::omniverse { -class FabricMaterial; - class FabricGeometry { public: FabricGeometry( - const pxr::SdfPath& path, + const omni::fabric::Path& path, const FabricGeometryDefinition& geometryDefinition, bool debugRandomColors, long stageId); @@ -37,7 +35,7 @@ class FabricGeometry { void setActive(bool active); void setVisibility(bool visible); - [[nodiscard]] omni::fabric::Path getPathFabric() const; + [[nodiscard]] omni::fabric::Path getPath() const; [[nodiscard]] const FabricGeometryDefinition& getGeometryDefinition() const; void setMaterial(const omni::fabric::Path& materialPath); @@ -47,7 +45,7 @@ class FabricGeometry { void reset(); bool stageDestroyed(); - const omni::fabric::Path _pathFabric; + const omni::fabric::Path _path; const FabricGeometryDefinition _geometryDefinition; const bool _debugRandomColors; const long _stageId; diff --git a/src/core/include/cesium/omniverse/FabricMaterial.h b/src/core/include/cesium/omniverse/FabricMaterial.h index d19c80b34..9f410ed0b 100644 --- a/src/core/include/cesium/omniverse/FabricMaterial.h +++ b/src/core/include/cesium/omniverse/FabricMaterial.h @@ -4,6 +4,7 @@ #include "cesium/omniverse/GltfUtil.h" #include +#include #include #include @@ -11,51 +12,54 @@ namespace omni::ui { class DynamicTextureProvider; } -namespace CesiumGltf { -struct ImageCesium; -struct MeshPrimitive; -struct Model; -} // namespace CesiumGltf - namespace cesium::omniverse { -class FabricTexture; - class FabricMaterial { public: FabricMaterial( - pxr::SdfPath path, + const omni::fabric::Path& path, const FabricMaterialDefinition& materialDefinition, - pxr::SdfAssetPath defaultTextureAssetPath, + const pxr::TfToken& defaultTextureAssetPathToken, long stageId); ~FabricMaterial(); void setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo); + void setBaseColorTexture(const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo); - void setBaseColorTexture(const std::shared_ptr& texture, const TextureInfo& textureInfo); - + void clearMaterial(); void clearBaseColorTexture(); void setActive(bool active); - [[nodiscard]] omni::fabric::Path getPathFabric() const; + [[nodiscard]] omni::fabric::Path getPath() const; [[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const; private: - void initialize(pxr::SdfPath path, const FabricMaterialDefinition& materialDefinition); + void initialize(); + + void createMaterial(const omni::fabric::Path& materialPath); + void createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath); + void createTexture( + const omni::fabric::Path& texturePath, + const omni::fabric::Path& shaderPath, + const omni::fabric::Token& shaderInput); + void reset(); + void setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo); + void setTextureValues( + const omni::fabric::Path& texturePath, + const pxr::TfToken& textureAssetPathToken, + const TextureInfo& textureInfo); void setTilesetId(int64_t tilesetId); - void setMaterialValues(const MaterialInfo& materialInfo); - void setBaseColorTextureValues(const pxr::SdfAssetPath& textureAssetPath, const TextureInfo& textureInfo); bool stageDestroyed(); + omni::fabric::Path _materialPath; const FabricMaterialDefinition _materialDefinition; - const pxr::SdfAssetPath _defaultTextureAssetPath; + const pxr::TfToken _defaultTextureAssetPathToken; const long _stageId; - omni::fabric::Path _materialPathFabric; - omni::fabric::Path _shaderPathFabric; - omni::fabric::Path _baseColorTexPathFabric; + omni::fabric::Path _shaderPath; + omni::fabric::Path _baseColorTexturePath; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricMaterialDefinition.h b/src/core/include/cesium/omniverse/FabricMaterialDefinition.h index f5de5f636..2b7a005cf 100644 --- a/src/core/include/cesium/omniverse/FabricMaterialDefinition.h +++ b/src/core/include/cesium/omniverse/FabricMaterialDefinition.h @@ -4,11 +4,6 @@ #include #include -namespace CesiumGltf { -struct MeshPrimitive; -struct Model; -} // namespace CesiumGltf - namespace cesium::omniverse { struct MaterialInfo; diff --git a/src/core/include/cesium/omniverse/FabricMaterialPool.h b/src/core/include/cesium/omniverse/FabricMaterialPool.h index 0b5d34e67..699276a8d 100644 --- a/src/core/include/cesium/omniverse/FabricMaterialPool.h +++ b/src/core/include/cesium/omniverse/FabricMaterialPool.h @@ -14,7 +14,7 @@ class FabricMaterialPool final : public ObjectPool { int64_t poolId, const FabricMaterialDefinition& materialDefinition, uint64_t initialCapacity, - pxr::SdfAssetPath defaultTextureAssetPath, + const pxr::TfToken& defaultTextureAssetPathToken, long stageId); [[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const; @@ -26,7 +26,7 @@ class FabricMaterialPool final : public ObjectPool { private: const int64_t _poolId; const FabricMaterialDefinition _materialDefinition; - const pxr::SdfAssetPath _defaultTextureAssetPath; + const pxr::TfToken _defaultTextureAssetPathToken; const long _stageId; }; diff --git a/src/core/include/cesium/omniverse/FabricResourceManager.h b/src/core/include/cesium/omniverse/FabricResourceManager.h index f06036ffe..6808e7872 100644 --- a/src/core/include/cesium/omniverse/FabricResourceManager.h +++ b/src/core/include/cesium/omniverse/FabricResourceManager.h @@ -44,7 +44,7 @@ class FabricResourceManager { bool shouldAcquireMaterial( const CesiumGltf::MeshPrimitive& primitive, bool hasImagery, - const pxr::SdfPath& materialPath) const; + const pxr::SdfPath& tilesetMaterialPath) const; std::shared_ptr acquireGeometry( const CesiumGltf::Model& model, @@ -116,7 +116,7 @@ class FabricResourceManager { std::mutex _poolMutex; std::unique_ptr _defaultTexture; - pxr::SdfAssetPath _defaultTextureAssetPath; + pxr::TfToken _defaultTextureAssetPathToken; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricTexture.h b/src/core/include/cesium/omniverse/FabricTexture.h index a11cae6fe..48378b4b0 100644 --- a/src/core/include/cesium/omniverse/FabricTexture.h +++ b/src/core/include/cesium/omniverse/FabricTexture.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -23,12 +24,12 @@ class FabricTexture { void setActive(bool active); - [[nodiscard]] const pxr::SdfAssetPath& getAssetPath() const; + [[nodiscard]] const pxr::TfToken& getAssetPathToken() const; private: void reset(); std::unique_ptr _texture; - pxr::SdfAssetPath _assetPath; + pxr::TfToken _assetPathToken; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricUtil.h b/src/core/include/cesium/omniverse/FabricUtil.h index 82fd32e8e..a958d9c30 100644 --- a/src/core/include/cesium/omniverse/FabricUtil.h +++ b/src/core/include/cesium/omniverse/FabricUtil.h @@ -31,6 +31,8 @@ std::string printFabricStage(); FabricStatistics getStatistics(); void destroyPrim(const omni::fabric::Path& path); void setTilesetTransform(int64_t tilesetId, const glm::dmat4& ecefToUsdTransform); -void setTilesetId(const omni::fabric::Path& pathFabric, int64_t tilesetId); +void setTilesetId(const omni::fabric::Path& path, int64_t tilesetId); +omni::fabric::Path toFabricPath(const pxr::SdfPath& path); +omni::fabric::Path joinPaths(const omni::fabric::Path& absolutePath, const omni::fabric::Token& relativePath); } // namespace cesium::omniverse::FabricUtil diff --git a/src/core/include/cesium/omniverse/OmniImagery.h b/src/core/include/cesium/omniverse/OmniImagery.h index c36e3287e..d3e419c7c 100644 --- a/src/core/include/cesium/omniverse/OmniImagery.h +++ b/src/core/include/cesium/omniverse/OmniImagery.h @@ -6,7 +6,7 @@ namespace cesium::omniverse { class OmniImagery { public: - OmniImagery(pxr::SdfPath path); + OmniImagery(const pxr::SdfPath& path); [[nodiscard]] pxr::SdfPath getPath() const; [[nodiscard]] std::string getName() const; diff --git a/src/core/include/cesium/omniverse/Tokens.h b/src/core/include/cesium/omniverse/Tokens.h index 47524679a..079640a83 100644 --- a/src/core/include/cesium/omniverse/Tokens.h +++ b/src/core/include/cesium/omniverse/Tokens.h @@ -6,15 +6,14 @@ // clang-format off namespace cesium::omniverse::FabricTokens { -extern const omni::fabric::TokenC baseColorTex; +extern const omni::fabric::TokenC baseColorTexture; +extern const omni::fabric::TokenC cesium_material; +extern const omni::fabric::TokenC cesium_texture_lookup; extern const omni::fabric::TokenC constant; extern const omni::fabric::TokenC doubleSided; extern const omni::fabric::TokenC extent; extern const omni::fabric::TokenC faceVertexCounts; extern const omni::fabric::TokenC faceVertexIndices; -extern const omni::fabric::TokenC gltf_material; -extern const omni::fabric::TokenC gltf_pbr_mdl; -extern const omni::fabric::TokenC gltf_texture_lookup; extern const omni::fabric::TokenC info_implementationSource; extern const omni::fabric::TokenC info_mdl_sourceAsset; extern const omni::fabric::TokenC info_mdl_sourceAsset_subIdentifier; @@ -24,6 +23,7 @@ extern const omni::fabric::TokenC inputs_base_alpha; extern const omni::fabric::TokenC inputs_base_color_factor; extern const omni::fabric::TokenC inputs_base_color_texture; extern const omni::fabric::TokenC inputs_emissive_factor; +extern const omni::fabric::TokenC inputs_excludeFromWhiteMode; extern const omni::fabric::TokenC inputs_metallic_factor; extern const omni::fabric::TokenC inputs_offset; extern const omni::fabric::TokenC inputs_rotation; @@ -70,15 +70,14 @@ extern const omni::fabric::TokenC _worldVisibility; } namespace cesium::omniverse::UsdTokens { -extern const pxr::TfToken& baseColorTex; +extern const pxr::TfToken& baseColorTexture; +extern const pxr::TfToken& cesium_material; +extern const pxr::TfToken& cesium_texture_lookup; extern const pxr::TfToken& constant; extern const pxr::TfToken& doubleSided; extern const pxr::TfToken& extent; extern const pxr::TfToken& faceVertexCounts; extern const pxr::TfToken& faceVertexIndices; -extern const pxr::TfToken& gltf_material; -extern const pxr::TfToken& gltf_pbr_mdl; -extern const pxr::TfToken& gltf_texture_lookup; extern const pxr::TfToken& info_implementationSource; extern const pxr::TfToken& info_mdl_sourceAsset; extern const pxr::TfToken& info_mdl_sourceAsset_subIdentifier; @@ -88,6 +87,7 @@ extern const pxr::TfToken& inputs_base_alpha; extern const pxr::TfToken& inputs_base_color_factor; extern const pxr::TfToken& inputs_base_color_texture; extern const pxr::TfToken& inputs_emissive_factor; +extern const pxr::TfToken& inputs_excludeFromWhiteMode; extern const pxr::TfToken& inputs_metallic_factor; extern const pxr::TfToken& inputs_offset; extern const pxr::TfToken& inputs_rotation; @@ -147,6 +147,7 @@ const omni::fabric::Type inputs_alpha_mode(omni::fabric::BaseDataType::eInt, 1, const omni::fabric::Type inputs_base_alpha(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_base_color_factor(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eColor); const omni::fabric::Type inputs_emissive_factor(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eColor); +const omni::fabric::Type inputs_excludeFromWhiteMode(omni::fabric::BaseDataType::eBool, 1, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_metallic_factor(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_offset(omni::fabric::BaseDataType::eFloat, 2, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_rotation(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone); diff --git a/src/core/include/cesium/omniverse/UsdUtil.h b/src/core/include/cesium/omniverse/UsdUtil.h index 130715975..8b690e2fa 100644 --- a/src/core/include/cesium/omniverse/UsdUtil.h +++ b/src/core/include/cesium/omniverse/UsdUtil.h @@ -33,8 +33,8 @@ struct Decomposed { class ScopedEdit { public: - ScopedEdit(pxr::UsdStageRefPtr stage) - : _stage(std::move(stage)) + ScopedEdit(const pxr::UsdStageRefPtr& stage) + : _stage(stage) , _sessionLayer(_stage->GetSessionLayer()) , _sessionLayerWasEditable(_sessionLayer->PermissionToEdit()) , _originalEditTarget(_stage->GetEditTarget()) { @@ -78,7 +78,7 @@ double getUsdMetersPerUnit(); pxr::SdfPath getRootPath(); pxr::SdfPath getPathUnique(const pxr::SdfPath& parentPath, const std::string& name); std::string getSafeName(const std::string& name); -pxr::SdfAssetPath getDynamicTextureProviderAssetPath(const std::string& name); +pxr::TfToken getDynamicTextureProviderAssetPathToken(const std::string& name); glm::dmat4 computeEcefToUsdTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath); glm::dmat4 computeUsdToEcefTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath); Cesium3DTilesSelection::ViewState diff --git a/src/core/src/Context.cpp b/src/core/src/Context.cpp index 404fe281c..45139bebb 100644 --- a/src/core/src/Context.cpp +++ b/src/core/src/Context.cpp @@ -76,6 +76,8 @@ void Context::initialize(int64_t contextId, const std::filesystem::path& cesiumE _cesiumExtensionLocation = cesiumExtensionLocation.lexically_normal(); _certificatePath = _cesiumExtensionLocation / "certs" / "cacert.pem"; + const auto cesiumMdlPath = _cesiumExtensionLocation / "mdl" / "cesium.mdl"; + _cesiumMdlPathToken = pxr::TfToken(cesiumMdlPath.generic_string()); _taskProcessor = std::make_shared(); _httpAssetAccessor = std::make_shared(_certificatePath); @@ -364,7 +366,7 @@ void Context::processPrimAdded(const ChangedPrim& changedPrim) { if (changedPrim.primType == ChangedPrimType::CESIUM_TILESET) { // Add the tileset to the asset registry const auto tilesetPath = changedPrim.path; - AssetRegistry::getInstance().addTileset(tilesetPath, pxr::SdfPath("/CesiumGeoreference")); + AssetRegistry::getInstance().addTileset(tilesetPath, UsdUtil::GEOREFERENCE_PATH); } else if (changedPrim.primType == ChangedPrimType::CESIUM_IMAGERY) { // Add the imagery to the asset registry and reload the tileset that the imagery is attached to const auto imageryPath = changedPrim.path; @@ -672,14 +674,18 @@ void Context::updateTroubleshootingDetails( } } -std::filesystem::path Context::getCesiumExtensionLocation() const { +const std::filesystem::path& Context::getCesiumExtensionLocation() const { return _cesiumExtensionLocation; } -std::filesystem::path Context::getCertificatePath() const { +const std::filesystem::path& Context::getCertificatePath() const { return _certificatePath; } +const pxr::TfToken& Context::getCesiumMdlPathToken() const { + return _cesiumMdlPathToken; +} + bool Context::getDebugDisableMaterials() const { const auto cesiumDataUsd = UsdUtil::getOrCreateCesiumData(); bool disableMaterials; diff --git a/src/core/src/FabricGeometry.cpp b/src/core/src/FabricGeometry.cpp index 2bc0f8a0b..038a2bc10 100644 --- a/src/core/src/FabricGeometry.cpp +++ b/src/core/src/FabricGeometry.cpp @@ -32,11 +32,11 @@ const auto DEFAULT_VISIBILITY = false; } // namespace FabricGeometry::FabricGeometry( - const pxr::SdfPath& path, + const omni::fabric::Path& path, const FabricGeometryDefinition& geometryDefinition, bool debugRandomColors, long stageId) - : _pathFabric(path.GetText()) + : _path(path) , _geometryDefinition(geometryDefinition) , _debugRandomColors(debugRandomColors) , _stageId(stageId) { @@ -53,7 +53,7 @@ FabricGeometry::~FabricGeometry() { return; } - FabricUtil::destroyPrim(_pathFabric); + FabricUtil::destroyPrim(_path); } void FabricGeometry::setActive(bool active) { @@ -73,12 +73,12 @@ void FabricGeometry::setVisibility(bool visible) { auto srw = UsdUtil::getFabricStageReaderWriter(); - auto worldVisibilityFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldVisibility); + auto worldVisibilityFabric = srw.getAttributeWr(_path, FabricTokens::_worldVisibility); *worldVisibilityFabric = visible; } -omni::fabric::Path FabricGeometry::getPathFabric() const { - return _pathFabric; +omni::fabric::Path FabricGeometry::getPath() const { + return _path; } const FabricGeometryDefinition& FabricGeometry::getGeometryDefinition() const { @@ -91,8 +91,8 @@ void FabricGeometry::setMaterial(const omni::fabric::Path& materialPath) { } auto srw = UsdUtil::getFabricStageReaderWriter(); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::material_binding, 1); - auto materialBindingFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::material_binding); + srw.setArrayAttributeSize(_path, FabricTokens::material_binding, 1); + auto materialBindingFabric = srw.getArrayAttributeWr(_path, FabricTokens::material_binding); materialBindingFabric[0] = omni::fabric::PathC(materialPath).path; } @@ -104,7 +104,7 @@ void FabricGeometry::initialize() { auto srw = UsdUtil::getFabricStageReaderWriter(); - srw.createPrim(_pathFabric); + srw.createPrim(_path); FabricAttributesBuilder attributes; attributes.addAttribute(FabricTypes::faceVertexCounts, FabricTokens::faceVertexCounts); @@ -139,11 +139,11 @@ void FabricGeometry::initialize() { attributes.addAttribute(FabricTypes::primvars_vertexColor, FabricTokens::primvars_vertexColor); } - attributes.createAttributes(_pathFabric); + attributes.createAttributes(_path); // clang-format off - auto doubleSidedFabric = srw.getAttributeWr(_pathFabric, FabricTokens::doubleSided); - auto subdivisionSchemeFabric = srw.getAttributeWr(_pathFabric, FabricTokens::subdivisionScheme); + auto doubleSidedFabric = srw.getAttributeWr(_path, FabricTokens::doubleSided); + auto subdivisionSchemeFabric = srw.getAttributeWr(_path, FabricTokens::subdivisionScheme); // clang-format on *doubleSidedFabric = doubleSided; @@ -170,14 +170,14 @@ void FabricGeometry::initialize() { primvarIndexVertexColor = primvarsCount++; } - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars, primvarsCount); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvarInterpolations, primvarsCount); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_displayColor, 1); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_displayOpacity, 1); + srw.setArrayAttributeSize(_path, FabricTokens::primvars, primvarsCount); + srw.setArrayAttributeSize(_path, FabricTokens::primvarInterpolations, primvarsCount); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayColor, 1); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayOpacity, 1); // clang-format off - auto primvarsFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars); - auto primvarInterpolationsFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvarInterpolations); + auto primvarsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars); + auto primvarInterpolationsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvarInterpolations); // clang-format on primvarsFabric[primvarIndexDisplayColor] = FabricTokens::primvars_displayColor; @@ -210,15 +210,15 @@ void FabricGeometry::reset() { auto srw = UsdUtil::getFabricStageReaderWriter(); // clang-format off - auto extentFabric = srw.getAttributeWr(_pathFabric, FabricTokens::extent); - auto worldExtentFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldExtent); - auto worldVisibilityFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldVisibility); - auto localToEcefTransformFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_cesium_localToEcefTransform); - auto worldPositionFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldPosition); - auto worldOrientationFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldOrientation); - auto worldScaleFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldScale); - auto displayColorFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_displayColor); - auto displayOpacityFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_displayOpacity); + auto extentFabric = srw.getAttributeWr(_path, FabricTokens::extent); + auto worldExtentFabric = srw.getAttributeWr(_path, FabricTokens::_worldExtent); + auto worldVisibilityFabric = srw.getAttributeWr(_path, FabricTokens::_worldVisibility); + auto localToEcefTransformFabric = srw.getAttributeWr(_path, FabricTokens::_cesium_localToEcefTransform); + auto worldPositionFabric = srw.getAttributeWr(_path, FabricTokens::_worldPosition); + auto worldOrientationFabric = srw.getAttributeWr(_path, FabricTokens::_worldOrientation); + auto worldScaleFabric = srw.getAttributeWr(_path, FabricTokens::_worldScale); + auto displayColorFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayColor); + auto displayOpacityFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayOpacity); // clang-format on *extentFabric = DEFAULT_EXTENT; @@ -231,23 +231,23 @@ void FabricGeometry::reset() { displayColorFabric[0] = DEFAULT_VERTEX_COLOR; displayOpacityFabric[0] = DEFAULT_VERTEX_OPACITY; - FabricUtil::setTilesetId(_pathFabric, NO_TILESET_ID); + FabricUtil::setTilesetId(_path, NO_TILESET_ID); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::material_binding, 0); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::faceVertexCounts, 0); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::faceVertexIndices, 0); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::points, 0); + srw.setArrayAttributeSize(_path, FabricTokens::material_binding, 0); + srw.setArrayAttributeSize(_path, FabricTokens::faceVertexCounts, 0); + srw.setArrayAttributeSize(_path, FabricTokens::faceVertexIndices, 0); + srw.setArrayAttributeSize(_path, FabricTokens::points, 0); if (hasTexcoords) { - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_st, 0); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_st, 0); } if (hasNormals) { - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_normals, 0); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_normals, 0); } if (hasVertexColors) { - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_vertexColor, 0); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_vertexColor, 0); } } @@ -290,22 +290,22 @@ void FabricGeometry::setGeometry( const auto [worldPosition, worldOrientation, worldScale] = UsdUtil::glmToUsdMatrixDecomposed(localToUsdTransform); const auto worldExtent = UsdUtil::computeWorldExtent(localExtent, localToUsdTransform); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::faceVertexCounts, faceVertexCounts.size()); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::faceVertexIndices, indices.size()); - srw.setArrayAttributeSize(_pathFabric, FabricTokens::points, positions.size()); + srw.setArrayAttributeSize(_path, FabricTokens::faceVertexCounts, faceVertexCounts.size()); + srw.setArrayAttributeSize(_path, FabricTokens::faceVertexIndices, indices.size()); + srw.setArrayAttributeSize(_path, FabricTokens::points, positions.size()); // clang-format off - auto faceVertexCountsFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::faceVertexCounts); - auto faceVertexIndicesFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::faceVertexIndices); - auto pointsFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::points); - auto extentFabric = srw.getAttributeWr(_pathFabric, FabricTokens::extent); - auto worldExtentFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldExtent); - auto localToEcefTransformFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_cesium_localToEcefTransform); - auto worldPositionFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldPosition); - auto worldOrientationFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldOrientation); - auto worldScaleFabric = srw.getAttributeWr(_pathFabric, FabricTokens::_worldScale); - auto displayColorFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_displayColor); - auto displayOpacityFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_displayOpacity); + auto faceVertexCountsFabric = srw.getArrayAttributeWr(_path, FabricTokens::faceVertexCounts); + auto faceVertexIndicesFabric = srw.getArrayAttributeWr(_path, FabricTokens::faceVertexIndices); + auto pointsFabric = srw.getArrayAttributeWr(_path, FabricTokens::points); + auto extentFabric = srw.getAttributeWr(_path, FabricTokens::extent); + auto worldExtentFabric = srw.getAttributeWr(_path, FabricTokens::_worldExtent); + auto localToEcefTransformFabric = srw.getAttributeWr(_path, FabricTokens::_cesium_localToEcefTransform); + auto worldPositionFabric = srw.getAttributeWr(_path, FabricTokens::_worldPosition); + auto worldOrientationFabric = srw.getAttributeWr(_path, FabricTokens::_worldOrientation); + auto worldScaleFabric = srw.getAttributeWr(_path, FabricTokens::_worldScale); + auto displayColorFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayColor); + auto displayOpacityFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayOpacity); // clang-format on faceVertexCounts.fill(faceVertexCountsFabric); @@ -319,7 +319,7 @@ void FabricGeometry::setGeometry( *worldOrientationFabric = worldOrientation; *worldScaleFabric = worldScale; - FabricUtil::setTilesetId(_pathFabric, tilesetId); + FabricUtil::setTilesetId(_path, tilesetId); if (_debugRandomColors) { const auto r = glm::linearRand(0.0f, 1.0f); @@ -335,25 +335,25 @@ void FabricGeometry::setGeometry( if (hasTexcoords) { const auto& texcoords = hasImagery ? imageryTexcoords : texcoords_0; - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_st, texcoords.size()); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_st, texcoords.size()); - auto stFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_st); + auto stFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_st); texcoords.fill(stFabric); } if (hasNormals) { - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_normals, normals.size()); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_normals, normals.size()); - auto normalsFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_normals); + auto normalsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_normals); normals.fill(normalsFabric); } if (hasVertexColors) { - srw.setArrayAttributeSize(_pathFabric, FabricTokens::primvars_vertexColor, vertexColors.size()); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_vertexColor, vertexColors.size()); - auto vertexColorsFabric = srw.getArrayAttributeWr(_pathFabric, FabricTokens::primvars_vertexColor); + auto vertexColorsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_vertexColor); vertexColors.fill(vertexColorsFabric); } diff --git a/src/core/src/FabricGeometryPool.cpp b/src/core/src/FabricGeometryPool.cpp index a4b7b407a..eed6d7aea 100644 --- a/src/core/src/FabricGeometryPool.cpp +++ b/src/core/src/FabricGeometryPool.cpp @@ -23,7 +23,8 @@ const FabricGeometryDefinition& FabricGeometryPool::getGeometryDefinition() cons } std::shared_ptr FabricGeometryPool::createObject(uint64_t objectId) { - const auto path = pxr::SdfPath(fmt::format("/fabric_geometry_pool_{}_object_{}", _poolId, objectId)); + const auto pathStr = fmt::format("/fabric_geometry_pool_{}_object_{}", _poolId, objectId); + const auto path = omni::fabric::Path(pathStr.c_str()); return std::make_shared(path, _geometryDefinition, _debugRandomColors, _stageId); } diff --git a/src/core/src/FabricMaterial.cpp b/src/core/src/FabricMaterial.cpp index 0c3810bcc..cc3530e1d 100644 --- a/src/core/src/FabricMaterial.cpp +++ b/src/core/src/FabricMaterial.cpp @@ -1,41 +1,31 @@ #include "cesium/omniverse/FabricMaterial.h" +#include "cesium/omniverse/Context.h" #include "cesium/omniverse/FabricAttributesBuilder.h" -#include "cesium/omniverse/FabricMaterialDefinition.h" -#include "cesium/omniverse/FabricTexture.h" #include "cesium/omniverse/FabricUtil.h" -#include "cesium/omniverse/GltfUtil.h" #include "cesium/omniverse/Tokens.h" #include "cesium/omniverse/UsdUtil.h" -#ifdef CESIUM_OMNI_MSVC -#pragma push_macro("OPAQUE") -#undef OPAQUE -#endif - -#include #include -#include -#include #include -#include - namespace cesium::omniverse { FabricMaterial::FabricMaterial( - pxr::SdfPath path, + const omni::fabric::Path& path, const FabricMaterialDefinition& materialDefinition, - pxr::SdfAssetPath defaultTextureAssetPath, + const pxr::TfToken& defaultTextureAssetPathToken, long stageId) - : _materialDefinition(materialDefinition) - , _defaultTextureAssetPath(std::move(defaultTextureAssetPath)) + : _materialPath(path) + , _materialDefinition(materialDefinition) + , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) , _stageId(stageId) { + if (stageDestroyed()) { return; } - initialize(std::move(path), materialDefinition); + initialize(); reset(); } @@ -44,11 +34,11 @@ FabricMaterial::~FabricMaterial() { return; } - FabricUtil::destroyPrim(_materialPathFabric); - FabricUtil::destroyPrim(_shaderPathFabric); + FabricUtil::destroyPrim(_materialPath); + FabricUtil::destroyPrim(_shaderPath); if (_materialDefinition.hasBaseColorTexture()) { - FabricUtil::destroyPrim(_baseColorTexPathFabric); + FabricUtil::destroyPrim(_baseColorTexturePath); } } @@ -62,175 +52,177 @@ void FabricMaterial::setActive(bool active) { } } -omni::fabric::Path FabricMaterial::getPathFabric() const { - return _materialPathFabric; +omni::fabric::Path FabricMaterial::getPath() const { + return _materialPath; } const FabricMaterialDefinition& FabricMaterial::getMaterialDefinition() const { return _materialDefinition; } -void FabricMaterial::initialize(pxr::SdfPath path, const FabricMaterialDefinition& materialDefinition) { - const auto hasBaseColorTexture = materialDefinition.hasBaseColorTexture(); - const auto hasVertexColors = materialDefinition.hasVertexColors(); +void FabricMaterial::initialize() { + const auto hasBaseColorTexture = _materialDefinition.hasBaseColorTexture(); + + const auto& materialPath = _materialPath; + const auto shaderPath = FabricUtil::joinPaths(materialPath, FabricTokens::Shader); + const auto baseColorTexturePath = FabricUtil::joinPaths(materialPath, FabricTokens::baseColorTexture); + + createMaterial(materialPath); + _materialPath = materialPath; + + createShader(shaderPath, materialPath); + _shaderPath = shaderPath; + if (hasBaseColorTexture) { + createTexture(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture); + _baseColorTexturePath = baseColorTexturePath; + } +} + +void FabricMaterial::createMaterial(const omni::fabric::Path& materialPath) { auto srw = UsdUtil::getFabricStageReaderWriter(); + srw.createPrim(materialPath); - const auto materialPath = std::move(path); - const auto shaderPath = materialPath.AppendChild(UsdTokens::Shader); - const auto baseColorTexPath = materialPath.AppendChild(UsdTokens::baseColorTex); + FabricAttributesBuilder attributes; - const auto materialPathFabric = omni::fabric::Path(materialPath.GetText()); - const auto shaderPathFabric = omni::fabric::Path(shaderPath.GetText()); - const auto baseColorTexPathFabric = omni::fabric::Path(baseColorTexPath.GetText()); + attributes.addAttribute(FabricTypes::Material, FabricTokens::Material); + attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); - // Material - { - srw.createPrim(materialPathFabric); + attributes.createAttributes(materialPath); +} - FabricAttributesBuilder attributes; +void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath) { + const auto hasVertexColors = _materialDefinition.hasVertexColors(); - attributes.addAttribute(FabricTypes::Material, FabricTokens::Material); - attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); + auto srw = UsdUtil::getFabricStageReaderWriter(); - attributes.createAttributes(materialPathFabric); - } + srw.createPrim(shaderPath); + + FabricAttributesBuilder attributes; + + // clang-format off + attributes.addAttribute(FabricTypes::inputs_alpha_cutoff, FabricTokens::inputs_alpha_cutoff); + attributes.addAttribute(FabricTypes::inputs_alpha_mode, FabricTokens::inputs_alpha_mode); + attributes.addAttribute(FabricTypes::inputs_base_alpha, FabricTokens::inputs_base_alpha); + attributes.addAttribute(FabricTypes::inputs_base_color_factor, FabricTokens::inputs_base_color_factor); + attributes.addAttribute(FabricTypes::inputs_emissive_factor, FabricTokens::inputs_emissive_factor); + attributes.addAttribute(FabricTypes::inputs_metallic_factor, FabricTokens::inputs_metallic_factor); + attributes.addAttribute(FabricTypes::inputs_roughness_factor, FabricTokens::inputs_roughness_factor); + attributes.addAttribute(FabricTypes::inputs_excludeFromWhiteMode, FabricTokens::inputs_excludeFromWhiteMode); + attributes.addAttribute(FabricTypes::outputs_out, FabricTokens::outputs_out); + attributes.addAttribute(FabricTypes::info_implementationSource, FabricTokens::info_implementationSource); + attributes.addAttribute(FabricTypes::info_mdl_sourceAsset, FabricTokens::info_mdl_sourceAsset); + attributes.addAttribute(FabricTypes::info_mdl_sourceAsset_subIdentifier, FabricTokens::info_mdl_sourceAsset_subIdentifier); + attributes.addAttribute(FabricTypes::_paramColorSpace, FabricTokens::_paramColorSpace); + attributes.addAttribute(FabricTypes::_sdrMetadata, FabricTokens::_sdrMetadata); + attributes.addAttribute(FabricTypes::Shader, FabricTokens::Shader); + attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); + // clang-format on - // Shader - { - srw.createPrim(shaderPathFabric); - - FabricAttributesBuilder attributes; - - // clang-format off - attributes.addAttribute(FabricTypes::inputs_alpha_cutoff, FabricTokens::inputs_alpha_cutoff); - attributes.addAttribute(FabricTypes::inputs_alpha_mode, FabricTokens::inputs_alpha_mode); - attributes.addAttribute(FabricTypes::inputs_base_alpha, FabricTokens::inputs_base_alpha); - attributes.addAttribute(FabricTypes::inputs_base_color_factor, FabricTokens::inputs_base_color_factor); - attributes.addAttribute(FabricTypes::inputs_emissive_factor, FabricTokens::inputs_emissive_factor); - attributes.addAttribute(FabricTypes::inputs_metallic_factor, FabricTokens::inputs_metallic_factor); - attributes.addAttribute(FabricTypes::inputs_roughness_factor, FabricTokens::inputs_roughness_factor); - attributes.addAttribute(FabricTypes::outputs_out, FabricTokens::outputs_out); - attributes.addAttribute(FabricTypes::info_implementationSource, FabricTokens::info_implementationSource); - attributes.addAttribute(FabricTypes::info_mdl_sourceAsset, FabricTokens::info_mdl_sourceAsset); - attributes.addAttribute(FabricTypes::info_mdl_sourceAsset_subIdentifier, FabricTokens::info_mdl_sourceAsset_subIdentifier); - attributes.addAttribute(FabricTypes::_paramColorSpace, FabricTokens::_paramColorSpace); - attributes.addAttribute(FabricTypes::_sdrMetadata, FabricTokens::_sdrMetadata); - attributes.addAttribute(FabricTypes::Shader, FabricTokens::Shader); - attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); - // clang-format on - - if (hasVertexColors) { - attributes.addAttribute(FabricTypes::inputs_vertex_color_name, FabricTokens::inputs_vertex_color_name); - } - - attributes.createAttributes(shaderPathFabric); - - srw.setArrayAttributeSize(shaderPathFabric, FabricTokens::_paramColorSpace, 0); - srw.setArrayAttributeSize(shaderPathFabric, FabricTokens::_sdrMetadata, 0); - - // clang-format off - auto infoImplementationSourceFabric = srw.getAttributeWr(shaderPathFabric, FabricTokens::info_implementationSource); - auto infoMdlSourceAssetFabric = srw.getAttributeWr(shaderPathFabric, FabricTokens::info_mdl_sourceAsset); - auto infoMdlSourceAssetSubIdentifierFabric = srw.getAttributeWr(shaderPathFabric, FabricTokens::info_mdl_sourceAsset_subIdentifier); - // clang-format on - - *infoImplementationSourceFabric = FabricTokens::sourceAsset; - infoMdlSourceAssetFabric->assetPath = UsdTokens::gltf_pbr_mdl; - infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); - *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::gltf_material; - - if (hasVertexColors) { - // clang-format off - const auto vertexColorPrimvarNameSize = UsdTokens::vertexColor.GetString().size(); - srw.setArrayAttributeSize(shaderPathFabric, FabricTokens::inputs_vertex_color_name, vertexColorPrimvarNameSize); - auto vertexColorNameFabric = srw.getArrayAttributeWr(shaderPathFabric, FabricTokens::inputs_vertex_color_name); - memcpy(vertexColorNameFabric.data(), UsdTokens::vertexColor.GetText(), vertexColorPrimvarNameSize); - // clang-format on - } - - // Connect the material terminals to the shader. - srw.createConnection( - materialPathFabric, - FabricTokens::outputs_mdl_surface, - omni::fabric::Connection{omni::fabric::PathC(shaderPathFabric), FabricTokens::outputs_out}); - srw.createConnection( - materialPathFabric, - FabricTokens::outputs_mdl_displacement, - omni::fabric::Connection{omni::fabric::PathC(shaderPathFabric), FabricTokens::outputs_out}); - srw.createConnection( - materialPathFabric, - FabricTokens::outputs_mdl_volume, - omni::fabric::Connection{omni::fabric::PathC(shaderPathFabric), FabricTokens::outputs_out}); + if (hasVertexColors) { + attributes.addAttribute(FabricTypes::inputs_vertex_color_name, FabricTokens::inputs_vertex_color_name); } - if (hasBaseColorTexture) { - // baseColorTex - { - srw.createPrim(baseColorTexPathFabric); - - FabricAttributesBuilder attributes; - - // clang-format off - attributes.addAttribute(FabricTypes::inputs_offset, FabricTokens::inputs_offset); - attributes.addAttribute(FabricTypes::inputs_rotation, FabricTokens::inputs_rotation); - attributes.addAttribute(FabricTypes::inputs_scale, FabricTokens::inputs_scale); - attributes.addAttribute(FabricTypes::inputs_tex_coord_index, FabricTokens::inputs_tex_coord_index); - attributes.addAttribute(FabricTypes::inputs_texture, FabricTokens::inputs_texture); - attributes.addAttribute(FabricTypes::inputs_wrap_s, FabricTokens::inputs_wrap_s); - attributes.addAttribute(FabricTypes::inputs_wrap_t, FabricTokens::inputs_wrap_t); - attributes.addAttribute(FabricTypes::outputs_out, FabricTokens::outputs_out); - attributes.addAttribute(FabricTypes::info_implementationSource, FabricTokens::info_implementationSource); - attributes.addAttribute(FabricTypes::info_mdl_sourceAsset, FabricTokens::info_mdl_sourceAsset); - attributes.addAttribute(FabricTypes::info_mdl_sourceAsset_subIdentifier, FabricTokens::info_mdl_sourceAsset_subIdentifier); - attributes.addAttribute(FabricTypes::_paramColorSpace, FabricTokens::_paramColorSpace); - attributes.addAttribute(FabricTypes::_sdrMetadata, FabricTokens::_sdrMetadata); - attributes.addAttribute(FabricTypes::Shader, FabricTokens::Shader); - attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); - // clang-format on - - attributes.createAttributes(baseColorTexPathFabric); - - // _paramColorSpace is an array of pairs: [texture_parameter_token, color_space_enum], [texture_parameter_token, color_space_enum], ... - srw.setArrayAttributeSize(baseColorTexPathFabric, FabricTokens::_paramColorSpace, 2); - srw.setArrayAttributeSize(baseColorTexPathFabric, FabricTokens::_sdrMetadata, 0); - - // clang-format off - auto infoImplementationSourceFabric = srw.getAttributeWr(baseColorTexPathFabric, FabricTokens::info_implementationSource); - auto infoMdlSourceAssetFabric = srw.getAttributeWr(baseColorTexPathFabric, FabricTokens::info_mdl_sourceAsset); - auto infoMdlSourceAssetSubIdentifierFabric = srw.getAttributeWr(baseColorTexPathFabric, FabricTokens::info_mdl_sourceAsset_subIdentifier); - auto paramColorSpaceFabric = srw.getArrayAttributeWr(baseColorTexPathFabric, FabricTokens::_paramColorSpace); - // clang-format on - - *infoImplementationSourceFabric = FabricTokens::sourceAsset; - infoMdlSourceAssetFabric->assetPath = UsdTokens::gltf_pbr_mdl; - infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); - *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::gltf_texture_lookup; - paramColorSpaceFabric[0] = FabricTokens::inputs_texture; - paramColorSpaceFabric[1] = FabricTokens::_auto; - - // Create connection from shader to texture. - srw.createConnection( - shaderPathFabric, - FabricTokens::inputs_base_color_texture, - omni::fabric::Connection{omni::fabric::PathC(baseColorTexPathFabric), FabricTokens::outputs_out}); - } + attributes.createAttributes(shaderPath); + + srw.setArrayAttributeSize(shaderPath, FabricTokens::_paramColorSpace, 0); + srw.setArrayAttributeSize(shaderPath, FabricTokens::_sdrMetadata, 0); + + // clang-format off + auto inputsExcludeFromWhiteModeFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_excludeFromWhiteMode); + auto infoImplementationSourceFabric = srw.getAttributeWr(shaderPath, FabricTokens::info_implementationSource); + auto infoMdlSourceAssetFabric = srw.getAttributeWr(shaderPath, FabricTokens::info_mdl_sourceAsset); + auto infoMdlSourceAssetSubIdentifierFabric = srw.getAttributeWr(shaderPath, FabricTokens::info_mdl_sourceAsset_subIdentifier); + // clang-format on + + *inputsExcludeFromWhiteModeFabric = false; + *infoImplementationSourceFabric = FabricTokens::sourceAsset; + infoMdlSourceAssetFabric->assetPath = Context::instance().getCesiumMdlPathToken(); + infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); + *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::cesium_material; + + if (hasVertexColors) { + const auto vertexColorPrimvarNameSize = UsdTokens::vertexColor.GetString().size(); + srw.setArrayAttributeSize(shaderPath, FabricTokens::inputs_vertex_color_name, vertexColorPrimvarNameSize); + auto vertexColorNameFabric = + srw.getArrayAttributeWr(shaderPath, FabricTokens::inputs_vertex_color_name); + memcpy(vertexColorNameFabric.data(), UsdTokens::vertexColor.GetText(), vertexColorPrimvarNameSize); } - _materialPathFabric = materialPathFabric; - _shaderPathFabric = shaderPathFabric; - _baseColorTexPathFabric = baseColorTexPathFabric; + // Connect the material terminals to the shader. + srw.createConnection( + materialPath, + FabricTokens::outputs_mdl_surface, + omni::fabric::Connection{omni::fabric::PathC(shaderPath), FabricTokens::outputs_out}); + srw.createConnection( + materialPath, + FabricTokens::outputs_mdl_displacement, + omni::fabric::Connection{omni::fabric::PathC(shaderPath), FabricTokens::outputs_out}); + srw.createConnection( + materialPath, + FabricTokens::outputs_mdl_volume, + omni::fabric::Connection{omni::fabric::PathC(shaderPath), FabricTokens::outputs_out}); } -void FabricMaterial::reset() { +void FabricMaterial::createTexture( + const omni::fabric::Path& texturePath, + const omni::fabric::Path& shaderPath, + const omni::fabric::Token& shaderInput) { auto srw = UsdUtil::getFabricStageReaderWriter(); - setMaterialValues(GltfUtil::getDefaultMaterialInfo()); - setTilesetId(NO_TILESET_ID); + srw.createPrim(texturePath); - if (_materialDefinition.hasBaseColorTexture()) { - clearBaseColorTexture(); - } + FabricAttributesBuilder attributes; + + // clang-format off + attributes.addAttribute(FabricTypes::inputs_offset, FabricTokens::inputs_offset); + attributes.addAttribute(FabricTypes::inputs_rotation, FabricTokens::inputs_rotation); + attributes.addAttribute(FabricTypes::inputs_scale, FabricTokens::inputs_scale); + attributes.addAttribute(FabricTypes::inputs_tex_coord_index, FabricTokens::inputs_tex_coord_index); + attributes.addAttribute(FabricTypes::inputs_texture, FabricTokens::inputs_texture); + attributes.addAttribute(FabricTypes::inputs_wrap_s, FabricTokens::inputs_wrap_s); + attributes.addAttribute(FabricTypes::inputs_wrap_t, FabricTokens::inputs_wrap_t); + attributes.addAttribute(FabricTypes::inputs_excludeFromWhiteMode, FabricTokens::inputs_excludeFromWhiteMode); + attributes.addAttribute(FabricTypes::outputs_out, FabricTokens::outputs_out); + attributes.addAttribute(FabricTypes::info_implementationSource, FabricTokens::info_implementationSource); + attributes.addAttribute(FabricTypes::info_mdl_sourceAsset, FabricTokens::info_mdl_sourceAsset); + attributes.addAttribute(FabricTypes::info_mdl_sourceAsset_subIdentifier, FabricTokens::info_mdl_sourceAsset_subIdentifier); + attributes.addAttribute(FabricTypes::_paramColorSpace, FabricTokens::_paramColorSpace); + attributes.addAttribute(FabricTypes::_sdrMetadata, FabricTokens::_sdrMetadata); + attributes.addAttribute(FabricTypes::Shader, FabricTokens::Shader); + attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); + // clang-format on + + attributes.createAttributes(texturePath); + + // _paramColorSpace is an array of pairs: [texture_parameter_token, color_space_enum], [texture_parameter_token, color_space_enum], ... + srw.setArrayAttributeSize(texturePath, FabricTokens::_paramColorSpace, 2); + srw.setArrayAttributeSize(texturePath, FabricTokens::_sdrMetadata, 0); + + // clang-format off + auto inputsExcludeFromWhiteModeFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_excludeFromWhiteMode); + auto infoImplementationSourceFabric = srw.getAttributeWr(texturePath, FabricTokens::info_implementationSource); + auto infoMdlSourceAssetFabric = srw.getAttributeWr(texturePath, FabricTokens::info_mdl_sourceAsset); + auto infoMdlSourceAssetSubIdentifierFabric = srw.getAttributeWr(texturePath, FabricTokens::info_mdl_sourceAsset_subIdentifier); + auto paramColorSpaceFabric = srw.getArrayAttributeWr(texturePath, FabricTokens::_paramColorSpace); + // clang-format on + + *inputsExcludeFromWhiteModeFabric = false; + *infoImplementationSourceFabric = FabricTokens::sourceAsset; + infoMdlSourceAssetFabric->assetPath = Context::instance().getCesiumMdlPathToken(); + infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); + *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::cesium_texture_lookup; + paramColorSpaceFabric[0] = FabricTokens::inputs_texture; + paramColorSpaceFabric[1] = FabricTokens::_auto; + + // Create connection from shader to texture. + srw.createConnection( + shaderPath, shaderInput, omni::fabric::Connection{omni::fabric::PathC(texturePath), FabricTokens::outputs_out}); +} + +void FabricMaterial::reset() { + clearMaterial(); + clearBaseColorTexture(); } void FabricMaterial::setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo) { @@ -240,13 +232,11 @@ void FabricMaterial::setMaterial(int64_t tilesetId, const MaterialInfo& material auto srw = UsdUtil::getFabricStageReaderWriter(); - setMaterialValues(materialInfo); + setShaderValues(_shaderPath, materialInfo); setTilesetId(tilesetId); } -void FabricMaterial::setBaseColorTexture( - const std::shared_ptr& texture, - const TextureInfo& textureInfo) { +void FabricMaterial::setBaseColorTexture(const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo) { if (stageDestroyed()) { return; } @@ -255,34 +245,36 @@ void FabricMaterial::setBaseColorTexture( return; } - setBaseColorTextureValues(texture->getAssetPath(), textureInfo); + setTextureValues(_baseColorTexturePath, textureAssetPathToken, textureInfo); +} + +void FabricMaterial::clearMaterial() { + setMaterial(NO_TILESET_ID, GltfUtil::getDefaultMaterialInfo()); } void FabricMaterial::clearBaseColorTexture() { - setBaseColorTextureValues(_defaultTextureAssetPath, GltfUtil::getDefaultTextureInfo()); + setBaseColorTexture(_defaultTextureAssetPathToken, GltfUtil::getDefaultTextureInfo()); } void FabricMaterial::setTilesetId(int64_t tilesetId) { - FabricUtil::setTilesetId(_materialPathFabric, tilesetId); - FabricUtil::setTilesetId(_shaderPathFabric, tilesetId); + FabricUtil::setTilesetId(_materialPath, tilesetId); + FabricUtil::setTilesetId(_shaderPath, tilesetId); if (_materialDefinition.hasBaseColorTexture()) { - FabricUtil::setTilesetId(_baseColorTexPathFabric, tilesetId); + FabricUtil::setTilesetId(_baseColorTexturePath, tilesetId); } } -void FabricMaterial::setMaterialValues(const MaterialInfo& materialInfo) { +void FabricMaterial::setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo) { auto srw = UsdUtil::getFabricStageReaderWriter(); - // clang-format off - auto alphaCutoffFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_alpha_cutoff); - auto alphaModeFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_alpha_mode); - auto baseAlphaFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_base_alpha); - auto baseColorFactorFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_base_color_factor); - auto emissiveFactorFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_emissive_factor); - auto metallicFactorFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_metallic_factor); - auto roughnessFactorFabric = srw.getAttributeWr(_shaderPathFabric, FabricTokens::inputs_roughness_factor); - // clang-format on + auto alphaCutoffFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_alpha_cutoff); + auto alphaModeFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_alpha_mode); + auto baseAlphaFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_base_alpha); + auto baseColorFactorFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_base_color_factor); + auto emissiveFactorFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_emissive_factor); + auto metallicFactorFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_metallic_factor); + auto roughnessFactorFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_roughness_factor); *alphaCutoffFabric = static_cast(materialInfo.alphaCutoff); *alphaModeFabric = materialInfo.alphaMode; @@ -293,14 +285,15 @@ void FabricMaterial::setMaterialValues(const MaterialInfo& materialInfo) { *roughnessFactorFabric = static_cast(materialInfo.roughnessFactor); } -void FabricMaterial::setBaseColorTextureValues( - const pxr::SdfAssetPath& textureAssetPath, +void FabricMaterial::setTextureValues( + const omni::fabric::Path& texturePath, + const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo) { auto srw = UsdUtil::getFabricStageReaderWriter(); - glm::dvec2 offset = textureInfo.offset; - double rotation = textureInfo.rotation; - glm::dvec2 scale = textureInfo.scale; + auto offset = textureInfo.offset; + auto rotation = textureInfo.rotation; + auto scale = textureInfo.scale; if (!textureInfo.flipVertical) { // gltf/pbr.mdl does texture transform math in glTF coordinates (top-left origin), so we needed to convert @@ -310,18 +303,16 @@ void FabricMaterial::setBaseColorTextureValues( scale = {scale.x, scale.y}; } - // clang-format off - auto textureFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_texture); - auto texCoordIndexFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_tex_coord_index); - auto wrapSFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_wrap_s); - auto wrapTFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_wrap_t); - auto offsetFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_offset); - auto rotationFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_rotation); - auto scaleFabric = srw.getAttributeWr(_baseColorTexPathFabric, FabricTokens::inputs_scale); - // clang-format on + auto textureFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_texture); + auto texCoordIndexFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_tex_coord_index); + auto wrapSFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_wrap_s); + auto wrapTFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_wrap_t); + auto offsetFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_offset); + auto rotationFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_rotation); + auto scaleFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_scale); - textureFabric->assetPath = pxr::TfToken(textureAssetPath.GetAssetPath()); - textureFabric->resolvedPath = pxr::TfToken(textureAssetPath.GetResolvedPath()); + textureFabric->assetPath = textureAssetPathToken; + textureFabric->resolvedPath = pxr::TfToken(); *texCoordIndexFabric = static_cast(textureInfo.setIndex); *wrapSFabric = textureInfo.wrapS; *wrapTFabric = textureInfo.wrapT; diff --git a/src/core/src/FabricMaterialPool.cpp b/src/core/src/FabricMaterialPool.cpp index c05f625bd..edb34015d 100644 --- a/src/core/src/FabricMaterialPool.cpp +++ b/src/core/src/FabricMaterialPool.cpp @@ -8,12 +8,12 @@ FabricMaterialPool::FabricMaterialPool( int64_t poolId, const FabricMaterialDefinition& materialDefinition, uint64_t initialCapacity, - pxr::SdfAssetPath defaultTextureAssetPath, + const pxr::TfToken& defaultTextureAssetPathToken, long stageId) : ObjectPool() , _poolId(poolId) , _materialDefinition(materialDefinition) - , _defaultTextureAssetPath(std::move(defaultTextureAssetPath)) + , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) , _stageId(stageId) { setCapacity(initialCapacity); } @@ -23,12 +23,12 @@ const FabricMaterialDefinition& FabricMaterialPool::getMaterialDefinition() cons } std::shared_ptr FabricMaterialPool::createObject(uint64_t objectId) { - const auto path = pxr::SdfPath(fmt::format("/fabric_material_pool_{}_object_{}", _poolId, objectId)); - return std::make_shared(path, _materialDefinition, _defaultTextureAssetPath, _stageId); + const auto pathStr = fmt::format("/fabric_material_pool_{}_object_{}", _poolId, objectId); + const auto path = omni::fabric::Path(pathStr.c_str()); + return std::make_shared(path, _materialDefinition, _defaultTextureAssetPathToken, _stageId); } void FabricMaterialPool::setActive(std::shared_ptr material, bool active) { material->setActive(active); } - }; // namespace cesium::omniverse diff --git a/src/core/src/FabricPrepareRenderResources.cpp b/src/core/src/FabricPrepareRenderResources.cpp index 807ef9f93..16aa893e7 100644 --- a/src/core/src/FabricPrepareRenderResources.cpp +++ b/src/core/src/FabricPrepareRenderResources.cpp @@ -5,6 +5,7 @@ #include "cesium/omniverse/FabricMaterial.h" #include "cesium/omniverse/FabricResourceManager.h" #include "cesium/omniverse/FabricTexture.h" +#include "cesium/omniverse/FabricUtil.h" #include "cesium/omniverse/GeospatialUtil.h" #include "cesium/omniverse/GltfUtil.h" #include "cesium/omniverse/OmniTileset.h" @@ -104,6 +105,7 @@ std::vector acquireFabricMeshes( fabricMeshes.reserve(meshes.size()); auto& fabricResourceManager = FabricResourceManager::getInstance(); + const auto tilesetMaterialPath = tileset.getMaterialPath(); const auto stageId = UsdUtil::getUsdStageId(); for (const auto& mesh : meshes) { @@ -114,8 +116,8 @@ std::vector acquireFabricMeshes( fabricResourceManager.acquireGeometry(model, primitive, mesh.smoothNormals, stageId); fabricMesh.geometry = fabricGeometry; - const auto shouldAcquireMaterial = FabricResourceManager::getInstance().shouldAcquireMaterial( - primitive, hasImagery, tileset.getMaterialPath()); + const auto shouldAcquireMaterial = + FabricResourceManager::getInstance().shouldAcquireMaterial(primitive, hasImagery, tilesetMaterialPath); if (shouldAcquireMaterial) { const auto materialInfo = GltfUtil::getMaterialInfo(model, primitive); @@ -164,7 +166,7 @@ void setFabricMeshes( for (size_t i = 0; i < meshes.size(); i++) { const auto& meshInfo = meshes[i]; const auto& primitive = model.meshes[meshInfo.meshId].primitives[meshInfo.primitiveId]; - const auto& materialPath = tileset.getMaterialPath(); + const auto& tilesetMaterialPath = tileset.getMaterialPath(); auto& mesh = fabricMeshes[i]; auto& geometry = mesh.geometry; @@ -184,13 +186,14 @@ void setFabricMeshes( if (material != nullptr) { material->setMaterial(meshInfo.tilesetId, materialInfo); - geometry->setMaterial(material->getPathFabric()); + geometry->setMaterial(material->getPath()); if (baseColorTexture != nullptr && materialInfo.baseColorTexture.has_value()) { - material->setBaseColorTexture(baseColorTexture, materialInfo.baseColorTexture.value()); + material->setBaseColorTexture( + baseColorTexture->getAssetPathToken(), materialInfo.baseColorTexture.value()); } - } else if (!materialPath.IsEmpty()) { - geometry->setMaterial(omni::fabric::Path(omni::fabric::asInt(materialPath))); + } else if (!tilesetMaterialPath.IsEmpty()) { + geometry->setMaterial(FabricUtil::toFabricPath(tilesetMaterialPath)); } } } @@ -435,7 +438,7 @@ void FabricPrepareRenderResources::attachRasterInMainThread( }; // Replace the original base color texture with the imagery - material->setBaseColorTexture(texture, textureInfo); + material->setBaseColorTexture(texture->getAssetPathToken(), textureInfo); } } } @@ -469,7 +472,8 @@ void FabricPrepareRenderResources::detachRasterInMainThread( if (material != nullptr) { if (baseColorTexture != nullptr && materialInfo.baseColorTexture.has_value()) { // Switch back to the original base color texture - material->setBaseColorTexture(baseColorTexture, materialInfo.baseColorTexture.value()); + material->setBaseColorTexture( + baseColorTexture->getAssetPathToken(), materialInfo.baseColorTexture.value()); } else { material->clearBaseColorTexture(); } diff --git a/src/core/src/FabricResourceManager.cpp b/src/core/src/FabricResourceManager.cpp index 4d006a3e0..76f1f8ab4 100644 --- a/src/core/src/FabricResourceManager.cpp +++ b/src/core/src/FabricResourceManager.cpp @@ -3,11 +3,11 @@ #include "cesium/omniverse/FabricGeometry.h" #include "cesium/omniverse/FabricGeometryDefinition.h" #include "cesium/omniverse/FabricGeometryPool.h" -#include "cesium/omniverse/FabricMaterial.h" #include "cesium/omniverse/FabricMaterialDefinition.h" #include "cesium/omniverse/FabricMaterialPool.h" #include "cesium/omniverse/FabricTexture.h" #include "cesium/omniverse/FabricTexturePool.h" +#include "cesium/omniverse/FabricUtil.h" #include "cesium/omniverse/GltfUtil.h" #include "cesium/omniverse/UsdUtil.h" @@ -30,7 +30,7 @@ template void removePool(std::vector& pools, const T& pool) { FabricResourceManager::FabricResourceManager() { const auto defaultTextureName = "fabric_default_texture"; - _defaultTextureAssetPath = UsdUtil::getDynamicTextureProviderAssetPath(defaultTextureName); + _defaultTextureAssetPathToken = UsdUtil::getDynamicTextureProviderAssetPathToken(defaultTextureName); _defaultTexture = std::make_unique(defaultTextureName); const auto bytes = std::array{{255, 255, 255, 255}}; @@ -43,12 +43,12 @@ FabricResourceManager::~FabricResourceManager() = default; bool FabricResourceManager::shouldAcquireMaterial( const CesiumGltf::MeshPrimitive& primitive, bool hasImagery, - const pxr::SdfPath& materialPath) const { + const pxr::SdfPath& tilesetMaterialPath) const { if (_disableMaterials) { return false; } - if (!materialPath.IsEmpty()) { + if (!tilesetMaterialPath.IsEmpty()) { return false; } @@ -64,7 +64,8 @@ std::shared_ptr FabricResourceManager::acquireGeometry( FabricGeometryDefinition geometryDefinition(model, primitive, smoothNormals); if (_disableGeometryPool) { - const auto path = pxr::SdfPath(fmt::format("/fabric_geometry_{}", getNextGeometryId())); + const auto pathStr = fmt::format("/fabric_geometry_{}", getNextGeometryId()); + const auto path = omni::fabric::Path(pathStr.c_str()); return std::make_shared(path, geometryDefinition, _debugRandomColors, stageId); } @@ -85,8 +86,9 @@ FabricResourceManager::acquireMaterial(const MaterialInfo& materialInfo, bool ha FabricMaterialDefinition materialDefinition(materialInfo, hasImagery, _disableTextures); if (_disableMaterialPool) { - const auto path = pxr::SdfPath(fmt::format("/fabric_material_{}", getNextMaterialId())); - return std::make_shared(path, materialDefinition, _defaultTextureAssetPath, stageId); + const auto pathStr = fmt::format("/fabric_material_{}", getNextMaterialId()); + const auto path = omni::fabric::Path(pathStr.c_str()); + return std::make_shared(path, materialDefinition, _defaultTextureAssetPathToken, stageId); } std::scoped_lock lock(_poolMutex); @@ -258,7 +260,7 @@ FabricResourceManager::createGeometryPool(const FabricGeometryDefinition& geomet std::shared_ptr FabricResourceManager::createMaterialPool(const FabricMaterialDefinition& materialDefinition, long stageId) { return _materialPools.emplace_back(std::make_shared( - getNextPoolId(), materialDefinition, _materialPoolInitialCapacity, _defaultTextureAssetPath, stageId)); + getNextPoolId(), materialDefinition, _materialPoolInitialCapacity, _defaultTextureAssetPathToken, stageId)); } std::shared_ptr FabricResourceManager::createTexturePool() { diff --git a/src/core/src/FabricTexture.cpp b/src/core/src/FabricTexture.cpp index 46c669e89..7fe0228c6 100644 --- a/src/core/src/FabricTexture.cpp +++ b/src/core/src/FabricTexture.cpp @@ -12,7 +12,7 @@ namespace cesium::omniverse { FabricTexture::FabricTexture(const std::string& name) : _texture(std::make_unique(name)) - , _assetPath(UsdUtil::getDynamicTextureProviderAssetPath(name)) { + , _assetPathToken(UsdUtil::getDynamicTextureProviderAssetPathToken(name)) { reset(); } @@ -24,8 +24,8 @@ void FabricTexture::setActive(bool active) { } } -const pxr::SdfAssetPath& FabricTexture::getAssetPath() const { - return _assetPath; +const pxr::TfToken& FabricTexture::getAssetPathToken() const { + return _assetPathToken; } void FabricTexture::reset() { diff --git a/src/core/src/FabricUtil.cpp b/src/core/src/FabricUtil.cpp index 975c36a59..a90e217d7 100644 --- a/src/core/src/FabricUtil.cpp +++ b/src/core/src/FabricUtil.cpp @@ -663,12 +663,20 @@ void setTilesetTransform(int64_t tilesetId, const glm::dmat4& ecefToUsdTransform } } -void setTilesetId(const omni::fabric::Path& pathFabric, int64_t tilesetId) { +void setTilesetId(const omni::fabric::Path& path, int64_t tilesetId) { auto srw = UsdUtil::getFabricStageReaderWriter(); - auto tilesetIdFabric = srw.getAttributeWr(pathFabric, FabricTokens::_cesium_tilesetId); + auto tilesetIdFabric = srw.getAttributeWr(path, FabricTokens::_cesium_tilesetId); *tilesetIdFabric = tilesetId; } +omni::fabric::Path toFabricPath(const pxr::SdfPath& path) { + return {omni::fabric::asInt(path)}; +} + +omni::fabric::Path joinPaths(const omni::fabric::Path& absolutePath, const omni::fabric::Token& relativePath) { + return {fmt::format("{}/{}", absolutePath.getText(), relativePath.getText()).c_str()}; +} + } // namespace cesium::omniverse::FabricUtil diff --git a/src/core/src/OmniImagery.cpp b/src/core/src/OmniImagery.cpp index 704f52c24..df20c01b8 100644 --- a/src/core/src/OmniImagery.cpp +++ b/src/core/src/OmniImagery.cpp @@ -7,8 +7,8 @@ namespace cesium::omniverse { -OmniImagery::OmniImagery(pxr::SdfPath path) - : _path(std::move(path)) {} +OmniImagery::OmniImagery(const pxr::SdfPath& path) + : _path(path) {} pxr::SdfPath OmniImagery::getPath() const { return _path; diff --git a/src/core/src/OmniTileset.cpp b/src/core/src/OmniTileset.cpp index 521cb67f9..83a0382ab 100644 --- a/src/core/src/OmniTileset.cpp +++ b/src/core/src/OmniTileset.cpp @@ -280,6 +280,10 @@ TilesetStatistics OmniTileset::getStatistics() const { } void OmniTileset::reload() { + if (_renderResourcesPreparer != nullptr) { + _renderResourcesPreparer->detachTileset(); + } + _renderResourcesPreparer = std::make_shared(*this); auto& context = Context::instance(); auto asyncSystem = CesiumAsync::AsyncSystem(context.getTaskProcessor()); @@ -326,6 +330,8 @@ void OmniTileset::reload() { }; _pViewUpdateResult = nullptr; + _extentSet = false; + _activeLoading = false; if (getSourceType() == TilesetSourceType::URL) { _tileset = std::make_unique(externals, url, options); diff --git a/src/core/src/Tokens.cpp b/src/core/src/Tokens.cpp index 22752d54c..fce77e232 100644 --- a/src/core/src/Tokens.cpp +++ b/src/core/src/Tokens.cpp @@ -15,15 +15,14 @@ __pragma(warning(disable: 4003)) TF_DEFINE_PRIVATE_TOKENS( UsdTokens, - (baseColorTex) + (baseColorTexture) + (cesium_material) + (cesium_texture_lookup) (constant) (doubleSided) (extent) (faceVertexCounts) (faceVertexIndices) - (gltf_material) - ((gltf_pbr_mdl, "gltf/pbr.mdl")) - (gltf_texture_lookup) (Material) (Mesh) (none) @@ -56,6 +55,7 @@ TF_DEFINE_PRIVATE_TOKENS( ((inputs_base_color_factor, "inputs:base_color_factor")) ((inputs_base_color_texture, "inputs:base_color_texture")) ((inputs_emissive_factor, "inputs:emissive_factor")) + ((inputs_excludeFromWhiteMode, "inputs:excludeFromWhiteMode")) ((inputs_metallic_factor, "inputs:metallic_factor")) ((inputs_offset, "inputs:offset")) ((inputs_rotation, "inputs:rotation")) @@ -85,15 +85,14 @@ __pragma(warning(pop)) } namespace cesium::omniverse::FabricTokens { -const omni::fabric::TokenC baseColorTex = omni::fabric::asInt(pxr::UsdTokens->baseColorTex); +const omni::fabric::TokenC baseColorTexture = omni::fabric::asInt(pxr::UsdTokens->baseColorTexture); +const omni::fabric::TokenC cesium_material = omni::fabric::asInt(pxr::UsdTokens->cesium_material); +const omni::fabric::TokenC cesium_texture_lookup = omni::fabric::asInt(pxr::UsdTokens->cesium_texture_lookup); const omni::fabric::TokenC constant = omni::fabric::asInt(pxr::UsdTokens->constant); const omni::fabric::TokenC doubleSided = omni::fabric::asInt(pxr::UsdTokens->doubleSided); const omni::fabric::TokenC extent = omni::fabric::asInt(pxr::UsdTokens->extent); const omni::fabric::TokenC faceVertexCounts = omni::fabric::asInt(pxr::UsdTokens->faceVertexCounts); const omni::fabric::TokenC faceVertexIndices = omni::fabric::asInt(pxr::UsdTokens->faceVertexIndices); -const omni::fabric::TokenC gltf_material = omni::fabric::asInt(pxr::UsdTokens->gltf_material); -const omni::fabric::TokenC gltf_pbr_mdl = omni::fabric::asInt(pxr::UsdTokens->gltf_pbr_mdl); -const omni::fabric::TokenC gltf_texture_lookup = omni::fabric::asInt(pxr::UsdTokens->gltf_texture_lookup); const omni::fabric::TokenC info_implementationSource = omni::fabric::asInt(pxr::UsdTokens->info_implementationSource); const omni::fabric::TokenC info_mdl_sourceAsset = omni::fabric::asInt(pxr::UsdTokens->info_mdl_sourceAsset); const omni::fabric::TokenC info_mdl_sourceAsset_subIdentifier = omni::fabric::asInt(pxr::UsdTokens->info_mdl_sourceAsset_subIdentifier); @@ -103,6 +102,7 @@ const omni::fabric::TokenC inputs_base_alpha = omni::fabric::asInt(pxr::UsdToken const omni::fabric::TokenC inputs_base_color_factor = omni::fabric::asInt(pxr::UsdTokens->inputs_base_color_factor); const omni::fabric::TokenC inputs_base_color_texture = omni::fabric::asInt(pxr::UsdTokens->inputs_base_color_texture); const omni::fabric::TokenC inputs_emissive_factor = omni::fabric::asInt(pxr::UsdTokens->inputs_emissive_factor); +const omni::fabric::TokenC inputs_excludeFromWhiteMode = omni::fabric::asInt(pxr::UsdTokens->inputs_excludeFromWhiteMode); const omni::fabric::TokenC inputs_metallic_factor = omni::fabric::asInt(pxr::UsdTokens->inputs_metallic_factor); const omni::fabric::TokenC inputs_offset = omni::fabric::asInt(pxr::UsdTokens->inputs_offset); const omni::fabric::TokenC inputs_rotation = omni::fabric::asInt(pxr::UsdTokens->inputs_rotation); @@ -149,15 +149,14 @@ const omni::fabric::TokenC _worldVisibility = omni::fabric::asInt(pxr::UsdTokens } namespace cesium::omniverse::UsdTokens { -const pxr::TfToken& baseColorTex = pxr::UsdTokens->baseColorTex; +const pxr::TfToken& baseColorTexture = pxr::UsdTokens->baseColorTexture; +const pxr::TfToken& cesium_material = pxr::UsdTokens->cesium_material; +const pxr::TfToken& cesium_texture_lookup = pxr::UsdTokens->cesium_texture_lookup; const pxr::TfToken& constant = pxr::UsdTokens->constant; const pxr::TfToken& doubleSided = pxr::UsdTokens->doubleSided; const pxr::TfToken& extent = pxr::UsdTokens->extent; const pxr::TfToken& faceVertexCounts = pxr::UsdTokens->faceVertexCounts; const pxr::TfToken& faceVertexIndices = pxr::UsdTokens->faceVertexIndices; -const pxr::TfToken& gltf_material = pxr::UsdTokens->gltf_material; -const pxr::TfToken& gltf_pbr_mdl = pxr::UsdTokens->gltf_pbr_mdl; -const pxr::TfToken& gltf_texture_lookup = pxr::UsdTokens->gltf_texture_lookup; const pxr::TfToken& info_implementationSource = pxr::UsdTokens->info_implementationSource; const pxr::TfToken& info_mdl_sourceAsset = pxr::UsdTokens->info_mdl_sourceAsset; const pxr::TfToken& info_mdl_sourceAsset_subIdentifier = pxr::UsdTokens->info_mdl_sourceAsset_subIdentifier; @@ -167,6 +166,7 @@ const pxr::TfToken& inputs_base_alpha = pxr::UsdTokens->inputs_base_alpha; const pxr::TfToken& inputs_base_color_factor = pxr::UsdTokens->inputs_base_color_factor; const pxr::TfToken& inputs_base_color_texture = pxr::UsdTokens->inputs_base_color_texture; const pxr::TfToken& inputs_emissive_factor = pxr::UsdTokens->inputs_emissive_factor; +const pxr::TfToken& inputs_excludeFromWhiteMode = pxr::UsdTokens->inputs_excludeFromWhiteMode; const pxr::TfToken& inputs_metallic_factor = pxr::UsdTokens->inputs_metallic_factor; const pxr::TfToken& inputs_offset = pxr::UsdTokens->inputs_offset; const pxr::TfToken& inputs_rotation = pxr::UsdTokens->inputs_rotation; diff --git a/src/core/src/UsdNotificationHandler.cpp b/src/core/src/UsdNotificationHandler.cpp index a92cbd9b0..b12322633 100644 --- a/src/core/src/UsdNotificationHandler.cpp +++ b/src/core/src/UsdNotificationHandler.cpp @@ -89,6 +89,16 @@ void UsdNotificationHandler::onObjectsChanged(const pxr::UsdNotice::ObjectsChang for (const auto& path : resyncedPaths) { if (path.IsPrimPath()) { if (UsdUtil::primExists(path)) { + const auto isTileset = getType(path) == ChangedPrimType::CESIUM_TILESET; + const auto alreadyRegistered = AssetRegistry::getInstance().getTilesetByPath(path).has_value(); + + if (isTileset && alreadyRegistered) { + // A prim may be resynced even if its path doesn't change, like when an API Schema is applied to it + // This happens when a material is assigned to a tileset for the first time + // We don't want to add the prim again if it's already registered + continue; + } + onPrimAdded(path); } else { onPrimRemoved(path); diff --git a/src/core/src/UsdUtil.cpp b/src/core/src/UsdUtil.cpp index 4d6b7dbfb..5e778c4ef 100644 --- a/src/core/src/UsdUtil.cpp +++ b/src/core/src/UsdUtil.cpp @@ -196,8 +196,9 @@ std::string getSafeName(const std::string& name) { return std::regex_replace(name, regex, replace); } -pxr::SdfAssetPath getDynamicTextureProviderAssetPath(const std::string& name) { - return pxr::SdfAssetPath(fmt::format("{}{}", rtx::resourcemanager::kDynamicTexturePrefix, name)); +pxr::TfToken getDynamicTextureProviderAssetPathToken(const std::string& name) { + return pxr::TfToken( + pxr::SdfAssetPath(fmt::format("{}{}", rtx::resourcemanager::kDynamicTexturePrefix, name)).GetAssetPath()); } glm::dmat4