Skip to content

Commit 9c3c0b1

Browse files
committed
Fix solo material UI update to work per material vs per material assignment as
UI is tied to materials not assignments.
1 parent c970333 commit 9c3c0b1

1 file changed

Lines changed: 43 additions & 28 deletions

File tree

javascript/MaterialXView/source/viewer.js

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,6 @@ export class Material
997997
matTitle.classList.remove('peditor_material_assigned');
998998
let img = matTitle.getElementsByTagName('img')[0];
999999
img.src = 'public/shader_ball.svg';
1000-
//matTitle.classList.remove('peditor_material_unassigned');
10011000
}
10021001
}
10031002
}
@@ -1007,34 +1006,45 @@ export class Material
10071006
// Prevent the event from being passed to parent folder
10081007
event.stopPropagation();
10091008

1009+
let materialNameList = new Set()
10101010
for (let i = 0; i < materials.length; ++i)
10111011
{
10121012
let matassign = materials[i];
10131013
// Need to use path vs name to get a unique key.
10141014
let materialName = matassign.getMaterial().getNamePath();
1015+
if (materialNameList.has(materialName))
1016+
{
1017+
continue;
1018+
}
1019+
10151020
var matUI = matassign.getMaterialUI();
1016-
let matTitle = matUI.domElement.getElementsByClassName('title')[0];
1017-
let img = matTitle.getElementsByTagName('img')[0];
1018-
if (materialName == elemPath)
1021+
if (matUI)
10191022
{
1020-
if (this._soloMaterial == elemPath)
1023+
materialNameList.add(materialName);
1024+
1025+
let matTitle = matUI.domElement.getElementsByClassName('title')[0];
1026+
let img = matTitle.getElementsByTagName('img')[0];
1027+
if (materialName == elemPath)
10211028
{
1022-
img.src = 'public/shader_ball.svg';
1023-
matTitle.classList.remove('peditor_material_assigned');
1024-
this._soloMaterial = "";
1029+
if (this._soloMaterial == elemPath)
1030+
{
1031+
img.src = 'public/shader_ball.svg';
1032+
matTitle.classList.remove('peditor_material_assigned');
1033+
this._soloMaterial = "";
1034+
}
1035+
else
1036+
{
1037+
img.src = 'public/shader_ball2.svg';
1038+
matTitle.classList.add('peditor_material_assigned');
1039+
this._soloMaterial = elemPath;
1040+
}
10251041
}
10261042
else
10271043
{
1028-
img.src = 'public/shader_ball2.svg';
1029-
matTitle.classList.add('peditor_material_assigned');
1030-
this._soloMaterial = elemPath;
1044+
img.src = 'public/shader_ball.svg';
1045+
matTitle.classList.remove('peditor_material_assigned');
10311046
}
10321047
}
1033-
else
1034-
{
1035-
img.src = 'public/shader_ball.svg';
1036-
matTitle.classList.remove('peditor_material_assigned');
1037-
}
10381048
}
10391049
viewer.getMaterial().updateMaterialAssignments(viewer, this._soloMaterial);
10401050
}
@@ -1056,22 +1066,27 @@ export class Material
10561066
const elemPath = elem.getNamePath();
10571067

10581068
// Create and cache associated UI
1059-
var matUI = gui.addFolder(elemPath);
1069+
let matUI = gui.addFolder(elemPath);
1070+
console.log('Set material UI for: ', elemPath, matUI);
10601071
matassign.setMaterialUI(matUI);
10611072

1062-
let matTitle = matUI.domElement.getElementsByClassName('title')[0];
1063-
// Add a icon to the title to allow for assigning the material to geometry
1064-
// Clicking on the icon will "solo" the material to the geometry.
1065-
// Clicking on the title will open/close the material folder.
1066-
matTitle.innerHTML = "<img id='" + elemPath + "' src='public/shader_ball.svg' width='16' height='16' style='vertical-align:middle; margin-right: 5px;'>" + elem.getNamePath();
1067-
let img = matTitle.getElementsByTagName('img')[0];
1068-
if (img)
1073+
let matTitle = null
1074+
if (matUI && matUI.domElement)
10691075
{
1070-
// Add event listener to icon to call updateSoloMaterial function
1071-
img.addEventListener('click', function (event)
1076+
matTitle = matUI.domElement.getElementsByClassName('title')[0];
1077+
// Add a icon to the title to allow for assigning the material to geometry
1078+
// Clicking on the icon will "solo" the material to the geometry.
1079+
// Clicking on the title will open/close the material folder.
1080+
matTitle.innerHTML = "<img id='" + elemPath + "' src='public/shader_ball.svg' width='16' height='16' style='vertical-align:middle; margin-right: 5px;'>" + elem.getNamePath();
1081+
let img = matTitle.getElementsByTagName('img')[0];
1082+
if (img)
10721083
{
1073-
Material.updateSoloMaterial(viewer, elemPath, materials, event);
1074-
});
1084+
// Add event listener to icon to call updateSoloMaterial function
1085+
img.addEventListener('click', function (event)
1086+
{
1087+
Material.updateSoloMaterial(viewer, elemPath, materials, event);
1088+
});
1089+
}
10751090
}
10761091

10771092
if (closeUI)

0 commit comments

Comments
 (0)