diff --git a/src/core/include/cesium/omniverse/FabricMaterial.h b/src/core/include/cesium/omniverse/FabricMaterial.h index 3eb42adc7..ea4ed3c9d 100644 --- a/src/core/include/cesium/omniverse/FabricMaterial.h +++ b/src/core/include/cesium/omniverse/FabricMaterial.h @@ -80,6 +80,7 @@ class FabricMaterial { bool _useTextureArray; uint64_t _textureArrayLength; + std::vector _inputTextureTokens; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/Tokens.h b/src/core/include/cesium/omniverse/Tokens.h index 39eb3b826..8690683a6 100644 --- a/src/core/include/cesium/omniverse/Tokens.h +++ b/src/core/include/cesium/omniverse/Tokens.h @@ -61,9 +61,6 @@ __pragma(warning(push)) __pragma(warning(disable : 4003)) ((inputs_scale, "inputs:scale")) \ ((inputs_tex_coord_index, "inputs:tex_coord_index")) \ ((inputs_texture, "inputs:texture")) \ - ((inputs_texture_0, "inputs:texture_0")) \ - ((inputs_texture_1, "inputs:texture_1")) \ - ((inputs_texture_2, "inputs:texture_2")) \ ((inputs_vertex_color_name, "inputs:vertex_color_name")) \ ((inputs_wrap_s, "inputs:wrap_s")) \ ((inputs_wrap_t, "inputs:wrap_t")) \ diff --git a/src/core/src/FabricMaterial.cpp b/src/core/src/FabricMaterial.cpp index 247bc124f..600be3346 100644 --- a/src/core/src/FabricMaterial.cpp +++ b/src/core/src/FabricMaterial.cpp @@ -30,6 +30,14 @@ FabricMaterial::FabricMaterial( return; } + if (_useTextureArray) { + _inputTextureTokens.reserve(_textureArrayLength); + for (uint64_t i = 0; i < _textureArrayLength; i++) { + const auto name = fmt::format("inputs:texture_{}", i); + _inputTextureTokens.emplace_back(name.c_str()); + } + } + initialize(); reset(); } @@ -251,15 +259,6 @@ void FabricMaterial::createTextureArray( const omni::fabric::Path& texturePath, const omni::fabric::Path& shaderPath, const omni::fabric::Token& shaderInput) { - - const auto inputTextureTokens = std::vector{ - FabricTokens::inputs_texture_0, - FabricTokens::inputs_texture_1, - FabricTokens::inputs_texture_2, - }; - - assert(inputTextureTokens.size() == _textureArrayLength); - auto srw = UsdUtil::getFabricStageReaderWriter(); srw.createPrim(texturePath); @@ -267,7 +266,7 @@ void FabricMaterial::createTextureArray( FabricAttributesBuilder attributes; for (uint64_t i = 0; i < _textureArrayLength; i++) { - attributes.addAttribute(FabricTypes::inputs_texture, inputTextureTokens[i]); + attributes.addAttribute(FabricTypes::inputs_texture, _inputTextureTokens[i]); } // clang-format off @@ -303,7 +302,7 @@ void FabricMaterial::createTextureArray( *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::cesium_texture_array_lookup; for (uint64_t i = 0; i < _textureArrayLength; i++) { - paramColorSpaceFabric[i * 2] = inputTextureTokens[i]; + paramColorSpaceFabric[i * 2] = _inputTextureTokens[i]; paramColorSpaceFabric[i * 2 + 1] = FabricTokens::_auto; } @@ -438,18 +437,8 @@ void FabricMaterial::setTextureArrayValues( const std::vector& textureAssetPathTokens) { auto srw = UsdUtil::getFabricStageReaderWriter(); - assert(textureAssetPathTokens.size() == _textureArrayLength); - - const auto inputTextureTokens = std::vector{ - FabricTokens::inputs_texture_0, - FabricTokens::inputs_texture_1, - FabricTokens::inputs_texture_2, - }; - - assert(inputTextureTokens.size() == _textureArrayLength); - for (uint64_t i = 0; i < textureAssetPathTokens.size(); i++) { - auto textureFabric = srw.getAttributeWr(texturePath, inputTextureTokens[i]); + auto textureFabric = srw.getAttributeWr(texturePath, _inputTextureTokens[i]); textureFabric->assetPath = textureAssetPathTokens[i]; textureFabric->resolvedPath = pxr::TfToken(); }