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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | |
---|
31 | #include "Ogre.h" |
---|
32 | #include "OldMaterialReader.h" |
---|
33 | #include "OgreMaterialManager.h" |
---|
34 | #include "OgreMaterialSerializer.h" |
---|
35 | |
---|
36 | #include <iostream> |
---|
37 | #include <sys/stat.h> |
---|
38 | |
---|
39 | using namespace std; |
---|
40 | |
---|
41 | void help(void) |
---|
42 | { |
---|
43 | // Print help message |
---|
44 | cout << endl << "OgreMaterialUpgrader: Upgrades .material files to the latest version." << endl; |
---|
45 | cout << "Provided for OGRE by Steve Streeting 2003" << endl << endl; |
---|
46 | cout << "Usage: OgreMaterialUpgrade sourcefile [destfile] " << endl; |
---|
47 | cout << "sourcefile = name of file to convert" << endl; |
---|
48 | cout << "destfile = optional name of file to write to. If you don't" << endl; |
---|
49 | cout << " specify this OGRE overwrites the existing file." << endl; |
---|
50 | |
---|
51 | cout << endl; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | using namespace Ogre; |
---|
56 | |
---|
57 | // Crappy globals |
---|
58 | // NB some of these are not directly used, but are required to |
---|
59 | // instantiate the singletons used in the dlls |
---|
60 | LogManager* logMgr; |
---|
61 | Math* mth; |
---|
62 | ResourceGroupManager* resGrpMgr; |
---|
63 | MaterialManager* matMgr; |
---|
64 | |
---|
65 | int main(int numargs, char** args) |
---|
66 | { |
---|
67 | if (numargs < 2) |
---|
68 | { |
---|
69 | help(); |
---|
70 | return -1; |
---|
71 | } |
---|
72 | |
---|
73 | logMgr = new LogManager(); |
---|
74 | logMgr->createLog("OgreMaterialUpgrade.log", true); |
---|
75 | mth = new Math(); |
---|
76 | resGrpMgr = new ResourceGroupManager(); |
---|
77 | matMgr = new MaterialManager(); |
---|
78 | matMgr->initialise(); |
---|
79 | |
---|
80 | String source(args[1]); |
---|
81 | |
---|
82 | // Load the material |
---|
83 | struct stat tagStat; |
---|
84 | |
---|
85 | FILE* pFile = fopen( source.c_str(), "r" ); |
---|
86 | if (!pFile) |
---|
87 | { |
---|
88 | OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, |
---|
89 | "File " + source + " not found.", "OgreMaterialUpgrade"); |
---|
90 | } |
---|
91 | stat( source.c_str(), &tagStat ); |
---|
92 | MemoryDataStream* memStream = new MemoryDataStream(source, tagStat.st_size, true); |
---|
93 | fread( (void*)memStream->getPtr(), tagStat.st_size, 1, pFile ); |
---|
94 | fclose( pFile ); |
---|
95 | |
---|
96 | // Read script, note this will create potentially many Materials and load them |
---|
97 | // into the MaterialManager |
---|
98 | OldMaterialReader reader; |
---|
99 | DataStreamPtr stream(memStream); |
---|
100 | reader.parseScript(stream); |
---|
101 | |
---|
102 | // Write out the converted mesh |
---|
103 | String dest; |
---|
104 | if (numargs == 3) |
---|
105 | { |
---|
106 | dest = args[2]; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | dest = source; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | MaterialSerializer serializer; |
---|
115 | ResourceManager::ResourceMapIterator it = matMgr->getResourceIterator(); |
---|
116 | while (it.hasMoreElements()) |
---|
117 | { |
---|
118 | MaterialPtr m = it.getNext(); |
---|
119 | // Skip builtin materials |
---|
120 | if (m->getName() == "BaseWhite" || m->getName() == "BaseWhiteNoLighting") |
---|
121 | continue; |
---|
122 | serializer.queueForExport(m); |
---|
123 | } |
---|
124 | serializer.exportQueued(dest); |
---|
125 | |
---|
126 | delete matMgr; |
---|
127 | delete resGrpMgr; |
---|
128 | delete mth; |
---|
129 | delete logMgr; |
---|
130 | |
---|
131 | return 0; |
---|
132 | |
---|
133 | } |
---|
134 | |
---|