source: OGRE/trunk/ogrenew/Tools/MayaExport/maya2ogre/src/OgreMayaScene.cpp @ 657

Revision 657, 3.3 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2============================================================================
3This source file is part of the Ogre-Maya Tools.
4Distributed as part of Ogre (Object-oriented Graphics Rendering Engine).
5Copyright (C) 2003 Fifty1 Software Inc., Bytelords
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; either version 2
10of the License, or (at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20or go to http://www.gnu.org/licenses/gpl.txt
21============================================================================
22*/
23#include "OgreMayaScene.h"
24#include "OgreMayaOptions.h"
25
26#include <maya/MLibrary.h>
27#include <maya/MFileIO.h>
28#include <maya/MStatus.h>
29
30#ifdef _WIN32
31#include <direct.h>
32#endif
33
34#include <iostream>
35
36namespace OgreMaya {
37       
38        using namespace std;
39
40        //      --------------------------------------------------------------------------
41        /**     Standard constructor.
42        */     
43        //      --------------------------------------------------------------------------
44        SceneMgr::SceneMgr() {
45                mbInitialized = false;                 
46        }
47
48
49        //      --------------------------------------------------------------------------
50        /**     Destructor. Cleans up Maya library if required.
51        */     
52        //      --------------------------------------------------------------------------
53        SceneMgr::~SceneMgr() {
54                if (mbInitialized) {
55                        MLibrary::cleanup();
56                        mbInitialized = false;
57                }
58        }
59
60
61
62        //      --------------------------------------------------------------------------
63        /**     Loads a Maya scene file, initializing the Maya library first if required.
64                \param          sFilename
65                                        Path and filename of Maya scene file to load
66                \return         True if file loaded successfully, False otherwise
67        */     
68        //      --------------------------------------------------------------------------
69        bool SceneMgr::load() {
70
71        cout << "\nSceneMgr::load\n";
72
73                MStatus status;
74
75                // Store working directory to restore later
76                char szDir[300];
77#ifdef _WIN32
78                _getcwd(szDir, 300);
79#else
80                getcwd(szDir, 300);
81#endif
82
83                // Initialize Maya if required
84                if (!mbInitialized) {
85                        cout << "\tinitializing Maya...\n";
86
87                        status = MLibrary::initialize("Maya-to-Ogre", false);
88                        if (!status) {
89                                status.perror("MLibrary::initialize");
90                                return false;
91                        }
92                        mbInitialized = true;
93
94                        cout << "\tMaya initialized\n";
95        }
96
97                // Prepare Maya to read a new scene file
98                status = MFileIO::newFile(true);
99                if (!status) {
100                        cout << "\t[ERROR] MFileIO::newFile() failed\n";
101                        return false;
102                }
103
104                // Restore working directory
105#ifdef _WIN32
106                _chdir(szDir);
107#else
108                chdir(szDir);
109#endif
110
111                // Read the scene file
112                status = MFileIO::open(OPTIONS.inFile.c_str());
113                if (!status) {
114                        cout << "\t[ERROR] MFileIO::open() failed:\n";
115                        return false;
116                }
117                cout << "\tfile " << OPTIONS.inFile.c_str() << " opened\n";
118
119                // Done
120                return true;
121        }
122
123}
Note: See TracBrowser for help on using the repository browser.