16 #include "config_maya.h" 17 #include "string_utils.h" 20 #include "pre_maya_include.h" 21 #include <maya/MGlobal.h> 22 #include <maya/MDistance.h> 23 #include <maya/MFileIO.h> 24 #include <maya/MLibrary.h> 25 #include <maya/MStatus.h> 26 #include <maya/MFnAnimCurve.h> 27 #include "post_maya_include.h" 38 static MFnAnimCurve force_link_with_OpenMayaAnim;
47 MayaApi(
const string &program_name,
bool view_license,
bool revert_dir) {
48 if (program_name ==
"plug-in") {
68 MStatus stat = MLibrary::initialize(
false, (
char *)program_name.c_str(), view_license);
70 int error_count = init_maya_repeat_count;
71 while (!stat && error_count > 1) {
72 stat.perror(
"MLibrary::initialize");
74 stat = MLibrary::initialize(
false, (
char *)program_name.c_str(), view_license);
82 if (chdir(dirname.c_str()) < 0) {
84 <<
"Unable to restore current directory to " << _cwd
85 <<
" after initializing Maya.\n";
87 if (maya_cat.is_debug()) {
89 <<
"Restored current directory to " << _cwd <<
"\n";
96 stat.perror(
"MLibrary::initialize");
121 operator = (
const MayaApi ©) {
132 nassertv(_global_api ==
this);
133 if (_is_valid && !_plug_in) {
158 open_api(
string program_name,
bool view_license,
bool revertdir) {
159 if (_global_api == (
MayaApi *)NULL) {
161 if (program_name.empty()) {
163 if (program_name.empty()) {
164 program_name =
"Panda";
168 _global_api =
new MayaApi(program_name, view_license, revertdir);
180 string runtime_version = MGlobal::mayaVersion().asChar();
181 string simple_runtime_version = runtime_version;
182 runtime_version = trim(runtime_version);
186 size_t space = runtime_version.find(
' ');
187 if (space != string::npos) {
188 runtime_version = runtime_version.substr(0, space);
191 int rtver_a, rtver_b;
192 size_t dot1 = runtime_version.find(
'.');
193 if (dot1 == string::npos) {
194 string_to_int(runtime_version, rtver_a);
198 string_to_int(runtime_version.substr(0, dot1), rtver_a);
200 size_t dot2 = runtime_version.find(
'.', dot1 + 1);
201 if (dot2 == string::npos) {
202 string_to_int(runtime_version.substr(dot1 + 1), rtver_b);
205 string_to_int(runtime_version.substr(dot1 + 1, dot2 - dot1 - 1), rtver_b);
206 simple_runtime_version = runtime_version.substr(0, dot2);
210 int runtime_version_int = rtver_a * 100 + rtver_b * 10;
212 if (maya_cat.is_debug()) {
214 <<
"Compiled with Maya library version " 215 << (MAYA_API_VERSION / 100) <<
"." << (MAYA_API_VERSION / 10) % 10
216 <<
" (" << MAYA_API_VERSION <<
"); running with library version " 217 << runtime_version <<
".\n";
220 if (MAYA_API_VERSION / 10 != runtime_version_int / 10) {
222 <<
"This program was compiled using Maya version " 223 << (MAYA_API_VERSION / 100) <<
"." << (MAYA_API_VERSION / 10) % 10
224 <<
", but you are now running it with Maya version " 225 << simple_runtime_version
226 <<
". The program may crash or produce incorrect results.\n\n";
246 back_to_front_slash(
const string &str) {
249 for (si = result.begin(); si != result.end(); ++si) {
267 MFileIO::newFile(
true);
269 maya_cat.info() <<
"Reading " << filename <<
"\n";
276 if (maya_cat.is_debug()) {
277 maya_cat.debug() <<
"cwd(read:before): " << dirname.c_str() << endl;
280 MFileIO::newFile(
true);
281 MStatus stat = MFileIO::open(os_filename.c_str());
287 if (chdir(dirname.c_str()) < 0) {
289 <<
"Unable to restore current directory after ::read to " << _cwd
290 <<
" after initializing Maya.\n";
292 if (maya_cat.is_debug()) {
294 <<
"Restored current directory after ::read to " << _cwd <<
"\n";
298 stat.perror(os_filename.c_str());
312 maya_cat.info() <<
"Writing " << filename <<
"\n";
316 if (maya_cat.is_debug()) {
317 maya_cat.debug() <<
"cwd(write:before): " << dirname.c_str() << endl;
320 const char *type =
"mayaBinary";
322 if (extension ==
"ma") {
326 MStatus stat = MFileIO::saveAs(os_filename.c_str(), type,
true);
328 stat.perror(os_filename.c_str());
336 if (chdir(dirname.c_str()) < 0) {
338 <<
"Unable to restore current directory after ::write to " << _cwd
339 <<
" after initializing Maya.\n";
341 if (maya_cat.is_debug()) {
343 <<
"Restored current directory after ::write to " << _cwd <<
"\n";
358 MStatus stat = MFileIO::newFile(
true);
360 stat.perror(
"clear");
373 switch (MDistance::internalUnit()) {
374 case MDistance::kInches:
376 case MDistance::kFeet:
378 case MDistance::kYards:
380 case MDistance::kMiles:
381 return DU_statute_miles;
382 case MDistance::kMillimeters:
383 return DU_millimeters;
384 case MDistance::kCentimeters:
385 return DU_centimeters;
386 case MDistance::kKilometers:
387 return DU_kilometers;
388 case MDistance::kMeters:
405 MDistance::setUIUnit(MDistance::kInches);
408 MDistance::setUIUnit(MDistance::kFeet);
411 MDistance::setUIUnit(MDistance::kYards);
413 case DU_statute_miles:
414 MDistance::setUIUnit(MDistance::kMiles);
417 MDistance::setUIUnit(MDistance::kMillimeters);
420 MDistance::setUIUnit(MDistance::kCentimeters);
423 MDistance::setUIUnit(MDistance::kKilometers);
426 MDistance::setUIUnit(MDistance::kMeters);
441 if (MGlobal::isYAxisUp()) {
void set_units(DistanceUnit unit)
Set Maya's UI units.
bool read(const Filename &filename)
Reads the indicated maya file into the global model space.
static string get_binary_name()
Returns the name of the binary executable that started this program, if it can be determined...
bool write(const Filename &filename)
Writes the global model space to the indicated file.
DistanceUnit get_units()
Returns Maya's internal units in effect.
bool clear()
Resets the global model space to the empty state, for instance in preparation for building a new file...
string get_extension() const
Returns the file extension.
string to_os_generic() const
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood...
The name of a file, such as a texture file or an Egg file.
static void sleep(double seconds)
Suspends the current thread for at least the indicated amount of time.
bool is_valid() const
Returns true if the API has been successfully opened and may be used, or false if there is some probl...
static Filename get_cwd()
Returns the name of the current working directory.
CoordinateSystem get_coordinate_system()
Returns Maya's internal coordinate system in effect.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
This class presents a wrapper around the global Maya interface.