Skip to content

Graph Editor - UI support for enum #2395

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

inter-sakot4
Copy link

Description
In this PR, UI support for enumerator types are added to GraphEditor.

Some assumptions are made to execute this task:

  • Fix the issue for only GraphEditor , though similar issue exist also in MaterialXView ( NanoGUI )
  • Generalize the solution to int, bool, string, float, double, Vector2, Vector3, Vector4, Color3, Color4, Matrix types

With the above assumptions, scope of this task is limited only to GraphEditor ( IMGUI )

Solution

  • renderEnumInput<input_type>(input, uiProperties, temp) is a template function that does the rendering of enumerator input types.

Following edge cases are handled:

  • ui.enumerationValues and ui.ui.enumeration are not always populated ( See /MaterialXRender/Util.cpp ). In such cases, the enum and enumvalues are parsed directly from the attribute values to render the enumerators.
  • Its common to have string input with enum fields only , but no enumvalues

How to test?

Slightly modified standard_surface_jade.mtlx can be used like below.

<?xml version="1.0"?>
<materialx version="1.39" colorspace="lin_rec709">
  <standard_surface name="SR_jade" type="surfaceshader">
    <input name="base" type="float" value="0.5" />
    <input name="base_color" type="color3" value="0.0603,0.4398,0.1916" />
    <input name="specular_roughness" type="float" value="0.25" enum="0.0, 0.25, 0.5, 0.75" enumvalues="0.0,0.25,0.5,0.75"/>
    <input name="specular_IOR" type="float" value="2.418" />
    <input name="specular_anisotropy" type="float" value="0.5" />
    <input name="subsurface" type="float" value="0.4" enum="0.0,0.4,0.5,0.6,0.7" enumvalues="0.0,0.4,0.5,0.6,0.7" />
    <input name="subsurface_color" type="color3" value="0.0603, 0.4398, 0.1916" enum="DEFAULT_GREEN, RED" enumvalues="0.0603,0.4398,0.1916,0.8,0.04398,0.01916" />
  </standard_surface>
  <surfacematerial name="Jade" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="SR_jade" />
  </surfacematerial>
</materialx>

Expected Result

image

Copy link

linux-foundation-easycla bot commented May 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@jstone-lucasfilm
Copy link
Member

Thanks @inter-sakot4, and I'll link this to GitHub Issue #2366.

@jstone-lucasfilm jstone-lucasfilm changed the title Graph Editor - UI support for enum (#2366) Graph Editor - UI support for enum May 17, 2025
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very promising, @inter-sakot4, and I've added a note on the line that appears to be triggering build issues on some platforms.


// parse string values from the enum, enumvalues attribute directly and populate enumValues
enumVec = mx::splitString(enumStr, enumDelimiter);
int groupSize = mx::splitString(enumValueStr, enumDelimiter).size() / enumVec.size();
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the line that likely needs an update for cross-platform compatibility, since the return type of vector::size is size_t.

Copy link
Author

@inter-sakot4 inter-sakot4 May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankyou for taking time to review @jstone-lucasfilm ! Fixed the type issue as suggested and added short comments for clarity.

bool Graph::renderEnumInput(mx::InputPtr& input, const mx::UIProperties& ui, T &evalue)
{

// Eg. <input name="subsurface_color" type="color3" value="0.2,0.6,0.05"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is a minor style issue, I notice that this method uses 2-space indentation rather than our standard 4-space indentation, and that would be valuable to fix before we include this change in the codebase.

std::vector<mx::ValuePtr> enumValues = ui.enumerationValues;
std::vector<std::string> enumVec = ui.enumeration;

//Handling edge cases where enumvalues attribute is empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice some minor inconsistencies in these comments, and it would be valuable to use the same spacing and capitalization for all of them. Usually, we use a single space after the initial // marker, and the first letter of the first sentence is capitalized.

@@ -145,6 +145,7 @@ unsigned int getUIProperties(InputPtr input, const string& target, UIProperties&
propertyCount++;
}

//Enumeration fields are not populated for non uniform inputs. Is this intentional? This affects the issue #2366
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a useful note, and I'll CC @lfl-eholthouser for her thoughts, though we should make sure not to include this when the change is ultimately merged to main.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that currently MaterialXWebViewer does show enum/enumvalues for non-uniform inputs.
It probably should not, given the spec, but I'm not sure which one is right.

@hybridherbst
Copy link
Contributor

I closed my related PR #2438 because yours looks much more complete, but my test file does not actually show a dropdown UI when I build from this PR @inter-sakot4.

Here's the test file that doesn't bring up a dropdown:
MyKeywordGraph.mtlx.zip

Should look like this:
image

@jstone-lucasfilm
Copy link
Member

@inter-sakot4 Just following up on this PR, to see if you might have a chance to address the issue brought up by @hybridherbst above!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants