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/exts/cesium.omniverse/mdl/cesium.mdl b/exts/cesium.omniverse/mdl/cesium.mdl index f56b5a637..6ab153aac 100644 --- a/exts/cesium.omniverse/mdl/cesium.mdl +++ b/exts/cesium.omniverse/mdl/cesium.mdl @@ -18,7 +18,8 @@ export float2 world_coordinate_2d(float2 min_world_xy=float2(-5000.0,-5000.0), f anno::author("Cesium"), anno::in_group("Cesium functions"), anno::ui_order(300) -]]{ +]] +{ // Get the world pos of the pixel float3 world_pos = state::transform_vector(state::coordinate_internal, state::coordinate_world, state::position()); @@ -74,4 +75,17 @@ export color lookup_world_texture_color(uniform texture_2d texture = texture_2d( wrap_v: ::tex::wrap_clamp); } -export material cesium_gltf_material(*) = gltf_material(); +// For internal use only. See note in FabricMaterial.cpp +export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup(); + +export color cesium_base_color_texture(gltf_texture_lookup_value base_color_texture) +[[ + anno::display_name("Base color texture lookup color"), + anno::description("Returns color from the base color texture of the tile"), + anno::author("Cesium GS Inc."), + anno::in_group("Cesium functions"), + anno::ui_order(300) +]] +{ + return color(base_color_texture.value.x, base_color_texture.value.y, base_color_texture.value.z); +} 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 cd3ea2eac..5fe1079b6 100644 --- a/src/core/include/cesium/omniverse/FabricGeometry.h +++ b/src/core/include/cesium/omniverse/FabricGeometry.h @@ -13,8 +13,6 @@ struct Model; namespace cesium::omniverse { -class FabricMaterial; - class FabricGeometry { public: FabricGeometry( diff --git a/src/core/include/cesium/omniverse/FabricMaterial.h b/src/core/include/cesium/omniverse/FabricMaterial.h index 3b3f635be..f7c6b6027 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,28 +12,21 @@ 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 pxr::SdfPath& path, const FabricMaterialDefinition& materialDefinition, - pxr::SdfAssetPath defaultTextureAssetPath); + const pxr::TfToken& defaultTextureAssetPathToken); + ~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); @@ -41,18 +35,30 @@ class FabricMaterial { [[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const; private: - void initialize(pxr::SdfPath path, const FabricMaterialDefinition& materialDefinition); + void initialize(); + void initializeFromExistingMaterial(const omni::fabric::Path& path); + + 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 setTilesetId(int64_t tilesetId); - void setMaterialValues(const MaterialInfo& materialInfo); - void setBaseColorTextureValues(const pxr::SdfAssetPath& textureAssetPath, const TextureInfo& textureInfo); + void setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo); + void setTextureValues( + const omni::fabric::Path& texturePath, + const pxr::TfToken& textureAssetPathToken, + const TextureInfo& textureInfo); + omni::fabric::Path _materialPath; const FabricMaterialDefinition _materialDefinition; - const pxr::SdfAssetPath _defaultTextureAssetPath; + const pxr::TfToken _defaultTextureAssetPathToken; - omni::fabric::Path _materialPathFabric; - omni::fabric::Path _shaderPathFabric; - omni::fabric::Path _baseColorTexPathFabric; + std::vector _shaderPaths; + std::vector _baseColorTexturePaths; + std::vector _allPaths; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricMaterialDefinition.h b/src/core/include/cesium/omniverse/FabricMaterialDefinition.h index f5de5f636..8d7902696 100644 --- a/src/core/include/cesium/omniverse/FabricMaterialDefinition.h +++ b/src/core/include/cesium/omniverse/FabricMaterialDefinition.h @@ -3,11 +3,7 @@ #include #include #include - -namespace CesiumGltf { -struct MeshPrimitive; -struct Model; -} // namespace CesiumGltf +#include namespace cesium::omniverse { @@ -15,16 +11,23 @@ struct MaterialInfo; class FabricMaterialDefinition { public: - FabricMaterialDefinition(const MaterialInfo& materialInfo, bool hasImagery, bool disableTextures); + FabricMaterialDefinition( + const MaterialInfo& materialInfo, + bool hasImagery, + bool disableTextures, + const pxr::SdfPath& tilesetMaterialPath); [[nodiscard]] bool hasBaseColorTexture() const; [[nodiscard]] bool hasVertexColors() const; + [[nodiscard]] bool hasTilesetMaterial() const; + [[nodiscard]] const pxr::SdfPath& getTilesetMaterialPath() const; bool operator==(const FabricMaterialDefinition& other) const; private: bool _hasBaseColorTexture; bool _hasVertexColors; + pxr::SdfPath _tilesetMaterialPath; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricMaterialPool.h b/src/core/include/cesium/omniverse/FabricMaterialPool.h index 79cb3ecce..008176f30 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); [[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const; @@ -25,7 +25,7 @@ class FabricMaterialPool final : public ObjectPool { private: const int64_t _poolId; const FabricMaterialDefinition _materialDefinition; - const pxr::SdfAssetPath _defaultTextureAssetPath; + const pxr::TfToken _defaultTextureAssetPathToken; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricResourceManager.h b/src/core/include/cesium/omniverse/FabricResourceManager.h index 3ab2f4e67..fb6e53432 100644 --- a/src/core/include/cesium/omniverse/FabricResourceManager.h +++ b/src/core/include/cesium/omniverse/FabricResourceManager.h @@ -44,12 +44,13 @@ 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, const CesiumGltf::MeshPrimitive& primitive, bool smoothNormals); - std::shared_ptr acquireMaterial(const MaterialInfo& materialInfo, bool hasImagery); + std::shared_ptr + acquireMaterial(const MaterialInfo& materialInfo, bool hasImagery, const pxr::SdfPath& tilesetMaterialPath); std::shared_ptr acquireTexture(); @@ -107,7 +108,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..0f8eb9112 100644 --- a/src/core/include/cesium/omniverse/FabricUtil.h +++ b/src/core/include/cesium/omniverse/FabricUtil.h @@ -31,6 +31,13 @@ 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); +std::vector +copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric::Path& dstMaterialPath); +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 diff --git a/src/core/include/cesium/omniverse/Tokens.h b/src/core/include/cesium/omniverse/Tokens.h index 47524679a..455deeb87 100644 --- a/src/core/include/cesium/omniverse/Tokens.h +++ b/src/core/include/cesium/omniverse/Tokens.h @@ -7,6 +7,8 @@ namespace cesium::omniverse::FabricTokens { extern const omni::fabric::TokenC baseColorTex; +extern const omni::fabric::TokenC cesium_base_color_texture; +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; @@ -24,6 +26,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; @@ -71,6 +74,8 @@ extern const omni::fabric::TokenC _worldVisibility; namespace cesium::omniverse::UsdTokens { extern const pxr::TfToken& baseColorTex; +extern const pxr::TfToken& cesium_base_color_texture; +extern const pxr::TfToken& cesium_texture_lookup; extern const pxr::TfToken& constant; extern const pxr::TfToken& doubleSided; extern const pxr::TfToken& extent; @@ -88,6 +93,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 +153,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 3539a63b3..1aa98556e 100644 --- a/src/core/include/cesium/omniverse/UsdUtil.h +++ b/src/core/include/cesium/omniverse/UsdUtil.h @@ -77,7 +77,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..59139b06d 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); @@ -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/FabricMaterial.cpp b/src/core/src/FabricMaterial.cpp index e85dbf5a2..c9cb3f278 100644 --- a/src/core/src/FabricMaterial.cpp +++ b/src/core/src/FabricMaterial.cpp @@ -1,45 +1,37 @@ #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 pxr::SdfPath& path, const FabricMaterialDefinition& materialDefinition, - pxr::SdfAssetPath defaultTextureAssetPath) - : _materialDefinition(materialDefinition) - , _defaultTextureAssetPath(std::move(defaultTextureAssetPath)) { + const pxr::TfToken& defaultTextureAssetPathToken) + : _materialPath(FabricUtil::toFabricPath(path)) + , _materialDefinition(materialDefinition) + , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) { + + if (materialDefinition.hasTilesetMaterial()) { + const auto tilesetMaterialPath = FabricUtil::toFabricPath(materialDefinition.getTilesetMaterialPath()); + initializeFromExistingMaterial(tilesetMaterialPath); + } else { + initialize(); + } - initialize(std::move(path), materialDefinition); reset(); } FabricMaterial::~FabricMaterial() { - FabricUtil::destroyPrim(_materialPathFabric); - FabricUtil::destroyPrim(_shaderPathFabric); - - if (_materialDefinition.hasBaseColorTexture()) { - FabricUtil::destroyPrim(_baseColorTexPathFabric); + for (const auto& path : _allPaths) { + FabricUtil::destroyPrim(path); } } @@ -50,223 +42,251 @@ void FabricMaterial::setActive(bool active) { } omni::fabric::Path FabricMaterial::getPathFabric() const { - return _materialPathFabric; + 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(); - auto srw = UsdUtil::getFabricStageReaderWriter(); + const auto& materialPath = _materialPath; + const auto shaderPath = FabricUtil::joinPaths(materialPath, FabricTokens::Shader); + const auto baseColorTexturePath = FabricUtil::joinPaths(materialPath, FabricTokens::baseColorTex); - const auto materialPath = std::move(path); - const auto shaderPath = materialPath.AppendChild(UsdTokens::Shader); - const auto baseColorTexPath = materialPath.AppendChild(UsdTokens::baseColorTex); + createMaterial(materialPath); + _allPaths.push_back(materialPath); - const auto materialPathFabric = omni::fabric::Path(materialPath.GetText()); - const auto shaderPathFabric = omni::fabric::Path(shaderPath.GetText()); - const auto baseColorTexPathFabric = omni::fabric::Path(baseColorTexPath.GetText()); + createShader(shaderPath, materialPath); + _allPaths.push_back(shaderPath); + _shaderPaths.push_back(shaderPath); - // Material - { - srw.createPrim(materialPathFabric); + if (hasBaseColorTexture) { + createTexture(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture); + _allPaths.push_back(baseColorTexturePath); + _baseColorTexturePaths.push_back(baseColorTexturePath); + } +} - FabricAttributesBuilder attributes; +void FabricMaterial::initializeFromExistingMaterial(const omni::fabric::Path& srcMaterialPath) { + const auto hasBaseColorTexture = _materialDefinition.hasBaseColorTexture(); - attributes.addAttribute(FabricTypes::Material, FabricTokens::Material); - attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); + auto srw = UsdUtil::getFabricStageReaderWriter(); - attributes.createAttributes(materialPathFabric); - } + const auto& dstMaterialPath = _materialPath; - // 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); - } + const auto dstPaths = FabricUtil::copyMaterial(srcMaterialPath, dstMaterialPath); - 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 - } + for (const auto& dstPath : dstPaths) { + srw.createAttribute(dstPath, FabricTokens::_cesium_tilesetId, FabricTypes::_cesium_tilesetId); + _allPaths.push_back(dstPath); - // 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}); - } + const auto mdlIdentifier = FabricUtil::getMdlIdentifier(dstPath); - 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}); + if (mdlIdentifier == FabricTokens::cesium_base_color_texture) { + if (hasBaseColorTexture) { + // Create a base color texture node to fill the empty slot + const auto baseColorTexturePath = FabricUtil::joinPaths(dstMaterialPath, FabricTokens::baseColorTex); + createTexture(baseColorTexturePath, dstPath, FabricTokens::inputs_base_color_texture); + _allPaths.push_back(baseColorTexturePath); + _baseColorTexturePaths.push_back(baseColorTexturePath); + } } } +} + +void FabricMaterial::createMaterial(const omni::fabric::Path& materialPath) { + auto srw = UsdUtil::getFabricStageReaderWriter(); + srw.createPrim(materialPath); - _materialPathFabric = materialPathFabric; - _shaderPathFabric = shaderPathFabric; - _baseColorTexPathFabric = baseColorTexPathFabric; + FabricAttributesBuilder attributes; + + attributes.addAttribute(FabricTypes::Material, FabricTokens::Material); + attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); + + attributes.createAttributes(materialPath); } -void FabricMaterial::reset() { - if (!UsdUtil::hasStage()) { - return; - } +void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath) { + const auto hasVertexColors = _materialDefinition.hasVertexColors(); auto srw = UsdUtil::getFabricStageReaderWriter(); - setMaterialValues(GltfUtil::getDefaultMaterialInfo()); - setTilesetId(NO_TILESET_ID); + 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 - if (_materialDefinition.hasBaseColorTexture()) { - clearBaseColorTexture(); + if (hasVertexColors) { + attributes.addAttribute(FabricTypes::inputs_vertex_color_name, FabricTokens::inputs_vertex_color_name); } + + 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 = UsdTokens::gltf_pbr_mdl; + infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); + *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::gltf_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); + } + + // 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::setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo) { +void FabricMaterial::createTexture( + const omni::fabric::Path& texturePath, + const omni::fabric::Path& shaderPath, + const omni::fabric::Token& shaderInput) { auto srw = UsdUtil::getFabricStageReaderWriter(); - setMaterialValues(materialInfo); - setTilesetId(tilesetId); -} + srw.createPrim(texturePath); -void FabricMaterial::setBaseColorTexture( - const std::shared_ptr& texture, - const TextureInfo& textureInfo) { + 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 - if (!_materialDefinition.hasBaseColorTexture()) { + 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 + + // For some reason, when a material network has both cesium nodes and glTF nodes it causes an infinite loop of + // material loading. If this material is initialized from a tileset material use the cesium wrapper nodes instead. + const auto& custom = _materialDefinition.hasTilesetMaterial(); + const auto& assetPath = custom ? Context::instance().getCesiumMdlPathToken() : UsdTokens::gltf_pbr_mdl; + const auto& subIdentifier = custom ? FabricTokens::cesium_texture_lookup : FabricTokens::gltf_texture_lookup; + + *inputsExcludeFromWhiteModeFabric = false; + *infoImplementationSourceFabric = FabricTokens::sourceAsset; + infoMdlSourceAssetFabric->assetPath = assetPath; + infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); + *infoMdlSourceAssetSubIdentifierFabric = subIdentifier; + 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() { + if (!UsdUtil::hasStage()) { return; } - setBaseColorTextureValues(texture->getAssetPath(), textureInfo); + clearMaterial(); + clearBaseColorTexture(); } -void FabricMaterial::clearBaseColorTexture() { - setBaseColorTextureValues(_defaultTextureAssetPath, GltfUtil::getDefaultTextureInfo()); -} +void FabricMaterial::setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo) { + for (auto& shaderPath : _shaderPaths) { + setShaderValues(shaderPath, materialInfo); + } -void FabricMaterial::setTilesetId(int64_t tilesetId) { - FabricUtil::setTilesetId(_materialPathFabric, tilesetId); - FabricUtil::setTilesetId(_shaderPathFabric, tilesetId); + for (const auto& path : _allPaths) { + FabricUtil::setTilesetId(path, tilesetId); + } +} - if (_materialDefinition.hasBaseColorTexture()) { - FabricUtil::setTilesetId(_baseColorTexPathFabric, tilesetId); +void FabricMaterial::setBaseColorTexture(const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo) { + for (auto& _baseColorTexturePath : _baseColorTexturePaths) { + setTextureValues(_baseColorTexturePath, textureAssetPathToken, textureInfo); } } -void FabricMaterial::setMaterialValues(const MaterialInfo& materialInfo) { +void FabricMaterial::clearMaterial() { + setMaterial(NO_TILESET_ID, GltfUtil::getDefaultMaterialInfo()); +} + +void FabricMaterial::clearBaseColorTexture() { + setBaseColorTexture(_defaultTextureAssetPathToken, GltfUtil::getDefaultTextureInfo()); +} + +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; @@ -277,14 +297,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 @@ -294,18 +315,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/FabricMaterialDefinition.cpp b/src/core/src/FabricMaterialDefinition.cpp index 8ef742c3e..3d755d42f 100644 --- a/src/core/src/FabricMaterialDefinition.cpp +++ b/src/core/src/FabricMaterialDefinition.cpp @@ -14,7 +14,8 @@ namespace cesium::omniverse { FabricMaterialDefinition::FabricMaterialDefinition( const MaterialInfo& materialInfo, bool hasImagery, - bool disableTextures) { + bool disableTextures, + const pxr::SdfPath& tilesetMaterialPath) { _hasBaseColorTexture = materialInfo.baseColorTexture.has_value(); @@ -27,6 +28,7 @@ FabricMaterialDefinition::FabricMaterialDefinition( } _hasVertexColors = materialInfo.hasVertexColors; + _tilesetMaterialPath = tilesetMaterialPath; } bool FabricMaterialDefinition::hasBaseColorTexture() const { @@ -37,6 +39,14 @@ bool FabricMaterialDefinition::hasVertexColors() const { return _hasVertexColors; } +bool FabricMaterialDefinition::hasTilesetMaterial() const { + return !_tilesetMaterialPath.IsEmpty(); +} + +const pxr::SdfPath& FabricMaterialDefinition::getTilesetMaterialPath() const { + return _tilesetMaterialPath; +} + // In C++ 20 we can use the default equality comparison (= default) bool FabricMaterialDefinition::operator==(const FabricMaterialDefinition& other) const { if (_hasBaseColorTexture != other._hasBaseColorTexture) { @@ -47,6 +57,10 @@ bool FabricMaterialDefinition::operator==(const FabricMaterialDefinition& other) return false; } + if (_tilesetMaterialPath != other._tilesetMaterialPath) { + return false; + } + return true; } diff --git a/src/core/src/FabricMaterialPool.cpp b/src/core/src/FabricMaterialPool.cpp index 774563410..c3accc82a 100644 --- a/src/core/src/FabricMaterialPool.cpp +++ b/src/core/src/FabricMaterialPool.cpp @@ -8,11 +8,11 @@ FabricMaterialPool::FabricMaterialPool( int64_t poolId, const FabricMaterialDefinition& materialDefinition, uint64_t initialCapacity, - pxr::SdfAssetPath defaultTextureAssetPath) + const pxr::TfToken& defaultTextureAssetPathToken) : ObjectPool() , _poolId(poolId) , _materialDefinition(materialDefinition) - , _defaultTextureAssetPath(std::move(defaultTextureAssetPath)) { + , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) { setCapacity(initialCapacity); } @@ -22,7 +22,7 @@ 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); + return std::make_shared(path, _materialDefinition, _defaultTextureAssetPathToken); } void FabricMaterialPool::setActive(std::shared_ptr material, bool active) { diff --git a/src/core/src/FabricPrepareRenderResources.cpp b/src/core/src/FabricPrepareRenderResources.cpp index 31a2461e5..f7d7a6c19 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(); for (const auto& mesh : meshes) { auto& fabricMesh = fabricMeshes.emplace_back(); @@ -112,13 +114,13 @@ std::vector acquireFabricMeshes( const auto fabricGeometry = fabricResourceManager.acquireGeometry(model, primitive, mesh.smoothNormals); 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); - - const auto fabricMaterial = fabricResourceManager.acquireMaterial(materialInfo, hasImagery); + const auto fabricMaterial = + fabricResourceManager.acquireMaterial(materialInfo, hasImagery, tilesetMaterialPath); fabricMesh.material = fabricMaterial; fabricMesh.materialInfo = materialInfo; @@ -162,7 +164,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; @@ -185,10 +187,11 @@ void setFabricMeshes( geometry->setMaterial(material->getPathFabric()); 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)); } } } @@ -433,7 +436,7 @@ void FabricPrepareRenderResources::attachRasterInMainThread( }; // Replace the original base color texture with the imagery - material->setBaseColorTexture(texture, textureInfo); + material->setBaseColorTexture(texture->getAssetPathToken(), textureInfo); } } } @@ -467,7 +470,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 38e67a2ea..694440e49 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" @@ -18,7 +18,7 @@ namespace cesium::omniverse { 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}}; @@ -31,13 +31,13 @@ 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()) { - return false; + if (!tilesetMaterialPath.IsEmpty()) { + return FabricUtil::materialHasCesiumNodes(FabricUtil::toFabricPath(tilesetMaterialPath)); } return hasImagery || GltfUtil::hasMaterial(primitive); @@ -62,13 +62,15 @@ std::shared_ptr FabricResourceManager::acquireGeometry( return geometry; } -std::shared_ptr -FabricResourceManager::acquireMaterial(const MaterialInfo& materialInfo, bool hasImagery) { - FabricMaterialDefinition materialDefinition(materialInfo, hasImagery, _disableTextures); +std::shared_ptr FabricResourceManager::acquireMaterial( + const MaterialInfo& materialInfo, + bool hasImagery, + const pxr::SdfPath& tilesetMaterialPath) { + FabricMaterialDefinition materialDefinition(materialInfo, hasImagery, _disableTextures, tilesetMaterialPath); if (_disableMaterialPool) { const auto path = pxr::SdfPath(fmt::format("/fabric_material_{}", getNextMaterialId())); - return std::make_shared(path, materialDefinition, _defaultTextureAssetPath); + return std::make_shared(path, materialDefinition, _defaultTextureAssetPathToken); } std::scoped_lock lock(_poolMutex); @@ -199,7 +201,7 @@ FabricResourceManager::getMaterialPool(const FabricMaterialDefinition& materialD // Create a new pool return _materialPools.emplace_back(std::make_shared( - getNextPoolId(), materialDefinition, _materialPoolInitialCapacity, _defaultTextureAssetPath)); + getNextPoolId(), materialDefinition, _materialPoolInitialCapacity, _defaultTextureAssetPathToken)); } std::shared_ptr FabricResourceManager::getTexturePool() { 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 a140838d2..9595934a3 100644 --- a/src/core/src/FabricUtil.cpp +++ b/src/core/src/FabricUtil.cpp @@ -668,12 +668,228 @@ 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 { + +struct FabricConnection { + omni::fabric::Connection* connection; + omni::fabric::Token attributeName; +}; + +std::vector getConnections(const omni::fabric::Path& path) { + std::vector connections; + + auto srw = UsdUtil::getFabricStageReaderWriter(); + const auto attributes = srw.getAttributeNamesAndTypes(path); + const auto& names = attributes.first; + const auto& types = attributes.second; + + for (size_t i = 0; i < names.size(); i++) { + const auto& name = names[i]; + const auto& type = types[i]; + if (type.baseType == omni::fabric::BaseDataType::eConnection) { + const auto connection = srw.getConnection(path, name); + if (connection != nullptr) { + connections.push_back({connection, name}); + } + } + } + + return connections; +} + +bool isOutput(const omni::fabric::Token& attributeName) { + return attributeName == FabricTokens::outputs_out; +} + +bool isConnection(const omni::fabric::Type& attributeType) { + return attributeType.baseType == omni::fabric::BaseDataType::eConnection; +} + +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(path, attributeName); + if (attributeValue == nullptr || (*attributeValue).size() == 0) { + return true; + } + } + + return false; +} + +std::vector getAttributesToCopy(const omni::fabric::Path& path) { + std::vector attributeNames; + + auto srw = UsdUtil::getFabricStageReaderWriter(); + + const auto attributes = srw.getAttributeNamesAndTypes(path); + const auto& names = attributes.first; + const auto& types = attributes.second; + + for (size_t i = 0; i < names.size(); i++) { + const auto& name = names[i]; + const auto& type = types[i]; + + if (!isOutput(name) && !isConnection(type) && !isEmptyToken(path, name, type)) { + attributeNames.emplace_back(omni::fabric::TokenC(name)); + } + } + + return attributeNames; +} + +struct FabricAttribute { + omni::fabric::Token name; + omni::fabric::Type type; +}; + +std::vector getAttributesToCreate(const omni::fabric::Path& path) { + std::vector attributeNames; + + auto srw = UsdUtil::getFabricStageReaderWriter(); + + const auto attributes = srw.getAttributeNamesAndTypes(path); + const auto& names = attributes.first; + const auto& types = attributes.second; + + for (size_t i = 0; i < names.size(); i++) { + const auto& name = names[i]; + const auto& type = types[i]; + + if (isOutput(name) || isEmptyToken(path, name, type)) { + attributeNames.emplace_back(FabricAttribute{name, type}); + } + } + + return attributeNames; +} + +void getConnectedPrimsRecursive(const omni::fabric::Path& path, std::vector& connectedPaths) { + const auto connections = getConnections(path); + for (const auto& connection : connections) { + const auto it = std::find(connectedPaths.begin(), connectedPaths.end(), connection.connection->path); + if (it == connectedPaths.end()) { + connectedPaths.emplace_back(connection.connection->path); + getConnectedPrimsRecursive(connection.connection->path, connectedPaths); + } + } +} + +std::vector getPrimsInMaterialNetwork(const omni::fabric::Path& path) { + auto srw = UsdUtil::getFabricStageReaderWriter(); + std::vector paths; + paths.push_back(path); + getConnectedPrimsRecursive(path, paths); + return paths; +} + +} // namespace + +std::vector +copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric::Path& dstMaterialPath) { + auto srw = UsdUtil::getFabricStageReaderWriter(); + const auto isrw = carb::getCachedInterface(); + + const auto srcPaths = getPrimsInMaterialNetwork(srcMaterialPath); + + std::vector dstPaths; + dstPaths.reserve(srcPaths.size()); + + for (const auto& srcPath : srcPaths) { + auto dstPath = omni::fabric::Path(); + + if (srcPath == srcMaterialPath) { + dstPath = dstMaterialPath; + } else { + dstPath = FabricUtil::joinPaths( + dstMaterialPath, omni::fabric::Token(UsdUtil::getSafeName(srcPath.getText()).c_str())); + } + + dstPaths.push_back(dstPath); + + srw.createPrim(dstPath); + + // This excludes connections, outputs, and empty tokens + // The material network will be reconnected later once all the prims have been copied + // The reason for excluding outputs and empty tokens 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 the outputs and empty tokens back. This doesn't print a warning. + const auto attributesToCreate = getAttributesToCreate(srcPath); + for (const auto& attribute : attributesToCreate) { + srw.createAttribute(dstPath, attribute.name, attribute.type); + } + } + + // Reconnect the prims + for (size_t i = 0; i < srcPaths.size(); i++) { + const auto& srcPath = srcPaths[i]; + const auto& dstPath = dstPaths[i]; + const auto connections = getConnections(srcPath); + for (const auto& connection : connections) { + const auto it = std::find(srcPaths.begin(), srcPaths.end(), connection.connection->path); + assert(it != srcPaths.end()); // Ensure that all connections are part of the material network + const auto index = it - srcPaths.begin(); + const auto dstConnection = + omni::fabric::Connection{omni::fabric::PathC(dstPaths[index]), connection.connection->attrName}; + srw.createConnection(dstPath, connection.attributeName, dstConnection); + } + } + + return dstPaths; +} + +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 (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(path, FabricTokens::info_mdl_sourceAsset_subIdentifier); + if (infoMdlSourceAssetSubIdentifierFabric != nullptr) { + return *infoMdlSourceAssetSubIdentifierFabric; + } + } + return omni::fabric::Token{}; +} + } // namespace cesium::omniverse::FabricUtil diff --git a/src/core/src/Tokens.cpp b/src/core/src/Tokens.cpp index 22752d54c..1907862d4 100644 --- a/src/core/src/Tokens.cpp +++ b/src/core/src/Tokens.cpp @@ -16,13 +16,14 @@ __pragma(warning(disable: 4003)) TF_DEFINE_PRIVATE_TOKENS( UsdTokens, (baseColorTex) + (cesium_base_color_texture) + (cesium_texture_lookup) (constant) (doubleSided) (extent) (faceVertexCounts) (faceVertexIndices) (gltf_material) - ((gltf_pbr_mdl, "gltf/pbr.mdl")) (gltf_texture_lookup) (Material) (Mesh) @@ -47,6 +48,7 @@ TF_DEFINE_PRIVATE_TOKENS( (_worldScale) (_worldVisibility) ((_auto, "auto")) + ((gltf_pbr_mdl, "gltf/pbr.mdl")) ((info_implementationSource, "info:implementationSource")) ((info_mdl_sourceAsset, "info:mdl:sourceAsset")) ((info_mdl_sourceAsset_subIdentifier, "info:mdl:sourceAsset:subIdentifier")) @@ -56,6 +58,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")) @@ -86,6 +89,8 @@ __pragma(warning(pop)) namespace cesium::omniverse::FabricTokens { const omni::fabric::TokenC baseColorTex = omni::fabric::asInt(pxr::UsdTokens->baseColorTex); +const omni::fabric::TokenC cesium_base_color_texture = omni::fabric::asInt(pxr::UsdTokens->cesium_base_color_texture); +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); @@ -103,6 +108,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); @@ -150,6 +156,8 @@ const omni::fabric::TokenC _worldVisibility = omni::fabric::asInt(pxr::UsdTokens namespace cesium::omniverse::UsdTokens { const pxr::TfToken& baseColorTex = pxr::UsdTokens->baseColorTex; +const pxr::TfToken& cesium_base_color_texture = pxr::UsdTokens->cesium_base_color_texture; +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; @@ -167,6 +175,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/UsdUtil.cpp b/src/core/src/UsdUtil.cpp index c461d651f..37fde88de 100644 --- a/src/core/src/UsdUtil.cpp +++ b/src/core/src/UsdUtil.cpp @@ -192,8 +192,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