mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
allow multiple loads of the same file; don't open the Maya API until needed
This commit is contained in:
parent
73974017fa
commit
a74936709a
@ -77,6 +77,8 @@ MayaApi::
|
|||||||
~MayaApi() {
|
~MayaApi() {
|
||||||
nassertv(_global_api == this);
|
nassertv(_global_api == this);
|
||||||
if (_is_valid) {
|
if (_is_valid) {
|
||||||
|
// Caution! Calling this function seems to call exit() somewhere
|
||||||
|
// within Maya code.
|
||||||
MLibrary::cleanup();
|
MLibrary::cleanup();
|
||||||
}
|
}
|
||||||
_global_api = (MayaApi *)NULL;
|
_global_api = (MayaApi *)NULL;
|
||||||
@ -123,6 +125,21 @@ is_valid() const {
|
|||||||
return _is_valid;
|
return _is_valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
static string
|
||||||
|
back_to_front_slash(const string &str) {
|
||||||
|
string result = str;
|
||||||
|
string::iterator si;
|
||||||
|
for (si = result.begin(); si != result.end(); ++si) {
|
||||||
|
if ((*si) == '\\') {
|
||||||
|
(*si) = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif // WIN32
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: MayaApi::read
|
// Function: MayaApi::read
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -136,6 +153,12 @@ read(const Filename &filename) {
|
|||||||
mayaegg_cat.info() << "Reading " << filename << "\n";
|
mayaegg_cat.info() << "Reading " << filename << "\n";
|
||||||
// Load the file into Maya
|
// Load the file into Maya
|
||||||
string os_filename = filename.to_os_specific();
|
string os_filename = filename.to_os_specific();
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
// Actually, Maya seems to want forward slashes, even on Windows.
|
||||||
|
os_filename = back_to_front_slash(os_filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
MStatus stat = MFileIO::open(os_filename.c_str());
|
MStatus stat = MFileIO::open(os_filename.c_str());
|
||||||
if (!stat) {
|
if (!stat) {
|
||||||
stat.perror(filename.c_str());
|
stat.perror(filename.c_str());
|
||||||
|
@ -66,9 +66,9 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
MayaToEggConverter::
|
MayaToEggConverter::
|
||||||
MayaToEggConverter(const string &program_name) :
|
MayaToEggConverter(const string &program_name) :
|
||||||
_shaders(this)
|
_shaders(this),
|
||||||
|
_program_name(program_name)
|
||||||
{
|
{
|
||||||
_maya = MayaApi::open_api(program_name);
|
|
||||||
_polygon_output = false;
|
_polygon_output = false;
|
||||||
_polygon_tolerance = 0.01;
|
_polygon_tolerance = 0.01;
|
||||||
_ignore_transforms = false;
|
_ignore_transforms = false;
|
||||||
@ -93,9 +93,7 @@ MayaToEggConverter(const MayaToEggConverter ©) :
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
MayaToEggConverter::
|
MayaToEggConverter::
|
||||||
~MayaToEggConverter() {
|
~MayaToEggConverter() {
|
||||||
// We have to clear the shaders before we release the Maya API.
|
close_api();
|
||||||
_shaders.clear();
|
|
||||||
_maya.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -144,7 +142,7 @@ get_extension() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool MayaToEggConverter::
|
bool MayaToEggConverter::
|
||||||
convert_file(const Filename &filename) {
|
convert_file(const Filename &filename) {
|
||||||
if (!_maya->is_valid()) {
|
if (!open_api()) {
|
||||||
mayaegg_cat.error()
|
mayaegg_cat.error()
|
||||||
<< "Maya is not available.\n";
|
<< "Maya is not available.\n";
|
||||||
return false;
|
return false;
|
||||||
@ -166,6 +164,16 @@ convert_file(const Filename &filename) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool MayaToEggConverter::
|
bool MayaToEggConverter::
|
||||||
convert_maya() {
|
convert_maya() {
|
||||||
|
_textures.clear();
|
||||||
|
_shaders.clear();
|
||||||
|
_groups.clear();
|
||||||
|
|
||||||
|
if (!open_api()) {
|
||||||
|
mayaegg_cat.error()
|
||||||
|
<< "Maya is not available.\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (_egg_data->get_coordinate_system() == CS_default) {
|
if (_egg_data->get_coordinate_system() == CS_default) {
|
||||||
_egg_data->set_coordinate_system(_maya->get_coordinate_system());
|
_egg_data->set_coordinate_system(_maya->get_coordinate_system());
|
||||||
}
|
}
|
||||||
@ -210,6 +218,35 @@ convert_maya() {
|
|||||||
return all_ok;
|
return all_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: MayaToEggConverter::open_api
|
||||||
|
// Access: Public
|
||||||
|
// Description: Attempts to open the Maya API if it was not already
|
||||||
|
// open, and returns true if successful, or false if
|
||||||
|
// there is an error.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool MayaToEggConverter::
|
||||||
|
open_api() {
|
||||||
|
if (_maya == (MayaApi *)NULL || !_maya->is_valid()) {
|
||||||
|
_maya = MayaApi::open_api(_program_name);
|
||||||
|
}
|
||||||
|
return _maya->is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: MayaToEggConverter::close_api
|
||||||
|
// Access: Public
|
||||||
|
// Description: Closes the Maya API, if it was previously opened.
|
||||||
|
// Caution! Maya appears to call exit() when its API is
|
||||||
|
// closed.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void MayaToEggConverter::
|
||||||
|
close_api() {
|
||||||
|
// We have to clear the shaders before we release the Maya API.
|
||||||
|
_shaders.clear();
|
||||||
|
_maya.clear();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: MayaToEggConverter::process_node
|
// Function: MayaToEggConverter::process_node
|
||||||
// Access: Private
|
// Access: Private
|
||||||
|
@ -63,6 +63,9 @@ public:
|
|||||||
virtual bool convert_file(const Filename &filename);
|
virtual bool convert_file(const Filename &filename);
|
||||||
bool convert_maya();
|
bool convert_maya();
|
||||||
|
|
||||||
|
bool open_api();
|
||||||
|
void close_api();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool process_node(const MDagPath &dag_path, EggData &data);
|
bool process_node(const MDagPath &dag_path, EggData &data);
|
||||||
void get_transform(const MDagPath &dag_path, EggGroup *egg_group);
|
void get_transform(const MDagPath &dag_path, EggGroup *egg_group);
|
||||||
@ -90,6 +93,8 @@ private:
|
|||||||
typedef pmap<string, EggGroup *> Groups;
|
typedef pmap<string, EggGroup *> Groups;
|
||||||
Groups _groups;
|
Groups _groups;
|
||||||
|
|
||||||
|
string _program_name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MayaShaders _shaders;
|
MayaShaders _shaders;
|
||||||
EggTextureCollection _textures;
|
EggTextureCollection _textures;
|
||||||
|
@ -87,7 +87,7 @@ run() {
|
|||||||
|
|
||||||
nout << "Initializing Maya.\n";
|
nout << "Initializing Maya.\n";
|
||||||
MayaToEggConverter converter(_program_name);
|
MayaToEggConverter converter(_program_name);
|
||||||
if (!converter._maya->is_valid()) {
|
if (!converter.open_api()) {
|
||||||
nout << "Unable to initialize Maya.\n";
|
nout << "Unable to initialize Maya.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user