AnimationMaterial
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2018 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_ANIMATIONMATERIAL
#define OSG_ANIMATIONMATERIAL 1
#include <osg/Material>
#include <osg/Callback>
#include <osgPresentation/Export>
#include <iosfwd>
#include <map>
#include <float.h>
namespace osgPresentation {
class OSGPRESENTATION_EXPORT AnimationMaterial : public virtual osg::Object
{
public:
AnimationMaterial():_loopMode(LOOP) {}
AnimationMaterial(const AnimationMaterial& ap, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
Object(ap,copyop),
_timeControlPointMap(ap._timeControlPointMap),
_loopMode(ap._loopMode) {}
META_Object(osg,AnimationMaterial);
bool getMaterial(double time,osg::Material& material) const;
void insert(double time,osg::Material* material);
double getFirstTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.begin()->first; else return 0.0;}
double getLastTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.rbegin()->first; else return 0.0;}
double getPeriod() const { return getLastTime()-getFirstTime();}
enum LoopMode
{
SWING,
LOOP,
NO_LOOPING
};
void setLoopMode(LoopMode lm) { _loopMode = lm; }
LoopMode getLoopMode() const { return _loopMode; }
typedef std::map<double, osg::ref_ptr<osg::Material> > TimeControlPointMap;
TimeControlPointMap& getTimeControlPointMap() { return _timeControlPointMap; }
const TimeControlPointMap& getTimeControlPointMap() const { return _timeControlPointMap; }
void read(std::istream& in);
void write(std::ostream& out) const;
bool requiresBlending() const;
protected:
virtual ~AnimationMaterial() {}
void interpolate(osg::Material& material, float r, const osg::Material& lhs,const osg::Material& rhs) const;
TimeControlPointMap _timeControlPointMap;
LoopMode _loopMode;
};
class OSGPRESENTATION_EXPORT AnimationMaterialCallback : public osg::NodeCallback
{
public:
AnimationMaterialCallback():
_useInverseMatrix(false),
_timeOffset(0.0),
_timeMultiplier(1.0),
_firstTime(DBL_MAX),
_latestTime(0.0),
_pause(false),
_pauseTime(0.0) {}
AnimationMaterialCallback(const AnimationMaterialCallback& apc,const osg::CopyOp& copyop):
osg::Object(apc, copyop),
osg::Callback(apc, copyop),
osg::NodeCallback(apc,copyop),
_animationMaterial(apc._animationMaterial),
_useInverseMatrix(apc._useInverseMatrix),
_timeOffset(apc._timeOffset),
_timeMultiplier(apc._timeMultiplier),
_firstTime(apc._firstTime),
_latestTime(apc._latestTime),
_pause(apc._pause),
_pauseTime(apc._pauseTime) {}
META_Object(osg,AnimationMaterialCallback);
AnimationMaterialCallback(AnimationMaterial* ap,double timeOffset=0.0f,double timeMultiplier=1.0f):
_animationMaterial(ap),
_useInverseMatrix(false),
_timeOffset(timeOffset),
_timeMultiplier(timeMultiplier),
_firstTime(DBL_MAX),
_latestTime(0.0),
_pause(false),
_pauseTime(0.0) {}
void setAnimationMaterial(AnimationMaterial* path) { _animationMaterial = path; }
AnimationMaterial* getAnimationMaterial() { return _animationMaterial.get(); }
const AnimationMaterial* getAnimationMaterial() const { return _animationMaterial.get(); }
void setTimeOffset(double offset) { _timeOffset = offset; }
double getTimeOffset() const { return _timeOffset; }
void setTimeMultiplier(double multiplier) { _timeMultiplier = multiplier; }
double getTimeMultiplier() const { return _timeMultiplier; }
void reset();
void setPause(bool pause);
double getAnimationTime() const;
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
void update(osg::Node& node);
public:
osg::ref_ptr<AnimationMaterial> _animationMaterial;
bool _useInverseMatrix;
double _timeOffset;
double _timeMultiplier;
double _firstTime;
double _latestTime;
bool _pause;
double _pauseTime;
protected:
~AnimationMaterialCallback(){}
};
}
#endif
Callback
Material
osgPresentation::AnimationMaterialCallback::_timeOffset
double _timeOffset
Definition AnimationMaterial:162
osgPresentation::AnimationMaterialCallback::reset
void reset()
osgPresentation::AnimationMaterialCallback::getTimeOffset
double getTimeOffset() const
Definition AnimationMaterial:140
osgPresentation::AnimationMaterialCallback::AnimationMaterialCallback
AnimationMaterialCallback(AnimationMaterial *ap, double timeOffset=0.0f, double timeMultiplier=1.0f)
Definition AnimationMaterial:123
osgPresentation::AnimationMaterialCallback::_pause
bool _pause
Definition AnimationMaterial:166
osgPresentation::AnimationMaterialCallback::setPause
void setPause(bool pause)
osgPresentation::AnimationMaterialCallback::AnimationMaterialCallback
AnimationMaterialCallback(const AnimationMaterialCallback &apc, const osg::CopyOp &copyop)
Definition AnimationMaterial:107
osgPresentation::AnimationMaterialCallback::_pauseTime
double _pauseTime
Definition AnimationMaterial:167
osgPresentation::AnimationMaterialCallback::~AnimationMaterialCallback
~AnimationMaterialCallback()
Definition AnimationMaterial:171
osgPresentation::AnimationMaterialCallback::_useInverseMatrix
bool _useInverseMatrix
Definition AnimationMaterial:161
osgPresentation::AnimationMaterialCallback::_timeMultiplier
double _timeMultiplier
Definition AnimationMaterial:163
osgPresentation::AnimationMaterialCallback::getAnimationMaterial
AnimationMaterial * getAnimationMaterial()
Definition AnimationMaterial:135
osgPresentation::AnimationMaterialCallback::_animationMaterial
osg::ref_ptr< AnimationMaterial > _animationMaterial
Definition AnimationMaterial:160
osgPresentation::AnimationMaterialCallback::_firstTime
double _firstTime
Definition AnimationMaterial:164
osgPresentation::AnimationMaterialCallback::AnimationMaterialCallback
AnimationMaterialCallback()
Definition AnimationMaterial:97
osgPresentation::AnimationMaterialCallback::setTimeOffset
void setTimeOffset(double offset)
Definition AnimationMaterial:139
osgPresentation::AnimationMaterialCallback::getAnimationTime
double getAnimationTime() const
osgPresentation::AnimationMaterialCallback::getAnimationMaterial
const AnimationMaterial * getAnimationMaterial() const
Definition AnimationMaterial:137
osgPresentation::AnimationMaterialCallback::update
void update(osg::Node &node)
osgPresentation::AnimationMaterialCallback::operator()
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
osgPresentation::AnimationMaterialCallback::setAnimationMaterial
void setAnimationMaterial(AnimationMaterial *path)
Definition AnimationMaterial:133
osgPresentation::AnimationMaterialCallback::getTimeMultiplier
double getTimeMultiplier() const
Definition AnimationMaterial:143
osgPresentation::AnimationMaterialCallback::META_Object
META_Object(osg, AnimationMaterialCallback)
osgPresentation::AnimationMaterialCallback::_latestTime
double _latestTime
Definition AnimationMaterial:165
osgPresentation::AnimationMaterialCallback::setTimeMultiplier
void setTimeMultiplier(double multiplier)
Definition AnimationMaterial:142
osgPresentation::AnimationMaterial
Definition AnimationMaterial:33
osgPresentation::AnimationMaterial::_loopMode
LoopMode _loopMode
Definition AnimationMaterial:88
osgPresentation::AnimationMaterial::getLastTime
double getLastTime() const
Definition AnimationMaterial:52
osgPresentation::AnimationMaterial::getLoopMode
LoopMode getLoopMode() const
Definition AnimationMaterial:64
osgPresentation::AnimationMaterial::requiresBlending
bool requiresBlending() const
osgPresentation::AnimationMaterial::AnimationMaterial
AnimationMaterial(const AnimationMaterial &ap, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition AnimationMaterial:38
osgPresentation::AnimationMaterial::getMaterial
bool getMaterial(double time, osg::Material &material) const
osgPresentation::AnimationMaterial::insert
void insert(double time, osg::Material *material)
osgPresentation::AnimationMaterial::META_Object
META_Object(osg, AnimationMaterial)
osgPresentation::AnimationMaterial::setLoopMode
void setLoopMode(LoopMode lm)
Definition AnimationMaterial:62
osgPresentation::AnimationMaterial::getTimeControlPointMap
TimeControlPointMap & getTimeControlPointMap()
Definition AnimationMaterial:69
osgPresentation::AnimationMaterial::read
void read(std::istream &in)
osgPresentation::AnimationMaterial::TimeControlPointMap
std::map< double, osg::ref_ptr< osg::Material > > TimeControlPointMap
Definition AnimationMaterial:67
osgPresentation::AnimationMaterial::interpolate
void interpolate(osg::Material &material, float r, const osg::Material &lhs, const osg::Material &rhs) const
osgPresentation::AnimationMaterial::AnimationMaterial
AnimationMaterial()
Definition AnimationMaterial:36
osgPresentation::AnimationMaterial::getFirstTime
double getFirstTime() const
Definition AnimationMaterial:51
osgPresentation::AnimationMaterial::getPeriod
double getPeriod() const
Definition AnimationMaterial:53
osgPresentation::AnimationMaterial::~AnimationMaterial
virtual ~AnimationMaterial()
Definition AnimationMaterial:83
osgPresentation::AnimationMaterial::write
void write(std::ostream &out) const
osgPresentation::AnimationMaterial::LoopMode
LoopMode
Definition AnimationMaterial:56
osgPresentation::AnimationMaterial::SWING
@ SWING
Definition AnimationMaterial:57
osgPresentation::AnimationMaterial::LOOP
@ LOOP
Definition AnimationMaterial:58
osgPresentation::AnimationMaterial::NO_LOOPING
@ NO_LOOPING
Definition AnimationMaterial:59
osgPresentation::AnimationMaterial::_timeControlPointMap
TimeControlPointMap _timeControlPointMap
Definition AnimationMaterial:87
osgPresentation::AnimationMaterial::getTimeControlPointMap
const TimeControlPointMap & getTimeControlPointMap() const
Definition AnimationMaterial:71
osg::Callback::Callback
Callback()
Definition Callback:38
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Material
Definition Material:32
osg::NodeCallback
Definition Callback:215
osg::NodeCallback::NodeCallback
NodeCallback()
Definition Callback:219
osg::NodeVisitor
Definition NodeVisitor:82
osg::Node
Definition Node:72
osg::Object
Definition Object:61
osg::Object::Object
Object()
Definition Object:69
osg::ref_ptr
Definition ref_ptr:32
osgPresentation
Definition AnimationMaterial:26
osg
Definition AlphaFunc:19
Export
OSGPRESENTATION_EXPORT
#define OSGPRESENTATION_EXPORT
Definition osgPresentation/Export:38