1 | /*
|
---|
2 | ============================================================================
|
---|
3 | This source file is part of the Ogre-Maya Tools.
|
---|
4 | Distributed as part of Ogre (Object-oriented Graphics Rendering Engine).
|
---|
5 | Copyright (C) 2003 Fifty1 Software Inc., Bytelords
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or
|
---|
8 | modify it under the terms of the GNU General Public License
|
---|
9 | as published by the Free Software Foundation; either version 2
|
---|
10 | of the License, or (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
20 | or 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 |
|
---|
36 | namespace 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 | }
|
---|