+ fixes #0001363: VRML export can produce corrupt files
This commit is contained in:
parent
f5a4e68068
commit
351ad4f6c7
|
@ -90,6 +90,7 @@ void Gui::SoFCDB::init()
|
||||||
SoFCVectorizeU3DAction ::initClass();
|
SoFCVectorizeU3DAction ::initClass();
|
||||||
SoHighlightElementAction ::initClass();
|
SoHighlightElementAction ::initClass();
|
||||||
SoSelectionElementAction ::initClass();
|
SoSelectionElementAction ::initClass();
|
||||||
|
SoVRMLAction ::initClass();
|
||||||
SoSkipBoundingGroup ::initClass();
|
SoSkipBoundingGroup ::initClass();
|
||||||
SoTextLabel ::initClass();
|
SoTextLabel ::initClass();
|
||||||
SoStringLabel ::initClass();
|
SoStringLabel ::initClass();
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include <Inventor/elements/SoElements.h>
|
#include <Inventor/elements/SoElements.h>
|
||||||
#include <Inventor/elements/SoFontNameElement.h>
|
#include <Inventor/elements/SoFontNameElement.h>
|
||||||
#include <Inventor/elements/SoFontSizeElement.h>
|
#include <Inventor/elements/SoFontSizeElement.h>
|
||||||
|
#include <Inventor/elements/SoMaterialBindingElement.h>
|
||||||
#include <Inventor/elements/SoModelMatrixElement.h>
|
#include <Inventor/elements/SoModelMatrixElement.h>
|
||||||
#include <Inventor/elements/SoShapeStyleElement.h>
|
#include <Inventor/elements/SoShapeStyleElement.h>
|
||||||
#include <Inventor/elements/SoProfileCoordinateElement.h>
|
#include <Inventor/elements/SoProfileCoordinateElement.h>
|
||||||
|
@ -58,6 +59,8 @@
|
||||||
#include <Inventor/events/SoMouseButtonEvent.h>
|
#include <Inventor/events/SoMouseButtonEvent.h>
|
||||||
#include <Inventor/misc/SoState.h>
|
#include <Inventor/misc/SoState.h>
|
||||||
#include <Inventor/misc/SoChildList.h>
|
#include <Inventor/misc/SoChildList.h>
|
||||||
|
#include <Inventor/nodes/SoMaterial.h>
|
||||||
|
#include <Inventor/nodes/SoMaterialBinding.h>
|
||||||
#include <Inventor/events/SoLocation2Event.h>
|
#include <Inventor/events/SoLocation2Event.h>
|
||||||
#include <Inventor/SoPickedPoint.h>
|
#include <Inventor/SoPickedPoint.h>
|
||||||
|
|
||||||
|
@ -682,3 +685,43 @@ const SoDetail* SoSelectionElementAction::getElement() const
|
||||||
{
|
{
|
||||||
return this->_det;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -177,6 +177,24 @@ private:
|
||||||
const SoDetail* _det;
|
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
|
} // namespace Gui
|
||||||
|
|
||||||
|
|
|
@ -1041,6 +1041,8 @@ bool View3DInventorViewer::dumpToFile(const char* filename, bool binary) const
|
||||||
if (fi.hasExtension("wrz"))
|
if (fi.hasExtension("wrz"))
|
||||||
binary = true;
|
binary = true;
|
||||||
|
|
||||||
|
SoVRMLAction vrml2;
|
||||||
|
vrml2.apply(pcViewProviderRoot);
|
||||||
SoToVRML2Action tovrml2;
|
SoToVRML2Action tovrml2;
|
||||||
tovrml2.apply(pcViewProviderRoot);
|
tovrml2.apply(pcViewProviderRoot);
|
||||||
SoVRMLGroup* vrmlRoot = tovrml2.getVRML2SceneGraph();
|
SoVRMLGroup* vrmlRoot = tovrml2.getVRML2SceneGraph();
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
# include <Inventor/actions/SoWriteAction.h>
|
# include <Inventor/actions/SoWriteAction.h>
|
||||||
# include <Inventor/bundles/SoMaterialBundle.h>
|
# include <Inventor/bundles/SoMaterialBundle.h>
|
||||||
# include <Inventor/bundles/SoTextureCoordinateBundle.h>
|
# include <Inventor/bundles/SoTextureCoordinateBundle.h>
|
||||||
|
# include <Inventor/elements/SoLazyElement.h>
|
||||||
# include <Inventor/elements/SoOverrideElement.h>
|
# include <Inventor/elements/SoOverrideElement.h>
|
||||||
# include <Inventor/elements/SoCoordinateElement.h>
|
# include <Inventor/elements/SoCoordinateElement.h>
|
||||||
# include <Inventor/elements/SoGLCoordinateElement.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);
|
inherited::doAction(action);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user