+ 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

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