1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | #include "Ogre.h"
|
---|
28 | #include "OldMaterialReader.h"
|
---|
29 | #include "OgreMaterialManager.h"
|
---|
30 | #include "OgreMaterialSerializer.h"
|
---|
31 |
|
---|
32 | #include <iostream>
|
---|
33 | #include <sys/stat.h>
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | void help(void)
|
---|
38 | {
|
---|
39 | // Print help message
|
---|
40 | cout << endl << "OgreMaterialUpgrader: Upgrades .material files to the latest version." << endl;
|
---|
41 | cout << "Provided for OGRE by Steve Streeting 2003" << endl << endl;
|
---|
42 | cout << "Usage: OgreMaterialUpgrade sourcefile [destfile] " << endl;
|
---|
43 | cout << "sourcefile = name of file to convert" << endl;
|
---|
44 | cout << "destfile = optional name of file to write to. If you don't" << endl;
|
---|
45 | cout << " specify this OGRE overwrites the existing file." << endl;
|
---|
46 |
|
---|
47 | cout << endl;
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | using namespace Ogre;
|
---|
52 |
|
---|
53 | // Crappy globals
|
---|
54 | // NB some of these are not directly used, but are required to
|
---|
55 | // instantiate the singletons used in the dlls
|
---|
56 | LogManager* logMgr;
|
---|
57 | Math* mth;
|
---|
58 | ResourceGroupManager* resGrpMgr;
|
---|
59 | MaterialManager* matMgr;
|
---|
60 |
|
---|
61 | int main(int numargs, char** args)
|
---|
62 | {
|
---|
63 | if (numargs < 2)
|
---|
64 | {
|
---|
65 | help();
|
---|
66 | return -1;
|
---|
67 | }
|
---|
68 |
|
---|
69 | logMgr = new LogManager();
|
---|
70 | logMgr->createLog("OgreMaterialUpgrade.log", true);
|
---|
71 | mth = new Math();
|
---|
72 | resGrpMgr = new ResourceGroupManager();
|
---|
73 | matMgr = new MaterialManager();
|
---|
74 | matMgr->initialise();
|
---|
75 |
|
---|
76 | String source(args[1]);
|
---|
77 |
|
---|
78 | // Load the material
|
---|
79 | struct stat tagStat;
|
---|
80 |
|
---|
81 | FILE* pFile = fopen( source.c_str(), "r" );
|
---|
82 | if (!pFile)
|
---|
83 | {
|
---|
84 | OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
|
---|
85 | "File " + source + " not found.", "OgreMaterialUpgrade");
|
---|
86 | }
|
---|
87 | stat( source.c_str(), &tagStat );
|
---|
88 | MemoryDataStream* memStream = new MemoryDataStream(source, tagStat.st_size, true);
|
---|
89 | fread( (void*)memStream->getPtr(), tagStat.st_size, 1, pFile );
|
---|
90 | fclose( pFile );
|
---|
91 |
|
---|
92 | // Read script, note this will create potentially many Materials and load them
|
---|
93 | // into the MaterialManager
|
---|
94 | OldMaterialReader reader;
|
---|
95 | DataStreamPtr stream(memStream);
|
---|
96 | reader.parseScript(stream);
|
---|
97 |
|
---|
98 | // Write out the converted mesh
|
---|
99 | String dest;
|
---|
100 | if (numargs == 3)
|
---|
101 | {
|
---|
102 | dest = args[2];
|
---|
103 | }
|
---|
104 | else
|
---|
105 | {
|
---|
106 | dest = source;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | MaterialSerializer serializer;
|
---|
111 | ResourceManager::ResourceMapIterator it = matMgr->getResourceIterator();
|
---|
112 | while (it.hasMoreElements())
|
---|
113 | {
|
---|
114 | MaterialPtr m = it.getNext();
|
---|
115 | // Skip builtin materials
|
---|
116 | if (m->getName() == "BaseWhite" || m->getName() == "BaseWhiteNoLighting")
|
---|
117 | continue;
|
---|
118 | serializer.queueForExport(m);
|
---|
119 | }
|
---|
120 | serializer.exportQueued(dest);
|
---|
121 |
|
---|
122 | delete matMgr;
|
---|
123 | delete resGrpMgr;
|
---|
124 | delete mth;
|
---|
125 | delete logMgr;
|
---|
126 |
|
---|
127 | return 0;
|
---|
128 |
|
---|
129 | }
|
---|
130 |
|
---|