Changeset 428 for cafu/trunk
- Timestamp:
- 11/20/11 12:01:24 (6 months ago)
- Location:
- cafu/trunk
- Files:
-
- 3 removed
- 29 modified
-
CaWE/ModelEditor/Commands/TransformJoint.cpp (modified) (2 diffs)
-
CaWE/ModelEditor/ModelDocument.cpp (modified) (5 diffs)
-
CaWE/ModelEditor/ModelDocument.hpp (modified) (1 diff)
-
CaWE/ModelEditor/SceneView3D.cpp (modified) (4 diffs)
-
CaWE/ModelEditor/SceneView3D.hpp (modified) (1 diff)
-
CaWE/ParentFrame.cpp (modified) (2 diffs)
-
Games/DeathMatch/Code/GameImpl.cpp (modified) (1 diff)
-
Games/DeathMatch/Code/StaticDetailModel.cpp (modified) (2 diffs)
-
Libs/Models/AnimPose.cpp (modified) (1 diff)
-
Libs/Models/AnimPose.hpp (modified) (6 diffs)
-
Libs/Models/Loader_ase.cpp (modified) (3 diffs)
-
Libs/Models/Loader_ase.hpp (modified) (1 diff)
-
Libs/Models/Loader_assimp.cpp (modified) (1 diff)
-
Libs/Models/Loader_assimp.hpp (modified) (1 diff)
-
Libs/Models/Loader_cmdl.cpp (modified) (1 diff)
-
Libs/Models/Loader_cmdl.hpp (modified) (1 diff)
-
Libs/Models/Loader_dlod.cpp (modified) (1 diff)
-
Libs/Models/Loader_dlod.hpp (modified) (1 diff)
-
Libs/Models/Loader_fbx.hpp (modified) (1 diff)
-
Libs/Models/Loader_lwo.cpp (modified) (2 diffs)
-
Libs/Models/Loader_lwo.hpp (modified) (1 diff)
-
Libs/Models/Loader_md5.cpp (modified) (16 diffs)
-
Libs/Models/Loader_md5.hpp (modified) (1 diff)
-
Libs/Models/Loader_mdl.cpp (modified) (5 diffs)
-
Libs/Models/Loader_mdl.hpp (modified) (1 diff)
-
Libs/Models/Model.hpp (deleted)
-
Libs/Models/ModelManager.cpp (modified) (1 diff)
-
Libs/Models/Model_cmdl.cpp (modified) (7 diffs)
-
Libs/Models/Model_cmdl.hpp (modified) (7 diffs)
-
Libs/Models/Model_proxy.cpp (deleted)
-
Libs/Models/Model_proxy.hpp (deleted)
-
Libs/SConscript (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/CaWE/ModelEditor/Commands/TransformJoint.cpp
r400 r428 50 50 GetModelVec()=m_NewVec; 51 51 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. 54 53 m_ModelDoc->GetAnimState().Pose.SetNeedsRecache(); 55 54 … … 69 68 GetModelVec()=m_OldVec; 70 69 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. 73 71 m_ModelDoc->GetAnimState().Pose.SetNeedsRecache(); 74 72 -
cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp
r422 r428 66 66 ModelEditor::ModelDocumentT::ModelDocumentT(GameConfigT* GameConfig, const wxString& FileName) 67 67 : m_Model(LoadModel(FileName)), 68 m_SequenceBB(m_Model->GetBB(-1, 0.0f)),69 68 m_AnimState(*m_Model), 69 m_SequenceBB(m_AnimState.Pose.GetBB()), 70 70 m_Submodels(), 71 71 m_Gui(new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), … … 141 141 if (m_Selection[ANIM].Size()==0) 142 142 { 143 m_SequenceBB=m_ Model->GetBB(-1, 0.0f);143 m_SequenceBB=m_AnimState.Pose.GetBB(); 144 144 } 145 145 else … … 167 167 m_Submodels.PushBack(new SubmodelT(LoadModel(FileName))); 168 168 } 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 }174 169 catch (const ModelLoaderT::LoadErrorT& LE) 175 170 { … … 194 189 const unsigned int NextAnimSequNr=m_Selection[ANIM].Size()==0 ? 0 : m_Selection[ANIM][0]+1; 195 190 196 if (NextAnimSequNr < m_Model->Get NrOfSequences())191 if (NextAnimSequNr < m_Model->GetAnims().Size()) 197 192 NextSel.PushBack(NextAnimSequNr); 198 193 … … 204 199 { 205 200 ArrayT<unsigned int> NextSel; 206 const unsigned int NextAnimSequNr=m_Selection[ANIM].Size()==0 ? m_Model->Get NrOfSequences()-1 : m_Selection[ANIM][0]-1;207 208 if (NextAnimSequNr < m_Model->Get NrOfSequences())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()) 209 204 NextSel.PushBack(NextAnimSequNr); 210 205 -
cafu/trunk/CaWE/ModelEditor/ModelDocument.hpp
r422 r428 137 137 CafuModelT* m_Model; ///< The model that is being edited. 138 138 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).140 139 ArrayT<EditorMaterialI*> m_EditorMaterials; ///< One editor material for each material in the model (its material manager). 141 140 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). 142 142 ArrayT<SubmodelT*> m_Submodels; ///< The submodels that are shown with the main model. 143 143 cf::GuiSys::GuiImplT* m_Gui; ///< The GUI that is rendered where the model has GUI fixtures. -
cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp
r422 r428 61 61 62 62 63 Vector3fT ModelEditor::SceneView3DT::TraceCameraRay(const wxPoint& RefPtWin, ModelT::TraceResultT& ModelTR) const63 Vector3fT ModelEditor::SceneView3DT::TraceCameraRay(const wxPoint& RefPtWin, AnimPoseT::TraceResultT& ModelTR) const 64 64 { 65 65 const ModelDocumentT* ModelDoc =m_Parent->GetModelDoc(); … … 101 101 102 102 // Trace the ray against the model, which is a per-triangle accurate test. 103 ModelT::TraceResultT Result;103 AnimPoseT::TraceResultT Result; 104 104 105 105 if (ModelDoc->GetAnimState().Pose.TraceRay(ModelDoc->GetSelSkinNr(), RayOrigin, RayDir, Result) && Result.Fraction<BestFraction) … … 116 116 Vector3fT ModelEditor::SceneView3DT::GetRefPtWorld(const wxPoint& RefPtWin) const 117 117 { 118 ModelT::TraceResultT ModelTR;118 AnimPoseT::TraceResultT ModelTR; 119 119 120 120 return TraceCameraRay(RefPtWin, ModelTR); … … 231 231 }; 232 232 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; 239 239 240 240 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 42 42 SceneView3DT(ChildFrameT* Parent); 43 43 44 Vector3fT TraceCameraRay(const wxPoint& RefPtWin, ModelT::TraceResultT& ModelTR) const;44 Vector3fT TraceCameraRay(const wxPoint& RefPtWin, AnimPoseT::TraceResultT& ModelTR) const; 45 45 46 46 -
cafu/trunk/CaWE/ParentFrame.cpp
r415 r428 40 40 #include "MaterialSystem/TextureMap.hpp" 41 41 #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.43 42 #include "TextParser/TextParser.hpp" 44 43 #include "PlatformAux.hpp" … … 554 553 { 555 554 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");561 555 } 562 556 catch (const ModelLoaderT::LoadErrorT& LE) -
cafu/trunk/Games/DeathMatch/Code/GameImpl.cpp
r427 r428 46 46 47 47 #include "ConsoleCommands/Console.hpp" 48 #include "Models/Model_proxy.hpp"49 48 50 49 #include <map> -
cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.cpp
r427 r428 299 299 Vector3fT GuiAxisY; 300 300 301 if (m_Model->GetGuiPlane( m_SequNr, m_FrameNr, LodDist,GuiOrigin, GuiAxisX, GuiAxisY))301 if (m_Model->GetGuiPlane(GuiOrigin, GuiAxisX, GuiAxisY)) 302 302 { 303 303 #if 1 … … 390 390 bool EntStaticDetailModelT::GetGuiPlane(Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const 391 391 { 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; 393 393 394 394 // Okay, got the plane. Now transform it from model space into world space. -
cafu/trunk/Libs/Models/AnimPose.cpp
r426 r428 706 706 707 707 708 bool AnimPoseT::TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, ModelT::TraceResultT& Result) const708 bool AnimPoseT::TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 709 709 { 710 710 // if (m_Model.GetDlodModel() && LodDist >= m_Model.GetDlodDist()) -
cafu/trunk/Libs/Models/AnimPose.hpp
r425 r428 27 27 #include "Math3D/BoundingBox.hpp" 28 28 #include "Math3D/Matrix.hpp" 29 #include "Model.hpp" // For ModelT::TraceResultT30 29 31 30 32 31 class CafuModelT; 33 // class TraceResultT;32 class MaterialT; 34 33 35 34 … … 74 73 }; 75 74 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 76 88 77 89 /// The constructor. … … 101 113 102 114 /// Advances the pose in time. 115 /// Use GetFrameNr() to learn the new frame number after calling this method. 103 116 void Advance(float Time, bool ForceLoop=false); 104 117 … … 107 120 108 121 /// This method renders the model in this pose. 122 /// The current MatSys model-view matrix determines the position and orientation. 123 /// 109 124 /// @param SkinNr The skin to render the model with, -1 for the default skin. 110 125 /// @param LodDist The distance to the camera for reducing the level-of-detail. … … 120 135 /// 121 136 /// @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; 123 138 124 139 /// Considers the given triangle in the given mesh, and returns the vertex that the given point P is closest to in this pose. … … 135 150 const ArrayT<MeshInfoT>& GetMeshInfos() const; 136 151 137 /// Returns the MatSys meshes for th is pose.152 /// Returns the MatSys meshes for the model in this pose. 138 153 const ArrayT<MatSys::MeshT>& GetDrawMeshes() const; 139 154 140 /// Returns the bounding-box for th is pose.155 /// Returns the bounding-box for the model in this pose. 141 156 const BoundingBox3fT& GetBB() const; 142 157 -
cafu/trunk/Libs/Models/Loader_ase.cpp
r400 r428 297 297 298 298 299 LoaderAseT::LoaderAseT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/299 LoaderAseT::LoaderAseT(const std::string& FileName, int Flags) 300 300 : ModelLoaderT(FileName, Flags) 301 301 { … … 332 332 catch (const TextParserT::ParseError&) 333 333 { 334 throw ModelT::LoadError();334 throw LoadErrorT("Could not parse the file."); 335 335 } 336 336 … … 485 485 { 486 486 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."); 488 488 } 489 489 } -
cafu/trunk/Libs/Models/Loader_ase.hpp
r406 r428 37 37 /// @param FileName The name of the .ase file to import. 38 38 /// @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); 40 40 41 41 bool UseGivenTS() const { return true; } -
cafu/trunk/Libs/Models/Loader_assimp.cpp
r409 r428 30 30 31 31 32 LoaderAssimpT::LoaderAssimpT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/32 LoaderAssimpT::LoaderAssimpT(const std::string& FileName, int Flags) 33 33 : ModelLoaderT(FileName, Flags), 34 34 m_Scene(NULL) -
cafu/trunk/Libs/Models/Loader_assimp.hpp
r406 r428 41 41 /// 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. 42 42 /// 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); 44 44 45 45 bool UseGivenTS() const; -
cafu/trunk/Libs/Models/Loader_cmdl.cpp
r391 r428 32 32 33 33 34 LoaderCafuT::LoaderCafuT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/34 LoaderCafuT::LoaderCafuT(const std::string& FileName, int Flags) 35 35 : ModelLoaderT(FileName, Flags), 36 36 m_LuaState(lua_open()), -
cafu/trunk/Libs/Models/Loader_cmdl.hpp
r406 r428 37 37 /// @param FileName The name of the .cmdl file to load. 38 38 /// @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); 40 40 41 41 /// The destructor. -
cafu/trunk/Libs/Models/Loader_dlod.cpp
r406 r428 30 30 31 31 32 LoaderDlodT::LoaderDlodT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/32 LoaderDlodT::LoaderDlodT(const std::string& FileName, int Flags) 33 33 : ModelLoaderT(FileName, Flags) 34 34 { -
cafu/trunk/Libs/Models/Loader_dlod.hpp
r406 r428 34 34 /// @param FileName The name of the .dlod file to load. 35 35 /// @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); 37 37 38 38 /// The destructor. -
cafu/trunk/Libs/Models/Loader_fbx.hpp
r406 r428 35 35 /// @param UserCallbacks An implementation of the UserCallbacksI interface. 36 36 /// @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); 38 38 39 39 /// The destructor. -
cafu/trunk/Libs/Models/Loader_lwo.cpp
r400 r428 221 221 // - LWOs store their vertex positions in "points", the CafuModelT class in "weights" (CafuModelT::MeshT::WeightT). 222 222 // - 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)*/223 LoaderLwoT::LoaderLwoT(const std::string& FileName, int Flags) 224 224 : ModelLoaderT(FileName, Flags | REMOVE_UNUSED_VERTICES | REMOVE_UNUSED_WEIGHTS) // The code below relies on postprocessing removing unused vertices and weights. 225 225 { … … 235 235 if (lwo==NULL) 236 236 { 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"); 239 238 } 240 239 -
cafu/trunk/Libs/Models/Loader_lwo.hpp
r406 r428 34 34 /// @param FileName The name of the .lwo file to import. 35 35 /// @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); 37 37 38 38 bool UseGivenTS() const { return true; } -
cafu/trunk/Libs/Models/Loader_md5.cpp
r352 r428 30 30 31 31 32 LoaderMd5T::LoaderMd5T(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/32 LoaderMd5T::LoaderMd5T(const std::string& FileName, int Flags) 33 33 : ModelLoaderT(FileName, Flags) 34 34 { … … 53 53 54 54 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."); 56 56 57 57 size_t PrefixLength=m_FileName.length(); … … 88 88 const std::string Token=TP.GetNextToken(); 89 89 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."); } 91 91 else if (Token=="commandline") TP.GetNextToken(); // Ignore the command line. 92 92 else if (Token=="numJoints" ) TP.GetNextToken(); // Ignore the given number of joints - we just load as many as we find. … … 120 120 { 121 121 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! 123 123 } 124 124 … … 153 153 154 154 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()); } 158 158 else if (Token=="shader") 159 159 { … … 174 174 const unsigned long TriIdx=TP.GetNextTokenAsInt(); 175 175 176 if (TriIdx>=Mesh.Triangles.Size()) throw ModelT::LoadError();176 if (TriIdx>=Mesh.Triangles.Size()) throw LoadErrorT("TriIdx >= Mesh.Triangles.Size()"); 177 177 178 178 Mesh.Triangles[TriIdx].VertexIdx[0]=TP.GetNextTokenAsInt(); … … 184 184 const unsigned long VertIdx=TP.GetNextTokenAsInt(); 185 185 186 if (VertIdx>=Mesh.Vertices.Size()) throw ModelT::LoadError();186 if (VertIdx>=Mesh.Vertices.Size()) throw LoadErrorT("VertIdx >= Mesh.Vertices.Size()"); 187 187 188 188 TP.AssertAndSkipToken("("); … … 197 197 const unsigned long WeightIdx=TP.GetNextTokenAsInt(); 198 198 199 if (WeightIdx>=Mesh.Weights.Size()) throw ModelT::LoadError();199 if (WeightIdx>=Mesh.Weights.Size()) throw LoadErrorT("WeightIdx >= Mesh.Weights.Size()"); 200 200 201 201 Mesh.Weights[WeightIdx].JointIdx=TP.GetNextTokenAsInt(); … … 222 222 catch (const TextParserT::ParseError&) 223 223 { 224 throw ModelT::LoadError();224 throw LoadErrorT("Could not parse the file."); 225 225 } 226 226 … … 243 243 const std::string Token=TP.GetNextToken(); 244 244 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."); } 246 246 else if (Token=="commandline") TP.GetNextToken(); // Ignore the command line. 247 247 else if (Token=="frameRate" ) Anim.FPS=TP.GetNextTokenAsFloat(); … … 250 250 // Be stricter with numFrames than with some num* variables in the md5mesh file. 251 251 // 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"); 253 253 254 254 Anim.Frames.PushBackEmpty(TP.GetNextTokenAsInt()); … … 259 259 const unsigned long numJoints=TP.GetNextTokenAsInt(); 260 260 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"); } 263 263 264 264 Anim.AnimJoints.PushBackEmpty(numJoints); … … 270 270 // This is the number of components that is animated in the frames (and thus so many values are stored with each frame). 271 271 // 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"); 273 273 274 274 for (unsigned long FrameNr=0; FrameNr<Anim.Frames.Size(); FrameNr++) … … 282 282 { 283 283 // 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."); 286 286 287 287 Anim.AnimJoints[JointNr].Flags =TP.GetNextTokenAsInt(); … … 366 366 printf("WARNING: Loading animation sequence file %s failed just before input byte %lu!\n", ComponentFiles[FileNr].c_str(), TP.GetReadPosByte()); 367 367 } 368 catch (const ModelT::LoadError&)368 catch (const LoadErrorT& LE) 369 369 { 370 370 // Loading this animation sequence failed, but as the base mesh (the md5mesh file) … … 375 375 Anims.PushBack(InvalidAnim); // Note that InvalidAnim.Frames.Size()==0, too. 376 376 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()); 378 379 } 379 380 } -
cafu/trunk/Libs/Models/Loader_md5.hpp
r406 r428 36 36 /// 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. 37 37 /// 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); 39 39 40 40 bool UseGivenTS() const; -
cafu/trunk/Libs/Models/Loader_mdl.cpp
r406 r428 32 32 33 33 34 LoaderHL1mdlT::LoaderHL1mdlT(const std::string& FileName, int Flags) /*throw (ModelT::LoadError)*/34 LoaderHL1mdlT::LoaderHL1mdlT(const std::string& FileName, int Flags) 35 35 : ModelLoaderT(FileName, Flags | 36 36 REMOVE_DEGEN_TRIANGLES | // Need this flag in order to pass all assertions in the CafuModelT code. … … 40 40 // ********************************** 41 41 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"); 43 43 44 44 const std::string BaseName(m_FileName.c_str(), m_FileName.length()-4); … … 49 49 50 50 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."); 52 52 53 53 fseek(InFile, 0, SEEK_END); ModelData.PushBackEmpty(ftell(InFile)); … … 74 74 { 75 75 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."); 77 77 78 78 fseek(InFile, 0, SEEK_END); TextureData.PushBackEmpty(ftell(InFile)); … … 99 99 100 100 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."); 102 102 103 103 fseek(InFile, 0, SEEK_END); AnimationData[SeqGroupNr].PushBackEmpty(ftell(InFile)); -
cafu/trunk/Libs/Models/Loader_mdl.hpp
r406 r428 42 42 /// @param FileName The name of the .mdl file to import. 43 43 /// @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); 45 45 46 46 bool UseGivenTS() const; -
cafu/trunk/Libs/Models/ModelManager.cpp
r423 r428 75 75 "then load the cmdl model in place of this."); 76 76 } 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 }84 77 catch (const ModelLoaderT::LoadErrorT& LE) 85 78 { -
cafu/trunk/Libs/Models/Model_cmdl.cpp
r427 r428 176 176 Frames[FrameNr].BB=BoundingBox3fT(); 177 177 178 // This is a modified version of the loop in CafuModelT::RecomputeBindPoseBB().178 // This is very similar to the code in AnimPoseT::UpdateData(). 179 179 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 180 180 { … … 247 247 m_MaterialMan(), 248 248 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).250 249 m_DlodModel(NULL), 251 250 m_DlodDist(0.0f) … … 272 271 Loader.Postprocess(m_Meshes); 273 272 274 if (m_Joints.Size()==0) throw Model T::LoadError();275 // if (m_Meshes.Size()==0) throw Model T::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. 276 275 277 276 // Load the chain of dlod models, if any. … … 351 350 352 351 353 bool CafuModelT::IsMeshNrOK(const GuiFixtureT& GF, unsigned int PointNr) const354 {355 return GF.Points[PointNr].MeshNr < m_Meshes.Size();356 }357 358 359 bool CafuModelT::IsVertexNrOK(const GuiFixtureT& GF, unsigned int PointNr) const360 {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) const367 {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 else404 {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 420 352 void CafuModelT::InitMeshes() 421 353 { 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 426 354 // Compute auxiliary data for each mesh. 427 355 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) … … 946 874 947 875 948 /***********************************************/949 /*** Implementation of the ModelT interface. ***/950 /***********************************************/951 952 const std::string& CafuModelT::GetFileName() const953 {954 return m_FileName;955 }956 957 958 876 const MaterialT* CafuModelT::GetMaterial(unsigned long MeshNr, int SkinNr) const 959 877 { … … 990 908 991 909 992 void CafuModelT::Draw(int SequenceNr, float FrameNr, float LodDist, const ModelT* /*SubModel*/) const 993 { 994 m_TEMP_Pose->SetSequNr(SequenceNr); 910 bool CafuModelT::IsMeshNrOK(const GuiFixtureT& GF, unsigned int PointNr) const 911 { 912 return GF.Points[PointNr].MeshNr < m_Meshes.Size(); 913 } 914 915 916 bool 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 923 AnimPoseT* CafuModelT::GetSharedPose(int SequNr, float FrameNr) const 924 { 925 m_TEMP_Pose->SetSequNr(SequNr); 995 926 m_TEMP_Pose->SetFrameNr(FrameNr); 996 927 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) const928 return m_TEMP_Pose; 929 } 930 931 932 bool CafuModelT::GetGuiPlane(Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const 1002 933 { 1003 934 if (m_GuiLocs.Size()==0) return false; … … 1050 981 } 1051 982 } 1052 1053 1054 unsigned int CafuModelT::GetNrOfSequences() const1055 {1056 return m_Anims.Size();1057 }1058 1059 1060 BoundingBox3fT CafuModelT::GetBB(int SequenceNr, float FrameNr) const1061 {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) const1073 {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*/) const1082 // {1083 // return 0.0;1084 // }1085 1086 1087 float CafuModelT::AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop) const1088 {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 else1103 {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 29 29 #include "Math3D/Matrix.hpp" 30 30 #include "AnimPose.hpp" // Only for TEMPORARILY implementing the "old" ModelT interface methods. 31 #include "Model.hpp"32 31 33 32 #if defined(_WIN32) && _MSC_VER<1600 … … 54 53 55 54 /// This class represents a native Cafu model. 56 class CafuModelT : public ModelT55 class CafuModelT 57 56 { 58 57 public: … … 255 254 256 255 // Inspector methods. 257 bool GetUseGivenTS() const { return m_UseGivenTangentSpace; }256 const std::string& GetFileName() const { return m_FileName; } 258 257 const MaterialManagerImplT& GetMaterialManager() const { return m_MaterialMan; } 259 258 const ArrayT<JointT>& GetJoints() const { return m_Joints; } … … 263 262 const ArrayT<AnimT>& GetAnims() const { return m_Anims; } 264 263 const ArrayT<ChannelT>& GetChannels() const { return m_Channels; } 264 bool GetUseGivenTS() const { return m_UseGivenTangentSpace; } 265 265 const CafuModelT* GetDlodModel() const { return m_DlodModel; } 266 266 float GetDlodDist() const { return m_DlodDist; } … … 281 281 AnimPoseT* GetSharedPose(int SequNr, float FrameNr) const; 282 282 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; 295 291 296 292 … … 311 307 void operator = (const CafuModelT&); ///< Use of the Assignment Operator is not allowed. 312 308 313 void RecomputeBindPoseBB(); ///< Recomputes the bounding box for the model in bind pose (stored in m_BindPoseBB).314 309 void InitMeshes(); ///< An auxiliary method for the constructors. 315 310 … … 326 321 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). 327 322 // const bool m_CastShadows; ///< Should this model cast shadows? 328 BoundingBox3fT m_BindPoseBB; ///< [REMOVE???] The bounding-box for the base pose of the model.329 323 330 324 CafuModelT* m_DlodModel; ///< Use the m_DlodModel instead of this when the camera is more than m_DlodDist away. 331 325 float m_DlodDist; ///< The distance beyond which the m_DlodModel is used instead of this. 332 326 333 mutable AnimPoseT* m_TEMP_Pose;///< TEMPORARY!327 mutable AnimPoseT* m_TEMP_Pose; ///< TEMPORARY! 334 328 }; 335 329 -
cafu/trunk/Libs/SConscript
r414 r428 15 15 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 16 16 Models/Loader_mdl.cpp Models/AnimPose.cpp 17 Models/Model_cmdl.cpp Models/Model _proxy.cpp Models/ModelManager.cpp17 Models/Model_cmdl.cpp Models/ModelManager.cpp 18 18 Network/Network.cpp ParticleEngine/ParticleEngineMS.cpp PlatformAux.cpp Terrain/Terrain.cpp 19 19 TextParser/TextParser.cpp
