Changeset 428 for cafu/trunk

Show
Ignore:
Timestamp:
11/20/11 12:01:24 (6 months ago)
Author:
Carsten
Message:

Model code:
Finally removed the last fragments of the old model code: the newer code is now used everywhere! :-D

References #78.

Location:
cafu/trunk
Files:
3 removed
29 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/ModelEditor/Commands/TransformJoint.cpp

    r400 r428  
    5050    GetModelVec()=m_NewVec; 
    5151 
    52     // Make sure that the BB is updated and the draw cache is refreshed. 
    53     m_ModelDoc->GetModel()->RecomputeBindPoseBB(); 
     52    // Make sure that the caches are refreshed. 
    5453    m_ModelDoc->GetAnimState().Pose.SetNeedsRecache(); 
    5554 
     
    6968    GetModelVec()=m_OldVec; 
    7069 
    71     // Make sure that the BB is updated and the draw cache is refreshed. 
    72     m_ModelDoc->GetModel()->RecomputeBindPoseBB(); 
     70    // Make sure that the caches are refreshed. 
    7371    m_ModelDoc->GetAnimState().Pose.SetNeedsRecache(); 
    7472 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp

    r422 r428  
    6666ModelEditor::ModelDocumentT::ModelDocumentT(GameConfigT* GameConfig, const wxString& FileName) 
    6767    : m_Model(LoadModel(FileName)), 
    68       m_SequenceBB(m_Model->GetBB(-1, 0.0f)), 
    6968      m_AnimState(*m_Model), 
     69      m_SequenceBB(m_AnimState.Pose.GetBB()), 
    7070      m_Submodels(), 
    7171      m_Gui(new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), 
     
    141141        if (m_Selection[ANIM].Size()==0) 
    142142        { 
    143             m_SequenceBB=m_Model->GetBB(-1, 0.0f); 
     143            m_SequenceBB=m_AnimState.Pose.GetBB(); 
    144144        } 
    145145        else 
     
    167167        m_Submodels.PushBack(new SubmodelT(LoadModel(FileName))); 
    168168    } 
    169     catch (const ModelT::LoadError& /*E*/) 
    170     { 
    171         // TODO: We really should have more detailed information about what exactly went wrong when loading the model... 
    172         wxMessageBox(wxString("The submodel file \"")+FileName+"\" could not be loaded!", "Couldn't load or import submodel"); 
    173     } 
    174169    catch (const ModelLoaderT::LoadErrorT& LE) 
    175170    { 
     
    194189    const unsigned int   NextAnimSequNr=m_Selection[ANIM].Size()==0 ? 0 : m_Selection[ANIM][0]+1; 
    195190 
    196     if (NextAnimSequNr < m_Model->GetNrOfSequences()) 
     191    if (NextAnimSequNr < m_Model->GetAnims().Size()) 
    197192        NextSel.PushBack(NextAnimSequNr); 
    198193 
     
    204199{ 
    205200    ArrayT<unsigned int> NextSel; 
    206     const unsigned int   NextAnimSequNr=m_Selection[ANIM].Size()==0 ? m_Model->GetNrOfSequences()-1 : m_Selection[ANIM][0]-1; 
    207  
    208     if (NextAnimSequNr < m_Model->GetNrOfSequences()) 
     201    const unsigned int   NextAnimSequNr=m_Selection[ANIM].Size()==0 ? m_Model->GetAnims().Size()-1 : m_Selection[ANIM][0]-1; 
     202 
     203    if (NextAnimSequNr < m_Model->GetAnims().Size()) 
    209204        NextSel.PushBack(NextAnimSequNr); 
    210205 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.hpp

    r422 r428  
    137137        CafuModelT*              m_Model;           ///< The model that is being edited. 
    138138        ArrayT<unsigned int>     m_Selection[6];    ///< The selected joints, meshes, animations, channels, skins and GUI fixtures. 
    139         BoundingBox3fT           m_SequenceBB;      ///< The bounding-box encompassing all frames of the currently selected animation sequence(s). 
    140139        ArrayT<EditorMaterialI*> m_EditorMaterials; ///< One editor material for each material in the model (its material manager). 
    141140        AnimStateT               m_AnimState;       ///< The current state of the model animation. 
     141        BoundingBox3fT           m_SequenceBB;      ///< The bounding-box encompassing all frames of the currently selected animation sequence(s). 
    142142        ArrayT<SubmodelT*>       m_Submodels;       ///< The submodels that are shown with the main model. 
    143143        cf::GuiSys::GuiImplT*    m_Gui;             ///< The GUI that is rendered where the model has GUI fixtures. 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp

    r422 r428  
    6161 
    6262 
    63 Vector3fT ModelEditor::SceneView3DT::TraceCameraRay(const wxPoint& RefPtWin, ModelT::TraceResultT& ModelTR) const 
     63Vector3fT ModelEditor::SceneView3DT::TraceCameraRay(const wxPoint& RefPtWin, AnimPoseT::TraceResultT& ModelTR) const 
    6464{ 
    6565    const ModelDocumentT* ModelDoc    =m_Parent->GetModelDoc(); 
     
    101101 
    102102    // Trace the ray against the model, which is a per-triangle accurate test. 
    103     ModelT::TraceResultT Result; 
     103    AnimPoseT::TraceResultT Result; 
    104104 
    105105    if (ModelDoc->GetAnimState().Pose.TraceRay(ModelDoc->GetSelSkinNr(), RayOrigin, RayDir, Result) && Result.Fraction<BestFraction) 
     
    116116Vector3fT ModelEditor::SceneView3DT::GetRefPtWorld(const wxPoint& RefPtWin) const 
    117117{ 
    118     ModelT::TraceResultT ModelTR; 
     118    AnimPoseT::TraceResultT ModelTR; 
    119119 
    120120    return TraceCameraRay(RefPtWin, ModelTR); 
     
    231231    }; 
    232232 
    233     ModelT::TraceResultT ModelTR; 
    234     const Vector3fT      HitPos=TraceCameraRay(ScreenToClient(CE.GetPosition()), ModelTR); 
    235     const CafuModelT*    Model=m_Parent->GetModelDoc()->GetModel(); 
    236     const AnimPoseT&     Pose=m_Parent->GetModelDoc()->GetAnimState().Pose; 
    237     unsigned int         BestVertexNr=0; 
    238     bool                 HaveModelHit=false; 
     233    AnimPoseT::TraceResultT ModelTR; 
     234    const Vector3fT         HitPos=TraceCameraRay(ScreenToClient(CE.GetPosition()), ModelTR); 
     235    const CafuModelT*       Model=m_Parent->GetModelDoc()->GetModel(); 
     236    const AnimPoseT&        Pose=m_Parent->GetModelDoc()->GetAnimState().Pose; 
     237    unsigned int            BestVertexNr=0; 
     238    bool                    HaveModelHit=false; 
    239239 
    240240    if (ModelTR.Fraction>0.0f && ModelTR.MeshNr<Model->GetMeshes().Size() && ModelTR.TriNr<Model->GetMeshes()[ModelTR.MeshNr].Triangles.Size()) 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.hpp

    r353 r428  
    4242        SceneView3DT(ChildFrameT* Parent); 
    4343 
    44         Vector3fT TraceCameraRay(const wxPoint& RefPtWin, ModelT::TraceResultT& ModelTR) const; 
     44        Vector3fT TraceCameraRay(const wxPoint& RefPtWin, AnimPoseT::TraceResultT& ModelTR) const; 
    4545 
    4646 
  • cafu/trunk/CaWE/ParentFrame.cpp

    r415 r428  
    4040#include "MaterialSystem/TextureMap.hpp" 
    4141#include "Models/Loader.hpp"    // Needed for the ModelLoaderT::LoadErrorT exception that must be caught when model loading failed. 
    42 #include "Models/Model.hpp"     // Needed for the ModelT::LoadError exception that must be caught when model loading failed. 
    4342#include "TextParser/TextParser.hpp" 
    4443#include "PlatformAux.hpp" 
     
    554553    { 
    555554        wxMessageBox(wxString("The map file \"")+FileName+"\" could not be loaded!", "Couldn't load the map"); 
    556     } 
    557     catch (const ModelT::LoadError& /*E*/) 
    558     { 
    559         // TODO: We really should have more detailed information about what exactly went wrong when loading the model... 
    560         wxMessageBox(wxString("The model file \"")+FileName+"\" could not be loaded!", "Couldn't load or import model"); 
    561555    } 
    562556    catch (const ModelLoaderT::LoadErrorT& LE) 
  • cafu/trunk/Games/DeathMatch/Code/GameImpl.cpp

    r427 r428  
    4646 
    4747#include "ConsoleCommands/Console.hpp" 
    48 #include "Models/Model_proxy.hpp" 
    4948 
    5049#include <map> 
  • cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.cpp

    r427 r428  
    299299        Vector3fT GuiAxisY; 
    300300 
    301         if (m_Model->GetGuiPlane(m_SequNr, m_FrameNr, LodDist, GuiOrigin, GuiAxisX, GuiAxisY)) 
     301        if (m_Model->GetGuiPlane(GuiOrigin, GuiAxisX, GuiAxisY)) 
    302302        { 
    303303#if 1 
     
    390390bool EntStaticDetailModelT::GetGuiPlane(Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const 
    391391{ 
    392     if (!m_Model->GetGuiPlane(m_SequNr, m_FrameNr, 0.0, GuiOrigin, GuiAxisX, GuiAxisY)) return false; 
     392    if (!m_Model->GetGuiPlane(GuiOrigin, GuiAxisX, GuiAxisY)) return false; 
    393393 
    394394    // Okay, got the plane. Now transform it from model space into world space. 
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r426 r428  
    706706 
    707707 
    708 bool AnimPoseT::TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, ModelT::TraceResultT& Result) const 
     708bool AnimPoseT::TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 
    709709{ 
    710710    // if (m_Model.GetDlodModel() && LodDist >= m_Model.GetDlodDist()) 
  • cafu/trunk/Libs/Models/AnimPose.hpp

    r425 r428  
    2727#include "Math3D/BoundingBox.hpp" 
    2828#include "Math3D/Matrix.hpp" 
    29 #include "Model.hpp"    // For ModelT::TraceResultT 
    3029 
    3130 
    3231class CafuModelT; 
    33 // class TraceResultT; 
     32class MaterialT; 
    3433 
    3534 
     
    7473    }; 
    7574 
     75    /// This class describes the result of tracing a ray or a bounding box against the model. 
     76    struct TraceResultT 
     77    { 
     78        /// The constructor. 
     79        TraceResultT(float Fraction_=0.0f) : Fraction(Fraction_), Material(NULL), MeshNr(-1), TriNr(-1) { } 
     80 
     81        float            Fraction;  ///< The scalar along RayDir at which the hit occurred (RayOrigin + RayDir*Fraction). 
     82        Vector3fT        Normal;    ///< This is the normal vector of the hit surface. 
     83        const MaterialT* Material;  ///< The material at the point of impact. Can be NULL, e.g. when an edge (i.e. a bevel plane) was hit or the material is not available. 
     84        unsigned int     MeshNr;    ///< The number of the hit mesh. Can be -1 (that is, \emph{larger} then the number of meshes in the model) if the hit mesh cannot be determined. 
     85        unsigned int     TriNr;     ///< The number of the hit triangle in the hit mesh. Can be -1 (that is, \emph{larger} then the number of triangles in the mesh) if the hit triangle cannot be determined. 
     86    }; 
     87 
    7688 
    7789    /// The constructor. 
     
    101113 
    102114    /// Advances the pose in time. 
     115    /// Use GetFrameNr() to learn the new frame number after calling this method. 
    103116    void Advance(float Time, bool ForceLoop=false); 
    104117 
     
    107120 
    108121    /// This method renders the model in this pose. 
     122    /// The current MatSys model-view matrix determines the position and orientation. 
     123    /// 
    109124    /// @param SkinNr     The skin to render the model with, -1 for the default skin. 
    110125    /// @param LodDist    The distance to the camera for reducing the level-of-detail. 
     
    120135    /// 
    121136    /// @returns true if the ray hit the model, false otherwise. When the model was hit, additional details are returned via the Result parameter. 
    122     bool TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, ModelT::TraceResultT& Result) const; 
     137    bool TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 
    123138 
    124139    /// Considers the given triangle in the given mesh, and returns the vertex that the given point P is closest to in this pose. 
     
    135150    const ArrayT<MeshInfoT>& GetMeshInfos() const; 
    136151 
    137     /// Returns the MatSys meshes for this pose. 
     152    /// Returns the MatSys meshes for the model in this pose. 
    138153    const ArrayT<MatSys::MeshT>& GetDrawMeshes() const; 
    139154 
    140     /// Returns the bounding-box for this pose. 
     155    /// Returns the bounding-box for the model in this pose. 
    141156    const BoundingBox3fT& GetBB() const; 
    142157 
  • cafu/trunk/Libs/Models/Loader_ase.cpp

    r400 r428  
    297297 
    298298 
    299 LoaderAseT::LoaderAseT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     299LoaderAseT::LoaderAseT(const std::string& FileName, int Flags) 
    300300    : ModelLoaderT(FileName, Flags) 
    301301{ 
     
    332332    catch (const TextParserT::ParseError&) 
    333333    { 
    334         throw ModelT::LoadError(); 
     334        throw LoadErrorT("Could not parse the file."); 
    335335    } 
    336336 
     
    485485        { 
    486486            printf("ase model error (%s): GeomObject %lu refers to material index %lu, but there are only %lu materials total.\n", FileName.c_str(), GONr, m_GeomObjects[GONr].IndexMaterial, m_MaterialNames.Size()); 
    487             throw ModelT::LoadError(); 
     487            throw LoadErrorT("A GeomObject refers to an unknown material."); 
    488488        } 
    489489    } 
  • cafu/trunk/Libs/Models/Loader_ase.hpp

    r406 r428  
    3737    /// @param FileName   The name of the .ase file to import. 
    3838    /// @param Flags      The flags to load the model with. See ModelLoaderT::FlagsT for details. 
    39     LoaderAseT(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     39    LoaderAseT(const std::string& FileName, int Flags=NONE); 
    4040 
    4141    bool UseGivenTS() const { return true; } 
  • cafu/trunk/Libs/Models/Loader_assimp.cpp

    r409 r428  
    3030 
    3131 
    32 LoaderAssimpT::LoaderAssimpT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     32LoaderAssimpT::LoaderAssimpT(const std::string& FileName, int Flags) 
    3333    : ModelLoaderT(FileName, Flags), 
    3434      m_Scene(NULL) 
  • cafu/trunk/Libs/Models/Loader_assimp.hpp

    r406 r428  
    4141    /// If FileName ends with "md5", it is assumed that the file has a white-space separated list of one md5mesh and arbitrarily many md5anim files. 
    4242    /// If FileName ends with "md5mesh", this file is loaded without any animation information (e.g. for static detail models). 
    43     LoaderAssimpT(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     43    LoaderAssimpT(const std::string& FileName, int Flags=NONE); 
    4444 
    4545    bool UseGivenTS() const; 
  • cafu/trunk/Libs/Models/Loader_cmdl.cpp

    r391 r428  
    3232 
    3333 
    34 LoaderCafuT::LoaderCafuT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     34LoaderCafuT::LoaderCafuT(const std::string& FileName, int Flags) 
    3535    : ModelLoaderT(FileName, Flags), 
    3636      m_LuaState(lua_open()), 
  • cafu/trunk/Libs/Models/Loader_cmdl.hpp

    r406 r428  
    3737    /// @param FileName   The name of the .cmdl file to load. 
    3838    /// @param Flags      The flags to load the model with. See ModelLoaderT::FlagsT for details. 
    39     LoaderCafuT(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     39    LoaderCafuT(const std::string& FileName, int Flags=NONE); 
    4040 
    4141    /// The destructor. 
  • cafu/trunk/Libs/Models/Loader_dlod.cpp

    r406 r428  
    3030 
    3131 
    32 LoaderDlodT::LoaderDlodT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     32LoaderDlodT::LoaderDlodT(const std::string& FileName, int Flags) 
    3333    : ModelLoaderT(FileName, Flags) 
    3434{ 
  • cafu/trunk/Libs/Models/Loader_dlod.hpp

    r406 r428  
    3434    /// @param FileName   The name of the .dlod file to load. 
    3535    /// @param Flags      The flags to load the model with. See ModelLoaderT::FlagsT for details. 
    36     LoaderDlodT(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     36    LoaderDlodT(const std::string& FileName, int Flags=NONE); 
    3737 
    3838    /// The destructor. 
  • cafu/trunk/Libs/Models/Loader_fbx.hpp

    r406 r428  
    3535    /// @param UserCallbacks   An implementation of the UserCallbacksI interface. 
    3636    /// @param Flags      The flags to load the model with. See ModelLoaderT::FlagsT for details. 
    37     LoaderFbxT(const std::string& FileName, UserCallbacksI& UserCallbacks, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     37    LoaderFbxT(const std::string& FileName, UserCallbacksI& UserCallbacks, int Flags=NONE); 
    3838 
    3939    /// The destructor. 
  • cafu/trunk/Libs/Models/Loader_lwo.cpp

    r400 r428  
    221221// - LWOs store their vertex positions in "points", the CafuModelT class in "weights" (CafuModelT::MeshT::WeightT). 
    222222// - LWOs store their texture-coordinates in "VMAPs" and "VMADs", the CafuModelT class in "vertices" (CafuModelT::MeshT::VertexT). 
    223 LoaderLwoT::LoaderLwoT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     223LoaderLwoT::LoaderLwoT(const std::string& FileName, int Flags) 
    224224    : ModelLoaderT(FileName, Flags | REMOVE_UNUSED_VERTICES | REMOVE_UNUSED_WEIGHTS)    // The code below relies on postprocessing removing unused vertices and weights. 
    225225{ 
     
    235235    if (lwo==NULL) 
    236236    { 
    237         Console->Warning("Model \""+m_FileName+"\" could not be loaded.\n"); 
    238         throw ModelT::LoadError(); 
     237        throw LoadErrorT("The model could not be loaded.\n"); 
    239238    } 
    240239 
  • cafu/trunk/Libs/Models/Loader_lwo.hpp

    r406 r428  
    3434    /// @param FileName   The name of the .lwo file to import. 
    3535    /// @param Flags      The flags to load the model with. See ModelLoaderT::FlagsT for details. 
    36     LoaderLwoT(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     36    LoaderLwoT(const std::string& FileName, int Flags=NONE); 
    3737 
    3838    bool UseGivenTS() const { return true; } 
  • cafu/trunk/Libs/Models/Loader_md5.cpp

    r352 r428  
    3030 
    3131 
    32 LoaderMd5T::LoaderMd5T(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     32LoaderMd5T::LoaderMd5T(const std::string& FileName, int Flags) 
    3333    : ModelLoaderT(FileName, Flags) 
    3434{ 
     
    5353 
    5454        while (!TP.IsAtEOF()) ComponentFiles.PushBack(TP.GetNextToken()); 
    55         if (ComponentFiles.Size()<1) throw ModelT::LoadError(); 
     55        if (ComponentFiles.Size()<1) throw LoadErrorT("No component files found in md5 file."); 
    5656 
    5757        size_t PrefixLength=m_FileName.length(); 
     
    8888            const std::string Token=TP.GetNextToken(); 
    8989 
    90                  if (Token=="MD5Version" ) { if (TP.GetNextToken()!="10") throw ModelT::LoadError(); } 
     90                 if (Token=="MD5Version" ) { if (TP.GetNextToken()!="10") throw LoadErrorT("MD5Version is not 10."); } 
    9191            else if (Token=="commandline") TP.GetNextToken();       // Ignore the command line. 
    9292            else if (Token=="numJoints"  ) TP.GetNextToken();       // Ignore the given number of joints - we just load as many as we find. 
     
    120120                    { 
    121121                        printf("WARNING: Bad bone order!  %lu bones read so far, and the next (name \"%s\") is referring to parent %i.\n", Joints.Size(), Joint.Name.c_str(), Joint.Parent); 
    122                         throw ModelT::LoadError();  // TODO: Fix this by re-sorting the joints rather than by abortion! 
     122                        throw LoadErrorT("The bones are not properly ordered.");  // TODO: Fix this by re-sorting the joints rather than by abortion! 
    123123                    } 
    124124 
     
    153153 
    154154                         if (Token=="}"         ) break; 
    155                     else if (Token=="numtris"   ) { if (Mesh.Triangles.Size()>0) throw ModelT::LoadError(); Mesh.Triangles.PushBackEmpty(TP.GetNextTokenAsInt()); } 
    156                     else if (Token=="numverts"  ) { if (Mesh.Vertices .Size()>0) throw ModelT::LoadError(); Mesh.Vertices .PushBackEmpty(TP.GetNextTokenAsInt()); } 
    157                     else if (Token=="numweights") { if (Mesh.Weights  .Size()>0) throw ModelT::LoadError(); Mesh.Weights  .PushBackEmpty(TP.GetNextTokenAsInt()); } 
     155                    else if (Token=="numtris"   ) { if (Mesh.Triangles.Size()>0) throw LoadErrorT("Mesh.Triangles.Size()>0"); Mesh.Triangles.PushBackEmpty(TP.GetNextTokenAsInt()); } 
     156                    else if (Token=="numverts"  ) { if (Mesh.Vertices .Size()>0) throw LoadErrorT("Mesh.Vertices .Size()>0"); Mesh.Vertices .PushBackEmpty(TP.GetNextTokenAsInt()); } 
     157                    else if (Token=="numweights") { if (Mesh.Weights  .Size()>0) throw LoadErrorT("Mesh.Weights  .Size()>0"); Mesh.Weights  .PushBackEmpty(TP.GetNextTokenAsInt()); } 
    158158                    else if (Token=="shader") 
    159159                    { 
     
    174174                        const unsigned long TriIdx=TP.GetNextTokenAsInt(); 
    175175 
    176                         if (TriIdx>=Mesh.Triangles.Size()) throw ModelT::LoadError(); 
     176                        if (TriIdx>=Mesh.Triangles.Size()) throw LoadErrorT("TriIdx >= Mesh.Triangles.Size()"); 
    177177 
    178178                        Mesh.Triangles[TriIdx].VertexIdx[0]=TP.GetNextTokenAsInt(); 
     
    184184                        const unsigned long VertIdx=TP.GetNextTokenAsInt(); 
    185185 
    186                         if (VertIdx>=Mesh.Vertices.Size()) throw ModelT::LoadError(); 
     186                        if (VertIdx>=Mesh.Vertices.Size()) throw LoadErrorT("VertIdx >= Mesh.Vertices.Size()"); 
    187187 
    188188                        TP.AssertAndSkipToken("("); 
     
    197197                        const unsigned long WeightIdx=TP.GetNextTokenAsInt(); 
    198198 
    199                         if (WeightIdx>=Mesh.Weights.Size()) throw ModelT::LoadError(); 
     199                        if (WeightIdx>=Mesh.Weights.Size()) throw LoadErrorT("WeightIdx >= Mesh.Weights.Size()"); 
    200200 
    201201                        Mesh.Weights[WeightIdx].JointIdx=TP.GetNextTokenAsInt(); 
     
    222222    catch (const TextParserT::ParseError&) 
    223223    { 
    224         throw ModelT::LoadError(); 
     224        throw LoadErrorT("Could not parse the file."); 
    225225    } 
    226226 
     
    243243                const std::string Token=TP.GetNextToken(); 
    244244 
    245                      if (Token=="MD5Version" ) { if (TP.GetNextToken()!="10") throw ModelT::LoadError(); } 
     245                     if (Token=="MD5Version" ) { if (TP.GetNextToken()!="10") throw LoadErrorT("MD5Version is not 10."); } 
    246246                else if (Token=="commandline") TP.GetNextToken();       // Ignore the command line. 
    247247                else if (Token=="frameRate"  ) Anim.FPS=TP.GetNextTokenAsFloat(); 
     
    250250                    // Be stricter with numFrames than with some num* variables in the md5mesh file. 
    251251                    // This is required because for example there must be as many bounding boxes as frames. 
    252                     if (Anim.Frames.Size()>0) throw ModelT::LoadError(); 
     252                    if (Anim.Frames.Size()>0) throw LoadErrorT("Anim.Frames.Size() > 0"); 
    253253 
    254254                    Anim.Frames.PushBackEmpty(TP.GetNextTokenAsInt()); 
     
    259259                    const unsigned long numJoints=TP.GetNextTokenAsInt(); 
    260260 
    261                     if (numJoints!=Joints.Size()) { printf("%lu joints in md5anim file, %lu joints in md5mesh.\n", numJoints, Joints.Size()); throw ModelT::LoadError(); } 
    262                     if (Anim.AnimJoints.Size()>0) { printf("Anim.AnimJoints.Size()==%lu\n", Anim.AnimJoints.Size()); throw ModelT::LoadError(); } 
     261                    if (numJoints!=Joints.Size()) { printf("%lu joints in md5anim file, %lu joints in md5mesh.\n", numJoints, Joints.Size()); throw LoadErrorT("Number of joints in the md5anim file does not match number of bones in the md5mesh."); } 
     262                    if (Anim.AnimJoints.Size()>0) { printf("Anim.AnimJoints.Size()==%lu\n", Anim.AnimJoints.Size()); throw LoadErrorT("Anim.AnimJoints.Size() > 0"); } 
    263263 
    264264                    Anim.AnimJoints.PushBackEmpty(numJoints); 
     
    270270                    // This is the number of components that is animated in the frames (and thus so many values are stored with each frame). 
    271271                    // Therefore, the number of frames must have been specified already, so we can allocate all the memory here. 
    272                     if (Anim.Frames.Size()==0) throw ModelT::LoadError(); 
     272                    if (Anim.Frames.Size()==0) throw LoadErrorT("Anim.Frames.Size() == 0"); 
    273273 
    274274                    for (unsigned long FrameNr=0; FrameNr<Anim.Frames.Size(); FrameNr++) 
     
    282282                    { 
    283283                        // Make sure that the name and parent are identical with the joint from the md5mesh file. 
    284                         if (Joints[JointNr].Name  !=TP.GetNextToken()) throw ModelT::LoadError(); 
    285                         if (Joints[JointNr].Parent!=TP.GetNextTokenAsInt()) throw ModelT::LoadError(); 
     284                        if (Joints[JointNr].Name  !=TP.GetNextToken()) throw LoadErrorT("Mismatching joint name."); 
     285                        if (Joints[JointNr].Parent!=TP.GetNextTokenAsInt()) throw LoadErrorT("Mismatching joint parent."); 
    286286 
    287287                        Anim.AnimJoints[JointNr].Flags       =TP.GetNextTokenAsInt(); 
     
    366366            printf("WARNING: Loading animation sequence file %s failed just before input byte %lu!\n", ComponentFiles[FileNr].c_str(), TP.GetReadPosByte()); 
    367367        } 
    368         catch (const ModelT::LoadError&) 
     368        catch (const LoadErrorT& LE) 
    369369        { 
    370370            // Loading this animation sequence failed, but as the base mesh (the md5mesh file) 
     
    375375            Anims.PushBack(InvalidAnim);    // Note that InvalidAnim.Frames.Size()==0, too. 
    376376 
    377             printf("WARNING: Loading animation sequence file %s failed just before input byte %lu!\n", ComponentFiles[FileNr].c_str(), TP.GetReadPosByte()); 
     377            printf("WARNING: Loading animation sequence file %s failed just before input byte %lu:\n", ComponentFiles[FileNr].c_str(), TP.GetReadPosByte()); 
     378            printf("%s", LE.what()); 
    378379        } 
    379380    } 
  • cafu/trunk/Libs/Models/Loader_md5.hpp

    r406 r428  
    3636    /// If FileName ends with "md5", it is assumed that the file has a white-space separated list of one md5mesh and arbitrarily many md5anim files. 
    3737    /// If FileName ends with "md5mesh", this file is loaded without any animation information (e.g. for static detail models). 
    38     LoaderMd5T(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     38    LoaderMd5T(const std::string& FileName, int Flags=NONE); 
    3939 
    4040    bool UseGivenTS() const; 
  • cafu/trunk/Libs/Models/Loader_mdl.cpp

    r406 r428  
    3232 
    3333 
    34 LoaderHL1mdlT::LoaderHL1mdlT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/ 
     34LoaderHL1mdlT::LoaderHL1mdlT(const std::string& FileName, int Flags) 
    3535    : ModelLoaderT(FileName, Flags | 
    3636          REMOVE_DEGEN_TRIANGLES |                          // Need this flag in order to pass all assertions in the CafuModelT code. 
     
    4040    // ********************************** 
    4141 
    42     if (!cf::String::EndsWith(m_FileName, ".mdl")) throw ModelT::LoadError(); 
     42    if (!cf::String::EndsWith(m_FileName, ".mdl")) throw LoadErrorT("HL1 model file name doesn't end with .mdl"); 
    4343 
    4444    const std::string BaseName(m_FileName.c_str(), m_FileName.length()-4); 
     
    4949 
    5050    FILE* InFile=fopen(m_FileName.c_str(), "rb"); 
    51     if (InFile==NULL) throw ModelT::LoadError(); 
     51    if (InFile==NULL) throw LoadErrorT("Could not fopen() the model file."); 
    5252 
    5353    fseek(InFile, 0, SEEK_END); ModelData.PushBackEmpty(ftell(InFile)); 
     
    7474    { 
    7575        InFile=fopen((BaseName+"T.mdl").c_str(), "rb"); 
    76         if (InFile==NULL) throw ModelT::LoadError(); 
     76        if (InFile==NULL) throw LoadErrorT("Could not open the textures file."); 
    7777 
    7878        fseek(InFile, 0, SEEK_END); TextureData.PushBackEmpty(ftell(InFile)); 
     
    9999 
    100100            InFile=fopen((BaseName+NumStr+".mdl").c_str(), "rb"); 
    101             if (InFile==NULL) throw ModelT::LoadError(); 
     101            if (InFile==NULL) throw LoadErrorT("Could not open the file with anim sequences."); 
    102102 
    103103            fseek(InFile, 0, SEEK_END); AnimationData[SeqGroupNr].PushBackEmpty(ftell(InFile)); 
  • cafu/trunk/Libs/Models/Loader_mdl.hpp

    r406 r428  
    4242    /// @param FileName   The name of the .mdl file to import. 
    4343    /// @param Flags      The flags to load the model with. See ModelLoaderT::FlagsT for details. 
    44     LoaderHL1mdlT(const std::string& FileName, int Flags=NONE) /*throw (ModelT::LoadError)*/; 
     44    LoaderHL1mdlT(const std::string& FileName, int Flags=NONE); 
    4545 
    4646    bool UseGivenTS() const; 
  • cafu/trunk/Libs/Models/ModelManager.cpp

    r423 r428  
    7575            "then load the cmdl model in place of this."); 
    7676    } 
    77     catch (const ModelT::LoadError&) 
    78     { 
    79         LoaderDummyT Loader(FileName); 
    80  
    81         NewModel=new CafuModelT(Loader); 
    82         if (ErrorMsg) (*ErrorMsg)="The file could not be loaded (unknown error)."; 
    83     } 
    8477    catch (const ModelLoaderT::LoadErrorT& LE) 
    8578    { 
  • cafu/trunk/Libs/Models/Model_cmdl.cpp

    r427 r428  
    176176    Frames[FrameNr].BB=BoundingBox3fT(); 
    177177 
    178     // This is a modified version of the loop in CafuModelT::RecomputeBindPoseBB(). 
     178    // This is very similar to the code in AnimPoseT::UpdateData(). 
    179179    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
    180180    { 
     
    247247      m_MaterialMan(), 
    248248      m_UseGivenTangentSpace(Loader.UseGivenTS()),  // Should we use the fixed, given tangent space, or recompute it ourselves here? 
    249       m_BindPoseBB(Vector3fT()),                    // Re-initialized in InitMeshes() calling RecomputeBindPoseBB(), but start with a valid box anyways (e.g. for testing models that have a skeleton, but no mesh). 
    250249      m_DlodModel(NULL), 
    251250      m_DlodDist(0.0f) 
     
    272271    Loader.Postprocess(m_Meshes); 
    273272 
    274     if (m_Joints.Size()==0) throw ModelT::LoadError(); 
    275  // if (m_Meshes.Size()==0) throw ModelT::LoadError();  // Consider models with no meshes as valid, skeleton-only meshes are sometimes useful for testing. 
     273    if (m_Joints.Size()==0) throw ModelLoaderT::LoadErrorT("This model has no joints."); 
     274 // if (m_Meshes.Size()==0) throw ModelLoaderT::LoadErrorT("This model has no meshes.");  // Consider models with no meshes as valid, skeleton-only meshes are sometimes useful for testing. 
    276275 
    277276    // Load the chain of dlod models, if any. 
     
    351350 
    352351 
    353 bool CafuModelT::IsMeshNrOK(const GuiFixtureT& GF, unsigned int PointNr) const 
    354 { 
    355     return GF.Points[PointNr].MeshNr < m_Meshes.Size(); 
    356 } 
    357  
    358  
    359 bool CafuModelT::IsVertexNrOK(const GuiFixtureT& GF, unsigned int PointNr) const 
    360 { 
    361     return IsMeshNrOK(GF, PointNr) && 
    362            GF.Points[PointNr].VertexNr < m_Meshes[GF.Points[PointNr].MeshNr].Vertices.Size(); 
    363 } 
    364  
    365  
    366 AnimPoseT* CafuModelT::GetSharedPose(int SequNr, float FrameNr) const 
    367 { 
    368     m_TEMP_Pose->SetSequNr(SequNr); 
    369     m_TEMP_Pose->SetFrameNr(FrameNr); 
    370  
    371     return m_TEMP_Pose; 
    372 } 
    373  
    374  
    375 void CafuModelT::RecomputeBindPoseBB() 
    376 { 
    377     ArrayT<MatrixT> JointMatrices; 
    378     JointMatrices.PushBackEmpty(m_Joints.Size()); 
    379  
    380     for (unsigned long JointNr=0; JointNr<m_Joints.Size(); JointNr++) 
    381     { 
    382         const JointT& J=m_Joints[JointNr]; 
    383         const MatrixT RelMatrix(J.Pos, cf::math::QuaternionfT::FromXYZ(J.Qtr), J.Scale); 
    384  
    385         JointMatrices[JointNr]=(J.Parent==-1) ? RelMatrix : JointMatrices[J.Parent]*RelMatrix; 
    386     } 
    387  
    388     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    389     { 
    390         const MeshT& Mesh=m_Meshes[MeshNr]; 
    391  
    392         for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    393         { 
    394             const MeshT::VertexT& Vertex=Mesh.Vertices[VertexNr]; 
    395             Vector3fT             OutVert; 
    396  
    397             if (Vertex.NumWeights==1) 
    398             { 
    399                 const MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx]; 
    400  
    401                 OutVert=JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos); 
    402             } 
    403             else 
    404             { 
    405                 for (unsigned int WeightNr=0; WeightNr<Vertex.NumWeights; WeightNr++) 
    406                 { 
    407                     const MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx+WeightNr]; 
    408  
    409                     OutVert+=JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos) * Weight.Weight; 
    410                 } 
    411             } 
    412  
    413             if (MeshNr==0 && VertexNr==0) m_BindPoseBB=BoundingBox3fT(OutVert); 
    414                                      else m_BindPoseBB.Insert(OutVert); 
    415         } 
    416     } 
    417 } 
    418  
    419  
    420352void CafuModelT::InitMeshes() 
    421353{ 
    422     // Compute the bounding box for the model in bind pose (stored in m_BindPoseBB), just in case this model has no animations. 
    423     RecomputeBindPoseBB(); 
    424  
    425  
    426354    // Compute auxiliary data for each mesh. 
    427355    for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
     
    946874 
    947875 
    948 /***********************************************/ 
    949 /*** Implementation of the ModelT interface. ***/ 
    950 /***********************************************/ 
    951  
    952 const std::string& CafuModelT::GetFileName() const 
    953 { 
    954     return m_FileName; 
    955 } 
    956  
    957  
    958876const MaterialT* CafuModelT::GetMaterial(unsigned long MeshNr, int SkinNr) const 
    959877{ 
     
    990908 
    991909 
    992 void CafuModelT::Draw(int SequenceNr, float FrameNr, float LodDist, const ModelT* /*SubModel*/) const 
    993 { 
    994     m_TEMP_Pose->SetSequNr(SequenceNr); 
     910bool CafuModelT::IsMeshNrOK(const GuiFixtureT& GF, unsigned int PointNr) const 
     911{ 
     912    return GF.Points[PointNr].MeshNr < m_Meshes.Size(); 
     913} 
     914 
     915 
     916bool CafuModelT::IsVertexNrOK(const GuiFixtureT& GF, unsigned int PointNr) const 
     917{ 
     918    return IsMeshNrOK(GF, PointNr) && 
     919           GF.Points[PointNr].VertexNr < m_Meshes[GF.Points[PointNr].MeshNr].Vertices.Size(); 
     920} 
     921 
     922 
     923AnimPoseT* CafuModelT::GetSharedPose(int SequNr, float FrameNr) const 
     924{ 
     925    m_TEMP_Pose->SetSequNr(SequNr); 
    995926    m_TEMP_Pose->SetFrameNr(FrameNr); 
    996927 
    997     m_TEMP_Pose->Draw(-1 /*default skin*/, LodDist); 
    998 } 
    999  
    1000  
    1001 bool CafuModelT::GetGuiPlane(int SequenceNr, float FrameNr, float LodDist, Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const 
     928    return m_TEMP_Pose; 
     929} 
     930 
     931 
     932bool CafuModelT::GetGuiPlane(Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const 
    1002933{ 
    1003934    if (m_GuiLocs.Size()==0) return false; 
     
    1050981    } 
    1051982} 
    1052  
    1053  
    1054 unsigned int CafuModelT::GetNrOfSequences() const 
    1055 { 
    1056     return m_Anims.Size(); 
    1057 } 
    1058  
    1059  
    1060 BoundingBox3fT CafuModelT::GetBB(int SequenceNr, float FrameNr) const 
    1061 { 
    1062     if (SequenceNr==-1 || SequenceNr>=int(m_Anims.Size()) || m_Anims[SequenceNr].Frames.Size()==0 || m_Anims[SequenceNr].FPS<0.0) 
    1063         return m_BindPoseBB; 
    1064  
    1065     // Should we interpolate the bounding box between frames as we interpolate the bones? 
    1066     const int FNr=(int(FrameNr+0.5f)) % m_Anims[SequenceNr].Frames.Size(); 
    1067  
    1068     return m_Anims[SequenceNr].Frames[FNr].BB; 
    1069 } 
    1070  
    1071  
    1072 bool CafuModelT::TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 
    1073 { 
    1074     m_TEMP_Pose->SetSequNr(SequenceNr); 
    1075     m_TEMP_Pose->SetFrameNr(FrameNr); 
    1076  
    1077     return m_TEMP_Pose->TraceRay(SkinNr, RayOrigin, RayDir, Result); 
    1078 } 
    1079  
    1080  
    1081 // float CafuModelT::GetNrOfFrames(int /*SequenceNr*/) const 
    1082 // { 
    1083 //     return 0.0; 
    1084 // } 
    1085  
    1086  
    1087 float CafuModelT::AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop) const 
    1088 { 
    1089     if (SequenceNr<0 || SequenceNr>=int(m_Anims.Size())) return 0.0f; 
    1090     if (m_Anims[SequenceNr].Frames.Size()<=1) return 0.0f; 
    1091  
    1092     const float NumFrames=float(m_Anims[SequenceNr].Frames.Size()); 
    1093  
    1094     FrameNr+=DeltaTime*m_Anims[SequenceNr].FPS; 
    1095  
    1096     if (Loop) 
    1097     { 
    1098         // Wrap the sequence (it's a looping (repeating) sequence, like idle, walk, ...). 
    1099         FrameNr=fmod(FrameNr, NumFrames); 
    1100         if (FrameNr<0.0f) FrameNr+=NumFrames; 
    1101     } 
    1102     else 
    1103     { 
    1104         // Clamp the sequence (it's a play-once (non-repeating) sequence, like dying). 
    1105         // On clamping, stop the sequence 1/100th sec before the end of the last frame. 
    1106         if (FrameNr>=NumFrames-1.0f) FrameNr=NumFrames-1.0f-0.01f; 
    1107         if (FrameNr<0.0f) FrameNr=0.0f; 
    1108     } 
    1109  
    1110     return FrameNr; 
    1111 } 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r427 r428  
    2929#include "Math3D/Matrix.hpp" 
    3030#include "AnimPose.hpp"     // Only for TEMPORARILY implementing the "old" ModelT interface methods. 
    31 #include "Model.hpp" 
    3231 
    3332#if defined(_WIN32) && _MSC_VER<1600 
     
    5453 
    5554/// This class represents a native Cafu model. 
    56 class CafuModelT : public ModelT 
     55class CafuModelT 
    5756{ 
    5857    public: 
     
    255254 
    256255    // Inspector methods. 
    257     bool GetUseGivenTS() const { return m_UseGivenTangentSpace; } 
     256    const std::string&          GetFileName() const { return m_FileName; } 
    258257    const MaterialManagerImplT& GetMaterialManager() const { return m_MaterialMan; } 
    259258    const ArrayT<JointT>&       GetJoints() const { return m_Joints; } 
     
    263262    const ArrayT<AnimT>&        GetAnims() const { return m_Anims; } 
    264263    const ArrayT<ChannelT>&     GetChannels() const { return m_Channels; } 
     264    bool                        GetUseGivenTS() const { return m_UseGivenTangentSpace; } 
    265265    const CafuModelT*           GetDlodModel() const { return m_DlodModel; } 
    266266    float                       GetDlodDist() const { return m_DlodDist; } 
     
    281281    AnimPoseT* GetSharedPose(int SequNr, float FrameNr) const; 
    282282 
    283     // The ModelT interface. 
    284     const std::string& GetFileName() const; 
    285     void               Draw(int SequenceNr, float FrameNr, float LodDist, const ModelT* SubModel=NULL) const; 
    286     bool               GetGuiPlane(int SequenceNr, float FrameNr, float LodDist, Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const; 
    287     void               Print() const; 
    288     unsigned int       GetNrOfSequences() const; 
    289     BoundingBox3fT     GetBB(int SequenceNr, float FrameNr) const; 
    290     bool               TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 
    291  // float              GetNrOfFrames(int SequenceNr) const; 
    292     float              AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop=true) const; 
    293  
    294     static const unsigned int CMDL_FILE_VERSION;    ///< The current version of the \c cmdl file format. 
     283    /// An obsolete method that should not be used in new code. 
     284    bool GetGuiPlane(Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const; 
     285 
     286    /// Prints some model data to stdout, used for debugging. 
     287    void Print() const; 
     288 
     289    /// The current version of the \c cmdl file format. 
     290    static const unsigned int CMDL_FILE_VERSION; 
    295291 
    296292 
     
    311307    void operator = (const CafuModelT&);            ///< Use of the Assignment Operator is not allowed. 
    312308 
    313     void RecomputeBindPoseBB();                     ///< Recomputes the bounding box for the model in bind pose (stored in m_BindPoseBB). 
    314309    void InitMeshes();                              ///< An auxiliary method for the constructors. 
    315310 
     
    326321    const bool           m_UseGivenTangentSpace;    ///< Whether this model should use the fixed, given tangent space that was loaded from the model file, or it the tangent space is dynamically recomputed (useful for animated models). 
    327322 // const bool           m_CastShadows;             ///< Should this model cast shadows? 
    328     BoundingBox3fT       m_BindPoseBB;              ///< [REMOVE???] The bounding-box for the base pose of the model. 
    329323 
    330324    CafuModelT*          m_DlodModel;               ///< Use the m_DlodModel instead of this when the camera is more than m_DlodDist away. 
    331325    float                m_DlodDist;                ///< The distance beyond which the m_DlodModel is used instead of this. 
    332326 
    333     mutable AnimPoseT* m_TEMP_Pose;      ///< TEMPORARY! 
     327    mutable AnimPoseT*   m_TEMP_Pose;               ///< TEMPORARY! 
    334328}; 
    335329 
  • cafu/trunk/Libs/SConscript

    r414 r428  
    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 Models/ModelManager.cpp 
     17                    Models/Model_cmdl.cpp Models/ModelManager.cpp 
    1818                    Network/Network.cpp ParticleEngine/ParticleEngineMS.cpp PlatformAux.cpp Terrain/Terrain.cpp 
    1919                    TextParser/TextParser.cpp