Panda3D
eggToMaya.cxx
1 // Filename: eggToMaya.cxx
2 // Created by: drose (11Aug05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "eggToMaya.h"
16 #include "mayaEggLoader.h"
17 #include "mayaApi.h"
18 #ifdef _WIN32
19  #include "pystub.h"
20 #endif
21 
22 // We must define this to prevent Maya from doubly-declaring its
23 // MApiVersion string in this file as well as in libmayaegg.
24 #define _MApiVersion
25 
26 #include "pre_maya_include.h"
27 #include <maya/MString.h>
28 #include <maya/MFileIO.h>
29 #include "post_maya_include.h"
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: EggToMaya::Constructor
33 // Access: Public
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 EggToMaya::
37 EggToMaya() :
38  EggToSomething("Maya", ".mb", true, false)
39 {
40  add_units_options();
41 
42  set_binary_output(true);
43  set_program_brief("convert .egg files to Maya .mb or .ma files");
44  set_program_description
45  ("egg2maya converts files from egg format to Maya .mb or .ma "
46  "format. It contains support for basic geometry (polygons with textures)."
47  "It also supports animation for joints.");
48 
49  add_option
50  ("a", "", 0,
51  "Convert animation tables.",
52  &EggToMaya::dispatch_none, &_convert_anim);
53 
54  add_option
55  ("m", "", 0,
56  "Convert polygon models. You may specify both -a and -m at the same "
57  "time. If you specify neither, the default is -m.",
58  &EggToMaya::dispatch_none, &_convert_model);
59 
60  add_option
61  ("nv", "", 0,
62  "respect vertex and polygon normals.",
63  &EggToMaya::dispatch_none, &_respect_normals);
64 
65  // Maya files always store centimeters.
66  _output_units = DU_centimeters;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: EggToMaya::run
71 // Access: Public
72 // Description:
73 ////////////////////////////////////////////////////////////////////
74 void EggToMaya::
75 run() {
76  if (!_convert_anim && !_convert_model) {
77  _convert_model = true;
78  }
79 
80  // Let's convert the output file to a full path before we initialize
81  // Maya, since Maya now has a nasty habit of changing the current
82  // directory.
83  _output_filename.make_absolute();
84 
85  nout << "Initializing Maya.\n";
86  PT(MayaApi) maya = MayaApi::open_api(_program_name);
87  if (!maya->is_valid()) {
88  nout << "Unable to initialize Maya.\n";
89  exit(1);
90  }
91 
92  MStatus status;
93  status = MFileIO::newFile(true);
94  if (!status) {
95  status.perror("Could not initialize file");
96  exit(1);
97  }
98 
99  // [gjeon] since maya's internal unit is fixed to cm
100  // and when we can't change UI unit without affecting data
101  // all distance data is converted to cm
102  // we need to convert them back to proper output unit user provided here
103  // along with UI unit
104  maya->set_units(_output_units);
105 
106  if (_output_units != DU_centimeters && _output_units != DU_invalid) {
107  nout << "Converting from centimeters"
108  << " to " << format_long_unit(_output_units) << "\n";
109  }
110 
111  // Now convert the data.
112  if (!MayaLoadEggData(_data, true, _convert_model, _convert_anim, _respect_normals)) {
113  nout << "Unable to convert egg file.\n";
114  exit(1);
115  }
116 
117  if (!maya->write(_output_filename)) {
118  status.perror("Could not save file");
119  exit(1);
120  }
121 
122  /*
123  // And write out the resulting Maya file.
124  string os_specific = _output_filename.to_os_generic();
125  const char *file_type = NULL;
126  if (_output_filename.get_extension() == "mb") {
127  file_type = "mayaBinary";
128  }
129  status = MFileIO::saveAs(os_specific.c_str(), file_type);
130  if (!status) {
131  status.perror("Could not save file");
132  exit(1);
133  }
134  */
135 }
136 
137 int main(int argc, char *argv[]) {
138  // We don't want pystub on linux, since it gives problems with Maya's python.
139 #ifdef _WIN32
140  // A call to pystub() to force libpystub.so to be linked in.
141  pystub();
142 #endif
143 
144  EggToMaya prog;
145  prog.parse_command_line(argc, argv);
146  prog.run();
147  return 0;
148 }
149 
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
A program to read an egg file and write a maya file.
Definition: eggToMaya.h:26
This is the general base class for a file-converter program that reads some model file format and gen...
This class presents a wrapper around the global Maya interface.
Definition: mayaApi.h:33