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

This commit is contained in:
Cedric Pinson
2009-07-23 12:42:01 +00:00
parent 48a1934ca8
commit 5a73834cbe
5 changed files with 91 additions and 29 deletions

View File

@@ -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();
}

View File

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

View File

@@ -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);
}