Changeset 422 for cafu/trunk

Show
Ignore:
Timestamp:
11/14/11 13:43:11 (6 months ago)
Author:
Carsten
Message:

Model code:
Removed struct AnimPoseT::SuperT again, which greatly simplifies the user code.
The performance impact for searching the joints in AnimPoseT::GetJointMatrix() seems negligible, if present at all.

Location:
cafu/trunk
Files:
7 modified

Legend:

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

    r415 r422  
    4141 
    4242 
    43 ModelEditor::ModelDocumentT::SubmodelT::SubmodelT(const wxString& fn, CafuModelT* sm, const ArrayT<unsigned int>& jm) 
    44     : m_Filename(fn), 
    45       m_Submodel(sm), 
    46       m_Pose(*sm, -1, 0.0f), 
    47       m_JointsMap(jm) 
     43ModelEditor::ModelDocumentT::SubmodelT::SubmodelT(CafuModelT* Submodel) 
     44    : m_Submodel(Submodel), 
     45      m_Pose(*Submodel, -1, 0.0f) 
    4846{ 
    4947} 
     
    167165    try 
    168166    { 
    169         CafuModelT*          Submodel=LoadModel(FileName); 
    170         ArrayT<unsigned int> JointsMap; 
    171  
    172         for (unsigned int JointNr=0; JointNr<Submodel->GetJoints().Size(); JointNr++) 
    173         { 
    174             const std::string& SubName=Submodel->GetJoints()[JointNr].Name; 
    175  
    176             unsigned int JNr; 
    177             for (JNr=0; JNr<m_Model->GetJoints().Size(); JNr++) 
    178                 if (wxStricmp(SubName, m_Model->GetJoints()[JNr].Name)==0) 
    179                     break; 
    180  
    181             // Not found / no correspondence is indicated by a too large and thus invalid JNr. 
    182             JointsMap.PushBack(JNr); 
    183         } 
    184  
    185         m_Submodels.PushBack(new SubmodelT(FileName, Submodel, JointsMap)); 
     167        m_Submodels.PushBack(new SubmodelT(LoadModel(FileName))); 
    186168    } 
    187169    catch (const ModelT::LoadError& /*E*/) 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.hpp

    r400 r422  
    7676            public: 
    7777 
    78             SubmodelT(const wxString& fn, CafuModelT* sm, const ArrayT<unsigned int>& jm); 
     78            SubmodelT(CafuModelT* Submodel); 
    7979            ~SubmodelT(); 
    8080 
    81             const wxString&             GetFilename() const { return m_Filename; } 
    82             const CafuModelT*           GetSubmodel() const { return m_Submodel; } 
    83             AnimPoseT&                  GetPose() { return m_Pose; } 
    84             const ArrayT<unsigned int>& GetJointsMap() const { return m_JointsMap; } 
     81            const CafuModelT* GetSubmodel() const { return m_Submodel; } 
     82            AnimPoseT&        GetPose() { return m_Pose; } 
    8583 
    8684 
    8785            private: 
    8886 
    89             wxString             m_Filename;    ///< The filename of the submodel. 
    90             CafuModelT*          m_Submodel;    ///< The submodel that is shown with the main model. 
    91             AnimPoseT            m_Pose;        ///< The pose of the submodel. 
    92             ArrayT<unsigned int> m_JointsMap;   ///< Describes how the joints of the m_Submodel map to the joints of the m_Model super model. 
    93  
    9487            SubmodelT(const SubmodelT&);        ///< Use of the Copy    Constructor is not allowed. 
    9588            void operator = (const SubmodelT&); ///< Use of the Assignment Operator is not allowed. 
     89 
     90            CafuModelT* m_Submodel;   ///< The submodel that is shown with the main model. 
     91            AnimPoseT   m_Pose;       ///< The pose of the submodel. 
    9692        }; 
    9793 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp

    r402 r422  
    379379            AnimPoseT&                 SmPose=SM->GetPose(); 
    380380 
    381             const AnimPoseT::SuperT Super( 
    382                 Anim.Pose.GetJointMatrices(), 
    383                 SM->GetJointsMap()); 
    384  
    385             SmPose.SetSuper(&Super); 
     381            SmPose.SetSuperPose(&Anim.Pose); 
    386382            SmPose.Draw(-1 /*SkinNr*/, 0.0f /*LodDist*/); 
    387             SmPose.SetSuper(NULL); 
     383            SmPose.SetSuperPose(NULL); 
    388384        } 
    389385    } 
     
    400396            AnimPoseT&                 SmPose=SM->GetPose(); 
    401397 
    402             const AnimPoseT::SuperT Super( 
    403                 Anim.Pose.GetJointMatrices(), 
    404                 SM->GetJointsMap()); 
    405  
    406             SmPose.SetSuper(&Super); 
     398            SmPose.SetSuperPose(&Anim.Pose); 
    407399            RenderSkeleton(SM->GetSubmodel()->GetJoints(), SmPose.GetJointMatrices(), true); 
    408             SmPose.SetSuper(NULL); 
     400            SmPose.SetSuperPose(NULL); 
    409401        } 
    410402    } 
  • cafu/trunk/CaWE/ModelEditor/SubmodelsList.cpp

    r343 r422  
    9494    for (unsigned long ElemNr=0; ElemNr<m_ModelDoc->GetSubmodels().Size(); ElemNr++) 
    9595    { 
    96         wxFileName fn(m_ModelDoc->GetSubmodels()[ElemNr]->GetFilename()); 
     96        wxFileName fn(m_ModelDoc->GetSubmodels()[ElemNr]->GetSubmodel()->GetFileName()); 
    9797 
    9898        fn.MakeRelativeTo(m_ModelDoc->GetGameConfig()->ModDir); 
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r406 r422  
    3333      m_SequNr(SequNr), 
    3434      m_FrameNr(FrameNr), 
    35       m_Super(NULL), 
     35      m_SuperPose(NULL), 
    3636      m_DlodPose(m_Model.GetDlodModel() ? new AnimPoseT(*m_Model.GetDlodModel(), SequNr, FrameNr) : NULL),  // Recursively create the chain of dlod poses matching the chain of dlod models. 
    3737      m_NeedsRecache(true), 
     
    7676 
    7777 
    78 void AnimPoseT::SetSuper(const SuperT* Super) 
    79 { 
    80     if (m_Super==Super) return; 
    81  
    82     m_Super=Super; 
     78void AnimPoseT::SetSuperPose(const AnimPoseT* SuperPose) 
     79{ 
     80    if (m_SuperPose==SuperPose) return; 
     81 
     82    m_SuperPose=SuperPose; 
    8383 
    8484    m_NeedsRecache=true; 
    8585 
    8686    // Recursively update the chain of dlod poses. 
    87     if (m_DlodPose) m_DlodPose->SetSuper(Super); 
     87    if (m_DlodPose) m_DlodPose->SetSuperPose(SuperPose); 
    8888} 
    8989 
     
    406406 
    407407 
     408const MatrixT* AnimPoseT::GetJointMatrix(const std::string& JointName) const 
     409{ 
     410    Recache(); 
     411 
     412    for (unsigned int JointNr=0; JointNr<m_Model.GetJoints().Size(); JointNr++) 
     413        if (m_Model.GetJoints()[JointNr].Name == JointName) 
     414            return &m_JointMatrices[JointNr]; 
     415 
     416    return NULL; 
     417} 
     418 
     419 
    408420const ArrayT<AnimPoseT::MeshInfoT>& AnimPoseT::GetMeshInfos() const 
    409421{ 
     
    526538        for (unsigned long JointNr=0; JointNr<Joints.Size(); JointNr++) 
    527539        { 
    528             if (m_Super && m_Super->HasMatrix(JointNr)) 
    529             { 
    530                 m_JointMatrices[JointNr]=m_Super->GetMatrix(JointNr); 
    531                 continue; 
     540            if (m_SuperPose) 
     541            { 
     542                const MatrixT* SuperMat=m_SuperPose->GetJointMatrix(Joints[JointNr].Name); 
     543 
     544                if (SuperMat) 
     545                { 
     546                    m_JointMatrices[JointNr]=*SuperMat; 
     547                    continue; 
     548                } 
    532549            } 
    533550 
     
    548565        for (unsigned long JointNr=0; JointNr<Joints.Size(); JointNr++) 
    549566        { 
    550             if (m_Super && m_Super->HasMatrix(JointNr)) 
    551             { 
    552                 m_JointMatrices[JointNr]=m_Super->GetMatrix(JointNr); 
    553                 continue; 
     567            if (m_SuperPose) 
     568            { 
     569                const MatrixT* SuperMat=m_SuperPose->GetJointMatrix(Joints[JointNr].Name); 
     570 
     571                if (SuperMat) 
     572                { 
     573                    m_JointMatrices[JointNr]=*SuperMat; 
     574                    continue; 
     575                } 
    554576            } 
    555577 
     
    820842void AnimPoseT::Recache() const 
    821843{ 
    822     if (!m_NeedsRecache && !m_Super) return; 
     844    if (!m_NeedsRecache && !m_SuperPose) return; 
    823845 
    824846    SyncDimensions(); 
  • cafu/trunk/Libs/Models/AnimPose.hpp

    r416 r422  
    7575 
    7676 
    77     /// This struct describes information about a parent or "super" model whose skeleton pose 
    78     /// should be used when rendering this model. For example, a player model can act as the 
    79     /// super model for a weapon, so that the skeleton of the weapon is copied from the 
    80     /// player model in order to align the weapon with the hands of the player. 
    81     struct SuperT 
    82     { 
    83         /// The constructor. 
    84         /// @param Matrices_   The draw matrices of the super model. 
    85         /// @param Map_        Describes how our joints map to the joints of the super model. 
    86         ///                    If <tt>Map_[i]</tt> is not a valid index into \c Matrices_, then our joint \c i has no match in the skeleton of the super model. 
    87         SuperT(const ArrayT<MatrixT>& Matrices_, const ArrayT<unsigned int>& Map_) : Matrices(Matrices_), Map(Map_) { } 
    88  
    89         /// Has our joint \c JointNr a correspondence in the super model? 
    90         bool HasMatrix(unsigned long JointNr) const { return Map[JointNr] < Matrices.Size(); } 
    91  
    92         /// For our joint \c JointNr, return the corresponding matrix from the super model. 
    93         /// Only call this if HasMatrix(JointNr) returns \c true. 
    94         const MatrixT& GetMatrix(unsigned long JointNr) const { return Matrices[Map[JointNr]]; } 
    95  
    96         const ArrayT<MatrixT>&      Matrices;   ///< The draw matrices of the super model. 
    97         const ArrayT<unsigned int>& Map;        ///< Describes how our joints map to the joints of the super model. If <tt>Map[i]</tt> is not a valid index into \c Matrices, then our joint \c i has no match in the skeleton of the super model. 
    98     }; 
    99  
    100  
    10177    /// The constructor. 
    10278    AnimPoseT(const CafuModelT& Model, int SequNr=-1, float FrameNr=0.0f); 
     
    11288    float GetFrameNr() const { return m_FrameNr; } 
    11389 
    114     /// @param FrameNr      The frame number in the animation sequence to render to model at. 
     90    /// @param FrameNr      The frame number in the animation sequence to render the model at. 
    11591    void SetFrameNr(float FrameNr); 
    11692 
    117     /// @param Super        Information about a parent or "super" model whose skeleton pose should be used when rendering this model. 
    118     void SetSuper(const SuperT* Super); 
     93    /// This method assigns a pose of a parent or "super" model that should be used when rendering this model. 
     94    /// 
     95    /// For example, a player model can act as the super model for a weapon, 
     96    /// so that the skeleton of the weapon is copied from the player model 
     97    /// in order to align the weapon with the hands of the player. 
     98    /// 
     99    /// @param SuperPose   The super model pose that should be used when rendering this model. 
     100    void SetSuperPose(const AnimPoseT* SuperPose); 
    119101 
    120102    /// Advances the pose in time. 
     
    147129    const ArrayT<MatrixT>& GetJointMatrices() const; 
    148130 
     131    /// Returns the transformation matrix for the joint with the given name, or \c NULL if there is no such joint. 
     132    const MatrixT* GetJointMatrix(const std::string& JointName) const; 
     133 
    149134    /// Returns the mesh infos with additional data for each mesh in this pose. 
    150135    const ArrayT<MeshInfoT>& GetMeshInfos() const; 
     
    170155    int                           m_SequNr;         ///< The animation sequence number at which we have computed the cache data. 
    171156    float                         m_FrameNr;        ///< The animation frame    number at which we have computed the cache data. 
    172     const SuperT*                 m_Super; 
     157    const AnimPoseT*              m_SuperPose; 
    173158    AnimPoseT*                    m_DlodPose;       ///< The next pose in the chain of dlod poses matching the chain of dlod models. 
    174159 // ArrayT<...>                   m_Def;            ///< Array of { channel, sequence, framenr, (forceloop), blendweight } tuples. 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r414 r422  
    279279 
    280280    // The ModelT interface. 
    281     const std::string& GetFileName() const;     // TODO: Remove!?! 
     281    const std::string& GetFileName() const; 
    282282    void               Draw(int SequenceNr, float FrameNr, float LodDist, const ModelT* SubModel=NULL) const; 
    283283    bool               GetGuiPlane(int SequenceNr, float FrameNr, float LodDist, Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const;