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

Runtime token support #1157

Merged
merged 15 commits into from
Apr 7, 2021
Merged

Conversation

bernardkwok
Copy link

@bernardkwok bernardkwok commented Apr 1, 2021

Update #1159

Add in support for <token> as a runtime "input" which is marked as a token.

Example nodegraph with token called mytoken which is marked as non-visible.

<?xml version="1.0"?>
<materialx version="1.38">
  <nodegraph name="Tokenized_graph" xpos="1044.25" ypos="852.077" >
    <token name="mytoken" type="color3" value="1, 1, 1" uivisible="false" uiname="My Token"/>
    <input name="value" type="color3" value="0, 0, 0" uivisible="false"/>
    <constant name="constant" type="color3" xpos="-136.498" ypos="-120.44">
      <input name="value" type="color3" interfacename="value" value="0, 0, 0" uivisible="true" />
    </constant>
    <output name="out" type="color3" nodename="constant" />
  </nodegraph>
  <collection name="defaultCollection" includecollection="" includegeom="/*" xpos="315" ypos="229" />
</materialx>

Would look like this graphically:
image

With the contents looking like this (token in "neon pink").
image

Based on the current specification <token> elements are not connectable.

Unit test will produce this file:

<?xml version="1.0"?>
<materialx version="1.38">
  <nodegraph name="nodegraph1">
    <input name="in" type="float" value="0" />
    <token name="token1" type="float" uniform="true" value="0" />
    <add name="add" type="float">
      <input name="in1" type="float" interfacename="in" value="0" />
    </add>
    <add name="add1" type="float">
      <input name="in1" type="float" nodename="add" />
    </add>
    <add name="add2" type="float" />
    <output name="out" type="float" nodename="add1" />
  </nodegraph>
  <add name="add" type="float">
    <input name="in1" type="float" nodegraph="nodegraph1" />
  </add>
</materialx>

@bernardkwok bernardkwok added this to the 1.39 milestone Apr 1, 2021
@bernardkwok bernardkwok added this to In progress in Develop via automation Apr 1, 2021
@bernardkwok bernardkwok added the Do Not Merge This PR should not be merged label Apr 1, 2021
@@ -39,6 +39,11 @@ PvtInput::PvtInput(const RtIdentifier& name, const RtIdentifier& type, uint32_t

bool PvtInput::isConnectable(const PvtOutput* output) const
{
if (isToken() || output->isToken())
Copy link
Author

Choose a reason for hiding this comment

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

Disallow connections.

@@ -148,6 +166,24 @@ class PvtInput : public PvtPort
}
}

bool isUIVisible() const
Copy link
Author

Choose a reason for hiding this comment

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

Wrote some wrappers for reuse.

@@ -901,7 +917,16 @@ namespace
for (PvtObject* obj : src->getInputs())
{
const PvtInput* input = obj->asA<PvtInput>();
ValueElementPtr destPort = destNodeDef->addInput(input->getName().str(), input->getType().str());
ValueElementPtr destPort = nullptr;
if (input->isToken())
Copy link
Author

Choose a reason for hiding this comment

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

File save.

@@ -200,6 +200,12 @@ namespace
const uint32_t flags = elem->asA<Input>()->getIsUniform() ? RtPortFlag::UNIFORM : 0;
port = schema.createInput(portName, portType, flags);
}
else if (elem->isA<Token>())
Copy link
Author

Choose a reason for hiding this comment

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

File read.

@@ -1299,20 +1300,35 @@ TEST_CASE("Runtime: FileIo NodeGraph", "[runtime]")
// Create a nodegraph.
mx::RtNodeGraph graph = stage->createPrim(mx::RtNodeGraph::typeName());
graph.createInput(IN, mx::RtType::FLOAT);
graph.createInput(TOKEN1, mx::RtType::FLOAT, mx::RtPortFlag::UNIFORM | mx::RtPortFlag::TOKEN);
Copy link
Author

Choose a reason for hiding this comment

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

Basic test for create and connectivity.

@bernardkwok bernardkwok removed the Do Not Merge This PR should not be merged label Apr 1, 2021
@bernardkwok bernardkwok self-assigned this Apr 1, 2021
@bernardkwok bernardkwok requested a review from feldstj April 1, 2021 19:03
@@ -487,7 +492,17 @@ namespace
if (!socket)
{
const RtIdentifier inputType(elem->getType());
RtInput input = nodegraph.createInput(socketName, inputType);

Copy link

Choose a reason for hiding this comment

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

Just a suggestion, but you could convert this into one or two lines if you wanted to:

const uint32_t flags = elem->isA() ? RtPortFlag::UNIFORM | RtPortFlag::TOKEN : 0;
RtInput input = nodegraph.createInput(socketName, inputType, flags);

or even:
RtInput input = nodegraph.createInput(socketName, inputType, elem->isA() ? RtPortFlag::UNIFORM | RtPortFlag::TOKEN : 0);

Copy link
Author

Choose a reason for hiding this comment

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

I can do the first. Bit too hard to read the second :).

v = destNodeGraph->addInput(nodegraphInput.getName().str(), nodegraphInput.getType().str());
if (nodegraphInput.isToken())
{
v = destNodeGraph->addToken(nodegraphInput.getName().str());
Copy link

Choose a reason for hiding this comment

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

Question out of curiousity. If addInput takes a type as a second parameter, shouldn't addToken as well so you don't need two lines to accomplish what could be done on one line?

Develop automation moved this from In progress to Reviewer approved Apr 7, 2021
@bernardkwok bernardkwok merged commit 43885e2 into adsk_contrib/dev Apr 7, 2021
Develop automation moved this from Reviewer approved to Done Apr 7, 2021
@bernardkwok bernardkwok deleted the adsk_contrib/token_runtime branch April 7, 2021 17:11
ashwinbhat pushed a commit that referenced this pull request Jan 4, 2023
This PR adds a tangent input to the glTF PBR, similar to how it's done in the standard surface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Develop
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants