From Cedric Pinson, Store the linkvisitor to be able to configure it by user, like changing the nodemaskoverride, or use a custom LinkVisitor

remotes/origin/OpenSceneGraph-2.8
Cedric Pinson 15 years ago
parent 48a1934ca8
commit 5a73834cbe

@ -1,5 +1,5 @@
/* -*-c++-*-
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
*
* 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
@ -15,6 +15,7 @@
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE_H
#define OSGANIMATION_ANIMATION_MANAGER_BASE_H
#include <osgAnimation/LinkVisitor>
#include <osgAnimation/Animation>
#include <osgAnimation/Export>
#include <osg/FrameStamp>
@ -46,8 +47,12 @@ namespace osgAnimation
void clearTargets();
void normalizeTargets();
LinkVisitor* getOrCreateLinkVisitor();
void setLinkVisitor(LinkVisitor*);
protected:
osg::ref_ptr<LinkVisitor> _linker;
AnimationList _animations;
TargetSet _targets;
bool _needToLink;

@ -1,5 +1,5 @@
/* -*-c++-*-
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
*
* 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
@ -17,36 +17,28 @@
#include <osg/NodeVisitor>
#include <osgAnimation/Animation>
#include <osgAnimation/UpdateCallback>
namespace osgAnimation
{
struct LinkVisitor : public osg::NodeVisitor
/** This class is instancied by the AnimationManagerBase, it will link animation target to updatecallback that have the same name
*/
class OSGANIMATION_EXPORT LinkVisitor : public osg::NodeVisitor
{
public:
LinkVisitor();
META_NodeVisitor("osgAnimation","LinkVisitor");
void apply(osg::Node& node);
AnimationList& getAnimationList();
void reset();
protected:
// animation list to link
AnimationList _animations;
// number of success link done
unsigned int _nbLinkedTarget;
LinkVisitor(Animation* animation) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _animations.push_back(animation); _nbLinkedTarget = 0;}
LinkVisitor(const AnimationList& animations) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _animations = animations; _nbLinkedTarget = 0;}
META_NodeVisitor("osgAnimation","LinkVisitor")
void apply(osg::Node& node)
{
osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(node.getUpdateCallback());
if (cb)
{
int result = 0;
for (int i = 0; i < (int)_animations.size(); i++)
{
result += cb->link(_animations[i].get());
_nbLinkedTarget += result;
}
std::cout << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl;
}
traverse(node);
}
};
}

@ -21,7 +21,7 @@ AnimationManagerBase::~AnimationManagerBase() {}
AnimationManagerBase::AnimationManagerBase()
{
_needToLink = false;
_needToLink = false;
}
void AnimationManagerBase::clearTargets()
@ -95,11 +95,25 @@ void AnimationManagerBase::registerAnimation (Animation* animation)
bool AnimationManagerBase::needToLink() const { return _needToLink; }
void AnimationManagerBase::setLinkVisitor(LinkVisitor* visitor)
{
_linker = visitor;
}
LinkVisitor* AnimationManagerBase::getOrCreateLinkVisitor()
{
if (!_linker.valid())
_linker = new LinkVisitor;
return _linker.get();
}
void AnimationManagerBase::link(osg::Node* subgraph)
{
LinkVisitor linker(_animations);
subgraph->accept(linker);
LinkVisitor* linker = getOrCreateLinkVisitor();
linker->getAnimationList().clear();
linker->getAnimationList() = _animations;
subgraph->accept(*linker);
_needToLink = false;
buildTargetReference();
}

@ -54,6 +54,7 @@ ADD_LIBRARY(${LIB_NAME}
BasicAnimationManager.cpp
Bone.cpp
Channel.cpp
LinkVisitor.cpp
MorphGeometry.cpp
RigGeometry.cpp
Skeleton.cpp

@ -0,0 +1,50 @@
/* -*-c++-*-
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
*
* 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.
*/
#include <osgAnimation/LinkVisitor>
#include <osgAnimation/UpdateCallback>
#include <osg/Notify>
using namespace osgAnimation;
LinkVisitor::LinkVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
_nbLinkedTarget = 0;
}
void LinkVisitor::reset()
{
_nbLinkedTarget = 0;
}
AnimationList& LinkVisitor::getAnimationList()
{
return _animations;
}
void LinkVisitor::apply(osg::Node& node)
{
osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(node.getUpdateCallback());
if (cb)
{
int result = 0;
for (int i = 0; i < (int)_animations.size(); i++)
{
result += cb->link(_animations[i].get());
_nbLinkedTarget += result;
}
osg::notify(osg::NOTICE) << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl;
}
traverse(node);
}
Loading…
Cancel
Save