00001 #include "global.h"
00002 #include "MercuryModel.h"
00003 #include "MercuryDisplay.h"
00004 #include "MercuryLog.h"
00005 #include "MercuryUtil.h"
00006
00007 MercuryModel::MercuryModel()
00008 {
00009 m_polys = 0;
00010 m_file = NULL;
00011
00012 }
00013
00014 MercuryModel::~MercuryModel()
00015 {
00016
00017 if( m_bClone )
00018 return;
00019 unsigned int i;
00020 unsigned int num = m_meshes.size();
00021 for (i = 0; i < num; i++)
00022 MESHMAN.UnregMesh( m_meshes[i] );
00023 }
00024
00025 void MercuryModel::AddMesh(MercuryMesh* mesh)
00026 {
00027 m_meshes.push_back(mesh);
00028 AddObject(mesh);
00029 }
00030
00031 void MercuryModel::AddMaterial(MercuryMaterial* material)
00032 {
00033 ASSERT(material);
00034 m_materials.push_back(material);
00035 }
00036
00037 void MercuryModel::OpenFile(const MString& path)
00038 {
00039 SAFE_DELETE(m_file);
00040 m_file = FILEMAN.Open(path);
00041
00042 if (m_file==NULL)
00043 {
00044 LOG.Warn("File not oppened:" + path);
00045 throw;
00046 }
00047 }
00048
00049 void MercuryModel::Load(MString path)
00050 {
00051 m_path = path.substr(0, path.find_last_of("/")+1);
00052 m_filename = path.substr(path.find_last_of("/")+1);
00053 OpenFile(path);
00054 LoadModel();
00055 CloseFile();
00056 }
00057
00058 bool MercuryModel::ReadLine()
00059 {
00060
00061 do
00062 {
00063 if (!m_file->Eof())
00064 m_file->ReadLine(m_line);
00065 else
00066 return false;
00067
00068 if (!m_line.empty())
00069 {
00070
00071 while ((m_line.find(" ") == 0)||(m_line.find("\t") == 0))
00072 m_line = m_line.substr(1, m_line.length());
00073
00074
00075 int comment = m_line.find("//");
00076 if (comment >= 0)
00077 m_line = m_line.substr(0,comment);
00078
00079
00080 while ((m_line.rfind(" ") == 0)||(m_line.rfind("\t") == 0))
00081 m_line = m_line.substr(0, m_line.length()-1);
00082 }
00083 }
00084 while (m_line.length() <= 0);
00085
00086 return true;
00087 }
00088
00089 bool MercuryModel::Command( PStack & ret, const char * command, PStack & args )
00090 {
00091 if ( strcmp( command, "LoadModel" ) == 0 )
00092 {
00093 MString Parameter = args.PopItem().GetValueS();
00094 while( args.GetSize() )
00095 Parameter = args.PopItem().GetValueS() + "," + Parameter;
00096 Load( Parameter );
00097 return true;
00098 }
00099 return MercuryObject::Command( ret, command, args );
00100 }
00101
00102 void MercuryModel::EnumerateCommands( MVector< MString > & toAdd )
00103 {
00104 toAdd.push_back( "LoadModel" );
00105 MercuryObject::EnumerateCommands( toAdd );
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134