git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / 3dsparse / ModelStore.cpp
blob10781f32b966b75ea42b1069be3f2fa02af665e2
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <3dsparse/ASEModelFactory.h>
22 #include <3dsparse/MSModelFactory.h>
23 #include <3dsparse/TreeModelFactory.h>
24 #include <3dsparse/ModelStore.h>
25 #include <3dsparse/Model.h>
26 #include <common/Defines.h>
28 ModelStore *ModelStore::instance_ = 0;
30 ModelStore *ModelStore::instance()
32 if (!instance_)
34 instance_ = new ModelStore;
36 return instance_;
39 ModelStore::ModelStore()
43 ModelStore::~ModelStore()
47 Model *ModelStore::loadModel(ModelID &modelId)
49 std::map<std::string, Model *>::iterator findItor =
50 fileMap_.find(modelId.getStringHash());
51 if (findItor == fileMap_.end())
53 Model *model = getModel(modelId);
54 fileMap_[modelId.getStringHash()] = model;
55 return model;
57 return (*findItor).second;
60 Model *ModelStore::getModel(ModelID &id)
62 Model *model = 0;
63 if (0 == strcmp(id.getType(), "ase"))
65 // Load the ASEFile containing the tank definitions
66 std::string meshName(S3D::getDataFile(id.getMeshName()));
68 bool noSkin =
69 (0 == strcmp("none", id.getSkinName()));
70 ASEModelFactory factory;
71 std::string skinName = S3D::getDataFile(id.getSkinName());
72 model = factory.createModel(meshName.c_str(),
73 (noSkin?"":skinName.c_str()));
75 else if (0 == strcmp(id.getType(), "MilkShape"))
77 // Load the Milkshape containing the tank definitions
78 std::string meshName(S3D::getDataFile(id.getMeshName()));
79 MSModelFactory factory;
80 model = factory.createModel(meshName.c_str());
82 else if (0 == strcmp(id.getType(), "Tree"))
84 // Create a model for the tree
85 TreeModelFactory factory;
86 model = factory.createModel(id.getMeshName(), id.getSkinName());
88 else
90 DIALOG_ASSERT(0);
93 return model;