Skip to content

Commit

Permalink
+ respect placement in VRML and Inventor objects
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 21, 2014
1 parent 833bd4e commit 763eb13
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Gui/ViewProviderInventorObject.cpp
Expand Up @@ -27,6 +27,7 @@
# include <Inventor/SoDB.h>
# include <Inventor/SoInput.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoTransform.h>
# include <QFile>
#endif

Expand Down Expand Up @@ -105,7 +106,7 @@ void ViewProviderInventorObject::updateData(const App::Property* prop)
pcBuffer->addChild(node);
}
}
if (prop == &ivObj->FileName) {
else if (prop == &ivObj->FileName) {
// read also from file
const char* filename = ivObj->FileName.getValue();
QString fn = QString::fromUtf8(filename);
Expand All @@ -124,6 +125,29 @@ void ViewProviderInventorObject::updateData(const App::Property* prop)
}
}
}
else if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId()) &&
strcmp(prop->getName(), "Placement") == 0) {
// Note: If R is the rotation, c the rotation center and t the translation
// vector then Inventor applies the following transformation: R*(x-c)+c+t
// In FreeCAD a placement only has a rotation and a translation part but
// no rotation center. This means that the following equation must be ful-
// filled: R * (x-c) + c + t = R * x + t
// <==> R * x + t - R * c + c = R * x + t
// <==> (I-R) * c = 0 ==> c = 0
// This means that the center point must be the origin!
Base::Placement p = static_cast<const App::PropertyPlacement*>(prop)->getValue();
float q0 = (float)p.getRotation().getValue()[0];
float q1 = (float)p.getRotation().getValue()[1];
float q2 = (float)p.getRotation().getValue()[2];
float q3 = (float)p.getRotation().getValue()[3];
float px = (float)p.getPosition().x;
float py = (float)p.getPosition().y;
float pz = (float)p.getPosition().z;
pcTransform->rotation.setValue(q0,q1,q2,q3);
pcTransform->translation.setValue(px,py,pz);
pcTransform->center.setValue(0.0f,0.0f,0.0f);
pcTransform->scaleFactor.setValue(1.0f,1.0f,1.0f);
}
}

void ViewProviderInventorObject::adjustSelectionNodes(SoNode* child, const char* docname,
Expand Down
24 changes: 24 additions & 0 deletions src/Gui/ViewProviderVRMLObject.cpp
Expand Up @@ -27,6 +27,7 @@
# include <Inventor/SoDB.h>
# include <Inventor/SoInput.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoTransform.h>
# include <QFile>
#endif

Expand Down Expand Up @@ -96,4 +97,27 @@ void ViewProviderVRMLObject::updateData(const App::Property* prop)
if (node) pcVRML->addChild(node);
}
}
else if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId()) &&
strcmp(prop->getName(), "Placement") == 0) {
// Note: If R is the rotation, c the rotation center and t the translation
// vector then Inventor applies the following transformation: R*(x-c)+c+t
// In FreeCAD a placement only has a rotation and a translation part but
// no rotation center. This means that the following equation must be ful-
// filled: R * (x-c) + c + t = R * x + t
// <==> R * x + t - R * c + c = R * x + t
// <==> (I-R) * c = 0 ==> c = 0
// This means that the center point must be the origin!
Base::Placement p = static_cast<const App::PropertyPlacement*>(prop)->getValue();
float q0 = (float)p.getRotation().getValue()[0];
float q1 = (float)p.getRotation().getValue()[1];
float q2 = (float)p.getRotation().getValue()[2];
float q3 = (float)p.getRotation().getValue()[3];
float px = (float)p.getPosition().x;
float py = (float)p.getPosition().y;
float pz = (float)p.getPosition().z;
pcTransform->rotation.setValue(q0,q1,q2,q3);
pcTransform->translation.setValue(px,py,pz);
pcTransform->center.setValue(0.0f,0.0f,0.0f);
pcTransform->scaleFactor.setValue(1.0f,1.0f,1.0f);
}
}

0 comments on commit 763eb13

Please sign in to comment.