+ fix rendering problems for FEM elements

This commit is contained in:
wmayer 2015-04-13 22:11:27 +02:00
parent 1c79de55ed
commit 2dc1890fd2
4 changed files with 52 additions and 43 deletions

View File

@ -72,12 +72,9 @@ ViewProviderFemConstraint::ViewProviderFemConstraint()
pTextColor = new SoBaseColor(); pTextColor = new SoBaseColor();
pTextColor->ref(); pTextColor->ref();
pMaterials = new SoMaterial(); pMaterials = new SoBaseColor();
pMaterials->ref(); pMaterials->ref();
pMaterials->diffuseColor.setValue(1.0f, 0.0f, 0.2f); pMaterials->rgb.setValue(1.0f, 0.0f, 0.2f);
pMaterials->transparency.setValue(0.1f);
//pMaterials->ambientColor.setValue(0.8f, 0.8f, 0.8f);
//pMaterials->shininess.setValue(1.0);
pShapeSep = new SoSeparator(); pShapeSep = new SoSeparator();
pShapeSep->ref(); pShapeSep->ref();
@ -157,7 +154,7 @@ void ViewProviderFemConstraint::onChanged(const App::Property* prop)
} }
else if (prop == &FaceColor) { else if (prop == &FaceColor) {
const App::Color& c = FaceColor.getValue(); const App::Color& c = FaceColor.getValue();
pMaterials->diffuseColor.setValue(c.r,c.g,c.b); pMaterials->rgb.setValue(c.r,c.g,c.b);
} }
else if (prop == &FontSize) { else if (prop == &FontSize) {
pFont->size = FontSize.getValue(); pFont->size = FontSize.getValue();

View File

@ -102,7 +102,7 @@ private:
SoFontStyle * pFont; SoFontStyle * pFont;
SoText2 * pLabel; SoText2 * pLabel;
SoBaseColor * pTextColor; SoBaseColor * pTextColor;
SoMaterial * pMaterials; SoBaseColor * pMaterials;
protected: protected:
SoSeparator * pShapeSep; SoSeparator * pShapeSep;

View File

@ -107,24 +107,22 @@ bool ViewProviderFemConstraintFixed::setEdit(int ModNum)
#define HEIGHT 4 #define HEIGHT 4
#define WIDTH (1.5*HEIGHT) #define WIDTH (1.5*HEIGHT)
#define USE_MULTIPLE_COPY
void ViewProviderFemConstraintFixed::updateData(const App::Property* prop) void ViewProviderFemConstraintFixed::updateData(const App::Property* prop)
{ {
// Gets called whenever a property of the attached object changes // Gets called whenever a property of the attached object changes
Fem::ConstraintFixed* pcConstraint = static_cast<Fem::ConstraintFixed*>(this->getObject()); Fem::ConstraintFixed* pcConstraint = static_cast<Fem::ConstraintFixed*>(this->getObject());
/* #ifdef USE_MULTIPLE_COPY
// This has a HUGE performance penalty as opposed to separate nodes for every symbol
// The problem seems to be SoCone
if (pShapeSep->getNumChildren() == 0) { if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes // Set up the nodes
SoMultipleCopy* cp = new SoMultipleCopy(); SoMultipleCopy* cp = new SoMultipleCopy();
cp->ref();
cp->matrix.setNum(0); cp->matrix.setNum(0);
cp->addChild((SoNode*)createFixed(HEIGHT, WIDTH)); cp->addChild((SoNode*)createFixed(HEIGHT, WIDTH));
pShapeSep->addChild(cp); pShapeSep->addChild(cp);
} }
*/ #endif
if (strcmp(prop->getName(),"Points") == 0) { if (strcmp(prop->getName(),"Points") == 0) {
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues(); const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
@ -133,32 +131,36 @@ void ViewProviderFemConstraintFixed::updateData(const App::Property* prop)
return; return;
std::vector<Base::Vector3d>::const_iterator n = normals.begin(); std::vector<Base::Vector3d>::const_iterator n = normals.begin();
// Note: Points and Normals are always updated together #ifdef USE_MULTIPLE_COPY
pShapeSep->removeAllChildren();
/*
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0)); SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
cp->matrix.setNum(points.size()); cp->matrix.setNum(points.size());
SbMatrix* matrices = cp->matrix.startEditing();
int idx = 0; int idx = 0;
*/ #else
// Note: Points and Normals are always updated together
pShapeSep->removeAllChildren();
#endif
for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) { for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) {
SbVec3f base(p->x, p->y, p->z); SbVec3f base(p->x, p->y, p->z);
SbVec3f dir(n->x, n->y, n->z); SbVec3f dir(n->x, n->y, n->z);
SbRotation rot(SbVec3f(0,-1,0), dir); SbRotation rot(SbVec3f(0,-1,0), dir);
/* #ifdef USE_MULTIPLE_COPY
SbMatrix m; SbMatrix m;
m.setTransform(base, rot, SbVec3f(1,1,1)); m.setTransform(base, rot, SbVec3f(1,1,1));
cp->matrix.set1Value(idx, m); matrices[idx] = m;
idx++ idx++;
*/ #else
SoSeparator* sep = new SoSeparator(); SoSeparator* sep = new SoSeparator();
createPlacement(sep, base, rot); createPlacement(sep, base, rot);
createFixed(sep, HEIGHT, WIDTH); createFixed(sep, HEIGHT, WIDTH);
pShapeSep->addChild(sep); pShapeSep->addChild(sep);
#endif
n++; n++;
} }
#ifdef USE_MULTIPLE_COPY
cp->matrix.finishEditing();
#endif
} }
ViewProviderFemConstraint::updateData(prop); ViewProviderFemConstraint::updateData(prop);

View File

@ -106,15 +106,14 @@ bool ViewProviderFemConstraintForce::setEdit(int ModNum)
#define ARROWLENGTH 9 #define ARROWLENGTH 9
#define ARROWHEADRADIUS (ARROWLENGTH/3) #define ARROWHEADRADIUS (ARROWLENGTH/3)
#define USE_MULTIPLE_COPY
void ViewProviderFemConstraintForce::updateData(const App::Property* prop) void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
{ {
// Gets called whenever a property of the attached object changes // Gets called whenever a property of the attached object changes
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject()); Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject());
/* #ifdef USE_MULTIPLE_COPY
// This has a HUGE performance penalty as opposed to separate nodes for every symbol
// The problem seems to be SoCone
if (pShapeSep->getNumChildren() == 0) { if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes // Set up the nodes
SoMultipleCopy* cp = new SoMultipleCopy(); SoMultipleCopy* cp = new SoMultipleCopy();
@ -123,12 +122,20 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS)); cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS));
pShapeSep->addChild(cp); pShapeSep->addChild(cp);
} }
*/ #endif
if (strcmp(prop->getName(),"Points") == 0) { if (strcmp(prop->getName(),"Points") == 0) {
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
#ifdef USE_MULTIPLE_COPY
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
cp->matrix.setNum(points.size());
SbMatrix* matrices = cp->matrix.startEditing();
int idx = 0;
#else
// Redraw all arrows // Redraw all arrows
pShapeSep->removeAllChildren(); pShapeSep->removeAllChildren();
#endif
// This should always point outside of the solid // This should always point outside of the solid
Base::Vector3d normal = pcConstraint->NormalDirection.getValue(); Base::Vector3d normal = pcConstraint->NormalDirection.getValue();
@ -140,29 +147,27 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
SbVec3f dir(forceDirection.x, forceDirection.y, forceDirection.z); SbVec3f dir(forceDirection.x, forceDirection.y, forceDirection.z);
SbRotation rot(SbVec3f(0,1,0), dir); SbRotation rot(SbVec3f(0,1,0), dir);
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
/*
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
cp->matrix.setNum(points.size());
int idx = 0;*/
for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) { for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) {
SbVec3f base(p->x, p->y, p->z); SbVec3f base(p->x, p->y, p->z);
if (forceDirection.GetAngle(normal) < M_PI_2) // Move arrow so it doesn't disappear inside the solid if (forceDirection.GetAngle(normal) < M_PI_2) // Move arrow so it doesn't disappear inside the solid
base = base + dir * ARROWLENGTH; base = base + dir * ARROWLENGTH;
/* #ifdef USE_MULTIPLE_COPY
SbMatrix m; SbMatrix m;
m.setTransform(base, rot, SbVec3f(1,1,1)); m.setTransform(base, rot, SbVec3f(1,1,1));
cp->matrix.set1Value(idx, m); matrices[idx] = m;
idx++; idx++;
*/ #else
SoSeparator* sep = new SoSeparator(); SoSeparator* sep = new SoSeparator();
createPlacement(sep, base, rot); createPlacement(sep, base, rot);
createArrow(sep, ARROWLENGTH, ARROWHEADRADIUS); createArrow(sep, ARROWLENGTH, ARROWHEADRADIUS);
pShapeSep->addChild(sep); pShapeSep->addChild(sep);
#endif
} }
} else if (strcmp(prop->getName(),"DirectionVector") == 0) { // Note: "Reversed" also triggers "DirectionVector" #ifdef USE_MULTIPLE_COPY
cp->matrix.finishEditing();
#endif
}
else if (strcmp(prop->getName(),"DirectionVector") == 0) { // Note: "Reversed" also triggers "DirectionVector"
// Re-orient all arrows // Re-orient all arrows
Base::Vector3d normal = pcConstraint->NormalDirection.getValue(); Base::Vector3d normal = pcConstraint->NormalDirection.getValue();
Base::Vector3d forceDirection = pcConstraint->DirectionVector.getValue(); Base::Vector3d forceDirection = pcConstraint->DirectionVector.getValue();
@ -174,26 +179,31 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues(); const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
/* #ifdef USE_MULTIPLE_COPY
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0)); SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
cp->matrix.setNum(points.size()); cp->matrix.setNum(points.size());
*/ SbMatrix* matrices = cp->matrix.startEditing();
#endif
int idx = 0; int idx = 0;
for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) { for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) {
SbVec3f base(p->x, p->y, p->z); SbVec3f base(p->x, p->y, p->z);
if (forceDirection.GetAngle(normal) < M_PI_2) if (forceDirection.GetAngle(normal) < M_PI_2)
base = base + dir * ARROWLENGTH; base = base + dir * ARROWLENGTH;
/* #ifdef USE_MULTIPLE_COPY
SbMatrix m; SbMatrix m;
m.setTransform(base, rot, SbVec3f(1,1,1)); m.setTransform(base, rot, SbVec3f(1,1,1));
cp->matrix.set1Value(idx, m);*/ matrices[idx] = m;
#else
SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(idx)); SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(idx));
updatePlacement(sep, 0, base, rot); updatePlacement(sep, 0, base, rot);
updateArrow(sep, 2, ARROWLENGTH, ARROWHEADRADIUS); updateArrow(sep, 2, ARROWLENGTH, ARROWHEADRADIUS);
#endif
idx++; idx++;
} }
#ifdef USE_MULTIPLE_COPY
cp->matrix.finishEditing();
#endif
} }
ViewProviderFemConstraint::updateData(prop); ViewProviderFemConstraint::updateData(prop);