MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / initialize

Method initialize

source/MaterialXGenShader/ShaderNode.cpp:358–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358void ShaderNode::initialize(const Node& node, const NodeDef& nodeDef, GenContext& context)
359{
360 // Copy input values from the given node
361 for (InputPtr nodeInput : node.getActiveInputs())
362 {
363 ShaderInput* input = getInput(nodeInput->getName());
364 ValueElementPtr nodeDefInput = nodeDef.getActiveValueElement(nodeInput->getName());
365 if (input && nodeDefInput)
366 {
367 ValuePtr portValue = nodeInput->getResolvedValue();
368 if (!portValue)
369 {
370 InputPtr interfaceInput = nodeInput->getInterfaceInput();
371 if (interfaceInput)
372 {
373 portValue = interfaceInput->getResolvedValue();
374 }
375 }
376 const string& valueString = portValue ? portValue->getValueString() : EMPTY_STRING;
377 if (!valueString.empty())
378 {
379 // We explicitly check the valueString is not empty before checking the enumeration,
380 // because otherwise the enumeration value would always return nullptr
381 std::pair<TypeDesc, ValuePtr> enumResult;
382 const string& enumNames = nodeDefInput->getAttribute(ValueElement::ENUM_ATTRIBUTE);
383 const TypeDesc type = context.getTypeDesc(nodeDefInput->getType());
384 if (context.getShaderGenerator().getSyntax().remapEnumeration(valueString, type, enumNames, enumResult))
385 {
386 input->setValue(enumResult.second);
387 }
388 else
389 {
390 input->setValue(portValue);
391 }
392 }
393 }
394 }
395
396 // Set implementation specific values.
397 if (_impl)
398 {
399 _impl->setValues(node, *this, context);
400 }
401
402 // Set element paths for children on the node
403 for (const ValueElementPtr& nodeValue : node.getActiveValueElements())
404 {
405 ShaderInput* input = getInput(nodeValue->getName());
406 if (input)
407 {
408 string path = nodeValue->getNamePath();
409 InputPtr nodeInput = nodeValue->asA<Input>();
410 if (nodeInput)
411 {
412 InputPtr interfaceInput = nodeInput->getInterfaceInput();
413 if (interfaceInput)
414 {
415 path = interfaceInput->getNamePath();

Callers 2

getImplementationMethod · 0.45
createNodeMethod · 0.45

Calls 14

getActiveInputsMethod · 0.80
getActiveValueElementMethod · 0.80
getResolvedValueMethod · 0.80
getInterfaceInputMethod · 0.80
getNamePathMethod · 0.80
getInputFunction · 0.70
getNameMethod · 0.45
getValueStringMethod · 0.45
emptyMethod · 0.45
getTypeMethod · 0.45
remapEnumerationMethod · 0.45

Tested by

no test coverage detected