From 976867e719c5b016e158cc5612936227c9ce1757 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 8 Sep 2020 14:35:29 +0200 Subject: [PATCH] Gui: [skip ci] set crease angle if possible when exporting to x3d/xhtml --- src/Gui/SoFCDB.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 5079d2cd2cd2..9fe24ad55b08 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -35,6 +35,9 @@ #endif #include +#include +#include +#include #include #include @@ -466,6 +469,33 @@ bool Gui::SoFCDB::writeToX3D(SoNode* node, bool exportViewpoints, std::string& b vrmlRoot->setInstancePrefix(SbString("o")); vrmlRoot->ref(); + // Search for SoVRMLIndexedFaceSet nodes and set creaseAngle to 0.5 + { + SoSearchAction sa; + sa.setType(SoVRMLShape::getClassTypeId()); + sa.setInterest(SoSearchAction::ALL); + sa.setSearchingAll(true); + sa.apply(vrmlRoot); + SoPathList& paths = sa.getPaths(); + for (int i=0; i(path->getTail()); + SoNode* geom = shape->geometry.getValue(); + if (geom && geom->getTypeId() == SoVRMLIndexedFaceSet::getClassTypeId()) { + SoNode* norm = static_cast(geom)->normal.getValue(); + if (norm && norm->getTypeId() == SoVRMLNormal::getClassTypeId()) { + // if empty then nullify the normal field node + if (static_cast(norm)->vector.getNum() == 0) + static_cast(geom)->normal.setValue(nullptr); + } + else { + static_cast(geom)->creaseAngle.setValue(0.5f); + } + } + } + sa.reset(); // clear the internal cache + } + std::stringstream out; writeX3D(vrmlRoot, exportViewpoints, out); buffer = out.str(); @@ -562,6 +592,9 @@ void Gui::SoFCDB::writeX3DFields(SoNode* node, std::map& n void Gui::SoFCDB::writeX3DChild(SoNode* node, std::map& nodeMap, int& numDEF, int spaces, std::ostream& out) { + if (!node) + return; + // check if the node is already used auto mapIt = nodeMap.find(node); if (mapIt == nodeMap.end()) { @@ -588,7 +621,7 @@ void Gui::SoFCDB::writeX3D(SoVRMLGroup* node, bool exportViewpoints, std::ostrea " \n"; std::map nodeMap; - out << "\n"; + out << " \n"; // compute a sensible view point SoGetBoundingBoxAction bboxAction(SbViewportRegion(1280, 1024)); @@ -605,7 +638,7 @@ void Gui::SoFCDB::writeX3D(SoVRMLGroup* node, bool exportViewpoints, std::ostrea const SbVec3f& pos, const SbRotation& rot) { SbVec3f axis; float angle; rot.getValue(axis, angle); - out << " \n"; + writeX3DFields(node, nodeMap, true, numDEF, 4, out); + out << " \n"; out << "\n"; }