2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
7 #include "Loader_dlod.hpp"
8 #include "Loader_ase.hpp"
9 #include "Loader_cmdl.hpp"
10 #include "Loader_lwo.hpp"
11 #include "Loader_md5.hpp"
12 #include "Loader_mdl_hl1.hpp"
13 #include "TextParser/TextParser.hpp"
17 LoaderDlodT::LoaderDlodT(const std::string
& FileName
, int Flags
)
18 : ModelLoaderT(FileName
, Flags
)
20 TextParserT
TP(FileName
.c_str());
26 m_ModelNames
.PushBack(TP
.GetNextToken());
27 m_EndRanges
.PushBack(TP
.GetNextTokenAsFloat());
30 catch (const TextParserT::ParseError
&)
32 throw LoadErrorT("Could not parse the dlod file.");
35 if (m_EndRanges
.Size() < m_ModelNames
.Size())
37 // The last end-range number is optional, as it is ignored:
38 // The last model is always used up to infinity.
39 m_EndRanges
.PushBack(0.0f
);
42 if (m_ModelNames
.Size()==0 ||
43 m_ModelNames
.Size()!=m_EndRanges
.Size()) throw LoadErrorT("Invalid dlod file.");
45 // Acquire loader instances for each model in the dlod chain.
48 for (unsigned long ModelNr
=0; ModelNr
<m_ModelNames
.Size(); ModelNr
++)
50 // The m_ModelNames are specified relative to the parent file name,
51 // thus extract the path portion from FileName and prepend it to the m_ModelNames.
52 const std::string fn
=cf::String::GetPath(FileName
) + "/" + m_ModelNames
[ModelNr
];
54 if (cf::String::EndsWith(fn
, "ase" )) m_ModelLoaders
.PushBack(new LoaderAseT (fn
, m_Flags
));
55 else if (cf::String::EndsWith(fn
, "cmdl" )) m_ModelLoaders
.PushBack(new LoaderCafuT (fn
, m_Flags
));
56 // else if (cf::String::EndsWith(fn, "3ds" )) m_ModelLoaders.PushBack(new LoaderFbxT (fn, m_Flags));
57 // else if (cf::String::EndsWith(fn, "dae" )) m_ModelLoaders.PushBack(new LoaderFbxT (fn, m_Flags));
58 // else if (cf::String::EndsWith(fn, "dxf" )) m_ModelLoaders.PushBack(new LoaderFbxT (fn, m_Flags));
59 // else if (cf::String::EndsWith(fn, "fbx" )) m_ModelLoaders.PushBack(new LoaderFbxT (fn, m_Flags));
60 // else if (cf::String::EndsWith(fn, "dlod" )) m_ModelLoaders.PushBack(new LoaderDlodT (fn, m_Flags)); // Don't recurse.
61 else if (cf::String::EndsWith(fn
, "lwo" )) m_ModelLoaders
.PushBack(new LoaderLwoT (fn
, m_Flags
));
62 else if (cf::String::EndsWith(fn
, "mdl" )) m_ModelLoaders
.PushBack(new LoaderHL1mdlT(fn
, m_Flags
));
63 else if (cf::String::EndsWith(fn
, "md5" )) m_ModelLoaders
.PushBack(new LoaderMd5T (fn
, m_Flags
));
64 else if (cf::String::EndsWith(fn
, "md5mesh")) m_ModelLoaders
.PushBack(new LoaderMd5T (fn
, m_Flags
));
65 // else if (cf::String::EndsWith(fn, "obj" )) m_ModelLoaders.PushBack(new LoaderFbxT (fn, m_Flags));
66 else throw LoadErrorT("Model file format not supported as dlod model.");
69 catch (const LoadErrorT
&)
71 for (unsigned long ModelNr
=0; ModelNr
<m_ModelLoaders
.Size(); ModelNr
++)
72 delete m_ModelLoaders
[ModelNr
];
79 LoaderDlodT::~LoaderDlodT()
81 for (unsigned long ModelNr
=0; ModelNr
<m_ModelLoaders
.Size(); ModelNr
++)
82 delete m_ModelLoaders
[ModelNr
];
86 const std::string
& LoaderDlodT::GetFileName() const
88 // The model will (attempt to) register a wrong .cmat file
89 // with its material manager if we return m_FileName here.
90 return m_ModelLoaders
[0]->GetFileName();
94 void LoaderDlodT::Load(ArrayT
<CafuModelT::JointT
>& Joints
, ArrayT
<CafuModelT::MeshT
>& Meshes
, ArrayT
<CafuModelT::AnimT
>& Anims
, MaterialManagerImplT
& MaterialMan
)
96 m_ModelLoaders
[0]->Load(Joints
, Meshes
, Anims
, MaterialMan
);
100 void LoaderDlodT::Load(ArrayT
<CafuModelT::SkinT
>& Skins
, const MaterialManagerImplT
& MaterialMan
)
102 m_ModelLoaders
[0]->Load(Skins
, MaterialMan
);
106 void LoaderDlodT::Load(ArrayT
<CafuModelT::GuiFixtureT
>& GuiFixtures
)
108 m_ModelLoaders
[0]->Load(GuiFixtures
);
112 void LoaderDlodT::Load(ArrayT
<CafuModelT::ChannelT
>& Channels
)
114 m_ModelLoaders
[0]->Load(Channels
);
118 bool LoaderDlodT::Load(unsigned int Level
, CafuModelT
*& DlodModel
, float& DlodDist
)
120 if (Level
>= m_ModelLoaders
.Size()) return false;
127 DlodModel
=new CafuModelT(*m_ModelLoaders
[Level
]);
129 catch (const LoadErrorT
&)
134 DlodDist
=m_EndRanges
[Level
-1];