00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Scorched3D is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #include <3dsparse/ASEModelFactory.h> 00022 #include <3dsparse/MSModelFactory.h> 00023 #include <3dsparse/TreeModelFactory.h> 00024 #include <3dsparse/ModelStore.h> 00025 #include <3dsparse/Model.h> 00026 #include <common/Defines.h> 00027 00028 ModelStore *ModelStore::instance_ = 0; 00029 00030 ModelStore *ModelStore::instance() 00031 { 00032 if (!instance_) 00033 { 00034 instance_ = new ModelStore; 00035 } 00036 return instance_; 00037 } 00038 00039 ModelStore::ModelStore() 00040 { 00041 } 00042 00043 ModelStore::~ModelStore() 00044 { 00045 } 00046 00047 Model *ModelStore::loadModel(ModelID &modelId) 00048 { 00049 std::map<std::string, Model *>::iterator findItor = 00050 fileMap_.find(modelId.getStringHash()); 00051 if (findItor == fileMap_.end()) 00052 { 00053 Model *model = getModel(modelId); 00054 fileMap_[modelId.getStringHash()] = model; 00055 return model; 00056 } 00057 return (*findItor).second; 00058 } 00059 00060 Model *ModelStore::getModel(ModelID &id) 00061 { 00062 Model *model = 0; 00063 if (0 == strcmp(id.getType(), "ase")) 00064 { 00065 // Load the ASEFile containing the tank definitions 00066 std::string meshName(S3D::getDataFile(id.getMeshName())); 00067 00068 bool noSkin = 00069 (0 == strcmp("none", id.getSkinName())); 00070 ASEModelFactory factory; 00071 std::string skinName = S3D::getDataFile(id.getSkinName()); 00072 model = factory.createModel(meshName.c_str(), 00073 (noSkin?"":skinName.c_str())); 00074 } 00075 else if (0 == strcmp(id.getType(), "MilkShape")) 00076 { 00077 // Load the Milkshape containing the tank definitions 00078 std::string meshName(S3D::getDataFile(id.getMeshName())); 00079 MSModelFactory factory; 00080 model = factory.createModel(meshName.c_str()); 00081 } 00082 else if (0 == strcmp(id.getType(), "Tree")) 00083 { 00084 // Create a model for the tree 00085 TreeModelFactory factory; 00086 model = factory.createModel(id.getMeshName(), id.getSkinName()); 00087 } 00088 else 00089 { 00090 DIALOG_ASSERT(0); 00091 } 00092 00093 return model; 00094 }
1.5.3