Skip to content

Commit

Permalink
+ fixes #1363: VRML export can produce corrupt files
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Dec 2, 2014
1 parent f5a4e68 commit 351ad4f
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Gui/SoFCDB.cpp
Expand Up @@ -90,6 +90,7 @@ void Gui::SoFCDB::init()
SoFCVectorizeU3DAction ::initClass();
SoHighlightElementAction ::initClass();
SoSelectionElementAction ::initClass();
SoVRMLAction ::initClass();
SoSkipBoundingGroup ::initClass();
SoTextLabel ::initClass();
SoStringLabel ::initClass();
Expand Down
43 changes: 43 additions & 0 deletions src/Gui/SoFCUnifiedSelection.cpp
Expand Up @@ -46,6 +46,7 @@
#include <Inventor/elements/SoElements.h>
#include <Inventor/elements/SoFontNameElement.h>
#include <Inventor/elements/SoFontSizeElement.h>
#include <Inventor/elements/SoMaterialBindingElement.h>
#include <Inventor/elements/SoModelMatrixElement.h>
#include <Inventor/elements/SoShapeStyleElement.h>
#include <Inventor/elements/SoProfileCoordinateElement.h>
Expand All @@ -58,6 +59,8 @@
#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/misc/SoState.h>
#include <Inventor/misc/SoChildList.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoMaterialBinding.h>
#include <Inventor/events/SoLocation2Event.h>
#include <Inventor/SoPickedPoint.h>

Expand Down Expand Up @@ -682,3 +685,43 @@ const SoDetail* SoSelectionElementAction::getElement() const
{
return this->_det;
}

// ---------------------------------------------------------------

SO_ACTION_SOURCE(SoVRMLAction);

void SoVRMLAction::initClass()
{
SO_ACTION_INIT_CLASS(SoVRMLAction,SoAction);

SO_ENABLE(SoVRMLAction, SoSwitchElement);

SO_ACTION_ADD_METHOD(SoNode,nullAction);

SO_ENABLE(SoVRMLAction, SoCoordinateElement);
SO_ENABLE(SoVRMLAction, SoMaterialBindingElement);
SO_ENABLE(SoVRMLAction, SoLazyElement);
SO_ENABLE(SoVRMLAction, SoShapeStyleElement);

SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
SO_ACTION_ADD_METHOD(SoMaterialBinding,callDoAction);
SO_ACTION_ADD_METHOD(SoMaterial,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()
{
SO_ACTION_CONSTRUCTOR(SoVRMLAction);
}

SoVRMLAction::~SoVRMLAction()
{
}

void SoVRMLAction::callDoAction(SoAction *action,SoNode *node)
{
node->doAction(action);
}
18 changes: 18 additions & 0 deletions src/Gui/SoFCUnifiedSelection.h
Expand Up @@ -177,6 +177,24 @@ class GuiExport SoSelectionElementAction : public SoAction
const SoDetail* _det;
};

/**
* @author Werner Mayer
*/
class GuiExport SoVRMLAction : public SoAction
{
SO_ACTION_HEADER(SoVRMLAction);

public:
SoVRMLAction();
~SoVRMLAction();

static void initClass();

private:
static void callDoAction(SoAction *action,SoNode *node);

};


} // namespace Gui

Expand Down
2 changes: 2 additions & 0 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -1041,6 +1041,8 @@ bool View3DInventorViewer::dumpToFile(const char* filename, bool binary) const
if (fi.hasExtension("wrz"))
binary = true;

SoVRMLAction vrml2;
vrml2.apply(pcViewProviderRoot);
SoToVRML2Action tovrml2;
tovrml2.apply(pcViewProviderRoot);
SoVRMLGroup* vrmlRoot = tovrml2.getVRML2SceneGraph();
Expand Down
30 changes: 30 additions & 0 deletions src/Mod/Part/Gui/SoBrepFaceSet.cpp
Expand Up @@ -44,6 +44,7 @@
# include <Inventor/actions/SoWriteAction.h>
# include <Inventor/bundles/SoMaterialBundle.h>
# include <Inventor/bundles/SoTextureCoordinateBundle.h>
# include <Inventor/elements/SoLazyElement.h>
# include <Inventor/elements/SoOverrideElement.h>
# include <Inventor/elements/SoCoordinateElement.h>
# include <Inventor/elements/SoGLCoordinateElement.h>
Expand Down Expand Up @@ -148,6 +149,35 @@ void SoBrepFaceSet::doAction(SoAction* action)
}
}
}
else if (action->getTypeId() == Gui::SoVRMLAction::getClassTypeId()) {
// update the materialIndex field to match with the number of triangles if needed
SoState * state = action->getState();
Binding mbind = this->findMaterialBinding(state);
if (mbind == PER_PART) {
const SoLazyElement* mat = SoLazyElement::getInstance(state);
int numColor = 1;
int numParts = partIndex.getNum();
if (mat) {
numColor = mat->getNumDiffuse();
if (numColor == numParts) {
int count = 0;
const int32_t * indices = this->partIndex.getValues(0);
for (int i=0; i<numParts; i++) {
count += indices[i];
}
this->materialIndex.setNum(count);
int32_t * matind = this->materialIndex.startEditing();
int32_t k = 0;
for (int i=0; i<numParts; i++) {
for (int j=0; j<indices[i]; j++) {
matind[k++] = i;
}
}
this->materialIndex.finishEditing();
}
}
}
}

inherited::doAction(action);
}
Expand Down

0 comments on commit 351ad4f

Please sign in to comment.