Changeset 454 for cafu/trunk

Show
Ignore:
Timestamp:
01/08/12 19:02:41 (5 months ago)
Author:
Carsten
Message:

Model code:

  • Small enhancements and fixes to the new AnimExpressionT classes.
  • Put the new anim expressions to use in the Model Editor: Changing the selected model animation now blends from the old to the new animation, demonstrating the new code. :-)
Location:
cafu/trunk
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/ModelEditor/ChildFrame.cpp

    r437 r454  
    871871            m_ModelDoc->UpdateAllObservers_SelectionChanged(ANIM, OldSel, m_ModelDoc->GetSelection(ANIM)); 
    872872 
    873             m_ModelDoc->GetAnimState().Pose.SetFrameNr(0.0f); 
    874             m_ModelDoc->UpdateAllObservers_AnimStateChanged(); 
     873            // This is not needed: setting a new ANIM selection also sets the frame number to 0. 
     874            // m_ModelDoc->GetAnimState().LastStdAE->SetFrameNr(0.0f); 
     875            // m_ModelDoc->UpdateAllObservers_AnimStateChanged(); 
    875876            break; 
    876877        } 
     
    882883            m_ModelDoc->UpdateAllObservers_SelectionChanged(ANIM, OldSel, m_ModelDoc->GetSelection(ANIM)); 
    883884 
    884             m_ModelDoc->GetAnimState().Pose.SetFrameNr(0.0f); 
    885             m_ModelDoc->UpdateAllObservers_AnimStateChanged(); 
     885            // This is not needed: setting a new ANIM selection also sets the frame number to 0. 
     886            // m_ModelDoc->GetAnimState().LastStdAE->SetFrameNr(0.0f); 
     887            // m_ModelDoc->UpdateAllObservers_AnimStateChanged(); 
    886888            break; 
    887889        } 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp

    r439 r454  
    138138    if (Type==ANIM) 
    139139    { 
    140         m_AnimState.Pose.SetSequNr(m_Selection[ANIM].Size()==0 ? -1 : m_Selection[ANIM][0]); 
     140        IntrusivePtrT<AnimExpressionT> BlendFrom=m_AnimState.Pose.GetAnimExpr(); 
     141 
     142        // If BlendFrom is a blend anim expression that has not yet begun (Frac is still 0), 
     143        // this means that we got another call to SetSelection() immediately before this one. 
     144        // This can happen when the user clicked on a new animation in the animations list, 
     145        // which (when CTRL is not used) issues two calls, one for the deselection of the previous 
     146        // anim (causing us to blend to the -1 sequence), and one for the selection of the new. 
     147        // In this case, just skip the intermediate "-1" blend target. 
     148        { 
     149            AnimExprBlendT* Blend=dynamic_cast<AnimExprBlendT*>(&*BlendFrom); 
     150 
     151            if (Blend && Blend->GetFrac()==0.0f) 
     152                BlendFrom=Blend->GetA(); 
     153        } 
     154 
     155        m_AnimState.LastStdAE=m_AnimState.Pool.GetStandard(m_Selection[ANIM].Size()==0 ? -1 : m_Selection[ANIM][0], 0.0f); 
     156        m_AnimState.Pose.SetAnimExpr(m_AnimState.Pool.GetBlend(BlendFrom, m_AnimState.LastStdAE, 3.0f)); 
    141157 
    142158        if (m_Selection[ANIM].Size()==0) 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.hpp

    r428 r454  
    6565 
    6666            AnimStateT(const CafuModelT& Model) 
    67                 : Pose(Model), Speed(1.0f), Loop(true) { } 
     67                : Pool(Model), LastStdAE(Pool.GetStandard(-1, 0.0f)), Pose(Model, LastStdAE), Speed(1.0f), Loop(true) { } 
    6868 
    69             AnimPoseT Pose;     ///< The current pose of the model, as defined by sequence and frame number. 
    70             float     Speed;    ///< The speed (relative to clock time) with which the animation is advanced, usually 0 for stop or 1 for playback. 
    71             bool      Loop;     ///< When playing the sequence, loop automatically when its end has been reached? 
     69            AnimExprPoolT                    Pool; 
     70            IntrusivePtrT<AnimExprStandardT> LastStdAE; 
     71            AnimPoseT                        Pose;      ///< The current pose of the model, as defined by sequence and frame number. 
     72            float                            Speed;     ///< The speed (relative to clock time) with which the animation is advanced, usually 0 for stop or 1 for playback. 
     73            bool                             Loop;      ///< When playing the sequence, loop automatically when its end has been reached? 
    7274        }; 
    7375 
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.cpp

    r431 r454  
    143143 
    144144    wxPGProperty* AnimControlCat=Append(new wxPropertyCategory("Animation Control")); 
    145     m_AnimFrameNrProp=AppendIn(AnimControlCat, new wxFloatProperty("Frame No.", wxPG_LABEL, Anim.Pose.GetFrameNr())); 
     145    m_AnimFrameNrProp=AppendIn(AnimControlCat, new wxFloatProperty("Frame No.", wxPG_LABEL, Anim.LastStdAE->GetFrameNr())); 
    146146    m_AnimSpeedProp  =AppendIn(AnimControlCat, new wxFloatProperty("Speed", wxPG_LABEL, Anim.Speed)); 
    147147    m_AnimLoopProp   =AppendIn(AnimControlCat, new wxBoolProperty("Loop", wxPG_LABEL, Anim.Loop)); 
     
    229229    else if (PropName=="Model.Show tangent-space")    m_Model_ShowTangentSpace   =Prop->GetValue().GetBool(); 
    230230    else if (PropName=="Model.Debug material")        m_Model_DebugMaterial      =Prop->GetValue().GetInteger(); 
    231     else if (PropName=="Frame No.") { AnimState.Pose.SetFrameNr(PropValueF); m_IsRecursiveSelfNotify=true; m_Parent->GetModelDoc()->UpdateAllObservers_AnimStateChanged(); m_IsRecursiveSelfNotify=false; } 
     231    else if (PropName=="Frame No.") { AnimState.LastStdAE->SetFrameNr(PropValueF); m_IsRecursiveSelfNotify=true; m_Parent->GetModelDoc()->UpdateAllObservers_AnimStateChanged(); m_IsRecursiveSelfNotify=false; } 
    232232    else if (PropName=="Speed")     { AnimState.Speed=PropValueF; m_IsRecursiveSelfNotify=true; m_Parent->GetModelDoc()->UpdateAllObservers_AnimStateChanged(); m_IsRecursiveSelfNotify=false; } 
    233233    else if (PropName=="Loop")      { AnimState.Loop =Prop->GetValue().GetBool(); m_IsRecursiveSelfNotify=true; m_Parent->GetModelDoc()->UpdateAllObservers_AnimStateChanged(); m_IsRecursiveSelfNotify=false; } 
     
    286286    const ModelDocumentT::AnimStateT& AnimState=m_Parent->GetModelDoc()->GetAnimState(); 
    287287 
    288     if (m_AnimFrameNrProp->GetValue().GetDouble()!=AnimState.Pose.GetFrameNr()) 
    289         m_AnimFrameNrProp->SetValue(AnimState.Pose.GetFrameNr()); 
     288    if (m_AnimFrameNrProp->GetValue().GetDouble()!=AnimState.LastStdAE->GetFrameNr()) 
     289        m_AnimFrameNrProp->SetValue(AnimState.LastStdAE->GetFrameNr()); 
    290290 
    291291    if (m_AnimSpeedProp->GetValue().GetDouble()!=AnimState.Speed) 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp

    r431 r454  
    162162            ModelDoc->UpdateAllObservers_SelectionChanged(ANIM, OldSel, ModelDoc->GetSelection(ANIM)); 
    163163 
    164             ModelDoc->GetAnimState().Pose.SetFrameNr(0.0f); 
    165             ModelDoc->UpdateAllObservers_AnimStateChanged(); 
     164            // This is not needed: setting a new ANIM selection also sets the frame number to 0. 
     165            // ModelDoc->GetAnimState().LastStdAE->SetFrameNr(0.0f); 
     166            // ModelDoc->UpdateAllObservers_AnimStateChanged(); 
    166167            break; 
    167168        } 
     
    174175            ModelDoc->UpdateAllObservers_SelectionChanged(ANIM, OldSel, ModelDoc->GetSelection(ANIM)); 
    175176 
    176             ModelDoc->GetAnimState().Pose.SetFrameNr(0.0f); 
    177             ModelDoc->UpdateAllObservers_AnimStateChanged(); 
     177            // This is not needed: setting a new ANIM selection also sets the frame number to 0. 
     178            // ModelDoc->GetAnimState().LastStdAE->SetFrameNr(0.0f); 
     179            // ModelDoc->UpdateAllObservers_AnimStateChanged(); 
    178180            break; 
    179181        } 
  • cafu/trunk/Libs/Models/AnimExpr.cpp

    r453 r454  
    223223unsigned int AnimExprFilterT::GetChangeNum() const 
    224224{ 
    225     return std::max(GetChangeNum(), m_SubExpr->GetChangeNum()); 
     225    return std::max(AnimExpressionT::GetChangeNum(), m_SubExpr->GetChangeNum()); 
    226226} 
    227227 
     
    263263unsigned int AnimExprCombineT::GetChangeNum() const 
    264264{ 
    265     return std::max(GetChangeNum(), 
     265    return std::max(AnimExpressionT::GetChangeNum(), 
    266266                    std::max(m_A->GetChangeNum(), m_B->GetChangeNum())); 
    267267} 
     
    324324unsigned int AnimExprBlendT::GetChangeNum() const 
    325325{ 
    326     return std::max(GetChangeNum(), 
     326    if (m_Frac >= 1.0f) 
     327    { 
     328        return std::max(AnimExpressionT::GetChangeNum(), m_B->GetChangeNum()); 
     329    } 
     330 
     331    return std::max(AnimExpressionT::GetChangeNum(), 
    327332                    std::max(m_A->GetChangeNum(), m_B->GetChangeNum())); 
    328333} 
     
    356361    Weight = w[0]*f0 + w[1]*f1; 
    357362    Pos    = p[0]*f0 + p[1]*f1; 
    358     Quat   = slerp(q[0], q[1], f0);   // slerp() is why we cannot have generic "add" and "mul" AnimExpressionT's. 
     363    Quat   = slerp(q[0], q[1], f1);   // slerp() is why we cannot have generic "add" and "mul" AnimExpressionT's. 
    359364    Scale  = s[0]*f0 + s[1]*f1; 
    360365} 
  • cafu/trunk/Libs/Models/AnimExpr.hpp

    r453 r454  
    187187    void ReInit(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration); 
    188188 
     189    /// Returns the "blend from" sub-expression. 
     190    IntrusivePtrT<AnimExpressionT> GetA() const { return m_A; } 
     191 
     192    /// Returns the "blend to" sub-expression. 
     193    IntrusivePtrT<AnimExpressionT> GetB() const { return m_B; } 
     194 
     195    /// Returns how far the blend has advanced. 
     196    float GetFrac() const { return m_Frac; } 
     197 
    189198    // Implementations and overrides for base class methods. 
    190199    virtual unsigned int GetChangeNum() const; 
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r453 r454  
    488488    m_AnimExpr->AdvanceTime(Time, ForceLoop); 
    489489 
    490     // Recursively update the chain of dlod poses. 
    491     if (m_DlodPose) m_DlodPose->Advance(Time, ForceLoop); 
     490    // Don't do this -- the dlod models share the same anim expression as the main model. 
     491    // In fact, this method should be removed. Have the caller call Pose->GetAnimExpr()->AdvanceTime() instead. 
     492    // 
     493    // // Recursively update the chain of dlod poses. 
     494    // if (m_DlodPose) m_DlodPose->Advance(Time, ForceLoop); 
    492495} 
    493496 
  • cafu/trunk/Libs/Models/AnimPose.hpp

    r453 r454  
    9494    /// The destructor. 
    9595    ~AnimPoseT(); 
     96 
     97    /// Returns the current anim expression of this pose. 
     98    IntrusivePtrT<AnimExpressionT> GetAnimExpr() const { return m_AnimExpr; } 
    9699 
    97100    /// Sets a new anim expression to use for this pose. 
  • cafu/trunk/Libs/Templates/Pointer.hpp

    r453 r454  
    4949    } 
    5050 
     51    /// The copy constructor (for Y classes that are derived from T). 
     52    template<class Y> IntrusivePtrT(const IntrusivePtrT<Y>& IP) 
     53        : m_Ptr(IP.get()) 
     54    { 
     55        if (m_Ptr) m_Ptr->m_RefCount++; 
     56    } 
     57 
    5158    /// The destructor. 
    5259    ~IntrusivePtrT() 
     
    7986    } 
    8087 
     88    /// Returns the stored pointer. 
     89    T* get() const { return m_Ptr; } 
     90 
    8191    /// The structure dereference operator. 
    8292    T* operator -> () { return m_Ptr; }