+ fixes #0001363: VRML export can produce corrupt files

This commit is contained in:
wmayer 2014-12-02 15:40:36 +01:00
parent f5a4e68068
commit 351ad4f6c7
5 changed files with 94 additions and 0 deletions

View File

@ -90,6 +90,7 @@ void Gui::SoFCDB::init()
SoFCVectorizeU3DAction ::initClass();
SoHighlightElementAction ::initClass();
SoSelectionElementAction ::initClass();
SoVRMLAction ::initClass();
SoSkipBoundingGroup ::initClass();
SoTextLabel ::initClass();
SoStringLabel ::initClass();

View File

@ -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>
@ -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>
@ -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);
}

View File

@ -177,6 +177,24 @@ private:
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

View File

@ -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();

View File

@ -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>
@ -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);
}