From c135ca40a5d797941a59701f04a9581e14fe9f88 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 14 Sep 2015 14:45:34 +0200 Subject: [PATCH] + fixes #0002222: Number of normals in exported VRML is wrong --- src/Gui/SoFCDB.cpp | 5 +++++ src/Gui/SoFCUnifiedSelection.cpp | 32 ++++++++++++++++++++++++++++++-- src/Gui/SoFCUnifiedSelection.h | 5 +++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 87a4541d2..4c7a4ebdc 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -211,6 +211,7 @@ const std::string& Gui::SoFCDB::writeNodesToString(SoNode * root) bool Gui::SoFCDB::writeToVRML(SoNode* node, const char* filename, bool binary) { SoVRMLAction vrml2; + vrml2.setOverrideMode(true); vrml2.apply(node); SoToVRML2Action tovrml2; tovrml2.apply(node); @@ -219,6 +220,10 @@ bool Gui::SoFCDB::writeToVRML(SoNode* node, const char* filename, bool binary) std::string buffer = SoFCDB::writeNodesToString(vrmlRoot); vrmlRoot->unref(); // release the memory as soon as possible + // restore old settings + vrml2.setOverrideMode(false); + vrml2.apply(node); + Base::FileInfo fi(filename); if (binary) { // We want to write compressed VRML but Coin 2.4.3 doesn't do it even though diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index 8b11f065d..0834d8d00 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -704,13 +705,14 @@ void SoVRMLAction::initClass() SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction); SO_ACTION_ADD_METHOD(SoMaterialBinding,callDoAction); SO_ACTION_ADD_METHOD(SoMaterial,callDoAction); + SO_ACTION_ADD_METHOD(SoNormalBinding,callDoAction); SO_ACTION_ADD_METHOD(SoGroup,callDoAction); SO_ACTION_ADD_METHOD(SoIndexedLineSet,callDoAction); SO_ACTION_ADD_METHOD(SoIndexedFaceSet,callDoAction); SO_ACTION_ADD_METHOD(SoPointSet,callDoAction); } -SoVRMLAction::SoVRMLAction() +SoVRMLAction::SoVRMLAction() : overrideMode(true) { SO_ACTION_CONSTRUCTOR(SoVRMLAction); } @@ -719,7 +721,33 @@ SoVRMLAction::~SoVRMLAction() { } -void SoVRMLAction::callDoAction(SoAction *action,SoNode *node) +void SoVRMLAction::setOverrideMode(SbBool on) { + overrideMode = on; +} + +SbBool SoVRMLAction::isOverrideMode() const +{ + return overrideMode; +} + +void SoVRMLAction::callDoAction(SoAction *action, SoNode *node) +{ + if (node->getTypeId().isDerivedFrom(SoNormalBinding::getClassTypeId()) && action->isOfType(SoVRMLAction::getClassTypeId())) { + SoVRMLAction* vrmlAction = static_cast(action); + if (vrmlAction->overrideMode) { + SoNormalBinding* bind = static_cast(node); + vrmlAction->bindList.push_back(bind->value.getValue()); + // this normal binding causes some problems for the part view provider + // See also #0002222: Number of normals in exported VRML is wrong + if (bind->value.getValue() == static_cast(SoNormalBinding::PER_VERTEX_INDEXED)) + bind->value = SoNormalBinding::OVERALL; + } + else if (!vrmlAction->bindList.empty()) { + static_cast(node)->value = static_cast(vrmlAction->bindList.front()); + vrmlAction->bindList.pop_front(); + } + } + node->doAction(action); } diff --git a/src/Gui/SoFCUnifiedSelection.h b/src/Gui/SoFCUnifiedSelection.h index aab5158db..4e3cf69fd 100644 --- a/src/Gui/SoFCUnifiedSelection.h +++ b/src/Gui/SoFCUnifiedSelection.h @@ -40,6 +40,7 @@ #include #include #include "View3DInventorViewer.h" +#include class SoFullPath; class SoPickedPoint; @@ -187,10 +188,14 @@ class GuiExport SoVRMLAction : public SoAction public: SoVRMLAction(); ~SoVRMLAction(); + void setOverrideMode(SbBool); + SbBool isOverrideMode() const; static void initClass(); private: + SbBool overrideMode; + std::list bindList; static void callDoAction(SoAction *action,SoNode *node); };