source: OGRE/trunk/ogrenew/Tools/MaterialUpgrader/src/main.cpp @ 692

Revision 692, 3.8 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
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
35using namespace std;
36
37void 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
51using 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
56LogManager* logMgr;
57Math* mth;
58ResourceGroupManager* resGrpMgr;
59MaterialManager* matMgr;
60
61int 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
Note: See TracBrowser for help on using the repository browser.