Changeset 10556
- Timestamp:
- 08/26/09 11:24:02 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 9 modified
-
include/osgAnimation/Animation (modified) (2 diffs)
-
include/osgAnimation/Channel (modified) (4 diffs)
-
include/osgAnimation/Target (modified) (3 diffs)
-
src/osgAnimation/Animation.cpp (modified) (3 diffs)
-
src/osgAnimation/BasicAnimationManager.cpp (modified) (2 diffs)
-
src/osgAnimation/Channel.cpp (modified) (3 diffs)
-
src/osgAnimation/MorphGeometry.cpp (modified) (2 diffs)
-
src/osgAnimation/Target.cpp (modified) (2 diffs)
-
src/osgPlugins/osgAnimation/ReaderWriter.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/Animation
r10386 r10556 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 72 72 float getWeight() const; 73 73 74 bool update (float time );74 bool update (float time, int priority = 0); 75 75 void resetTargets(); 76 76 -
OpenSceneGraph/trunk/include/osgAnimation/Channel
r10527 r10556 38 38 virtual Channel* clone() const = 0; 39 39 40 virtual void update(float time ) = 0;40 virtual void update(float time, float weight, int priority) = 0; 41 41 virtual void reset() = 0; 42 42 virtual Target* getTarget() = 0; … … 52 52 void setTargetName(const std::string& name); 53 53 54 float getWeight() const;55 void setWeight(float w);56 57 54 virtual Sampler* getSampler() = 0; 58 55 virtual const Sampler* getSampler() const = 0; … … 62 59 std::string _targetName; 63 60 std::string _name; 64 float _weight;65 61 }; 66 62 … … 93 89 94 90 virtual ~TemplateChannel() {} 95 virtual void update(float time )91 virtual void update(float time, float weight, int priority) 96 92 { 97 93 // skip if weight == 0 98 if ( _weight < 1e-4)94 if (weight < 1e-4) 99 95 return; 100 96 typename SamplerType::UsingType value; 101 97 _sampler->getValueAt(time, value); 102 _target->update( _weight, value);98 _target->update(weight, value, priority); 103 99 } 104 100 virtual void reset() { _target->reset(); } -
OpenSceneGraph/trunk/include/osgAnimation/Target
r10344 r10556 37 37 virtual ~Target(); 38 38 virtual void normalize() = 0; 39 void reset() { _weight = 0; _priorityWeight = 0; } 40 int getCount() const { return referenceCount(); } 39 41 float getWeight() const { return _weight; } 40 void reset() { _weight = 0;}41 int getCount() const { return referenceCount(); }42 42 protected: 43 44 void addWeight(float w) { _weight += w; }45 43 float _weight; 44 float _priorityWeight; 45 int _lastPriority; 46 46 }; 47 47 … … 55 55 TemplateTarget(const T& v) { setValue(v); } 56 56 57 void update(float weight, const T& val) 57 inline void lerp(float t, const T& a, const T& b); 58 59 /** 60 * The priority is used to detect a change of priority 61 * It's important to update animation target in priority 62 * order. eg: 63 * all animation with priority 1 64 * all animation with priority 0 65 * all animation with priority -1 66 * ... 67 */ 68 void update(float weight, const T& val, int priority) 58 69 { 59 if (!_weight) 60 _target = val * weight; 70 if (_weight || _priorityWeight) 71 { 72 if (_lastPriority != priority) 73 { 74 // change in priority 75 // add to weight with the same previous priority cumulated weight 76 _weight += _priorityWeight * (1.0 - _weight); 77 _priorityWeight = 0; 78 _lastPriority = priority; 79 } 80 81 _priorityWeight += weight; 82 float t = (1.0 - _weight) * weight / _priorityWeight; 83 lerp(t, _target, val); 84 } 61 85 else 62 86 { 63 weight = (1.0 - _weight) * weight; 64 _target += val * weight; 87 _priorityWeight = weight; 88 _lastPriority = priority; 89 _target = val; 65 90 } 66 addWeight(weight);67 91 } 68 const T& getValue() const { return _target; }92 const T& getValue() const { return _target; } 69 93 70 void normalize() 71 { 72 float weightSummed = getWeight(); 73 if (fabs(weightSummed) < 1e-4 || fabs(weightSummed-1) < 1e-4) 74 return; 75 (_target) /= weightSummed; 76 } 94 inline void normalize(); 77 95 78 void setValue(const T& value) { _target = value; }96 void setValue(const T& value) { _target = value; } 79 97 80 98 protected: … … 83 101 }; 84 102 103 template <class T> 104 inline void TemplateTarget<T>::normalize() 105 { 106 _weight += _priorityWeight * (1.0f - _weight); 107 if (_weight < 0.9999f ) 108 if (_weight > 0.0001f) 109 _target /= _weight; // rescale by default 110 } 85 111 86 // Target Specialisation for Quaternions 112 template <class T> 113 inline void TemplateTarget<T>::lerp(float t, const T& a, const T& b) 114 { 115 _target = a * (1.0f - t) + b * t; 116 } 117 87 118 template <> 88 class TemplateTarget< osg::Quat > : public Target119 inline void TemplateTarget<osg::Quat>::lerp(float t, const osg::Quat& a, const osg::Quat& b) 89 120 { 90 public:91 92 TemplateTarget () {}93 TemplateTarget (const osg::Quat& q) { setValue(q); }94 95 const osg::Quat& getValue() const { return _target;}96 void update(float weight, const osg::Quat& val)97 {98 if (!_weight)99 _target = val * weight;100 else121 _target = a * (1.0f - t) + b * t; 122 osg::Quat::value_type len2 = _target.length2(); 123 if ( len2 != 1.0 && len2 != 0.0) 124 _target *= 1.0/sqrt(len2); 125 } 126 template <> 127 inline void TemplateTarget<osg::Quat>::normalize() 128 { 129 _weight += _priorityWeight * (1.0f - _weight); 130 if (_weight < 0.9999f ) 131 if (_weight > 0.0001f) 101 132 { 102 weight = (1.0 - _weight) * weight; 103 _target += val * weight; 133 osg::Quat::value_type len2 = _target.length2(); // normalize 134 if ( len2 != 1.0 && len2 != 0.0) 135 _target *= 1.0/sqrt(len2); 104 136 } 105 addWeight(weight); 106 } 107 108 // maybe normalize could be non virtual and put on ITarget 109 void normalize() 110 { 111 float weightSummed = getWeight(); 112 if (fabs(weightSummed) < 1e-4 || fabs(weightSummed-1.0) < 1e-4) 113 return; 114 (_target) /= weightSummed; 115 } 116 117 void setValue(const osg::Quat& value) { _target = value;} 118 119 protected: 120 121 osg::Quat _target; 122 }; 137 } 123 138 124 139 typedef TemplateTarget<osg::Quat> QuatTarget; -
OpenSceneGraph/trunk/src/osgAnimation/Animation.cpp
r10393 r10556 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 96 96 } 97 97 98 bool Animation::update (float time )98 bool Animation::update (float time, int priority) 99 99 { 100 100 if (!_duration) // if not initialized then do it … … 139 139 for( chan=_channels.begin(); chan!=_channels.end(); ++chan) 140 140 { 141 (*chan)->setWeight(_weight); 142 (*chan)->update(t); 141 (*chan)->update(t, _weight, priority); 143 142 } 144 143 return true; -
OpenSceneGraph/trunk/src/osgAnimation/BasicAnimationManager.cpp
r9877 r10556 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 91 91 // update all animation 92 92 std::vector<int> toremove; 93 int priority = iterAnim->first; 93 94 AnimationList& list = iterAnim->second; 94 95 for (unsigned int i = 0; i < list.size(); i++) 95 96 { 96 if (! list[i]->update(time ))97 if (! list[i]->update(time, priority)) 97 98 { 98 99 // debug -
OpenSceneGraph/trunk/src/osgAnimation/Channel.cpp
r10386 r10556 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 16 16 using namespace osgAnimation; 17 17 18 Channel::Channel() { _weight=1;}18 Channel::Channel() {} 19 19 Channel::~Channel() {} 20 20 Channel::Channel(const Channel& channel) : osg::Referenced(channel), 21 21 _targetName(channel._targetName), 22 _name(channel._name), 23 _weight(channel._weight) 22 _name(channel._name) 24 23 { 25 24 } … … 30 29 const std::string& Channel::getTargetName() const { return _targetName;} 31 30 void Channel::setTargetName (const std::string& name) { _targetName = name; } 32 33 float Channel::getWeight() const { return _weight;}34 void Channel::setWeight(float w) { _weight = w;}35 -
OpenSceneGraph/trunk/src/osgAnimation/MorphGeometry.cpp
r10518 r10556 203 203 } 204 204 205 UpdateMorph::UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop) : AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) 205 UpdateMorph::UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop) : 206 osg::Object(apc, copyop), 207 AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) 206 208 { 207 209 } … … 272 274 else 273 275 { 274 std::cerr<< "Channel " << channel->getName() << " does not contain a valid symbolic name for this class" << std::endl;276 osg::notify(osg::WARN) << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class" << std::endl; 275 277 } 276 278 return false; -
OpenSceneGraph/trunk/src/osgAnimation/Target.cpp
r9093 r10556 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 19 19 using namespace osgAnimation; 20 20 21 Target::Target() { reset();}21 Target::Target() : _weight(0), _priorityWeight(0), _lastPriority(0) {} 22 22 Target::~Target() {} -
OpenSceneGraph/trunk/src/osgPlugins/osgAnimation/ReaderWriter.cpp
r10518 r10556 147 147 pChannel->setTargetName(target); 148 148 149 // we dont need this info 149 150 float weight = 1.0; 150 151 if (fr.matchSequence("weight %f")) … … 154 155 iteratorAdvanced = true; 155 156 } 156 pChannel->setWeight(weight);157 // pChannel->setWeight(weight); 157 158 return iteratorAdvanced; 158 159 } … … 547 548 fw.indent() << "target \"" << pChannel->getTargetName() << "\"" << std::endl; 548 549 549 fw.indent() << "weight " << pChannel->getWeight() << std::endl;550 // fw.indent() << "weight " << pChannel->getWeight() << std::endl; 550 551 551 552 ContainerType* kfc = pChannel->getSamplerTyped()->getKeyframeContainerTyped();
