@@ -1316,30 +1316,59 @@ void Document::upgradeVersion()
13161316 }
13171317 else if (nodeCategory == " normalmap" )
13181318 {
1319- // Handle a rename of the float-typed nodedef.
1320- if (node-> getNodeDefString () == " ND_normalmap " )
1319+ InputPtr space = node-> getInput ( " space " );
1320+ if (space && space-> getValueString () == " object " )
13211321 {
1322- node->setNodeDefString (" ND_normalmap_float" );
1323- }
1324-
1325- node->removeInput (" space" );
1322+ // Replace object-space normalmap with a graph.
1323+ GraphElementPtr graph = node->getAncestorOfType <GraphElement>();
1324+ NodePtr multiply = graph->addNode (" multiply" , graph->createValidChildName (" multiply" ), " vector3" );
1325+ copyInputWithBindings (node, " in" , multiply, " in1" );
1326+ multiply->setInputValue (" in2" , 2 .0f );
1327+ NodePtr subtract = graph->addNode (" subtract" , graph->createValidChildName (" subtract" ), " vector3" );
1328+ subtract->addInput (" in1" , " vector3" )->setConnectedNode (multiply);
1329+ subtract->setInputValue (" in2" , 1 .0f );
1330+ node->setCategory (" normalize" );
1331+ vector<InputPtr> origInputs = node->getInputs ();
1332+ for (InputPtr input : origInputs)
1333+ {
1334+ node->removeChild (input->getName ());
1335+ }
1336+ node->addInput (" in" , " vector3" )->setConnectedNode (subtract);
13261337
1327- // If the normal or tangent inputs are set and the bitangent input is not,
1328- // the bitangent should be set to normalize(cross(N, T))
1329- InputPtr normalInput = node->getInput (" normal" );
1330- InputPtr tangentInput = node->getInput (" tangent" );
1331- InputPtr bitangentInput = node->getInput (" bitangent" );
1332- if ((normalInput || tangentInput) && !bitangentInput)
1338+ // Update nodedef name if present.
1339+ if (node->hasNodeDefString ())
1340+ {
1341+ node->setNodeDefString (" ND_normalize_vector3" );
1342+ }
1343+ }
1344+ else
13331345 {
1334- GraphElementPtr graph = node->getAncestorOfType <GraphElement>();
1335- NodePtr crossNode = graph->addNode (" crossproduct" , graph->createValidChildName (" normalmap_cross" ), " vector3" );
1336- copyInputWithBindings (node, " normal" , crossNode, " in1" );
1337- copyInputWithBindings (node, " tangent" , crossNode, " in2" );
1346+ // Clear tangent-space input.
1347+ node->removeInput (" space" );
1348+
1349+ // If the normal or tangent inputs are set and the bitangent input is not,
1350+ // the bitangent should be set to normalize(cross(N, T))
1351+ InputPtr normalInput = node->getInput (" normal" );
1352+ InputPtr tangentInput = node->getInput (" tangent" );
1353+ InputPtr bitangentInput = node->getInput (" bitangent" );
1354+ if ((normalInput || tangentInput) && !bitangentInput)
1355+ {
1356+ GraphElementPtr graph = node->getAncestorOfType <GraphElement>();
1357+ NodePtr crossNode = graph->addNode (" crossproduct" , graph->createValidChildName (" normalmap_cross" ), " vector3" );
1358+ copyInputWithBindings (node, " normal" , crossNode, " in1" );
1359+ copyInputWithBindings (node, " tangent" , crossNode, " in2" );
13381360
1339- NodePtr normalizeNode = graph->addNode (" normalize" , graph->createValidChildName (" normalmap_cross_norm" ), " vector3" );
1340- normalizeNode->addInput (" in" , " vector3" )->setConnectedNode (crossNode);
1361+ NodePtr normalizeNode = graph->addNode (" normalize" , graph->createValidChildName (" normalmap_cross_norm" ), " vector3" );
1362+ normalizeNode->addInput (" in" , " vector3" )->setConnectedNode (crossNode);
13411363
1342- node->addInput (" bitangent" , " vector3" )->setConnectedNode (normalizeNode);
1364+ node->addInput (" bitangent" , " vector3" )->setConnectedNode (normalizeNode);
1365+ }
1366+
1367+ // Update nodedef name if present.
1368+ if (node->getNodeDefString () == " ND_normalmap" )
1369+ {
1370+ node->setNodeDefString (" ND_normalmap_float" );
1371+ }
13431372 }
13441373 }
13451374 }
0 commit comments