From c42a7e05ed3043dcef08d625c56e2c716441baae Mon Sep 17 00:00:00 2001 From: Bei Yang Date: Wed, 20 Jan 2010 19:50:20 +0000 Subject: [PATCH] Changed the way licensing works for loading the Maya API. Also changed the way directories are reverted for maya2egg. Added flag so this can be turned off which seems to be causing problems with maya 2010 --- pandatool/src/maya/mayaApi.cxx | 38 +++++++++++--------- pandatool/src/maya/mayaApi.h | 4 +-- pandatool/src/mayaegg/mayaToEggConverter.cxx | 14 ++++---- pandatool/src/mayaegg/mayaToEggConverter.h | 2 +- pandatool/src/mayaprogs/mayaToEgg.cxx | 4 ++- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/pandatool/src/maya/mayaApi.cxx b/pandatool/src/maya/mayaApi.cxx index 36cee58f9c..1014b64661 100644 --- a/pandatool/src/maya/mayaApi.cxx +++ b/pandatool/src/maya/mayaApi.cxx @@ -44,7 +44,7 @@ static MFnAnimCurve force_link_with_OpenMayaAnim; // instead, use the open_api() method. //////////////////////////////////////////////////////////////////// MayaApi:: -MayaApi(const string &program_name) { +MayaApi(const string &program_name, bool view_license, bool revert_dir) { if (program_name == "plug-in") { // In this special case, we are invoking the code from within a // plug-in, so we need not (and should not) call @@ -65,28 +65,32 @@ MayaApi(const string &program_name) { // Furthermore, the current directory may change during the call to // any Maya function! Egad! _cwd = ExecutionEnvironment::get_cwd(); - MStatus stat = MLibrary::initialize((char *)program_name.c_str()); + MStatus stat = MLibrary::initialize(false, (char *)program_name.c_str(), view_license); int error_count = init_maya_repeat_count; while (!stat && error_count > 1) { stat.perror("MLibrary::initialize"); Thread::sleep(init_maya_timeout); - stat = MLibrary::initialize((char *)program_name.c_str()); + stat = MLibrary::initialize(false, (char *)program_name.c_str(), view_license); --error_count; } - - // Restore the current directory. - string dirname = _cwd.to_os_specific(); - if (chdir(dirname.c_str()) < 0) { - maya_cat.warning() - << "Unable to restore current directory to " << _cwd - << " after initializing Maya.\n"; - } else { - if (maya_cat.is_debug()) { - maya_cat.debug() - << "Restored current directory to " << _cwd << "\n"; - } + + // Restore the current directory. Ever since Maya 2010, there seems to be + // some bad mojo when you do this. + if( revert_dir ){ + string dirname = _cwd.to_os_specific(); + if (chdir(dirname.c_str()) < 0) { + maya_cat.warning() + << "Unable to restore current directory to " << _cwd + << " after initializing Maya.\n"; + } else { + if (maya_cat.is_debug()) { + maya_cat.debug() + << "Restored current directory to " << _cwd << "\n"; + } + } } + if (!stat) { stat.perror("MLibrary::initialize"); @@ -151,7 +155,7 @@ MayaApi:: // case, the maya library is not re-initialized. //////////////////////////////////////////////////////////////////// PT(MayaApi) MayaApi:: -open_api(string program_name) { +open_api(string program_name, bool view_license, bool revertdir) { if (_global_api == (MayaApi *)NULL) { // We need to create a new MayaApi object. if (program_name.empty()) { @@ -161,7 +165,7 @@ open_api(string program_name) { } } - _global_api = new MayaApi(program_name); + _global_api = new MayaApi(program_name, view_license, revertdir); // Try to compare the string-formatted runtime version number with // the numeric compile-time version number, so we can sanity check diff --git a/pandatool/src/maya/mayaApi.h b/pandatool/src/maya/mayaApi.h index 601ca970e7..0c2fe30e1a 100644 --- a/pandatool/src/maya/mayaApi.h +++ b/pandatool/src/maya/mayaApi.h @@ -32,14 +32,14 @@ class Filename; //////////////////////////////////////////////////////////////////// class MayaApi : public ReferenceCount { protected: - MayaApi(const string &program_name); + MayaApi(const string &program_name, bool view_license = false, bool revertdir = true); MayaApi(const MayaApi ©); void operator = (const MayaApi ©); public: ~MayaApi(); - static PT(MayaApi) open_api(string program_name = ""); + static PT(MayaApi) open_api(string program_name = "", bool view_license = false, bool revertdir = true); bool is_valid() const; bool read(const Filename &filename); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 39d42178bf..9ac80f8cbe 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -593,9 +593,11 @@ convert_maya() { // there is an error. //////////////////////////////////////////////////////////////////// bool MayaToEggConverter:: -open_api() { +open_api(bool revert_directory) { if (_maya == (MayaApi *)NULL || !_maya->is_valid()) { - _maya = MayaApi::open_api(_program_name); + //maya to egg converter only needs a read license. + //only egg2maya need write lisences. + _maya = MayaApi::open_api(_program_name, true, revert_directory); } return _maya->is_valid(); } @@ -2612,9 +2614,9 @@ set_shader_legacy(EggPrimitive &primitive, const MayaShader &shader, if (color_def->_has_texture) { // If we have a texture on color, apply it as the filename. - //if (mayaegg_cat.is_debug()) { - //mayaegg_cat.debug() << "ssa:got texture name" << color_def->_texture_filename << endl; - //} + if (mayaegg_cat.is_debug()) { + mayaegg_cat.debug() << "ssa:got texture name" << color_def->_texture_filename << endl; + } Filename filename = Filename::from_os_specific(color_def->_texture_filename); Filename fullpath, outpath; _path_replace->full_convert_path(filename, get_model_path(), fullpath, outpath); @@ -2665,7 +2667,7 @@ set_shader_legacy(EggPrimitive &primitive, const MayaShader &shader, fullpath, outpath); tex.set_alpha_filename(outpath); tex.set_alpha_fullpath(fullpath); - } + } } else { // If there is no transparency texture specified, we don't // have any transparency, so tell the egg format to ignore any diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 987217d0a7..d8048f2955 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -100,7 +100,7 @@ public: void clear(); - bool open_api(); + bool open_api(bool revert_directory=true); void close_api(); private: diff --git a/pandatool/src/mayaprogs/mayaToEgg.cxx b/pandatool/src/mayaprogs/mayaToEgg.cxx index e2444fdf8f..6c01496736 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg.cxx @@ -185,7 +185,9 @@ run() { nout << "Initializing Maya.\n"; MayaToEggConverter converter(_program_name); - if (!converter.open_api()) { + //reverting directories is really not needed for maya2egg. It's + //more needed for mayaeggloader and such + if (!converter.open_api(false)) { nout << "Unable to initialize Maya.\n"; exit(1); }