simgear/scene/model: expose some animation info for use by Highlight system.

simgear/scene/model/animation.*: added TransformExpression() - returns SGExpressiond
if given a SGRotAnimTransform or SGTranslateTransform.

simgear/scene/model/SGTranslateTransform.hxx:SGTranslateTransform: added copy
of SGExpressiond for use by TransformExpression().
This commit is contained in:
Julian Smith 2021-09-20 21:32:20 +01:00
parent e7cca0c407
commit 50170da13d
3 changed files with 25 additions and 0 deletions

View File

@ -24,6 +24,9 @@
#include <osg/Transform> #include <osg/Transform>
#include <simgear/math/SGMath.hxx> #include <simgear/math/SGMath.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/structure/SGExpression.hxx>
class SGTranslateTransform : public osg::Transform { class SGTranslateTransform : public osg::Transform {
public: public:
@ -49,6 +52,9 @@ public:
osg::NodeVisitor* nv) const; osg::NodeVisitor* nv) const;
virtual osg::BoundingSphere computeBound() const; virtual osg::BoundingSphere computeBound() const;
// Only used for highlighting.
SGSharedPtr<SGExpressiond const> _animationValue;
private: private:
SGVec3d _axis; SGVec3d _axis;
double _value; double _value;

View File

@ -982,6 +982,7 @@ SGTranslateAnimation::createAnimationGroup(osg::Group& parent)
if (_animationValue && !_animationValue->isConst()) { if (_animationValue && !_animationValue->isConst()) {
UpdateCallback* uc = new UpdateCallback(_condition, _animationValue); UpdateCallback* uc = new UpdateCallback(_condition, _animationValue);
transform->setUpdateCallback(uc); transform->setUpdateCallback(uc);
transform->_animationValue = _animationValue;
} }
transform->setAxis(_axis); transform->setAxis(_axis);
transform->setValue(_initialValue); transform->setValue(_initialValue);
@ -2494,3 +2495,16 @@ SGTexTransformAnimation::appendTexTrapezoid( const SGPropertyNode& cfg,
trapezoid->setValue(cfg.getDoubleValue("starting-position", 0)); trapezoid->setValue(cfg.getDoubleValue("starting-position", 0));
updateCallback->appendTransform(trapezoid, readValue(cfg)); updateCallback->appendTransform(trapezoid, readValue(cfg));
} }
SGSharedPtr<SGExpressiond const> TransformExpression(osg::Transform* transform)
{
SGSharedPtr<SGExpressiond const> ret;
if (auto rot_anim_transform = dynamic_cast<SGRotAnimTransform*>(transform)) {
ret = rot_anim_transform->_animationValue;
}
else if (auto translate_transform = dynamic_cast<SGTranslateTransform*>(transform)) {
ret = translate_transform->_animationValue;
}
return ret;
}

View File

@ -38,6 +38,11 @@ read_value(const SGPropertyNode* configNode, SGPropertyNode* modelRoot,
SGVec3d readTranslateAxis(const SGPropertyNode* configNode); SGVec3d readTranslateAxis(const SGPropertyNode* configNode);
/**
* Returns transform's expression if it has one.
*/
SGSharedPtr<SGExpressiond const> TransformExpression(osg::Transform* transform);
/** /**
* Base class for animation installers * Base class for animation installers
*/ */