diff --git a/pandatool/src/converter/Sources.pp b/pandatool/src/converter/Sources.pp new file mode 100644 index 0000000000..464a0d201e --- /dev/null +++ b/pandatool/src/converter/Sources.pp @@ -0,0 +1,19 @@ +#begin ss_lib_target + #define TARGET converter + #define LOCAL_LIBS pandatoolbase + #define OTHER_LIBS \ + egg:c pandaegg:m \ + mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool + #define UNIX_SYS_LIBS \ + m + + #define SOURCES \ + distanceUnit.cxx distanceUnit.h \ + somethingToEggConverter.I somethingToEggConverter.cxx \ + somethingToEggConverter.h + + #define INSTALL_HEADERS \ + distanceUnit.h \ + somethingToEggConverter.I somethingToEggConverter.h + +#end ss_lib_target diff --git a/pandatool/src/progbase/distanceUnit.cxx b/pandatool/src/converter/distanceUnit.cxx similarity index 100% rename from pandatool/src/progbase/distanceUnit.cxx rename to pandatool/src/converter/distanceUnit.cxx diff --git a/pandatool/src/progbase/distanceUnit.h b/pandatool/src/converter/distanceUnit.h similarity index 100% rename from pandatool/src/progbase/distanceUnit.h rename to pandatool/src/converter/distanceUnit.h diff --git a/pandatool/src/converter/somethingToEggConverter.I b/pandatool/src/converter/somethingToEggConverter.I new file mode 100644 index 0000000000..6f962a27d2 --- /dev/null +++ b/pandatool/src/converter/somethingToEggConverter.I @@ -0,0 +1,74 @@ +// Filename: somethingToEggConverter.I +// Created by: drose (26Apr01) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::set_texture_path_convert +// Access: Public +// Description: Sets the mode for converting texture paths extracted +// from the source file. The following options are +// defined: +// +// PC_relative - texture pathnames are made relative +// to the indicated tpc_directory. +// +// PC_absolute - textures are looked up along the +// search path and then converted to absolute +// filenames. tpc_directory is ignored. +// +// PC_rel_abs - as above, but the resulting filename +// is guaranteed to be relative to tpc_directory, and +// may include a number of ../ paths to guarantee +// this, if necessary. +// +// PC_strip - pathname components are stripped from +// the texture names, and only the base filename is +// retained. +// +// PC_unchanged - texture pathnames are left exactly +// as they appear in the source file. +//////////////////////////////////////////////////////////////////// +INLINE void SomethingToEggConverter:: +set_texture_path_convert(PathConvert tpc, + const Filename &tpc_directory) { + _tpc = tpc; + _tpc_directory = tpc_directory; +} + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::set_model_path_convert +// Access: Public +// Description: Sets the mode for converting model paths extracted +// from the source file. These are typically for +// external references. See set_texture_path_convert +// for a complete list of PathConvert values and their +// interpretations. +//////////////////////////////////////////////////////////////////// +INLINE void SomethingToEggConverter:: +set_model_path_convert(PathConvert mpc, + const Filename &mpc_directory) { + _mpc = mpc; + _mpc_directory = mpc_directory; +} + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::clear_egg_data +// Access: Public +// Description: Sets the EggData to NULL and makes the converter +// invalid. +//////////////////////////////////////////////////////////////////// +INLINE void SomethingToEggConverter:: +clear_egg_data() { + set_egg_data((EggData *)NULL, false); +} + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::get_egg_data +// Access: Public +// Description: Returns the EggData structure. +//////////////////////////////////////////////////////////////////// +INLINE EggData &SomethingToEggConverter:: +get_egg_data() { + return *_egg_data; +} diff --git a/pandatool/src/converter/somethingToEggConverter.cxx b/pandatool/src/converter/somethingToEggConverter.cxx new file mode 100644 index 0000000000..bc0eba5394 --- /dev/null +++ b/pandatool/src/converter/somethingToEggConverter.cxx @@ -0,0 +1,51 @@ +// Filename: somethingToEggConverter.cxx +// Created by: drose (26Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "somethingToEggConverter.h" + +#include + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +SomethingToEggConverter:: +SomethingToEggConverter() { + _egg_data = (EggData *)NULL; + _owns_egg_data = false; + _tpc = PC_unchanged; + _mpc = PC_unchanged; + _error = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +SomethingToEggConverter:: +~SomethingToEggConverter() { + clear_egg_data(); +} + +//////////////////////////////////////////////////////////////////// +// Function: SomethingToEggConverter::set_egg_data +// Access: Public +// Description: Sets the egg data that will be filled in when +// convert_file() is called. This must be called before +// convert_file(). If owns_egg_data is true, the +// egg_data will be deleted when the converter +// destructs. (We don't use the reference counting on +// EggData, to allow static EggDatas to be passed in.) +//////////////////////////////////////////////////////////////////// +void SomethingToEggConverter:: +set_egg_data(EggData *egg_data, bool owns_egg_data) { + if (_owns_egg_data) { + delete _egg_data; + } + _egg_data = egg_data; + _owns_egg_data = owns_egg_data; +} diff --git a/pandatool/src/converter/somethingToEggConverter.h b/pandatool/src/converter/somethingToEggConverter.h new file mode 100644 index 0000000000..2dd3ebb79e --- /dev/null +++ b/pandatool/src/converter/somethingToEggConverter.h @@ -0,0 +1,67 @@ +// Filename: somethingToEggConverter.h +// Created by: drose (17Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef SOMETHINGTOEGGCONVERTER_H +#define SOMETHINGTOEGGCONVERTER_H + +#include + +#include + +class EggData; + +//////////////////////////////////////////////////////////////////// +// Class : SomethingToEggConverter +// Description : This is a base class for a family of converter +// classes that manage a conversion from some file type +// to egg format. +// +// Classes of this type can be used to implement xxx2egg +// converter programs, as well as LoaderFileTypeXXX +// run-time loaders. +//////////////////////////////////////////////////////////////////// +class SomethingToEggConverter { +public: + SomethingToEggConverter(); + virtual ~SomethingToEggConverter(); + + enum PathConvert { + PC_relative, + PC_absolute, + PC_rel_abs, + PC_strip, + PC_unchanged + }; + INLINE void set_texture_path_convert(PathConvert tpc, + const Filename &tpc_directory = Filename()); + INLINE void set_model_path_convert(PathConvert mpc, + const Filename &mpc_directory = Filename()); + + void set_egg_data(EggData *egg_data, bool owns_egg_data); + INLINE void clear_egg_data(); + INLINE EggData &get_egg_data(); + + virtual string get_name() const=0; + virtual string get_extension() const=0; + + virtual bool convert_file(const Filename &filename)=0; + +protected: + PathConvert _tpc; + Filename _tpc_directory; + PathConvert _mpc; + Filename _mpc_directory; + + EggData *_egg_data; + bool _owns_egg_data; + + bool _error; +}; + +#include "somethingToEggConverter.I" + +#endif + + diff --git a/pandatool/src/eggprogs/Sources.pp b/pandatool/src/eggprogs/Sources.pp index 236f38eeed..bceb27d27f 100644 --- a/pandatool/src/eggprogs/Sources.pp +++ b/pandatool/src/eggprogs/Sources.pp @@ -1,5 +1,5 @@ #define LOCAL_LIBS \ - eggbase progbase + converter eggbase progbase #define OTHER_LIBS \ egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \ dtoolutil:c dconfig:c dtoolconfig:m dtool:m pystub diff --git a/pandatool/src/eggprogs/lwoToEgg.cxx b/pandatool/src/eggprogs/lwoToEgg.cxx index 090a124c84..2618ebb792 100644 --- a/pandatool/src/eggprogs/lwoToEgg.cxx +++ b/pandatool/src/eggprogs/lwoToEgg.cxx @@ -50,42 +50,16 @@ LwoToEgg() : //////////////////////////////////////////////////////////////////// void LwoToEgg:: run() { - LwoInputFile in; - - nout << "Reading " << _input_filename << "\n"; - if (!in.open_read(_input_filename)) { - nout << "Unable to open " << _input_filename << "\n"; - exit(1); - } - - PT(IffChunk) chunk = in.get_chunk(); - if (chunk == (IffChunk *)NULL) { - nout << "Unable to read " << _input_filename << "\n"; - exit(1); - } - - if (!chunk->is_of_type(LwoHeader::get_class_type())) { - nout << "File " << _input_filename << " is not a Lightwave Object file.\n"; - exit(1); - } - - LwoHeader *header = DCAST(LwoHeader, chunk); - if (!header->is_valid()) { - nout << "File " << _input_filename - << " is not recognized as a Lightwave Object file. " - << "Perhaps the version is too recent.\n"; - exit(1); - } - _data.set_coordinate_system(_coordinate_system); if (_input_units == DU_invalid) { _input_units = DU_meters; } - LwoToEggConverter converter(_data); + LwoToEggConverter converter; + converter.set_egg_data(&_data, false); - if (!converter.convert_lwo(header)) { + if (!converter.convert_file(_input_filename)) { nout << "Errors in conversion.\n"; exit(1); } diff --git a/pandatool/src/flt/Sources.pp b/pandatool/src/flt/Sources.pp index 7b9bb7903f..456af3e518 100644 --- a/pandatool/src/flt/Sources.pp +++ b/pandatool/src/flt/Sources.pp @@ -1,6 +1,6 @@ #begin ss_lib_target #define TARGET flt - #define LOCAL_LIBS progbase pandatoolbase + #define LOCAL_LIBS converter pandatoolbase #define OTHER_LIBS \ mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool #define UNIX_SYS_LIBS \ diff --git a/pandatool/src/fltegg/Sources.pp b/pandatool/src/fltegg/Sources.pp index 7625a4cd88..e9a82576f2 100644 --- a/pandatool/src/fltegg/Sources.pp +++ b/pandatool/src/fltegg/Sources.pp @@ -1,6 +1,6 @@ #begin ss_lib_target #define TARGET fltegg - #define LOCAL_LIBS pandatoolbase progbase flt + #define LOCAL_LIBS converter flt pandatoolbase #define OTHER_LIBS \ egg:c pandaegg:m \ mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool diff --git a/pandatool/src/fltegg/fltToEggConverter.I b/pandatool/src/fltegg/fltToEggConverter.I index 0612945144..6be2d5e33c 100644 --- a/pandatool/src/fltegg/fltToEggConverter.I +++ b/pandatool/src/fltegg/fltToEggConverter.I @@ -3,48 +3,3 @@ // //////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: FltToEggConverter::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE FltToEggConverter:: -~FltToEggConverter() { -} - -//////////////////////////////////////////////////////////////////// -// Function: FltToEggConverter::set_texture_path_convert -// Access: Public -// Description: Sets the mode for converting texture paths extracted -// from the flt file. If this is PC_relative, the -// texture paths are made relative to the indicated -// directory; if it is PC_absolute, they are made -// absolute to the indicated directory. PC_unchanged -// leaves them alone (and the directory, if specified, -// is ignored). -//////////////////////////////////////////////////////////////////// -INLINE void FltToEggConverter:: -set_texture_path_convert(PathConvert tpc, - const Filename &tpc_directory) { - _tpc = tpc; - _tpc_directory = tpc_directory; -} - -//////////////////////////////////////////////////////////////////// -// Function: FltToEggConverter::set_model_path_convert -// Access: Public -// Description: Sets the mode for converting model paths extracted -// from the flt file. If this is PC_relative, the -// model paths are made relative to the indicated -// directory; if it is PC_absolute, they are made -// absolute to the indicated directory. PC_unchanged -// leaves them alone (and the directory, if specified, -// is ignored). -//////////////////////////////////////////////////////////////////// -INLINE void FltToEggConverter:: -set_model_path_convert(PathConvert mpc, - const Filename &mpc_directory) { - _mpc = mpc; - _mpc_directory = mpc_directory; -} diff --git a/pandatool/src/fltegg/fltToEggConverter.cxx b/pandatool/src/fltegg/fltToEggConverter.cxx index 4cb2c54df6..b0df3200be 100644 --- a/pandatool/src/fltegg/fltToEggConverter.cxx +++ b/pandatool/src/fltegg/fltToEggConverter.cxx @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -32,10 +33,57 @@ // Description: //////////////////////////////////////////////////////////////////// FltToEggConverter:: -FltToEggConverter(EggData &egg_data) : _egg_data(egg_data) { - _tpc = PC_unchanged; - _mpc = PC_unchanged; - _error = false; +FltToEggConverter() { +} + + +//////////////////////////////////////////////////////////////////// +// Function: FltToEggConverter::get_name +// Access: Public, Virtual +// Description: Returns the English name of the file type this +// converter supports. +//////////////////////////////////////////////////////////////////// +string FltToEggConverter:: +get_name() const { + return "MultiGen"; +} + +//////////////////////////////////////////////////////////////////// +// Function: FltToEggConverter::get_extension +// Access: Public, Virtual +// Description: Returns the common extension of the file type this +// converter supports. +//////////////////////////////////////////////////////////////////// +string FltToEggConverter:: +get_extension() const { + return "flt"; +} + +//////////////////////////////////////////////////////////////////// +// Function: FltToEggConverter::convert_file +// Access: Public, Virtual +// Description: Handles the reading of the input file and converting +// it to egg. Returns true if successful, false +// otherwise. +// +// This is designed to be as generic as possible, +// generally in support of run-time loading. +// Command-line converters may choose to use +// convert_flt() instead, as it provides more control. +//////////////////////////////////////////////////////////////////// +bool FltToEggConverter:: +convert_file(const Filename &filename) { + PT(FltHeader) header = new FltHeader; + + nout << "Reading " << filename << "\n"; + FltError result = header->read_flt(filename); + if (result != FE_ok) { + nout << "Unable to read: " << result << "\n"; + return false; + } + + header->check_version(); + return convert_flt(header); } //////////////////////////////////////////////////////////////////// @@ -46,12 +94,16 @@ FltToEggConverter(EggData &egg_data) : _egg_data(egg_data) { //////////////////////////////////////////////////////////////////// bool FltToEggConverter:: convert_flt(const FltHeader *flt_header) { + if (_egg_data->get_coordinate_system() == CS_default) { + _egg_data->set_coordinate_system(CS_zup_right); + } + _error = false; _flt_header = flt_header; // Generate a default vertex pool. _main_egg_vpool = new EggVertexPool("vpool"); - _egg_data.add_child(_main_egg_vpool); + _egg_data->add_child(_main_egg_vpool); // We could populate the vertex pool right away, but it's better to // defer each vertex until we encounter it, since some of the @@ -60,13 +112,13 @@ convert_flt(const FltHeader *flt_header) { // something). FltToEggLevelState state; - state._egg_parent = &_egg_data; + state._egg_parent = _egg_data; convert_record(_flt_header, state); if (_main_egg_vpool->empty()) { // If we didn't get any global vertices, remove the vertex pool // just for cleanliness. - _egg_data.remove_child(_main_egg_vpool); + _egg_data->remove_child(_main_egg_vpool); } return !_error; @@ -641,6 +693,9 @@ convert_path(const Filename &orig_filename, const Filename &as_found, result = Filename(rel_dir, result); return result; + case PC_strip: + return orig_filename.get_basename(); + case PC_unchanged: return orig_filename; } diff --git a/pandatool/src/fltegg/fltToEggConverter.h b/pandatool/src/fltegg/fltToEggConverter.h index 05611bfefe..566c21feb7 100644 --- a/pandatool/src/fltegg/fltToEggConverter.h +++ b/pandatool/src/fltegg/fltToEggConverter.h @@ -10,10 +10,8 @@ #include "fltToEggLevelState.h" -#include - +#include #include -#include #include #include #include @@ -40,22 +38,14 @@ class EggVertexPool; // Reading and writing the egg and flt structures is // left to the user. //////////////////////////////////////////////////////////////////// -class FltToEggConverter { +class FltToEggConverter : public SomethingToEggConverter { public: - FltToEggConverter(EggData &egg_data); - INLINE ~FltToEggConverter(); + FltToEggConverter(); - enum PathConvert { - PC_relative, - PC_absolute, - PC_rel_abs, - PC_unchanged - }; - INLINE void set_texture_path_convert(PathConvert tpc, - const Filename &tpc_directory = Filename()); - INLINE void set_model_path_convert(PathConvert mpc, - const Filename &mpc_directory = Filename()); + virtual string get_name() const; + virtual string get_extension() const; + virtual bool convert_file(const Filename &filename); bool convert_flt(const FltHeader *flt_header); private: @@ -92,20 +82,12 @@ private: PT(EggVertex) make_egg_vertex(const FltVertex *flt_vertex); PT(EggTexture) make_egg_texture(const FltTexture *flt_texture); - PathConvert _tpc; - Filename _tpc_directory; - PathConvert _mpc; - Filename _mpc_directory; - - EggData &_egg_data; CPT(FltHeader) _flt_header; EggVertexPool *_main_egg_vpool; typedef map Textures; Textures _textures; - - bool _error; }; #include "fltToEggConverter.I" diff --git a/pandatool/src/fltprogs/fltToEgg.cxx b/pandatool/src/fltprogs/fltToEgg.cxx index 0cb5a72057..6a05d1baec 100644 --- a/pandatool/src/fltprogs/fltToEgg.cxx +++ b/pandatool/src/fltprogs/fltToEgg.cxx @@ -131,7 +131,8 @@ run() { _input_units = header->get_units(); } - FltToEggConverter converter(_data); + FltToEggConverter converter; + converter.set_egg_data(&_data, false); converter.set_texture_path_convert(_texture_path_convert, _make_rel_dir); converter.set_model_path_convert(_model_path_convert, _make_rel_dir); diff --git a/pandatool/src/lwoegg/Sources.pp b/pandatool/src/lwoegg/Sources.pp index b1049b85f3..c629a984cb 100644 --- a/pandatool/src/lwoegg/Sources.pp +++ b/pandatool/src/lwoegg/Sources.pp @@ -1,6 +1,6 @@ #begin ss_lib_target #define TARGET lwoegg - #define LOCAL_LIBS pandatoolbase lwo + #define LOCAL_LIBS converter lwo pandatoolbase #define OTHER_LIBS \ egg:c pandaegg:m \ mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool diff --git a/pandatool/src/lwoegg/cLwoLayer.cxx b/pandatool/src/lwoegg/cLwoLayer.cxx index 4987c56e3a..6d53f1284f 100644 --- a/pandatool/src/lwoegg/cLwoLayer.cxx +++ b/pandatool/src/lwoegg/cLwoLayer.cxx @@ -6,6 +6,8 @@ #include "cLwoLayer.h" #include "lwoToEggConverter.h" +#include + //////////////////////////////////////////////////////////////////// // Function: CLwoLayer::make_egg @@ -44,6 +46,6 @@ connect_egg() { << "; cannot parent layer " << _layer->_number << " properly.\n"; } - _converter->get_egg_root()->add_child(_egg_group.p()); + _converter->get_egg_data().add_child(_egg_group.p()); } diff --git a/pandatool/src/lwoegg/cLwoPolygons.cxx b/pandatool/src/lwoegg/cLwoPolygons.cxx index 290c96f066..265e70b67b 100644 --- a/pandatool/src/lwoegg/cLwoPolygons.cxx +++ b/pandatool/src/lwoegg/cLwoPolygons.cxx @@ -11,6 +11,7 @@ #include #include +#include #include #include #include diff --git a/pandatool/src/lwoegg/lwoToEggConverter.I b/pandatool/src/lwoegg/lwoToEggConverter.I index a7f25d393c..9811c2e985 100644 --- a/pandatool/src/lwoegg/lwoToEggConverter.I +++ b/pandatool/src/lwoegg/lwoToEggConverter.I @@ -2,25 +2,3 @@ // Created by: drose (25Apr01) // //////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: LwoToEggConverter::get_egg_root -// Access: Public -// Description: Returns a root node suitable for parenting egg -// structures to. -//////////////////////////////////////////////////////////////////// -INLINE EggGroupNode *LwoToEggConverter:: -get_egg_root() const { - return &_egg_data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LwoToEggConverter::get_egg_data -// Access: Public -// Description: Returns the EggData structure. -//////////////////////////////////////////////////////////////////// -INLINE EggData &LwoToEggConverter:: -get_egg_data() { - return _egg_data; -} diff --git a/pandatool/src/lwoegg/lwoToEggConverter.cxx b/pandatool/src/lwoegg/lwoToEggConverter.cxx index f88afa4434..37e64ce3fe 100644 --- a/pandatool/src/lwoegg/lwoToEggConverter.cxx +++ b/pandatool/src/lwoegg/lwoToEggConverter.cxx @@ -9,6 +9,7 @@ #include "cLwoPolygons.h" #include "cLwoSurface.h" +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////////////// @@ -24,14 +26,13 @@ // Description: //////////////////////////////////////////////////////////////////// LwoToEggConverter:: -LwoToEggConverter(EggData &egg_data) : _egg_data(egg_data) { +LwoToEggConverter() { _generic_layer = (CLwoLayer *)NULL; - _error = false; } //////////////////////////////////////////////////////////////////// // Function: LwoToEggConverter::Destructor -// Access: Public +// Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// LwoToEggConverter:: @@ -67,6 +68,72 @@ LwoToEggConverter:: } } +//////////////////////////////////////////////////////////////////// +// Function: LwoToEggConverter::get_name +// Access: Public, Virtual +// Description: Returns the English name of the file type this +// converter supports. +//////////////////////////////////////////////////////////////////// +string LwoToEggConverter:: +get_name() const { + return "Lightwave"; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoToEggConverter::get_extension +// Access: Public, Virtual +// Description: Returns the common extension of the file type this +// converter supports. +//////////////////////////////////////////////////////////////////// +string LwoToEggConverter:: +get_extension() const { + return "lwo"; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoToEggConverter::convert_file +// Access: Public, Virtual +// Description: Handles the reading of the input file and converting +// it to egg. Returns true if successful, false +// otherwise. +// +// This is designed to be as generic as possible, +// generally in support of run-time loading. +// Command-line converters may choose to use +// convert_lwo() instead, as it provides more control. +//////////////////////////////////////////////////////////////////// +bool LwoToEggConverter:: +convert_file(const Filename &filename) { + LwoInputFile in; + + nout << "Reading " << filename << "\n"; + if (!in.open_read(filename)) { + nout << "Unable to open " << filename << "\n"; + return false; + } + + PT(IffChunk) chunk = in.get_chunk(); + if (chunk == (IffChunk *)NULL) { + nout << "Unable to read " << filename << "\n"; + return false; + } + + if (!chunk->is_of_type(LwoHeader::get_class_type())) { + nout << "File " << filename << " is not a Lightwave Object file.\n"; + return false; + } + + LwoHeader *header = DCAST(LwoHeader, chunk); + if (!header->is_valid()) { + nout << "File " << filename + << " is not recognized as a Lightwave Object file. " + << "Perhaps the version is too recent.\n"; + return false; + } + + return convert_lwo(header); +} + //////////////////////////////////////////////////////////////////// // Function: LwoToEggConverter::convert_lwo // Access: Public @@ -75,13 +142,18 @@ LwoToEggConverter:: //////////////////////////////////////////////////////////////////// bool LwoToEggConverter:: convert_lwo(const LwoHeader *lwo_header) { + if (_egg_data->get_coordinate_system() == CS_default) { + _egg_data->set_coordinate_system(CS_yup_left); + } + + _error = false; _lwo_header = lwo_header; collect_lwo(); make_egg(); connect_egg(); - _egg_data.remove_unused_vertices(); + _egg_data->remove_unused_vertices(); return !_error; } diff --git a/pandatool/src/lwoegg/lwoToEggConverter.h b/pandatool/src/lwoegg/lwoToEggConverter.h index 37d3085b46..cc16da8812 100644 --- a/pandatool/src/lwoegg/lwoToEggConverter.h +++ b/pandatool/src/lwoegg/lwoToEggConverter.h @@ -8,8 +8,8 @@ #include +#include #include -#include #include #include @@ -27,15 +27,17 @@ class CLwoSurface; // Reading and writing the egg and lwo structures is // left to the user. //////////////////////////////////////////////////////////////////// -class LwoToEggConverter { +class LwoToEggConverter : public SomethingToEggConverter { public: - LwoToEggConverter(EggData &egg_data); - ~LwoToEggConverter(); + LwoToEggConverter(); + virtual ~LwoToEggConverter(); + virtual string get_name() const; + virtual string get_extension() const; + + virtual bool convert_file(const Filename &filename); bool convert_lwo(const LwoHeader *lwo_header); - INLINE EggGroupNode *get_egg_root() const; - INLINE EggData &get_egg_data(); CLwoLayer *get_layer(int number) const; CLwoSurface *get_surface(const string &name) const; @@ -48,7 +50,6 @@ private: void slot_layer(int number); CLwoLayer *make_generic_layer(); - EggData &_egg_data; CPT(LwoHeader) _lwo_header; CLwoLayer *_generic_layer; @@ -63,8 +64,6 @@ private: typedef map Surfaces; Surfaces _surfaces; - - bool _error; }; #include "lwoToEggConverter.I" diff --git a/pandatool/src/pandatoolbase/Sources.pp b/pandatool/src/pandatoolbase/Sources.pp index e7ec1a38e6..ddf445f1d1 100644 --- a/pandatool/src/pandatoolbase/Sources.pp +++ b/pandatool/src/pandatoolbase/Sources.pp @@ -2,9 +2,9 @@ #define TARGET pandatoolbase #define SOURCES \ - pandatoolbase.cxx pandatoolbase.h + pandatoolbase.cxx pandatoolbase.h pandatoolsymbols.h #define INSTALL_HEADERS \ - pandatoolbase.h + pandatoolbase.h pandatoolsymbols.h #end ss_lib_target diff --git a/pandatool/src/pandatoolbase/pandatoolbase.h b/pandatool/src/pandatoolbase/pandatoolbase.h index 2329429296..a03fb131f6 100644 --- a/pandatool/src/pandatoolbase/pandatoolbase.h +++ b/pandatool/src/pandatoolbase/pandatoolbase.h @@ -12,6 +12,7 @@ #define PANDATOOLBASE_H #include +#include "pandatoolsymbols.h" #endif diff --git a/pandatool/src/pandatoolbase/pandatoolsymbols.h b/pandatool/src/pandatoolbase/pandatoolsymbols.h new file mode 100644 index 0000000000..4a36c9bc16 --- /dev/null +++ b/pandatool/src/pandatoolbase/pandatoolsymbols.h @@ -0,0 +1,30 @@ +/* +// Filename: pandatoolsymbols.h +// Created by: drose (26Apr01) +// +//////////////////////////////////////////////////////////////////// +*/ + +#ifndef PANDATOOLSYMBOLS_H +#define PANDATOOLSYMBOLS_H + +/* See dtoolsymbols.h for a rant on the purpose of this file. */ + +#if defined(WIN32_VC) && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) + +#ifdef BUILDING_PTLOADER + #define EXPCL_PTLOADER __declspec(dllexport) + #define EXPTP_PTLOADER +#else + #define EXPCL_PTLOADER __declspec(dllimport) + #define EXPTP_PTLOADER extern +#endif + +#else /* !WIN32_VC */ + +#define EXPCL_PTLOADER +#define EXPTP_PTLOADER + +#endif /* WIN32_VC */ + +#endif diff --git a/pandatool/src/progbase/Sources.pp b/pandatool/src/progbase/Sources.pp index 4333d8e4ec..2138c71b96 100644 --- a/pandatool/src/progbase/Sources.pp +++ b/pandatool/src/progbase/Sources.pp @@ -1,12 +1,11 @@ #begin ss_lib_target #define TARGET progbase #define LOCAL_LIBS \ - pandatoolbase + converter pandatoolbase #define OTHER_LIBS \ linmath:c putil:c express:c panda:m pystub dtool #define SOURCES \ - distanceUnit.cxx distanceUnit.h \ programBase.I programBase.cxx programBase.h \ withOutputFile.cxx withOutputFile.h \ wordWrapStream.cxx \ @@ -14,7 +13,6 @@ wordWrapStreamBuf.h #define INSTALL_HEADERS \ - distanceUnit.h \ programBase.I programBase.h \ withOutputFile.h \ wordWrapStream.h wordWrapStreamBuf.I \ diff --git a/pandatool/src/progbase/programBase.h b/pandatool/src/progbase/programBase.h index 41fc3450d4..3958276907 100644 --- a/pandatool/src/progbase/programBase.h +++ b/pandatool/src/progbase/programBase.h @@ -8,8 +8,7 @@ #include -#include "distanceUnit.h" - +#include #include #include diff --git a/pandatool/src/ptloader/Sources.pp b/pandatool/src/ptloader/Sources.pp new file mode 100644 index 0000000000..423f89bd62 --- /dev/null +++ b/pandatool/src/ptloader/Sources.pp @@ -0,0 +1,18 @@ +#begin lib_target + #define TARGET ptloader + #define BUILDING_DLL BUILDING_PTLOADER + #define LOCAL_LIBS fltegg flt lwoegg lwo converter pandatoolbase + #define OTHER_LIBS \ + egg2sg:c builder:c egg:c pandaegg:m \ + mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool + #define UNIX_SYS_LIBS \ + m + + #define SOURCES \ + config_ptloader.cxx config_ptloader.h \ + loaderFileTypePandatool.cxx loaderFileTypePandatool.h + + #define INSTALL_HEADERS \ + config_ptloader.h loaderFileTypePandatool.h + +#end lib_target diff --git a/pandatool/src/ptloader/config_ptloader.cxx b/pandatool/src/ptloader/config_ptloader.cxx new file mode 100644 index 0000000000..907c68bff5 --- /dev/null +++ b/pandatool/src/ptloader/config_ptloader.cxx @@ -0,0 +1,47 @@ +// Filename: config_ptloader.cxx +// Created by: drose (26Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "config_ptloader.h" +#include "loaderFileTypePandatool.h" + +#include +#include + +#include +#include +#include + +ConfigureDef(config_ptloader); + +ConfigureFn(config_ptloader) { + init_libptloader(); +} + +//////////////////////////////////////////////////////////////////// +// Function: init_libptloader +// 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_libptloader() { + static bool initialized = false; + if (initialized) { + return; + } + initialized = true; + + LoaderFileTypePandatool::init_type(); + + LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr(); + + FltToEggConverter *flt = new FltToEggConverter; + reg->register_type(new LoaderFileTypePandatool(flt)); + + LwoToEggConverter *lwo = new LwoToEggConverter; + reg->register_type(new LoaderFileTypePandatool(lwo)); +} diff --git a/pandatool/src/ptloader/config_ptloader.h b/pandatool/src/ptloader/config_ptloader.h new file mode 100644 index 0000000000..3f2c5918c6 --- /dev/null +++ b/pandatool/src/ptloader/config_ptloader.h @@ -0,0 +1,17 @@ +// Filename: config_ptloader.h +// Created by: drose (26Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef CONFIG_PTLOADER_H +#define CONFIG_PTLOADER_H + +#include + +#include + +ConfigureDecl(config_ptloader, EXPCL_PANDAEGG, EXPTP_PANDAEGG); + +extern EXPCL_PTLOADER void init_libptloader(); + +#endif diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.cxx b/pandatool/src/ptloader/loaderFileTypePandatool.cxx new file mode 100644 index 0000000000..861eae0dd9 --- /dev/null +++ b/pandatool/src/ptloader/loaderFileTypePandatool.cxx @@ -0,0 +1,84 @@ +// Filename: loaderFileTypePandatool.cxx +// Created by: drose (26Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "loaderFileTypePandatool.h" + +#include +#include +#include +#include + +TypeHandle LoaderFileTypePandatool::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LoaderFileTypePandatool::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +LoaderFileTypePandatool:: +LoaderFileTypePandatool(SomethingToEggConverter *converter) : + _converter(converter) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderFileTypePandatool::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +LoaderFileTypePandatool:: +~LoaderFileTypePandatool() { +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderFileTypePandatool::get_name +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +string LoaderFileTypePandatool:: +get_name() const { + return _converter->get_name(); +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderFileTypePandatool::get_extension +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +string LoaderFileTypePandatool:: +get_extension() const { + return _converter->get_extension(); +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderFileTypePandatool::resolve_filename +// Access: Public, Virtual +// Description: Searches for the indicated filename on whatever paths +// are appropriate to this file type, and updates it if +// it is found. +//////////////////////////////////////////////////////////////////// +void LoaderFileTypePandatool:: +resolve_filename(Filename &path) const { + path.resolve_filename(get_model_path(), get_extension()); +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderFileTypePandatool::load_file +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +PT_Node LoaderFileTypePandatool:: +load_file(const Filename &path, bool) const { + PT_NamedNode result; + + EggData egg_data; + _converter->set_egg_data(&egg_data, false); + if (_converter->convert_file(path)) { + egg_data.set_coordinate_system(CS_default); + result = load_egg_data(egg_data); + } + _converter->clear_egg_data(); + return result.p(); +} diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.h b/pandatool/src/ptloader/loaderFileTypePandatool.h new file mode 100644 index 0000000000..fe2dbf49b4 --- /dev/null +++ b/pandatool/src/ptloader/loaderFileTypePandatool.h @@ -0,0 +1,55 @@ +// Filename: loaderFileTypePandatool.h +// Created by: drose (20Jun00) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LOADERFILETYPEPANDATOOL_H +#define LOADERFILETYPEPANDATOOL_H + +#include + +#include + +class SomethingToEggConverter; + +//////////////////////////////////////////////////////////////////// +// Class : LoaderFileTypePandatool +// Description : This defines the Loader interface to files whose +// converters are defined within the Pandatool package +// and inherit from SomethingToEggConverter, like +// FltToEggConverter and LwoToEggConverter. +//////////////////////////////////////////////////////////////////// +class EXPCL_PTLOADER LoaderFileTypePandatool : public LoaderFileType { +public: + LoaderFileTypePandatool(SomethingToEggConverter *converter); + virtual ~LoaderFileTypePandatool(); + + virtual string get_name() const; + virtual string get_extension() const; + + virtual void resolve_filename(Filename &path) const; + virtual PT_Node load_file(const Filename &path, bool report_errors) const; + +private: + SomethingToEggConverter *_converter; + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + LoaderFileType::init_type(); + register_type(_type_handle, "LoaderFileTypePandatool", + LoaderFileType::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; +}; + +#endif +