From 58426776626468e84f701d44832a7a9edce8c06c Mon Sep 17 00:00:00 2001 From: Cedric Pinson Date: Fri, 13 Nov 2009 13:39:21 +0000 Subject: [PATCH] From Cedric Pinson, Fix Skeleton to compute correctly bind matrix, fix compile issue on osganimationhardware after fixing Skeleton --- include/osgAnimation/Skeleton | 22 +++++++++++----------- src/osgAnimation/Skeleton.cpp | 35 ++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/include/osgAnimation/Skeleton b/include/osgAnimation/Skeleton index 88fb1df4c..1c75d0c1b 100644 --- a/include/osgAnimation/Skeleton +++ b/include/osgAnimation/Skeleton @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * 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 @@ -12,12 +12,11 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSGANIMATION_SKELETON_H -#define OSGANIMATION_SKELETON_H +#ifndef OSGANIMATION_SKELETON +#define OSGANIMATION_SKELETON 1 -#include -#include #include +#include namespace osgAnimation { @@ -31,18 +30,19 @@ namespace osgAnimation { public: META_Object(osgAnimation, UpdateSkeleton); - UpdateSkeleton() : _needValidate(true) {} - UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) { _needValidate = true;} + UpdateSkeleton(); + UpdateSkeleton(const UpdateSkeleton&, const osg::CopyOp&); virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - + bool needToValidate() const; protected: bool _needValidate; }; - Skeleton(const Skeleton& b, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : Bone(b,copyop) {} Skeleton(); - void setDefaultUpdateCallback(void); - void computeBindMatrix() { _invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace); _needToRecomputeBindMatrix = false; } + Skeleton(const Skeleton&, const osg::CopyOp&); + + void setDefaultUpdateCallback(); + void computeBindMatrix(); }; } diff --git a/src/osgAnimation/Skeleton.cpp b/src/osgAnimation/Skeleton.cpp index f80551ebd..4b991aacc 100644 --- a/src/osgAnimation/Skeleton.cpp +++ b/src/osgAnimation/Skeleton.cpp @@ -17,6 +17,20 @@ using namespace osgAnimation; +Skeleton::Skeleton() {} +Skeleton::Skeleton(const Skeleton& b, const osg::CopyOp& copyop) : Bone(b,copyop) {} + +Skeleton::UpdateSkeleton::UpdateSkeleton() : _needValidate(true) {} +Skeleton::UpdateSkeleton::UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) +{ + _needValidate = true; +} +bool Skeleton::UpdateSkeleton::needToValidate() const +{ + return _needValidate; +} + + class ValidateSkeletonVisitor : public osg::NodeVisitor { public: @@ -56,25 +70,28 @@ public: void Skeleton::UpdateSkeleton::operator()(osg::Node* node, osg::NodeVisitor* nv) { - if (_needValidate && nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) + if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) { - Skeleton* b = dynamic_cast(node); - if (b) + Skeleton* skeleton = dynamic_cast(node); + if (_needValidate && skeleton) { ValidateSkeletonVisitor visitor; node->accept(visitor); + _needValidate = false; } - - _needValidate = false; + if (skeleton->needToComputeBindMatrix()) + skeleton->computeBindMatrix(); } traverse(node,nv); } -Skeleton::Skeleton() -{ -} - void Skeleton::setDefaultUpdateCallback() { setUpdateCallback(new Skeleton::UpdateSkeleton ); } + +void Skeleton::computeBindMatrix() +{ + _invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace); + _needToRecomputeBindMatrix = false; +}