diff --git a/include/osgAnimation/BoneMapVisitor b/include/osgAnimation/BoneMapVisitor new file mode 100644 index 000000000..97cfa143f --- /dev/null +++ b/include/osgAnimation/BoneMapVisitor @@ -0,0 +1,42 @@ +/* -*-c++-*- + * Copyright (C) 2009 Cedric Pinson + * + * 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. + * + * Authors: + * Cedric Pinson + */ + +#ifndef OSGANIMATION_BONEMAP_VISITOR_H +#define OSGANIMATION_BONEMAP_VISITOR_H 1 + +#include +#include +#include + +namespace osgAnimation +{ + class OSGANIMATION_EXPORT BoneMapVisitor : public osg::NodeVisitor + { + public: + META_NodeVisitor("osgAnimation","BoneMapVisitor") + BoneMapVisitor(); + + void apply(osg::Node&); + void apply(osg::Transform& node); + const Bone::BoneMap& getBoneMap() const; + + protected: + Bone::BoneMap _map; + }; +} + +#endif diff --git a/include/osgAnimation/ComputeBindMatrixVisitor b/include/osgAnimation/ComputeBindMatrixVisitor new file mode 100644 index 000000000..a99ce15bc --- /dev/null +++ b/include/osgAnimation/ComputeBindMatrixVisitor @@ -0,0 +1,43 @@ +/* -*-c++-*- + * Copyright (C) 2008 Cedric Pinson + * + * 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 COMPUTE_BIND_MATRIX_VISITOR_H +#define COMPUTE_BIND_MATRIX_VISITOR_H 1 + +#include +#include + +namespace osgAnimation +{ + + class ComputeBindMatrixVisitor : public osg::NodeVisitor + { + public: + ComputeBindMatrixVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} + void apply(osg::Node& node) { return; } + void apply(osg::Transform& node) + { + osgAnimation::Bone* bone = dynamic_cast(&node); + if (!bone) + return; + if (bone->needToComputeBindMatrix()) + bone->computeBindMatrix(); + + traverse(node); + } + }; + +} + +#endif diff --git a/include/osgAnimation/FindParentAnimationManagerVisitor b/include/osgAnimation/FindParentAnimationManagerVisitor new file mode 100644 index 000000000..d15a32128 --- /dev/null +++ b/include/osgAnimation/FindParentAnimationManagerVisitor @@ -0,0 +1,42 @@ +/* -*-c++-*- + * Copyright (C) 2008 Cedric Pinson + * + * 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 FIND_PARENT_ANIMATIONMANAGER_VISITOR_H +#define FIND_PARENT_ANIMATIONMANAGER_VISITOR_H 1 + +#include +#include + +namespace osgAnimation +{ + class AnimationManagerBase; + + /** + * Find the nearest AnimationManager traversing parent to parent + */ + class OSGANIMATION_EXPORT FindParentAnimationManagerVisitor : public osg::NodeVisitor + { + public: + FindParentAnimationManagerVisitor(); + void apply(osg::Node& node); + osgAnimation::AnimationManagerBase* getAnimationManager(); + + protected: + osg::ref_ptr _manager; + + }; + +} + +#endif diff --git a/src/osgAnimation/BoneMapVisitor.cpp b/src/osgAnimation/BoneMapVisitor.cpp new file mode 100644 index 000000000..d5e1f20fb --- /dev/null +++ b/src/osgAnimation/BoneMapVisitor.cpp @@ -0,0 +1,35 @@ +/* -*-c++-*- + * Copyright (C) 2009 Cedric Pinson + * + * 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. + * + * Authors: + * Cedric Pinson + */ + +#include + +osgAnimation::BoneMapVisitor::BoneMapVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} + +void osgAnimation::BoneMapVisitor::apply(osg::Node&) { return; } +void osgAnimation::BoneMapVisitor::apply(osg::Transform& node) +{ + Bone* bone = dynamic_cast(&node); + if (bone) + { + _map[bone->getName()] = bone; + traverse(node); + } +} +const osgAnimation::Bone::BoneMap& osgAnimation::BoneMapVisitor::getBoneMap() const +{ + return _map; +} diff --git a/src/osgAnimation/FindParentAnimationManagerVisitor.cpp b/src/osgAnimation/FindParentAnimationManagerVisitor.cpp new file mode 100644 index 000000000..d8c6f8f84 --- /dev/null +++ b/src/osgAnimation/FindParentAnimationManagerVisitor.cpp @@ -0,0 +1,34 @@ +/* -*-c++-*- + * Copyright (C) 2008 Cedric Pinson + * + * 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 +#include + +osgAnimation::FindParentAnimationManagerVisitor::FindParentAnimationManagerVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {} +void osgAnimation::FindParentAnimationManagerVisitor::apply(osg::Node& node) +{ + if (_manager.valid()) + return; + osg::NodeCallback* callback = node.getUpdateCallback(); + while (callback) + { + _manager = dynamic_cast(callback); + if (_manager.valid()) + return; + callback = callback->getNestedCallback(); + } + traverse(node); +} + +osgAnimation::AnimationManagerBase* osgAnimation::FindParentAnimationManagerVisitor::getAnimationManager() { return _manager.get(); }