Skip to content

Commit 131d9f5

Browse files
Improve UDIM support in viewer (AcademySoftwareFoundation#2507)
This changelist improves the support for multi-UDIM materials in the MaterialX Viewer, allowing materials with explicit UDIM-associated names to be bound to implicit geometric UDIMs. Although explicit UDIM-associated names are not a recommended convention for multi-UDIM materials, they are common enough in studio pipelines that it's valuable to support them as an alternative.
1 parent ec66ab3 commit 131d9f5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

source/MaterialXView/Viewer.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const float IDEAL_MESH_SPHERE_RADIUS = 2.0f;
8383

8484
const float PI = std::acos(-1.0f);
8585

86+
const std::string UDIM_SEPARATORS = "._";
87+
8688
void writeTextFile(const std::string& text, const std::string& filePath)
8789
{
8890
std::ofstream file;
@@ -1494,13 +1496,25 @@ void Viewer::loadDocument(const mx::FilePath& filename, mx::DocumentPtr librarie
14941496
}
14951497
}
14961498

1497-
// Apply implicit udim assignments, if any.
1499+
// Apply UDIM assignments, if any.
14981500
for (mx::MaterialPtr mat : newMaterials)
14991501
{
15001502
mx::NodePtr materialNode = mat->getMaterialNode();
15011503
if (materialNode)
15021504
{
1505+
// First check for implicit UDIM assignments.
15031506
std::string udim = mat->getUdim();
1507+
if (udim.empty())
1508+
{
1509+
// Fall back to name-based UDIM assignments.
1510+
for (const std::string& token : mx::splitString(materialNode->getName(), UDIM_SEPARATORS))
1511+
{
1512+
if (token.size() == 4 && std::all_of(token.begin(), token.end(), isdigit))
1513+
{
1514+
udim = token;
1515+
}
1516+
}
1517+
}
15041518
if (!udim.empty())
15051519
{
15061520
for (mx::MeshPartitionPtr geom : _geometryList)

0 commit comments

Comments
 (0)