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