Changeset 10518
- Timestamp:
- 08/03/09 11:48:12 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 9 modified
-
include/osgAnimation/Bone (modified) (4 diffs)
-
include/osgAnimation/LinkVisitor (modified) (2 diffs)
-
include/osgAnimation/MorphGeometry (modified) (1 diff)
-
include/osgAnimation/UpdateCallback (modified) (3 diffs)
-
src/osgAnimation/Bone.cpp (modified) (1 diff)
-
src/osgAnimation/LinkVisitor.cpp (modified) (2 diffs)
-
src/osgAnimation/MorphGeometry.cpp (modified) (3 diffs)
-
src/osgAnimation/UpdateCallback.cpp (modified) (4 diffs)
-
src/osgPlugins/osgAnimation/ReaderWriter.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/Bone
r10344 r10518 24 24 #include <osg/Notify> 25 25 #include <osg/io_utils> 26 #include <osg/NodeVisitor> 26 27 #include <osgAnimation/Export> 27 28 #include <osgAnimation/Target> … … 92 93 93 94 94 class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback 95 class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback <osg::NodeCallback> 95 96 { 96 97 protected: … … 103 104 UpdateBone(const UpdateBone& apc,const osg::CopyOp& copyop); 104 105 105 UpdateBone(const std::string& name = "") 106 UpdateBone(const std::string& name = "") : AnimationUpdateCallback <osg::NodeCallback>(name) 106 107 { 107 108 setName(name); … … 156 157 else 157 158 { 158 std::cerr << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class"<< std::endl;159 osg::notify(osg::WARN) << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class" << className() << std::endl; 159 160 } 160 161 return false; -
OpenSceneGraph/trunk/include/osgAnimation/LinkVisitor
r10498 r10518 17 17 18 18 #include <osg/NodeVisitor> 19 #include <osg/StateSet> 19 20 #include <osgAnimation/Animation> 20 21 21 22 namespace osgAnimation 22 23 { 24 class AnimationUpdateCallbackBase; 25 23 26 /** This class is instancied by the AnimationManagerBase, it will link animation target to updatecallback that have the same name 24 27 */ … … 31 34 32 35 void apply(osg::Node& node); 36 void apply(osg::Geode& node); 37 33 38 AnimationList& getAnimationList(); 34 39 void reset(); 35 40 36 41 protected: 42 43 void handle_stateset(osg::StateSet* stateset); 44 void link(osgAnimation::AnimationUpdateCallbackBase* cb); 45 37 46 // animation list to link 38 47 AnimationList _animations; -
OpenSceneGraph/trunk/include/osgAnimation/MorphGeometry
r10504 r10518 132 132 }; 133 133 134 class OSGANIMATION_EXPORT UpdateMorph : public AnimationUpdateCallback 134 class OSGANIMATION_EXPORT UpdateMorph : public AnimationUpdateCallback<osg::NodeCallback> 135 135 { 136 136 protected: -
OpenSceneGraph/trunk/include/osgAnimation/UpdateCallback
r9150 r10518 18 18 #include <osg/Vec3> 19 19 #include <osg/NodeCallback> 20 #include <osg/StateAttribute> 21 #include <osg/Material> 20 22 #include <osg/observer_ptr> 21 23 #include <osgAnimation/AnimationManagerBase> … … 25 27 { 26 28 27 class OSGANIMATION_EXPORT AnimationUpdateCallback : public osg::NodeCallback 29 class AnimationUpdateCallbackBase 30 { 31 public: 32 virtual AnimationManagerBase* getAnimationManager() = 0; 33 virtual bool needLink() const = 0; 34 virtual bool link(osgAnimation::Channel* channel) = 0; 35 virtual int link(osgAnimation::Animation* animation) = 0; 36 virtual void updateLink() = 0; 37 virtual const std::string& getName() const = 0; 38 }; 39 40 template <class T> 41 class AnimationUpdateCallback : public AnimationUpdateCallbackBase, public T 28 42 { 29 43 protected: 44 30 45 osg::observer_ptr<osgAnimation::AnimationManagerBase> _manager; 31 46 32 47 public: 33 AnimationUpdateCallback(const std::string& name = "") { setName(name); } 34 AnimationUpdateCallback(const AnimationUpdateCallback& apc,const osg::CopyOp& copyop); 35 osgAnimation::AnimationManagerBase* getAnimationManager(); 36 virtual bool needLink() const = 0; 37 virtual bool link(osgAnimation::Channel* channel) = 0; 38 virtual int link(osgAnimation::Animation* animation); 39 virtual void updateLink(); 48 AnimationUpdateCallback(const std::string& name) { T::setName(name);} 49 AnimationUpdateCallback(const AnimationUpdateCallback& apc,const osg::CopyOp& copyop): 50 T(apc, copyop), 51 _manager(apc._manager) {} 52 53 osgAnimation::AnimationManagerBase* getAnimationManager() { return _manager.get(); } 54 55 const std::string& getName() const { return T::getName(); } 56 int link(osgAnimation::Animation* animation) 57 { 58 if (T::getName().empty()) 59 osg::notify(osg::WARN) << "An update callback has no name, it means it can link only with \"\" named Target, often an error" << std::endl; 60 int nbLinks = 0; 61 for (osgAnimation::ChannelList::iterator it = animation->getChannels().begin(); 62 it != animation->getChannels().end(); 63 it++) 64 { 65 std::string targetName = (*it)->getTargetName(); 66 if (targetName == T::getName()) 67 { 68 AnimationUpdateCallbackBase* a = this; 69 a->link((*it).get()); 70 nbLinks++; 71 } 72 } 73 return nbLinks; 74 } 75 76 void updateLink() 77 { 78 if (_manager.valid()) 79 { 80 if (needLink()) 81 { 82 /** this item is not linked yet then we do it for all animation 83 registered in the manager. 84 Maybe this function should be on the manager side like 85 _manager->linkItem(Bone); 86 */ 87 const AnimationList& animationList = _manager->getAnimationList(); 88 for (AnimationList::const_iterator it = animationList.begin(); it != animationList.end(); it++) 89 { 90 AnimationUpdateCallbackBase* a = this; 91 a->link(it->get()); 92 } 93 _manager->buildTargetReference(); 94 } 95 } 96 } 40 97 }; 41 42 98 43 class OSGANIMATION_EXPORT UpdateTransform : public AnimationUpdateCallback 99 100 101 102 class OSGANIMATION_EXPORT UpdateTransform : public AnimationUpdateCallback<osg::NodeCallback> 44 103 { 45 104 protected: … … 64 123 65 124 125 126 class OSGANIMATION_EXPORT UpdateMaterial : public AnimationUpdateCallback<osg::StateAttribute::Callback> 127 { 128 protected: 129 osg::ref_ptr<osgAnimation::Vec4Target> _diffuse; 130 131 public: 132 133 META_Object(osgAnimation, UpdateMaterial); 134 135 UpdateMaterial(const std::string& name = ""); 136 UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop); 137 138 /** Callback method called by the NodeVisitor when visiting a node.*/ 139 virtual void operator () (osg::StateAttribute*, osg::NodeVisitor*); 140 void update(osg::Material& material); 141 bool needLink() const; 142 bool link(osgAnimation::Channel* channel); 143 }; 144 66 145 } 67 146 -
OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp
r10386 r10518 19 19 osgAnimation::Bone::UpdateBone::UpdateBone(const osgAnimation::Bone::UpdateBone& apc,const osg::CopyOp& copyop) : 20 20 osg::Object(apc, copyop), 21 osgAnimation::AnimationUpdateCallback (apc, copyop)21 osgAnimation::AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) 22 22 { 23 23 _quaternion = new osgAnimation::QuatTarget(apc._quaternion->getValue()); -
OpenSceneGraph/trunk/src/osgAnimation/LinkVisitor.cpp
r10498 r10518 16 16 #include <osgAnimation/UpdateCallback> 17 17 #include <osg/Notify> 18 #include <osg/Geode> 18 19 19 20 using namespace osgAnimation; … … 33 34 return _animations; 34 35 } 36 void LinkVisitor::link(osgAnimation::AnimationUpdateCallbackBase* cb) 37 { 38 int result = 0; 39 for (int i = 0; i < (int)_animations.size(); i++) 40 { 41 result += cb->link(_animations[i].get()); 42 _nbLinkedTarget += result; 43 } 44 osg::notify(osg::NOTICE) << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl; 45 } 46 47 void LinkVisitor::handle_stateset(osg::StateSet* stateset) 48 { 49 if (!stateset) 50 return; 51 osg::StateSet::AttributeList& attr = stateset->getAttributeList(); 52 for (osg::StateSet::AttributeList::iterator it = attr.begin(); it != attr.end(); it++) 53 { 54 osg::StateAttribute* sattr = it->second.first.get(); 55 osgAnimation::AnimationUpdateCallbackBase* cb = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(sattr->getUpdateCallback()); 56 if (cb) 57 link(cb); 58 } 59 } 35 60 36 61 void LinkVisitor::apply(osg::Node& node) 37 62 { 38 osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(node.getUpdateCallback()); 39 if (cb) 63 osg::StateSet* st = node.getStateSet(); 64 if (st) 65 handle_stateset(st); 66 67 osg::NodeCallback* cb = node.getUpdateCallback(); 68 while (cb) 40 69 { 41 int result = 0; 42 for (int i = 0; i < (int)_animations.size(); i++) 43 { 44 result += cb->link(_animations[i].get()); 45 _nbLinkedTarget += result; 46 } 47 osg::notify(osg::NOTICE) << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl; 70 osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb); 71 if (cba) 72 link(cba); 73 cb = cb->getNestedCallback(); 48 74 } 49 75 traverse(node); 50 76 } 77 78 void LinkVisitor::apply(osg::Geode& node) 79 { 80 for (unsigned int i = 0; i < node.getNumDrawables(); i++) 81 { 82 osg::Drawable* drawable = node.getDrawable(i); 83 if (drawable && drawable->getStateSet()) 84 handle_stateset(drawable->getStateSet()); 85 } 86 apply(static_cast<osg::Node&>(node)); 87 } -
OpenSceneGraph/trunk/src/osgAnimation/MorphGeometry.cpp
r10186 r10518 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 program is free software; you can redistribute it and/or modify … … 19 19 * 20 20 * Roland Smeenk 21 * Cedric Pinson < mornifle@plopbyte.net>21 * Cedric Pinson <cedric.pinson@plopbyte.net> 22 22 * 23 23 */ … … 203 203 } 204 204 205 UpdateMorph::UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop) : AnimationUpdateCallback (apc, copyop)206 { 207 } 208 209 UpdateMorph::UpdateMorph(const std::string& name) : AnimationUpdateCallback (name)205 UpdateMorph::UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop) : AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) 206 { 207 } 208 209 UpdateMorph::UpdateMorph(const std::string& name) : AnimationUpdateCallback<osg::NodeCallback>(name) 210 210 { 211 211 } -
OpenSceneGraph/trunk/src/osgAnimation/UpdateCallback.cpp
r10390 r10518 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 osgAnimation::AnimationManagerBase* AnimationUpdateCallback::getAnimationManager() { return _manager.get(); }22 23 AnimationUpdateCallback::AnimationUpdateCallback(const AnimationUpdateCallback& apc,const osg::CopyOp& copyop):24 osg::NodeCallback(apc, copyop),25 _manager(apc._manager) {}26 27 int AnimationUpdateCallback::link(osgAnimation::Animation* animation)28 {29 if (getName().empty())30 osg::notify(osg::WARN) << "An update callback has no name, it means it can link only with \"\" named Target, often an error" << std::endl;31 int nbLinks = 0;32 for (osgAnimation::ChannelList::iterator it = animation->getChannels().begin();33 it != animation->getChannels().end();34 it++)35 {36 std::string targetName = (*it)->getTargetName();37 if (targetName == getName())38 {39 link((*it).get());40 nbLinks++;41 }42 }43 return nbLinks;44 }45 46 void AnimationUpdateCallback::updateLink()47 {48 if (_manager.valid())49 {50 if (needLink())51 {52 /** this item is not linked yet then we do it for all animation53 registered in the manager.54 Maybe this function should be on the manager side like55 _manager->linkItem(Bone);56 */57 const AnimationList& animationList = _manager->getAnimationList();58 for (AnimationList::const_iterator it = animationList.begin(); it != animationList.end(); it++)59 link(it->get());60 _manager->buildTargetReference();61 }62 }63 }64 65 66 67 21 68 22 UpdateTransform::UpdateTransform(const UpdateTransform& apc,const osg::CopyOp& copyop) 69 23 : osg::Object(apc, copyop), 70 AnimationUpdateCallback (apc, copyop)24 AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) 71 25 { 72 26 _euler = new osgAnimation::Vec3Target(apc._euler->getValue()); … … 75 29 } 76 30 77 UpdateTransform::UpdateTransform(const std::string& name) : AnimationUpdateCallback(name) 31 UpdateTransform::UpdateTransform(const std::string& name): 32 AnimationUpdateCallback<osg::NodeCallback>(name) 78 33 { 79 34 _euler = new osgAnimation::Vec3Target; … … 168 123 else 169 124 { 170 std::cerr << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class"<< std::endl;125 osg::notify(osg::WARN) << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class" << className() << std::endl; 171 126 } 172 127 return false; 173 128 } 129 130 131 132 133 134 UpdateMaterial::UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop) 135 : osg::Object(apc, copyop), 136 AnimationUpdateCallback<osg::StateAttribute::Callback>(apc, copyop) 137 { 138 _diffuse = new osgAnimation::Vec4Target(apc._diffuse->getValue()); 139 } 140 141 UpdateMaterial::UpdateMaterial(const std::string& name): 142 AnimationUpdateCallback<osg::StateAttribute::Callback>(name) 143 { 144 _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,1,1,1)); 145 } 146 147 /** Callback method called by the NodeVisitor when visiting a node.*/ 148 void UpdateMaterial::operator()(osg::StateAttribute* sa, osg::NodeVisitor* nv) 149 { 150 if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) 151 { 152 osg::Material* material = dynamic_cast<osg::Material*>(sa); 153 if (material) 154 update(*material); 155 } 156 } 157 158 void UpdateMaterial::update(osg::Material& material) 159 { 160 osg::Vec4 diffuse = _diffuse->getValue(); 161 material.setDiffuse(osg::Material::FRONT_AND_BACK, diffuse); 162 } 163 164 bool UpdateMaterial::needLink() const 165 { 166 // the idea is to return true if nothing is linked 167 return (_diffuse->getCount() < 2); 168 } 169 170 bool UpdateMaterial::link(osgAnimation::Channel* channel) 171 { 172 if (channel->getName().find("diffuse") != std::string::npos) 173 { 174 osgAnimation::Vec4LinearChannel* d = dynamic_cast<osgAnimation::Vec4LinearChannel*>(channel); 175 if (d) 176 { 177 d->setTarget(_diffuse.get()); 178 return true; 179 } 180 } 181 else 182 { 183 osg::notify(osg::WARN) << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class " << className() << std::endl; 184 } 185 return false; 186 } -
OpenSceneGraph/trunk/src/osgPlugins/osgAnimation/ReaderWriter.cpp
r10186 r10518 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 … … 1042 1042 ); 1043 1043 1044 1045 1046 bool UpdateMaterial_readLocalData(Object& obj, Input& fr) 1047 { 1048 bool iteratorAdvanced = false; 1049 return iteratorAdvanced; 1050 } 1051 1052 bool UpdateMaterial_writeLocalData(const Object& obj, Output& fw) 1053 { 1054 return true; 1055 } 1056 1057 RegisterDotOsgWrapperProxy g_UpdateMaterialProxy 1058 ( 1059 new osgAnimation::UpdateMaterial, 1060 "osgAnimation::UpdateMaterial", 1061 "Object StateAttribute::Callback osgAnimation::UpdateMaterial", 1062 &UpdateMaterial_readLocalData, 1063 &UpdateMaterial_writeLocalData, 1064 DotOsgWrapper::READ_AND_WRITE 1065 ); 1066 1044 1067 bool UpdateMorph_readLocalData(Object& obj, Input& fr) 1045 1068 {
