Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tools/MaterialUpgrader/src/main.cpp @ 7

Last change on this file since 7 was 6, checked in by anonymous, 17 years ago

=…

File size: 3.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus 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
39using namespace std;
40
41void 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
55using 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
60LogManager* logMgr;
61Math* mth;
62ResourceGroupManager* resGrpMgr;
63MaterialManager* matMgr;
64
65int 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
Note: See TracBrowser for help on using the repository browser.