Changeset 10656

Show
Ignore:
Timestamp:
10/21/09 17:45:13 (4 years ago)
Author:
cedricpinson
Message:

From Cedric Pinson, this commit contains the following change:
* Change ref_ptr to observer_ptr to avoid cross reference and leak in Skinning
* Set invalidate to true to re run the check visitor in Skeleton
* Shallow copy Sampler in channel copy constructor
* Add accessor in VertexInfluence?
* Remove dead code in Timeline.cpp
* Dont force linking in Bone::UpdateBone?, the decision is done by the user or the manager
* Add offset in timeline stats to display each manager on the screen
* Add a flag in animation manager base to enable or not automatic link when modifying the manager

Location:
OpenSceneGraph/trunk
Files:
11 modified

Legend:

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

    r10576 r10656  
    4545        virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); 
    4646 
    47         /// Operation that must be done each frame 
     47        /** Reset the value of targets 
     48            this Operation must be done each frame */ 
    4849        void clearTargets(); 
     50         
    4951 
    5052        LinkVisitor* getOrCreateLinkVisitor(); 
    5153        void setLinkVisitor(LinkVisitor*); 
     54 
     55        /// set a flag to define the behaviour 
     56        void setAutomaticLink(bool); 
     57        bool isAutomaticLink() const; 
     58 
     59        void dirty(); 
    5260 
    5361    protected: 
     
    5765        TargetSet _targets; 
    5866        bool _needToLink; 
     67        bool _automaticLink; 
    5968    }; 
    6069} 
  • OpenSceneGraph/trunk/include/osgAnimation/Channel

    r10581 r10656  
    7878 
    7979        TemplateChannel (const TemplateChannel& channel) : 
    80             Channel(channel), 
    81             _target(new TargetType(*channel.getTargetTyped())), 
    82             _sampler(channel._sampler.get()) 
     80            Channel(channel) 
    8381        { 
     82            if (channel.getTargetTyped()) 
     83                _target = new TargetType(*channel.getTargetTyped()); 
     84 
     85            if (channel.getSamplerTyped()) 
     86                _sampler = new SamplerType(*channel.getSamplerTyped()); 
    8487        } 
    8588 
     
    103106            typename KeyframeContainerType::KeyType key(0, _target->getValue()); 
    104107            // recreate the keyframe container 
    105             _sampler = 0; 
     108            getOrCreateSampler()->setKeyframeContainer(0); 
    106109            getOrCreateSampler()->getOrCreateKeyframeContainer(); 
    107110            // add the key 
  • OpenSceneGraph/trunk/include/osgAnimation/Skeleton

    r10558 r10656  
    3333            META_Object(osgAnimation, UpdateSkeleton); 
    3434            UpdateSkeleton() : _needValidate(true) {} 
    35             UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) {} 
     35            UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) { _needValidate = true;} 
    3636            virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); 
    3737 
  • OpenSceneGraph/trunk/include/osgAnimation/Skinning

    r9531 r10656  
    4747        public: 
    4848            BoneWeight(BoneType* bone, float weight) : _bone(bone), _weight(weight) {} 
    49             const BoneType* getBone() const { return &(*_bone); } 
     49            const BoneType* getBone() const { return _bone.get(); } 
    5050            float getWeight() const { return _weight; } 
    5151            void setWeight(float w) { _weight = w; } 
    5252        protected: 
    53             osg::ref_ptr<BoneType> _bone; 
     53            osg::observer_ptr<BoneType> _bone; 
    5454            float _weight; 
    5555        }; 
     
    192192                const VertexList& vertexes = uniq.getVertexes(); 
    193193                int vertexSize = vertexes.size(); 
    194                 for (int j = 0; j < vertexSize; j++)  
     194                for (int j = 0; j < vertexSize; j++) 
    195195                { 
    196196                    int idx = vertexes[j]; 
  • OpenSceneGraph/trunk/include/osgAnimation/VertexInfluence

    r10026 r10656  
    11/*  -*-c++-*-  
    2  *  Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> 
     2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 
    33 * 
    44 * This library is open source and may be redistributed and/or modified under   
     
    9797            _uniqVertexSetToBoneSet.clear(); 
    9898        } 
     99 
     100        const VertexIndexToBoneWeightMap& getVertexToBoneList() const; 
    99101    protected: 
    100102        BoneToVertexList _bone2Vertexes; 
  • OpenSceneGraph/trunk/src/osgAnimation/Animation.cpp

    r10556 r10656  
    134134    } 
    135135 
    136     //  std::cout << "t " << t << " / " << _duration << std::endl; 
    137  
    138136    ChannelList::const_iterator chan; 
    139137    for( chan=_channels.begin(); chan!=_channels.end(); ++chan) 
  • OpenSceneGraph/trunk/src/osgAnimation/AnimationManagerBase.cpp

    r10576 r10656  
    2424{ 
    2525    _needToLink = false; 
     26    _automaticLink = true; 
    2627} 
    2728 
     
    3132        (*it).get()->reset(); 
    3233} 
     34 
     35void AnimationManagerBase::dirty() 
     36{ 
     37    _needToLink = true; 
     38} 
     39 
     40void AnimationManagerBase::setAutomaticLink(bool state) { _automaticLink = state; } 
     41bool AnimationManagerBase::isAutomaticLink() const { return _automaticLink; } 
    3342 
    3443void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv) 
     
    6574    } 
    6675    _needToLink = true; 
     76    _automaticLink = b._automaticLink; 
    6777    buildTargetReference(); 
    6878} 
     
    7181{ 
    7282    _targets.clear(); 
    73     for( AnimationList::iterator iterAnim = _animations.begin(); iterAnim != _animations.end(); ++iterAnim )  
     83    for( AnimationList::iterator iterAnim = _animations.begin(); iterAnim != _animations.end(); ++iterAnim ) 
    7484    { 
    7585        Animation* anim = (*iterAnim).get(); 
     
    99109} 
    100110 
    101 bool AnimationManagerBase::needToLink() const { return _needToLink; } 
     111bool AnimationManagerBase::needToLink() const { return _needToLink && isAutomaticLink(); } 
    102112 
    103113 
  • OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp

    r10561 r10656  
    7070        } 
    7171 
    72         if (!_manager.valid()) 
    73         { 
    74             FindParentAnimationManagerVisitor finder; 
    75  
    76             if (b->getParents().size() > 1) 
    77             { 
    78                 osg::notify(osg::WARN) << "A Bone should not have multi parent ( " << b->getName() << " ) has parents "; 
    79                 osg::notify(osg::WARN) << "( " << b->getParents()[0]->getName(); 
    80                 for (int i = 1; i < (int)b->getParents().size(); i++) 
    81                     osg::notify(osg::WARN) << ", " << b->getParents()[i]->getName(); 
    82                 osg::notify(osg::WARN) << ")" << std::endl; 
    83                 return; 
    84             } 
    85             b->getParents()[0]->accept(finder); 
    86  
    87             if (!finder.getAnimationManager()) 
    88             { 
    89                 osg::notify(osg::WARN) << "Warning can't update Bone, path to parent AnimationManagerBase not found" << std::endl; 
    90                 return; 
    91             } 
    92  
    93             _manager = finder.getAnimationManager(); 
    94         } 
    95  
    96         updateLink(); 
    9772        update(*b); 
    9873 
     
    11893    _boneInSkeletonSpace(b._boneInSkeletonSpace) 
    11994{ 
    120 #if 0 
    121     osg::ref_ptr<osg::NodeCallback> updatecallback = getUpdateCallback(); 
    122     setUpdateCallback(0); 
    123     while (updatecallback.valid()) { 
    124         osg::NodeCallback* ucb = dynamic_cast<osg::NodeCallback*>(updatecallback->clone(copyop)); 
    125         ucb->setNestedCallback(0); 
    126         addUpdateCallback(ucb); 
    127         updatecallback = updatecallback->getNestedCallback(); 
    128     } 
    129 #endif 
    13095} 
    13196 
  • OpenSceneGraph/trunk/src/osgAnimation/StatsHandler.cpp

    r10432 r10656  
    564564 
    565565                    for (int i = 0; i < (int)finder._timelines.size(); i++) 
    566                         statsList.push_back(finder._timelines[0]->getStats()); 
     566                        statsList.push_back(finder._timelines[i]->getStats()); 
    567567 
    568568                    for(int i = statsList[0]->getEarliestFrameNumber(); i<= statsList[0]->getLatestFrameNumber()-1; ++i) 
     
    654654        osg::MatrixTransform* m = s->createStatsForTimeline(finder._timelines[i].get()); 
    655655        m->setUpdateCallback(s); 
     656        m->setMatrix(osg::Matrix::translate(0, -i * 100, 0)); 
    656657        _group->addChild(m); 
    657658    } 
  • OpenSceneGraph/trunk/src/osgAnimation/Timeline.cpp

    r10561 r10656  
    202202{ 
    203203    _actions[priority].insert(_actions[priority].begin(), ftl); 
    204 //    _actions[priority].push_back(ftl); 
    205 } 
    206  
    207 #if 0 
    208 void osgAnimation::Timeline::evaluateCallback(unsigned int frame) 
    209 { 
    210     // update from high priority to low priority 
    211     for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim ) 
    212     { 
    213         // update all animation 
    214         ActionList& list = iterAnim->second; 
    215         for (unsigned int i = 0; i < list.size(); i++) 
    216         { 
    217             unsigned int firstFrame = list[i].first; 
    218             Action* action = list[i].second.get(); 
    219             // check if current frame of timeline hit an action interval 
    220             if (frame >= firstFrame &&  
    221                 frame < (firstFrame + action->getNumFrames()) ) 
    222                 action->evaluateCallback(frame - firstFrame); 
    223         } 
    224     } 
    225     processPendingOperation(); 
    226 } 
    227 #endif 
     204} 
    228205 
    229206bool osgAnimation::Timeline::isActive(Action* activeAction) 
  • OpenSceneGraph/trunk/src/osgAnimation/VertexInfluence.cpp

    r9093 r10656  
    1414 
    1515#include <osgAnimation/VertexInfluence> 
     16#include <osg/Notify> 
    1617#include <iostream> 
    1718#include <algorithm> 
     
    1920using namespace osgAnimation; 
    2021 
     22const osgAnimation::VertexInfluenceSet::VertexIndexToBoneWeightMap& osgAnimation::VertexInfluenceSet::getVertexToBoneList() const { return _vertex2Bones;} 
    2123// this class manage VertexInfluence database by mesh 
    2224// reference bones per vertex ... 
     
    3436            float weight = viw.second; 
    3537            if (vi.getName().empty()) 
    36                 std::cout << "osgAnimation::VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl; 
     38                osg::notify(osg::WARN) << "osgAnimation::VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl; 
    3739            _vertex2Bones[index].push_back(BoneWeight(vi.getName(), weight)); 
    3840        } 
     
    4042 
    4143    // normalize weight per vertex 
    42     for (VertexIndexToBoneWeightMap::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); it++)  
     44    for (VertexIndexToBoneWeightMap::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); it++) 
    4345    { 
    4446        BoneWeightList& bones = it->second; 
     
    4951        if (sum < 1e-4)  
    5052        { 
    51             std::cerr << "VertexInfluenceSet::buildVertex2BoneList warning the vertex " << it->first << " seems to have 0 weight, skip normalize for this vertex" << std::endl; 
     53            osg::notify(osg::WARN) << "VertexInfluenceSet::buildVertex2BoneList warning the vertex " << it->first << " seems to have 0 weight, skip normalize for this vertex" << std::endl; 
    5254        } 
    5355        else