From 31c734468d5e8c99e582b24bc3409776763b62a4 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 9 Oct 2003 17:46:12 +0000 Subject: [PATCH] refine mayaloader --- .../src/converter/somethingToEggConverter.cxx | 14 +++++ .../src/converter/somethingToEggConverter.h | 2 + pandatool/src/fltegg/fltToEggConverter.cxx | 18 ++++++ pandatool/src/fltegg/fltToEggConverter.h | 3 + pandatool/src/fltprogs/fltToEgg.cxx | 8 +-- pandatool/src/mayaegg/mayaToEggConverter.cxx | 14 +++++ pandatool/src/mayaegg/mayaToEggConverter.h | 1 + pandatool/src/mayaprogs/Sources.pp | 3 +- pandatool/src/mayaprogs/config_mayaloader.cxx | 58 +++++++++++++++++++ pandatool/src/mayaprogs/mayaToEgg.cxx | 16 ++--- pandatool/src/ptloader/config_ptloader.cxx | 25 ++++---- pandatool/src/ptloader/config_ptloader.h | 4 ++ .../src/ptloader/loaderFileTypePandatool.cxx | 14 ++++- 13 files changed, 151 insertions(+), 29 deletions(-) create mode 100644 pandatool/src/mayaprogs/config_mayaloader.cxx diff --git a/pandatool/src/converter/somethingToEggConverter.cxx b/pandatool/src/converter/somethingToEggConverter.cxx index 2200aeecdd..067d4bb8ad 100644 --- a/pandatool/src/converter/somethingToEggConverter.cxx +++ b/pandatool/src/converter/somethingToEggConverter.cxx @@ -102,6 +102,20 @@ get_additional_extensions() const { return string(); } +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::get_input_units +// Access: Public, Virtual +// Description: This may be called after convert_file() has been +// called and returned true, indicating a successful +// conversion. It will return the distance units +// represented by the converted egg file, if known, or +// DU_invalid if not known. +//////////////////////////////////////////////////////////////////// +DistanceUnit SomethingToEggConverter:: +get_input_units() { + return DU_invalid; +} + //////////////////////////////////////////////////////////////////// // Function: SomethingToEggConverter::handle_external_reference // Access: Public diff --git a/pandatool/src/converter/somethingToEggConverter.h b/pandatool/src/converter/somethingToEggConverter.h index 046f155e77..fc48001f7f 100644 --- a/pandatool/src/converter/somethingToEggConverter.h +++ b/pandatool/src/converter/somethingToEggConverter.h @@ -26,6 +26,7 @@ #include "animationConvert.h" #include "pathReplace.h" #include "pointerTo.h" +#include "distanceUnit.h" class EggData; class EggGroupNode; @@ -104,6 +105,7 @@ public: virtual string get_additional_extensions() const; virtual bool convert_file(const Filename &filename)=0; + virtual DistanceUnit get_input_units(); bool handle_external_reference(EggGroupNode *egg_parent, const Filename &ref_filename); diff --git a/pandatool/src/fltegg/fltToEggConverter.cxx b/pandatool/src/fltegg/fltToEggConverter.cxx index b72819e8c4..9aa008cf5f 100644 --- a/pandatool/src/fltegg/fltToEggConverter.cxx +++ b/pandatool/src/fltegg/fltToEggConverter.cxx @@ -49,6 +49,7 @@ FltToEggConverter:: FltToEggConverter() { _compose_transforms = false; + _flt_units = DU_invalid; } //////////////////////////////////////////////////////////////////// @@ -130,9 +131,26 @@ convert_file(const Filename &filename) { } header->check_version(); + + _flt_units = header->get_units(); + return convert_flt(header); } +//////////////////////////////////////////////////////////////////// +// Function: FltToEggConverter::get_input_units +// Access: Public, Virtual +// Description: This may be called after convert_file() has been +// called and returned true, indicating a successful +// conversion. It will return the distance units +// represented by the converted egg file, if known, or +// DU_invalid if not known. +//////////////////////////////////////////////////////////////////// +DistanceUnit FltToEggConverter:: +get_input_units() { + return _flt_units; +} + //////////////////////////////////////////////////////////////////// // Function: FltToEggConverter::convert_flt // Access: Public diff --git a/pandatool/src/fltegg/fltToEggConverter.h b/pandatool/src/fltegg/fltToEggConverter.h index 09c7b55be8..6acefbc150 100644 --- a/pandatool/src/fltegg/fltToEggConverter.h +++ b/pandatool/src/fltegg/fltToEggConverter.h @@ -30,6 +30,7 @@ #include "pt_EggTexture.h" #include "pt_EggVertex.h" #include "pointerTo.h" +#include "distanceUnit.h" class FltRecord; class FltLOD; @@ -64,6 +65,7 @@ public: virtual string get_extension() const; virtual bool convert_file(const Filename &filename); + virtual DistanceUnit get_input_units(); bool convert_flt(const FltHeader *flt_header); // Set this true to store transforms in egg files as the fully @@ -102,6 +104,7 @@ private: PT_EggTexture make_egg_texture(const FltTexture *flt_texture); CPT(FltHeader) _flt_header; + DistanceUnit _flt_units; PT(EggVertexPool) _main_egg_vpool; diff --git a/pandatool/src/fltprogs/fltToEgg.cxx b/pandatool/src/fltprogs/fltToEgg.cxx index 6e69bac04e..c3144339ca 100644 --- a/pandatool/src/fltprogs/fltToEgg.cxx +++ b/pandatool/src/fltprogs/fltToEgg.cxx @@ -81,10 +81,6 @@ run() { _data.set_coordinate_system(_coordinate_system); - if (_input_units == DU_invalid) { - _input_units = header->get_units(); - } - FltToEggConverter converter; converter.set_merge_externals(_merge_externals); converter.set_egg_data(&_data, false); @@ -98,6 +94,10 @@ run() { exit(1); } + if (_input_units == DU_invalid) { + _input_units = converter.get_input_units(); + } + write_egg_file(); nout << "\n"; } diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 756ed8ba88..a03718464a 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -194,6 +194,20 @@ convert_file(const Filename &filename) { return convert_maya(false); } +//////////////////////////////////////////////////////////////////// +// Function: MayaToEggConverter::get_input_units +// Access: Public, Virtual +// Description: This may be called after convert_file() has been +// called and returned true, indicating a successful +// conversion. It will return the distance units +// represented by the converted egg file, if known, or +// DU_invalid if not known. +//////////////////////////////////////////////////////////////////// +DistanceUnit MayaToEggConverter:: +get_input_units() { + _maya->get_units(); +} + //////////////////////////////////////////////////////////////////// // Function: MayaToEggConverter::convert_maya // Access: Public diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index d79fc2e2b4..b2602323a5 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -73,6 +73,7 @@ public: virtual string get_additional_extensions() const; virtual bool convert_file(const Filename &filename); + virtual DistanceUnit get_input_units(); bool convert_maya(bool from_selection); bool open_api(); diff --git a/pandatool/src/mayaprogs/Sources.pp b/pandatool/src/mayaprogs/Sources.pp index 947e1ad939..a671e00b6f 100644 --- a/pandatool/src/mayaprogs/Sources.pp +++ b/pandatool/src/mayaprogs/Sources.pp @@ -105,8 +105,7 @@ egg2pg:c builder:c egg:c pandaegg:m \ mathutil:c linmath:c putil:c panda:m \ express:c pandaexpress:m \ - dtoolconfig dtool \ - $[if $[UNIX_PLATFORM],OpenMayalib] + dtoolconfig dtool #define SOURCES \ config_mayaloader.cxx diff --git a/pandatool/src/mayaprogs/config_mayaloader.cxx b/pandatool/src/mayaprogs/config_mayaloader.cxx new file mode 100644 index 0000000000..196b0acf95 --- /dev/null +++ b/pandatool/src/mayaprogs/config_mayaloader.cxx @@ -0,0 +1,58 @@ +// Filename: config_mayaloader.cxx +// Created by: drose (09Oct03) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "pandatoolbase.h" +#include "loaderFileTypePandatool.h" +#include "config_mayaegg.h" +#include "mayaToEggConverter.h" + +#include "dconfig.h" +#include "loaderFileTypeRegistry.h" + +Configure(config_mayaloader); + +void EXPCL_MISC init_libmayaloader(); + +ConfigureFn(config_mayaloader) { + init_libmayaloader(); +} + +//////////////////////////////////////////////////////////////////// +// Function: init_libmayaloader +// Description: Initializes the library. This must be called at +// least once before any of the functions or classes in +// this library can be used. Normally it will be +// called by the static initializers and need not be +// called explicitly, but special cases exist. +//////////////////////////////////////////////////////////////////// +void +init_libmayaloader() { + static bool initialized = false; + if (initialized) { + return; + } + initialized = true; + + LoaderFileTypePandatool::init_type(); + + LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr(); + + init_libmayaegg(); + MayaToEggConverter *maya = new MayaToEggConverter; + reg->register_type(new LoaderFileTypePandatool(maya)); +} diff --git a/pandatool/src/mayaprogs/mayaToEgg.cxx b/pandatool/src/mayaprogs/mayaToEgg.cxx index 8789243234..0a6c88dcdd 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg.cxx @@ -131,14 +131,6 @@ run() { } _data.set_coordinate_system(_coordinate_system); - // Use the standard Maya units, if the user didn't specify - // otherwise. This always returns centimeters, which is the way all - // Maya files are stored internally (and is the units returned by - // all of the API functions called here). - if (_input_units == DU_invalid) { - _input_units = converter._maya->get_units(); - } - converter.set_egg_data(&_data, false); apply_parameters(converter); @@ -147,6 +139,14 @@ run() { exit(1); } + // Use the standard Maya units, if the user didn't specify + // otherwise. This always returns centimeters, which is the way all + // Maya files are stored internally (and is the units returned by + // all of the API functions called here). + if (_input_units == DU_invalid) { + _input_units = converter.get_input_units(); + } + write_egg_file(); nout << "\n"; } diff --git a/pandatool/src/ptloader/config_ptloader.cxx b/pandatool/src/ptloader/config_ptloader.cxx index a4bee9aee0..d267fd0cab 100644 --- a/pandatool/src/ptloader/config_ptloader.cxx +++ b/pandatool/src/ptloader/config_ptloader.cxx @@ -31,23 +31,19 @@ #endif */ -/* -#ifdef HAVE_MAYA -#include "config_mayaegg.h" -#include "mayaToEggConverter.h" -#endif -*/ - #include "dconfig.h" #include "loaderFileTypeRegistry.h" #include "eggData.h" ConfigureDef(config_ptloader); +NotifyCategoryDef(ptloader, ""); ConfigureFn(config_ptloader) { init_libptloader(); } +DistanceUnit ptloader_units = DU_invalid; + //////////////////////////////////////////////////////////////////// // Function: init_libptloader // Description: Initializes the library. This must be called at @@ -84,11 +80,12 @@ init_libptloader() { #endif */ - /* -#ifdef HAVE_MAYA - init_libmayaegg(); - MayaToEggConverter *maya = new MayaToEggConverter; - reg->register_type(new LoaderFileTypePandatool(maya)); -#endif - */ + string units = config_ptloader.GetString("ptloader-units", "feet"); + if (!units.empty()) { + ptloader_units = string_distance_unit(units); + if (ptloader_units == DU_invalid) { + ptloader_cat->warning() + << "Invalid ptloader-units: " << units << "\n"; + } + } } diff --git a/pandatool/src/ptloader/config_ptloader.h b/pandatool/src/ptloader/config_ptloader.h index 7bc4a2990c..a99dbf5263 100644 --- a/pandatool/src/ptloader/config_ptloader.h +++ b/pandatool/src/ptloader/config_ptloader.h @@ -22,8 +22,12 @@ #include "pandatoolbase.h" #include "dconfig.h" +#include "distanceUnit.h" ConfigureDecl(config_ptloader, EXPCL_PTLOADER, EXPTP_PTLOADER); +NotifyCategoryDecl(ptloader, EXPCL_PTLOADER, EXPTP_PTLOADER); + +extern DistanceUnit ptloader_units; extern EXPCL_PTLOADER void init_libptloader(); diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.cxx b/pandatool/src/ptloader/loaderFileTypePandatool.cxx index 936db924b7..2debe3febc 100644 --- a/pandatool/src/ptloader/loaderFileTypePandatool.cxx +++ b/pandatool/src/ptloader/loaderFileTypePandatool.cxx @@ -17,7 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "loaderFileTypePandatool.h" - +#include "config_ptloader.h" #include "somethingToEggConverter.h" #include "config_util.h" #include "load_egg_file.h" @@ -107,6 +107,18 @@ load_file(const Filename &path, bool) const { _converter->get_path_replace()->_path = file_path; if (_converter->convert_file(path)) { + DistanceUnit input_units = _converter->get_input_units(); + if (input_units != DU_invalid && ptloader_units != DU_invalid && + input_units != ptloader_units) { + // Convert the file to the units specified by the ptloader-units + // Configrc variable. + ptloader_cat.info() + << "Converting from " << format_long_unit(input_units) + << " to " << format_long_unit(ptloader_units) << "\n"; + double scale = convert_units(input_units, ptloader_units); + egg_data.transform(LMatrix4d::scale_mat(scale)); + } + result = load_egg_data(egg_data); } _converter->clear_egg_data();