-
Notifications
You must be signed in to change notification settings - Fork 23
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
Runtime token support #1157
Changes from all commits
10ec57a
ec7183b
d1a5891
0631811
48aac55
f5493c2
a8d4acb
0fd6a92
c5f6a6e
cf0e537
729cd54
f14690a
2f1ed65
099aafd
9f9daa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
#include <MaterialXRuntime/RtValue.h> | ||
#include <MaterialXRuntime/RtTypeDef.h> | ||
#include <MaterialXRuntime/RtTraversal.h> | ||
#include <MaterialXRuntime/Identifiers.h> | ||
|
||
/// @file | ||
/// TODO: Docs | ||
|
@@ -106,6 +107,23 @@ class PvtPort : public PvtObject | |
attr->asIdentifier() = unit; | ||
} | ||
|
||
bool isToken() const | ||
{ | ||
return (_flags & RtPortFlag::TOKEN) != 0; | ||
} | ||
|
||
void setIsToken(bool val) | ||
{ | ||
if (val) | ||
{ | ||
_flags |= RtPortFlag::TOKEN; | ||
} | ||
else | ||
{ | ||
_flags &= ~RtPortFlag::TOKEN; | ||
} | ||
} | ||
|
||
static const RtIdentifier DEFAULT_OUTPUT_NAME; | ||
static const RtIdentifier COLOR_SPACE; | ||
static const RtIdentifier UNIT; | ||
|
@@ -148,6 +166,24 @@ class PvtInput : public PvtPort | |
} | ||
} | ||
|
||
bool isUIVisible() const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrote some wrappers for reuse. |
||
{ | ||
// For now since connections require ports to be created and hence visible | ||
// always assume a connection means visible. | ||
if (isConnected()) | ||
{ | ||
return true; | ||
} | ||
const RtTypedValue* attr = getAttribute(Identifiers::UIVISIBLE, RtType::BOOLEAN); | ||
return attr ? attr->asBool() : true; | ||
} | ||
|
||
void setIsUIVisible(bool val) | ||
{ | ||
RtTypedValue* attr = createAttribute(Identifiers::UIVISIBLE, RtType::BOOLEAN); | ||
attr->asBool() = val; | ||
} | ||
|
||
bool isConnected() const | ||
{ | ||
return _connection != nullptr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,11 @@ namespace | |
const uint32_t flags = elem->asA<Input>()->getIsUniform() ? RtPortFlag::UNIFORM : 0; | ||
port = schema.createInput(portName, portType, flags); | ||
} | ||
else if (elem->isA<Token>()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File read. |
||
{ | ||
const uint32_t flags = RtPortFlag::UNIFORM | RtPortFlag::TOKEN; | ||
port = schema.createInput(portName, portType, flags); | ||
} | ||
|
||
if (port) | ||
{ | ||
|
@@ -487,7 +492,9 @@ namespace | |
if (!socket) | ||
{ | ||
const RtIdentifier inputType(elem->getType()); | ||
RtInput input = nodegraph.createInput(socketName, inputType); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; or even: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do the first. Bit too hard to read the second :). |
||
const uint32_t flags = elem->isA<Token>() ? RtPortFlag::UNIFORM | RtPortFlag::TOKEN : 0; | ||
RtInput input = nodegraph.createInput(socketName, inputType, flags); | ||
socket = nodegraph.getInputSocket(input.getName()); | ||
|
||
// Set the input value | ||
|
@@ -901,7 +908,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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File save. |
||
{ | ||
destPort = destNodeDef->addToken(input->getName().str()); | ||
destPort->setType(input->getType().str()); | ||
} | ||
else | ||
{ | ||
destPort = destNodeDef->addInput(input->getName().str(), input->getType().str()); | ||
} | ||
if (input->isUniform()) | ||
{ | ||
destPort->setIsUniform(true); | ||
|
@@ -941,10 +957,8 @@ namespace | |
RtInput input = node.getInput(i); | ||
if (input) | ||
{ | ||
const RtTypedValue* uiVisible1 = input.getAttribute(Identifiers::UIVISIBLE, RtType::BOOLEAN); | ||
const RtTypedValue* uiVisible2 = nodedefInput.getAttribute(Identifiers::UIVISIBLE, RtType::BOOLEAN); | ||
const bool uiHidden1 = uiVisible1 && !uiVisible1->asBool(); | ||
const bool uiHidden2 = uiVisible2 && !uiVisible2->asBool(); | ||
const bool uiHidden1 = input.isUIVisible(); | ||
const bool uiHidden2 = nodedefInput.isUIVisible(); | ||
const bool writeUiVisibleData = uiHidden1 != uiHidden2; | ||
|
||
// Write input if it's connected or different from default value. | ||
|
@@ -955,7 +969,15 @@ namespace | |
ValueElementPtr valueElem; | ||
if (input.isUniform()) | ||
{ | ||
valueElem = destNode->addInput(input.getName().str(), input.getType().str()); | ||
if (input.isToken()) | ||
{ | ||
valueElem = destNode->addToken(input.getName().str()); | ||
valueElem->setType(input.getType().str()); | ||
} | ||
else | ||
{ | ||
valueElem = destNode->addInput(input.getName().str(), input.getType().str()); | ||
} | ||
valueElem->setIsUniform(true); | ||
if (input.isConnected()) | ||
{ | ||
|
@@ -1049,7 +1071,15 @@ namespace | |
ValueElementPtr v = nullptr; | ||
if (nodegraphInput.isUniform()) | ||
{ | ||
v = destNodeGraph->addInput(nodegraphInput.getName().str(), nodegraphInput.getType().str()); | ||
if (nodegraphInput.isToken()) | ||
{ | ||
v = destNodeGraph->addToken(nodegraphInput.getName().str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
v->setType(nodegraphInput.getType().str()); | ||
} | ||
else | ||
{ | ||
v = destNodeGraph->addInput(nodegraphInput.getName().str(), nodegraphInput.getType().str()); | ||
} | ||
v->setIsUniform(true); | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ namespace | |
} | ||
}; | ||
|
||
// Commonly used tokens. | ||
// Commonly used identifiers. | ||
const mx::RtIdentifier X("x"); | ||
const mx::RtIdentifier Y("y"); | ||
const mx::RtIdentifier Z("z"); | ||
|
@@ -95,6 +95,7 @@ namespace | |
const mx::RtIdentifier IN3("in3"); | ||
const mx::RtIdentifier OUT("out"); | ||
const mx::RtIdentifier IN("in"); | ||
const mx::RtIdentifier TOKEN1("token1"); | ||
const mx::RtIdentifier REFLECTIVITY("reflectivity"); | ||
const mx::RtIdentifier SURFACESHADER("surfaceshader"); | ||
const mx::RtIdentifier UIFOLDER("uifolder"); | ||
|
@@ -156,7 +157,7 @@ TEST_CASE("Runtime: Material Element Upgrade", "[runtime]") | |
} | ||
} | ||
|
||
TEST_CASE("Runtime: Token", "[runtime]") | ||
TEST_CASE("Runtime: Identifiers", "[runtime]") | ||
{ | ||
mx::RtIdentifier tok1("hej"); | ||
mx::RtIdentifier tok2("hey"); | ||
|
@@ -1299,20 +1300,36 @@ 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basic test for create and connectivity. |
||
graph.createOutput(OUT, mx::RtType::FLOAT); | ||
mx::RtInput graphIn = graph.getInput(IN); | ||
REQUIRE(graphIn.isUIVisible()); | ||
graphIn.setIsUIVisible(false); | ||
REQUIRE(!graphIn.isUIVisible()); | ||
mx::RtInput graphToken = graph.getInput(TOKEN1); | ||
REQUIRE(graphToken.isUniform()); | ||
mx::RtOutput graphOut = graph.getOutput(OUT); | ||
mx::RtOutput graphInSocket = graph.getInputSocket(IN); | ||
mx::RtOutput graphTokenSocket = graph.getInputSocket(TOKEN1); | ||
mx::RtInput graphOutSocket = graph.getOutputSocket(OUT); | ||
REQUIRE(graphIn); | ||
REQUIRE(graphToken); | ||
REQUIRE(graphOut); | ||
REQUIRE(graphInSocket); | ||
REQUIRE(graphTokenSocket); | ||
REQUIRE(graphOutSocket); | ||
|
||
// Add nodes to the graph. | ||
const mx::RtIdentifier ADD_FLOAT_NODEDEF("ND_add_float"); | ||
mx::RtNode add1 = stage->createPrim(graph.getPath(), NONAME, ADD_FLOAT_NODEDEF); | ||
mx::RtNode add2 = stage->createPrim(graph.getPath(), NONAME, ADD_FLOAT_NODEDEF); | ||
try { | ||
graphTokenSocket.connect(add1.getInput(IN1)); | ||
} | ||
catch (mx::Exception&) | ||
{ | ||
} | ||
REQUIRE(!graphTokenSocket.isConnected()); | ||
graphInSocket.connect(add1.getInput(IN1)); | ||
add1.getOutput(OUT).connect(add2.getInput(IN1)); | ||
add2.getOutput(OUT).connect(graphOutSocket); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disallow connections.