Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enumeration support to web viewer #1632

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions javascript/MaterialXView/source/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,17 @@ export class Material
}
var step = 0;
var enumList = []
var enumValues = []
if (nodeDefInput)
{
if (nodeDefInput.hasAttribute('enum'))
{
// Get enum and enum values attributes (if present)
enumList = nodeDefInput.getAttribute('enum').split(',');
if (nodeDefInput.hasAttribute('enumvalues'))
{
enumValues = nodeDefInput.getAttribute('enumvalues').split(',').map(Number);
}
}
else
{
Expand Down Expand Up @@ -989,8 +995,30 @@ export class Material
}
else
{
// TODO: Add enum support
currentFolder.add(material.uniforms[name], 'value' ).name(path);
// Map enumList strings to values
// Map to 0..N if no values are specified via enumvalues attribute
if (enumValues.length == 0)
{
for (let i = 0; i < enumList.length; ++i)
{
enumValues.push(i);
}
}
const enumeration = {};
enumList.forEach((str, index) => {
enumeration[str] = enumValues[index];
});

// Function to handle enum drop-down
function handleDropdownChange(value) {
if (material.uniforms[name])
{
material.uniforms[name].value = value;
}
}
const defaultOption = enumList[value]; // Set the default selected option
const dropdownController = gui.add(enumeration, defaultOption, enumeration).name(path);
dropdownController.onChange(handleDropdownChange);
}
}
break;
Expand Down Expand Up @@ -1046,7 +1074,7 @@ export class Material
break;

case 'color3':
// Irksome way to mape arrays to colors and back
// Irksome way to map arrays to colors and back
uniformToUpdate = material.uniforms[name];
if (uniformToUpdate && value != null)
{
Expand Down