Changeset 414

Show
Ignore:
Timestamp:
10/28/11 13:58:10 (7 months ago)
Author:
Carsten
Message:

Model code:

  • Added new class ModelManagerT, which essentially does for models what the MaterialManagerImplT does for materials, and which is supposed to completely replace the obsolete class ModelProxyT in the very near future.
  • Added method CafuModelT::GetSharedPose() in order to make the switch from ModelProxyT to the ModelManagerT easy to implement and backwards-compatible. (Improving the caching by better sharing (or not sharing) AnimPoseT instances among related models is a subject for future consideration and implementation.)
  • Exemplary started to update the related code in the Map Editor component of CaWE.
Location:
cafu/trunk
Files:
2 added
12 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/DialogInsp-PrimitiveProps.cpp

    r285 r414  
    3939#include "wx/propgrid/advprops.h" 
    4040 
     41#include "Models/Model_cmdl.hpp" 
    4142#include "TypeSys.hpp" 
    4243 
     
    270271            MapModelT* Model=(MapModelT*)SelectedPrimitives[i]; 
    271272 
    272             PropMan->AppendIn(Cat, new GameFilePropertyT("Model",           wxPG_LABEL, Model->m_Model.GetFileName(), MapDoc, "All Files (*.*)|*.*|Model files (*.mdl)|*.mdl|Model Files (*.ase)|*.ase|Model Files (*.dlod)|*.dlod", "/Models/"))->SetClientData(Model); 
     273            PropMan->AppendIn(Cat, new GameFilePropertyT("Model",           wxPG_LABEL, Model->m_Model->GetFileName(), MapDoc, "All Files (*.*)|*.*|Model files (*.mdl)|*.mdl|Model Files (*.ase)|*.ase|Model Files (*.dlod)|*.dlod", "/Models/"))->SetClientData(Model); 
    273274            PropMan->AppendIn(Cat, new GameFilePropertyT("Collision Model", wxPG_LABEL, Model->m_CollModelFileName, MapDoc, "Collision Model (*.cmap)|*.cmap|All Files (*.*)|*.*", "/Models/"))->SetClientData(Model); 
    274275            PropMan->AppendIn(Cat, new wxStringProperty ("Label",           wxPG_LABEL, Model->m_Label))->SetClientData(Model); 
  • cafu/trunk/CaWE/GameConfig.cpp

    r285 r414  
    250250 
    251251 
     252const CafuModelT* GameConfigT::GetModel(const wxString& FileName, wxString* ErrorMsg) const 
     253{ 
     254    std::string       Msg; 
     255    const CafuModelT* Model=m_ModelMan.GetModel(std::string(ModDir + "/" + FileName), Msg); 
     256 
     257    if (ErrorMsg) 
     258        *ErrorMsg=Msg; 
     259 
     260    return Model; 
     261} 
     262 
     263 
    252264BoundingBox3fT GameConfigT::GetMaxMapBB() const 
    253265{ 
  • cafu/trunk/CaWE/GameConfig.hpp

    r285 r414  
    2525#include "EditorMaterialManager.hpp" 
    2626#include "Math3D/BoundingBox.hpp" 
     27#include "Models/ModelManager.hpp" 
    2728#include "Templates/Array.hpp" 
    2829#include "wx/wx.h" 
     
    5960    const EditorMatManT& GetMatMan() const { return m_MatMan; } 
    6061 
     62    /// Returns the model for the given FileName that is relative to ModDir. 
     63    const CafuModelT* GetModel(const wxString& FileName, wxString* ErrorMsg=NULL) const; 
     64 
    6165    int GetMaxMapCoord() const { return  m_MaxMapCoord; } 
    6266    int GetMinMapCoord() const { return -m_MaxMapCoord; } 
     
    8488    void operator = (const GameConfigT&);   ///< Use of the Assignment Operator is not allowed. 
    8589 
    86  
    8790    ArrayT<cf::FileSys::FileSystemT*> m_MountedFileSystems;     ///< The file systems that have been mounted for this game config. 
    8891    ArrayT<const EntityClassT*>       m_EntityClasses;          ///< The entity classes as obtained from the EntityClassDefs.lua script. 
    89     EditorMatManT                     m_MatMan;                 ///< This material manager of this game config. 
     92    EditorMatManT                     m_MatMan;                 ///< The material manager for this game config. 
     93    ModelManagerT                     m_ModelMan;               ///< The model manager for this game config. 
    9094    int                               m_MaxMapCoord; 
    9195}; 
  • cafu/trunk/CaWE/LoadSave_cmap.cpp

    r285 r414  
    505505 
    506506    m_ModelFileName    =TP.GetNextToken(); 
    507     m_Model            =ModelProxyT(std::string(MapDoc.GetGameConfig()->ModDir+"/"+m_ModelFileName)); 
     507    m_Model            =MapDoc.GetGameConfig()->GetModel(m_ModelFileName); 
    508508    m_CollModelFileName=TP.GetNextToken(); 
    509509 
     
    690690        { 
    691691            // A model definition. 
    692             MapModelT* Model=new MapModelT(); 
     692            MapModelT* Model=new MapModelT(MapDoc, "dummy", Vector3fT()); 
    693693 
    694694            Model->Load_cmap(TP, MapDoc); 
  • cafu/trunk/CaWE/MapCommands/ModifyModel.cpp

    r285 r414  
    6666 
    6767    m_Model->m_ModelFileName    =m_NewModelFileName; 
    68     m_Model->m_Model            =ModelProxyT(std::string(m_MapDoc.GetGameConfig()->ModDir+"/"+m_NewModelFileName)); 
     68    m_Model->m_Model            =m_MapDoc.GetGameConfig()->GetModel(m_NewModelFileName); 
    6969    m_Model->m_CollModelFileName=m_NewCollModelFileName; 
    7070    m_Model->m_Label            =m_NewLabel; 
     
    9696 
    9797    m_Model->m_ModelFileName    =m_OldModelFileName; 
    98     m_Model->m_Model            =ModelProxyT(std::string(m_MapDoc.GetGameConfig()->ModDir+"/"+m_OldModelFileName)); 
     98    m_Model->m_Model            =m_MapDoc.GetGameConfig()->GetModel(m_OldModelFileName); 
    9999    m_Model->m_CollModelFileName=m_OldCollModelFileName; 
    100100    m_Model->m_Label            =m_OldLabel; 
  • cafu/trunk/CaWE/MapHelperModel.cpp

    r408 r414  
    3434#include "Math3D/BoundingBox.hpp" 
    3535#include "Math3D/Matrix3x3.hpp" 
     36#include "Models/Model_cmdl.hpp" 
    3637#include "EditorMaterialManager.hpp" 
    3738#include "MaterialSystem/Renderer.hpp" 
    3839#include "TypeSys.hpp" 
    3940 
    40 #include "wx/wx.h" 
    41 #include "wx/sstream.h" 
    42 #include "wx/txtstrm.h" 
    43  
    4441 
    4542/*** Begin of TypeSys related definitions for this class. ***/ 
     
    5855    : MapHelperT(ParentEntity), 
    5956      m_HelperInfo(HelperInfo), 
    60       m_ModelProxy(), 
     57      m_Model(NULL), 
    6158      m_ModelFrameNr(0.0f), 
    6259      m_Timer() 
     
    6865    : MapHelperT(Model), 
    6966      m_HelperInfo(Model.m_HelperInfo), 
    70       m_ModelProxy(Model.m_ModelProxy), 
     67      m_Model(Model.m_Model), 
    7168      m_ModelFrameNr(0.0f), 
    7269      m_Timer(Model.m_Timer) 
     
    9390    m_ParentEntity=Model->m_ParentEntity; 
    9491    m_HelperInfo  =Model->m_HelperInfo; 
    95     m_ModelProxy  =Model->m_ModelProxy; 
     92    m_Model       =Model->m_Model; 
    9693    m_ModelFrameNr=Model->m_ModelFrameNr; 
    9794    m_Timer       =Model->m_Timer; 
     
    110107    // The 3D bounds are the bounds of the oriented model's first sequence, so that frustum culling works properly in the 3D view. 
    111108    Vector3fT VerticesBB[8]; 
    112     m_ModelProxy.GetBB(GetSequenceNr(), 0.0f).GetCornerVertices(VerticesBB); 
     109    m_Model->GetSharedPose(GetSequenceNr(), 0.0f)->GetBB().GetCornerVertices(VerticesBB); 
    113110 
    114111    // Rotate all eight vertices. 
     
    146143    const Vector3fT ViewPoint=Renderer.GetViewWin3D().GetCamera().Pos; 
    147144    const float     ModelDist=length(Origin-ViewPoint); 
     145    AnimPoseT*      Pose     =m_Model->GetSharedPose(SequenceNr, m_ModelFrameNr); 
    148146 
    149147    if (Options.view3d.AnimateModels) 
    150         m_ModelFrameNr=m_ModelProxy.AdvanceFrameNr(SequenceNr, m_ModelFrameNr, float(m_Timer.GetSecondsSinceLastCall())); 
     148    { 
     149        Pose->Advance(float(m_Timer.GetSecondsSinceLastCall())); 
     150 
     151        m_ModelFrameNr=Pose->GetFrameNr(); 
     152    } 
    151153 
    152154    if (ModelDist < float(Options.view3d.ModelDistance)) 
     
    163165        MatSys::Renderer->RotateX  (MatSys::RendererI::MODEL_TO_WORLD,  Angles[ROLL ]); 
    164166 
    165         m_ModelProxy.Draw(SequenceNr, m_ModelFrameNr, CAFU_ENG_SCALE*ModelDist, NULL); 
     167        Pose->Draw(-1 /*default skin*/, CAFU_ENG_SCALE*ModelDist); 
    166168 
    167169        MatSys::Renderer->PopMatrix(MatSys::RendererI::MODEL_TO_WORLD); 
     
    180182void MapHelperModelT::UpdateModelCache() const 
    181183{ 
    182     const wxString* ModelName=m_HelperInfo->Parameters.Size()>0 ? &m_HelperInfo->Parameters[0] : NULL; 
    183  
    184     // If we weren't passed a model name as an argument, get it from our parent entity's "model" property. 
    185     if (ModelName==NULL) 
    186     { 
     184    wxString ModelName=""; 
     185    wxString ErrorMsg =""; 
     186 
     187    if (m_HelperInfo->Parameters.Size() > 0) 
     188    { 
     189        ModelName=m_HelperInfo->Parameters[0]; 
     190    } 
     191    else 
     192    { 
     193        // If we weren't passed a model name as an argument, get it from our parent entity's "model" property. 
    187194        // Calling FindProperty() each render frame is not particularly efficient... 
    188195        const EntPropertyT* ModelProp=m_ParentEntity->FindProperty("model"); 
    189196 
    190         if (ModelProp) ModelName=&ModelProp->Value; 
    191     } 
    192  
    193     // If the helper info has no argument and the parent has no "model" property, we shouldn't have gotten here. 
    194     if (ModelName==NULL) return; 
    195  
    196     const wxString FullName=m_ParentEntity->GetClass()->GetGameConfig().ModDir+"/"+(*ModelName); 
    197  
    198     if (m_ModelProxy.GetFileName()==FullName) return; 
    199  
    200     wxLogDebug("MapHelperModelT::UpdateModelCache(): Updating model from %s to %s.", m_ModelProxy.GetFileName(), FullName); 
    201  
    202     m_ModelProxy=ModelProxyT(std::string(FullName)); 
    203     m_ModelFrameNr=0.0f; 
     197        if (ModelProp) ModelName=ModelProp->Value; 
     198    } 
     199 
     200    const CafuModelT* Model=m_ParentEntity->GetClass()->GetGameConfig().GetModel(ModelName, &ErrorMsg); 
     201 
     202    if (m_Model!=Model) 
     203    { 
     204        const std::string PrevFileName=m_Model ? m_Model->GetFileName() : "<none>"; 
     205 
     206        wxLogDebug("MapHelperModelT::UpdateModelCache(): Updating model from %s to %s. %s", PrevFileName, Model->GetFileName(), ErrorMsg); 
     207 
     208        m_Model       =Model; 
     209        m_ModelFrameNr=0.0f; 
     210    } 
    204211} 
    205212 
  • cafu/trunk/CaWE/MapHelperModel.hpp

    r285 r414  
    2424 
    2525#include "MapHelper.hpp" 
    26 #include "Models/Model_proxy.hpp" 
    2726#include "Util/Util.hpp" 
    2827 
     
    3231class Renderer2DT; 
    3332class Renderer3DT; 
     33 
     34class CafuModelT; 
    3435namespace cf { namespace TypeSys { class TypeInfoT; } } 
    3536namespace cf { namespace TypeSys { class TypeInfoManT; } } 
     
    7071    int  GetSequenceNr() const; 
    7172 
    72     const HelperInfoT*  m_HelperInfo;       ///< The HelperInfoT instance that caused the instantiation of this helper. 
    73     mutable ModelProxyT m_ModelProxy;       ///< Our model (proxy). 
    74     mutable float       m_ModelFrameNr;     ///< The frame number of the sequence to render this model in. 
    75     mutable TimerT      m_Timer; 
     73    const HelperInfoT*        m_HelperInfo;     ///< The HelperInfoT instance that caused the instantiation of this helper. 
     74    mutable const CafuModelT* m_Model;          ///< Our model (obtained from the game config's model manager). 
     75    mutable float             m_ModelFrameNr;   ///< The frame number of the sequence to render this model in. 
     76    mutable TimerT            m_Timer; 
    7677}; 
    7778 
  • cafu/trunk/CaWE/MapModel.cpp

    r408 r414  
    3232 
    3333#include "MaterialSystem/Renderer.hpp" 
    34 #include "MaterialSystem/Mesh.hpp" 
    3534#include "Math3D/Matrix3x3.hpp" 
     35#include "Models/Model_cmdl.hpp" 
    3636 
    3737#include "wx/wx.h" 
     
    4848 
    4949/*** End of TypeSys related definitions for this class. ***/ 
    50  
    51  
    52 MapModelT::MapModelT() 
    53     : MapPrimitiveT(wxColour(150 + (rand() % 106), 150 + (rand() % 106), 0)), 
    54       m_ModelFileName(""), 
    55       m_Model(), 
    56       m_CollModelFileName(""), 
    57       m_Label(""), 
    58       m_Angles(), 
    59       m_Scale(1.0f), 
    60       m_SeqNumber(0), 
    61       m_FrameOffset(0.0f), 
    62       m_FrameTimeScale(1.0f), 
    63       m_FrameNumber(0.0f), 
    64       m_Animated(false), 
    65       m_Timer() 
    66 { 
    67 } 
    6850 
    6951 
     
    7153    : MapPrimitiveT(wxColour(150 + (rand() % 106), 150 + (rand() % 106), 0)), 
    7254      m_ModelFileName(ModelFileName), 
    73       m_Model(std::string(MapDoc.GetGameConfig()->ModDir+"/"+ModelFileName)), 
     55      m_Model(MapDoc.GetGameConfig()->GetModel(m_ModelFileName)), 
    7456      m_Origin(Position), 
    7557      m_CollModelFileName(""), 
     
    9072    : MapPrimitiveT(wxColour(150 + (rand() % 106), 150 + (rand() % 106), 0)), 
    9173      m_ModelFileName(ModelFileName), 
    92       m_Model(std::string(MapDoc.GetGameConfig()->ModDir+"/"+m_ModelFileName)), 
     74      m_Model(MapDoc.GetGameConfig()->GetModel(m_ModelFileName)), 
    9375      m_Origin(Position), 
    9476      m_CollModelFileName(CollisionModelFileName), 
     
    160142    // The 3D bounds are the bounds of the oriented model's first sequence, so that frustum culling works properly in the 3D view. 
    161143    Vector3fT VerticesBB[8]; 
    162     m_Model.GetBB(m_SeqNumber, 0.0f).GetCornerVertices(VerticesBB); 
     144    m_Model->GetSharedPose(m_SeqNumber, 0.0f)->GetBB().GetCornerVertices(VerticesBB); 
    163145 
    164146    // Rotate all eight vertices. 
     
    205187    const Vector3fT ViewPoint=Renderer.GetViewWin3D().GetCamera().Pos; 
    206188    const float     ModelDist=length(m_Origin-ViewPoint); 
     189    AnimPoseT*      Pose     =m_Model->GetSharedPose(m_SeqNumber, m_FrameNumber); 
    207190 
    208191    if (Options.view3d.AnimateModels && m_Animated) 
    209         m_FrameNumber=m_Model.AdvanceFrameNr(m_SeqNumber, m_FrameNumber, float(m_Timer.GetSecondsSinceLastCall())*m_FrameTimeScale); 
     192    { 
     193        Pose->Advance(float(m_Timer.GetSecondsSinceLastCall())*m_FrameTimeScale); 
     194 
     195        m_FrameNumber=Pose->GetFrameNr(); 
     196    } 
    210197 
    211198    if (ModelDist<float(Options.view3d.ModelDistance)) 
     
    222209        MatSys::Renderer->Scale    (MatSys::RendererI::MODEL_TO_WORLD, m_Scale); 
    223210 
    224         m_Model.Draw(m_SeqNumber, m_FrameNumber, CAFU_ENG_SCALE*ModelDist, NULL); 
     211        Pose->Draw(-1 /*default skin*/, CAFU_ENG_SCALE*ModelDist); 
    225212 
    226213        MatSys::Renderer->PopMatrix(MatSys::RendererI::MODEL_TO_WORLD); 
  • cafu/trunk/CaWE/MapModel.hpp

    r285 r414  
    2424 
    2525#include "MapPrimitive.hpp" 
    26  
    27 #include "Models/Model_proxy.hpp" 
    2826#include "Util/Util.hpp" 
    2927 
    3028 
    3129class MapDocumentT; 
     30class CafuModelT; 
    3231 
    3332 
     
    3635    public: 
    3736 
    38     MapModelT(); 
    39  
    4037    MapModelT(MapDocumentT& MapDoc, const wxString& ModelFileName, const Vector3fT& Position); 
    41  
    4238    MapModelT(MapDocumentT& MapDoc, const wxString& ModelFileName, const wxString& CollisionModelFileName, const wxString& Label, const Vector3fT& Position, const Vector3fT& Angles, float Scale, int Sequence, float FrameOffset, float FrameTimeScale, bool Animated); 
    4339 
     
    8379 
    8480    wxString           m_ModelFileName; 
    85     ModelProxyT        m_Model; 
     81    const CafuModelT*  m_Model; 
    8682    Vector3fT          m_Origin; 
    8783    wxString           m_CollModelFileName; 
  • cafu/trunk/Libs/Models/Model_cmdl.cpp

    r406 r414  
    353353    return IsMeshNrOK(GF, PointNr) && 
    354354           GF.Points[PointNr].VertexNr < m_Meshes[GF.Points[PointNr].MeshNr].Vertices.Size(); 
     355} 
     356 
     357 
     358AnimPoseT* CafuModelT::GetSharedPose(int SequNr, float FrameNr) const 
     359{ 
     360    m_TEMP_Pose->SetSequNr(SequNr); 
     361    m_TEMP_Pose->SetFrameNr(FrameNr); 
     362 
     363    return m_TEMP_Pose; 
    355364} 
    356365 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r412 r414  
    275275    bool IsVertexNrOK(const GuiFixtureT& GF, unsigned int PointNr) const; 
    276276 
     277    /// This method is strictly for backwards-compatibility only, do not use in new code! 
     278    AnimPoseT* GetSharedPose(int SequNr, float FrameNr) const; 
     279 
    277280    // The ModelT interface. 
    278281    const std::string& GetFileName() const;     // TODO: Remove!?! 
  • cafu/trunk/Libs/SConscript

    r410 r414  
    1515                    Models/Loader.cpp Models/Loader_ase.cpp Models/Loader_cmdl.cpp Models/Loader_dlod.cpp Models/Loader_dummy.cpp Models/Loader_lwo.cpp Models/Loader_md5.cpp 
    1616                    Models/Loader_mdl.cpp Models/AnimPose.cpp 
    17                     Models/Model_cmdl.cpp Models/Model_proxy.cpp 
     17                    Models/Model_cmdl.cpp Models/Model_proxy.cpp Models/ModelManager.cpp 
    1818                    Network/Network.cpp ParticleEngine/ParticleEngineMS.cpp PlatformAux.cpp Terrain/Terrain.cpp 
    1919                    TextParser/TextParser.cpp