Changeset 10877

Show
Ignore:
Timestamp:
12/09/09 19:45:46 (4 years ago)
Author:
cedricpinson
Message:

From Cedric Pinson,
Add check in RigTransformSoftware? if bones are null
Indent TimelineAnimationManager?
Add check for NaN in UpdateCallback?.cpp
Fix TimelineAnimationManager? clear target (a refactore of Timeline is require for futur)
Fix Computation of bounding box for RigGeometry?

Location:
OpenSceneGraph/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgAnimation/AnimationManagerBase

    r10656 r10877  
    1313*/ 
    1414 
    15 #ifndef OSGANIMATION_ANIMATION_MANAGER_BASE_H 
    16 #define OSGANIMATION_ANIMATION_MANAGER_BASE_H 
     15#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE 
     16#define OSGANIMATION_ANIMATION_MANAGER_BASE 1 
    1717 
    1818#include <osgAnimation/LinkVisitor> 
     
    5656        void setAutomaticLink(bool); 
    5757        bool isAutomaticLink() const; 
    58  
    5958        void dirty(); 
    6059 
  • OpenSceneGraph/trunk/include/osgAnimation/Interpolator

    r10552 r10877  
    1717 */ 
    1818 
    19 #ifndef OSGANIMATION_INTERPOLATOR_H 
    20 #define OSGANIMATION_INTERPOLATOR_H 
     19#ifndef OSGANIMATION_INTERPOLATOR 
     20#define OSGANIMATION_INTERPOLATOR 1 
    2121 
    2222#include <osg/Notify> 
  • OpenSceneGraph/trunk/include/osgAnimation/RigTransformSoftware

    r10693 r10877  
    8787                if (_bones.empty()) 
    8888                { 
    89                     osg::notify(osg::WARN) << "RigTransformSoftware::UniqBoneSetVertexSet no bones found" << std::endl; 
     89                    osg::notify(osg::WARN) << this << " RigTransformSoftware::UniqBoneSetVertexSet no bones found" << std::endl; 
    9090                    _result = osg::Matrix::identity(); 
    9191                    return; 
     
    9797                { 
    9898                    const Bone* bone = _bones[i].getBone(); 
     99                    if (!bone) 
     100                    { 
     101                        osg::notify(osg::WARN) << this << " RigTransformSoftware::computeMatrixForVertexSet Warning a bone is null, skip it" << std::endl; 
     102                        continue; 
     103                    } 
    99104                    const osg::Matrix& invBindMatrix = bone->getInvBindMatrixInSkeletonSpace(); 
    100105                    const osg::Matrix& matrix = bone->getMatrixInSkeletonSpace(); 
  • OpenSceneGraph/trunk/include/osgAnimation/Timeline

    r10693 r10877  
    1313*/ 
    1414 
    15 #ifndef OSGANIMATION_TIMELINE_H 
    16 #define OSGANIMATION_TIMELINE_H 
     15#ifndef OSGANIMATION_TIMELINE 
     16#define OSGANIMATION_TIMELINE 1 
    1717 
    1818#include <osgAnimation/Export> 
    1919#include <map> 
    2020#include <vector> 
     21#include <osg/observer_ptr> 
    2122#include <osg/Notify> 
    2223#include <osg/Stats> 
     
    2829namespace osgAnimation 
    2930{ 
    30     class OSGANIMATION_EXPORT Timeline : public Action //osg::Object 
     31    class OSGANIMATION_EXPORT Timeline : public Action 
    3132    { 
    3233    public: 
     
    8081 
    8182        void processPendingOperation(); 
    82  
     83        void setAnimationManager(AnimationManagerBase*); 
    8384    protected: 
    84  
     85        osg::observer_ptr<AnimationManagerBase> _animationManager; 
    8586        ActionLayers _actions; 
    8687        double _lastUpdate; 
     
    9091        bool _initFirstFrame; 
    9192        TimelineStatus _state; 
    92  
     93         
    9394        bool _collectStats; 
    9495        osg::ref_ptr<osg::Stats> _stats; 
  • OpenSceneGraph/trunk/include/osgAnimation/TimelineAnimationManager

    r10701 r10877  
    1313 */ 
    1414 
    15 #ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H 
    16 #define OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H 
     15#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER  
     16#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER 1 
    1717 
    1818#include <osgAnimation/Export> 
     
    2424{ 
    2525 
    26 class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase 
    27 { 
    28 protected: 
    29     osg::ref_ptr<Timeline> _timeline; 
     26    class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase 
     27    { 
     28    protected: 
     29        osg::ref_ptr<Timeline> _timeline; 
    3030 
    31 public: 
    32     META_Object(osgAnimation, TimelineAnimationManager); 
    33     TimelineAnimationManager(); 
    34     TimelineAnimationManager(const AnimationManagerBase& manager); 
    35     TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp&); 
     31    public: 
     32        META_Object(osgAnimation, TimelineAnimationManager); 
     33        TimelineAnimationManager(); 
     34        TimelineAnimationManager(const AnimationManagerBase& manager); 
     35        TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp&); 
    3636 
    37     Timeline* getTimeline() { return _timeline.get(); } 
    38     const Timeline* getTimeline() const { return _timeline.get(); } 
    39     void update(double time); 
    40 }; 
     37        Timeline* getTimeline() { return _timeline.get(); } 
     38        const Timeline* getTimeline() const { return _timeline.get(); } 
     39        void update(double time); 
     40    }; 
    4141 
    4242} 
  • OpenSceneGraph/trunk/src/osgAnimation/RigGeometry.cpp

    r10693 r10877  
    2020using namespace osgAnimation; 
    2121 
     22// The idea is to compute a bounding box with a factor x of the first step we compute the bounding box 
     23class RigComputeBoundingBoxCallback : public osg::Drawable::ComputeBoundingBoxCallback 
     24{ 
     25public: 
     26    RigComputeBoundingBoxCallback(double factor = 2.0) : _computed(false), _factor(factor) {} 
     27    void reset() { _computed = false; } 
     28    virtual osg::BoundingBox computeBound(const osg::Drawable& drawable) const 
     29    { 
     30        const osgAnimation::RigGeometry& rig = dynamic_cast<const osgAnimation::RigGeometry&>(drawable); 
     31 
     32        // if a valid inital bounding box is set we use it without asking more 
     33        if (rig.getInitialBound().valid()) 
     34            return rig.getInitialBound(); 
     35 
     36        if (_computed) 
     37            return _boundingBox; 
     38 
     39        // if the computing of bb is invalid (like no geometry inside) 
     40        // then dont tag the bounding box as computed 
     41        osg::BoundingBox bb = rig.computeBound(); 
     42        if (!bb.valid()) 
     43            return bb; 
     44 
     45 
     46        _boundingBox.expandBy(bb); 
     47        osg::Vec3 center = _boundingBox.center(); 
     48        osg::Vec3 vec = (_boundingBox._max-center)*_factor; 
     49        _boundingBox.expandBy(center + vec); 
     50        _boundingBox.expandBy(center - vec); 
     51        _computed = true; 
     52//        osg::notify(osg::NOTICE) << "build the bounding box for RigGeometry " << rig.getName() << " " << _boundingBox._min << " " << _boundingBox._max << std::endl; 
     53        return _boundingBox; 
     54    } 
     55protected: 
     56    mutable bool _computed; 
     57    double _factor; 
     58    mutable osg::BoundingBox _boundingBox; 
     59}; 
     60 
    2261RigGeometry::RigGeometry() 
    2362{ 
     
    3069 
    3170    // disable the computation of boundingbox for the rig mesh 
    32     setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 
     71    setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); 
    3372} 
    3473 
     
    4382 
    4483    // disable the computation of boundingbox for the rig mesh 
    45     setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 
     84    setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); 
    4685} 
    4786 
  • OpenSceneGraph/trunk/src/osgAnimation/TimelineAnimationManager.cpp

    r10576 r10877  
    3535void TimelineAnimationManager::update(double time) 
    3636{ 
    37     clearTargets(); 
     37    // clearTargets(); 
     38    _timeline->setAnimationManager(this); 
    3839    _timeline->update(time); 
    3940} 
  • OpenSceneGraph/trunk/src/osgAnimation/UpdateCallback.cpp

    r10689 r10877  
    2020#include <osg/MatrixTransform> 
    2121#include <osg/PositionAttitudeTransform> 
     22#include <osg/Math> 
    2223 
    2324using namespace osgAnimation; 
     
    7071        osg::Matrix::rotate(y,0.0,1.0,0.0) * 
    7172        osg::Matrix::rotate(z,0.0,0.0,1.0); 
    72     mat.setMatrix(osg::Matrix::scale(_scale->getValue()) *  
    73                   m * 
    74                   osg::Matrix::translate(_position->getValue())); 
    75     mat.dirtyBound(); 
     73    m = osg::Matrix::scale(_scale->getValue()) * m * osg::Matrix::translate(_position->getValue()); 
     74    mat.setMatrix(m); 
     75 
     76    if (!m.valid()) 
     77        osg::notify(osg::WARN) << this << " UpdateTransform::update detected NaN" << std::endl; 
    7678} 
    7779