Skip to content

Commit

Permalink
Avoid hardcoding the texture inputs length
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 6, 2023
1 parent f497b7c commit 95c1107
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class FabricMaterial {

bool _useTextureArray;
uint64_t _textureArrayLength;
std::vector<omni::fabric::Token> _inputTextureTokens;
};

} // namespace cesium::omniverse
3 changes: 0 additions & 3 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")) \
Expand Down
33 changes: 11 additions & 22 deletions src/core/src/FabricMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -251,23 +259,14 @@ void FabricMaterial::createTextureArray(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput) {

const auto inputTextureTokens = std::vector<omni::fabric::Token>{
FabricTokens::inputs_texture_0,
FabricTokens::inputs_texture_1,
FabricTokens::inputs_texture_2,
};

assert(inputTextureTokens.size() == _textureArrayLength);

auto srw = UsdUtil::getFabricStageReaderWriter();

srw.createPrim(texturePath);

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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -438,18 +437,8 @@ void FabricMaterial::setTextureArrayValues(
const std::vector<pxr::TfToken>& textureAssetPathTokens) {
auto srw = UsdUtil::getFabricStageReaderWriter();

assert(textureAssetPathTokens.size() == _textureArrayLength);

const auto inputTextureTokens = std::vector<omni::fabric::Token>{
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<omni::fabric::AssetPath>(texturePath, inputTextureTokens[i]);
auto textureFabric = srw.getAttributeWr<omni::fabric::AssetPath>(texturePath, _inputTextureTokens[i]);
textureFabric->assetPath = textureAssetPathTokens[i];
textureFabric->resolvedPath = pxr::TfToken();
}
Expand Down

0 comments on commit 95c1107

Please sign in to comment.