Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
ca73e4b415
30 changed files with 633 additions and 154 deletions
  1. 19 0
      pandatool/src/converter/Sources.pp
  2. 0 0
      pandatool/src/converter/distanceUnit.cxx
  3. 0 0
      pandatool/src/converter/distanceUnit.h
  4. 74 0
      pandatool/src/converter/somethingToEggConverter.I
  5. 51 0
      pandatool/src/converter/somethingToEggConverter.cxx
  6. 67 0
      pandatool/src/converter/somethingToEggConverter.h
  7. 1 1
      pandatool/src/eggprogs/Sources.pp
  8. 3 29
      pandatool/src/eggprogs/lwoToEgg.cxx
  9. 1 1
      pandatool/src/flt/Sources.pp
  10. 1 1
      pandatool/src/fltegg/Sources.pp
  11. 0 45
      pandatool/src/fltegg/fltToEggConverter.I
  12. 62 7
      pandatool/src/fltegg/fltToEggConverter.cxx
  13. 7 25
      pandatool/src/fltegg/fltToEggConverter.h
  14. 2 1
      pandatool/src/fltprogs/fltToEgg.cxx
  15. 1 1
      pandatool/src/lwoegg/Sources.pp
  16. 3 1
      pandatool/src/lwoegg/cLwoLayer.cxx
  17. 1 0
      pandatool/src/lwoegg/cLwoPolygons.cxx
  18. 0 22
      pandatool/src/lwoegg/lwoToEggConverter.I
  19. 76 4
      pandatool/src/lwoegg/lwoToEggConverter.cxx
  20. 8 9
      pandatool/src/lwoegg/lwoToEggConverter.h
  21. 2 2
      pandatool/src/pandatoolbase/Sources.pp
  22. 1 0
      pandatool/src/pandatoolbase/pandatoolbase.h
  23. 30 0
      pandatool/src/pandatoolbase/pandatoolsymbols.h
  24. 1 3
      pandatool/src/progbase/Sources.pp
  25. 1 2
      pandatool/src/progbase/programBase.h
  26. 18 0
      pandatool/src/ptloader/Sources.pp
  27. 47 0
      pandatool/src/ptloader/config_ptloader.cxx
  28. 17 0
      pandatool/src/ptloader/config_ptloader.h
  29. 84 0
      pandatool/src/ptloader/loaderFileTypePandatool.cxx
  30. 55 0
      pandatool/src/ptloader/loaderFileTypePandatool.h

+ 19 - 0
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

+ 0 - 0
pandatool/src/progbase/distanceUnit.cxx → pandatool/src/converter/distanceUnit.cxx


+ 0 - 0
pandatool/src/progbase/distanceUnit.h → pandatool/src/converter/distanceUnit.h


+ 74 - 0
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;
+}

+ 51 - 0
pandatool/src/converter/somethingToEggConverter.cxx

@@ -0,0 +1,51 @@
+// Filename: somethingToEggConverter.cxx
+// Created by:  drose (26Apr01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "somethingToEggConverter.h"
+
+#include <eggData.h>
+
+////////////////////////////////////////////////////////////////////
+//     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;
+}

+ 67 - 0
pandatool/src/converter/somethingToEggConverter.h

@@ -0,0 +1,67 @@
+// Filename: somethingToEggConverter.h
+// Created by:  drose (17Apr01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef SOMETHINGTOEGGCONVERTER_H
+#define SOMETHINGTOEGGCONVERTER_H
+
+#include <pandatoolbase.h>
+
+#include <filename.h>
+
+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
+
+

+ 1 - 1
pandatool/src/eggprogs/Sources.pp

@@ -1,5 +1,5 @@
 #define LOCAL_LIBS \
 #define LOCAL_LIBS \
-  eggbase progbase
+  converter eggbase progbase
 #define OTHER_LIBS \
 #define OTHER_LIBS \
   egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \
   egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \
   dtoolutil:c dconfig:c dtoolconfig:m dtool:m pystub
   dtoolutil:c dconfig:c dtoolconfig:m dtool:m pystub

+ 3 - 29
pandatool/src/eggprogs/lwoToEgg.cxx

@@ -50,42 +50,16 @@ LwoToEgg() :
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void LwoToEgg::
 void LwoToEgg::
 run() {
 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);
   _data.set_coordinate_system(_coordinate_system);
 
 
   if (_input_units == DU_invalid) {
   if (_input_units == DU_invalid) {
     _input_units = DU_meters;
     _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";
     nout << "Errors in conversion.\n";
     exit(1);
     exit(1);
   }
   }

+ 1 - 1
pandatool/src/flt/Sources.pp

@@ -1,6 +1,6 @@
 #begin ss_lib_target
 #begin ss_lib_target
   #define TARGET flt
   #define TARGET flt
-  #define LOCAL_LIBS progbase pandatoolbase
+  #define LOCAL_LIBS converter pandatoolbase
   #define OTHER_LIBS \
   #define OTHER_LIBS \
     mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool
     mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool
   #define UNIX_SYS_LIBS \
   #define UNIX_SYS_LIBS \

+ 1 - 1
pandatool/src/fltegg/Sources.pp

@@ -1,6 +1,6 @@
 #begin ss_lib_target
 #begin ss_lib_target
   #define TARGET fltegg
   #define TARGET fltegg
-  #define LOCAL_LIBS pandatoolbase progbase flt
+  #define LOCAL_LIBS converter flt pandatoolbase
   #define OTHER_LIBS \
   #define OTHER_LIBS \
     egg:c pandaegg:m \
     egg:c pandaegg:m \
     mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool
     mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool

+ 0 - 45
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;
-}

+ 62 - 7
pandatool/src/fltegg/fltToEggConverter.cxx

@@ -15,6 +15,7 @@
 #include <fltVertex.h>
 #include <fltVertex.h>
 #include <fltVertexList.h>
 #include <fltVertexList.h>
 #include <fltExternalReference.h>
 #include <fltExternalReference.h>
+#include <eggData.h>
 #include <eggGroup.h>
 #include <eggGroup.h>
 #include <eggSwitchCondition.h>
 #include <eggSwitchCondition.h>
 #include <eggPrimitive.h>
 #include <eggPrimitive.h>
@@ -32,10 +33,57 @@
 //  Description: 
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 FltToEggConverter::
 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::
 bool FltToEggConverter::
 convert_flt(const FltHeader *flt_header) {
 convert_flt(const FltHeader *flt_header) {
+  if (_egg_data->get_coordinate_system() == CS_default) {
+    _egg_data->set_coordinate_system(CS_zup_right);
+  }
+
   _error = false;
   _error = false;
   _flt_header = flt_header;
   _flt_header = flt_header;
 
 
   // Generate a default vertex pool.
   // Generate a default vertex pool.
   _main_egg_vpool = new EggVertexPool("vpool");
   _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
   // We could populate the vertex pool right away, but it's better to
   // defer each vertex until we encounter it, since some of the
   // defer each vertex until we encounter it, since some of the
@@ -60,13 +112,13 @@ convert_flt(const FltHeader *flt_header) {
   // something).
   // something).
 
 
   FltToEggLevelState state;
   FltToEggLevelState state;
-  state._egg_parent = &_egg_data;
+  state._egg_parent = _egg_data;
   convert_record(_flt_header, state);
   convert_record(_flt_header, state);
 
 
   if (_main_egg_vpool->empty()) {
   if (_main_egg_vpool->empty()) {
     // If we didn't get any global vertices, remove the vertex pool
     // If we didn't get any global vertices, remove the vertex pool
     // just for cleanliness.
     // just for cleanliness.
-    _egg_data.remove_child(_main_egg_vpool);
+    _egg_data->remove_child(_main_egg_vpool);
   }
   }
 
 
   return !_error;
   return !_error;
@@ -641,6 +693,9 @@ convert_path(const Filename &orig_filename, const Filename &as_found,
     result = Filename(rel_dir, result);
     result = Filename(rel_dir, result);
     return result;
     return result;
 
 
+  case PC_strip:
+    return orig_filename.get_basename();
+
   case PC_unchanged:
   case PC_unchanged:
     return orig_filename;
     return orig_filename;
   }
   }

+ 7 - 25
pandatool/src/fltegg/fltToEggConverter.h

@@ -10,10 +10,8 @@
 
 
 #include "fltToEggLevelState.h"
 #include "fltToEggLevelState.h"
 
 
-#include <distanceUnit.h>
-
+#include <somethingToEggConverter.h>
 #include <fltHeader.h>
 #include <fltHeader.h>
-#include <eggData.h>
 #include <eggVertex.h>
 #include <eggVertex.h>
 #include <eggTexture.h>
 #include <eggTexture.h>
 #include <pointerTo.h>
 #include <pointerTo.h>
@@ -40,22 +38,14 @@ class EggVertexPool;
 //               Reading and writing the egg and flt structures is
 //               Reading and writing the egg and flt structures is
 //               left to the user.
 //               left to the user.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-class FltToEggConverter {
+class FltToEggConverter : public SomethingToEggConverter {
 public:
 public:
-  FltToEggConverter(EggData &egg_data);
-  INLINE ~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());
+  FltToEggConverter();
+
+  virtual string get_name() const;
+  virtual string get_extension() const;
 
 
+  virtual bool convert_file(const Filename &filename);
   bool convert_flt(const FltHeader *flt_header);
   bool convert_flt(const FltHeader *flt_header);
 
 
 private:
 private:
@@ -92,20 +82,12 @@ private:
   PT(EggVertex) make_egg_vertex(const FltVertex *flt_vertex);
   PT(EggVertex) make_egg_vertex(const FltVertex *flt_vertex);
   PT(EggTexture) make_egg_texture(const FltTexture *flt_texture);
   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;
   CPT(FltHeader) _flt_header;
 
 
   EggVertexPool *_main_egg_vpool;
   EggVertexPool *_main_egg_vpool;
 
 
   typedef map<const FltTexture *, PT(EggTexture) > Textures;
   typedef map<const FltTexture *, PT(EggTexture) > Textures;
   Textures _textures;
   Textures _textures;
-
-  bool _error;
 };
 };
 
 
 #include "fltToEggConverter.I"
 #include "fltToEggConverter.I"

+ 2 - 1
pandatool/src/fltprogs/fltToEgg.cxx

@@ -131,7 +131,8 @@ run() {
     _input_units = header->get_units();
     _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_texture_path_convert(_texture_path_convert, _make_rel_dir);
   converter.set_model_path_convert(_model_path_convert, _make_rel_dir);
   converter.set_model_path_convert(_model_path_convert, _make_rel_dir);
 
 

+ 1 - 1
pandatool/src/lwoegg/Sources.pp

@@ -1,6 +1,6 @@
 #begin ss_lib_target
 #begin ss_lib_target
   #define TARGET lwoegg
   #define TARGET lwoegg
-  #define LOCAL_LIBS pandatoolbase lwo
+  #define LOCAL_LIBS converter lwo pandatoolbase
   #define OTHER_LIBS \
   #define OTHER_LIBS \
     egg:c pandaegg:m \
     egg:c pandaegg:m \
     mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool
     mathutil:c linmath:c putil:c express:c panda:m dtoolconfig dtool

+ 3 - 1
pandatool/src/lwoegg/cLwoLayer.cxx

@@ -6,6 +6,8 @@
 #include "cLwoLayer.h"
 #include "cLwoLayer.h"
 #include "lwoToEggConverter.h"
 #include "lwoToEggConverter.h"
 
 
+#include <eggData.h>
+
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: CLwoLayer::make_egg
 //     Function: CLwoLayer::make_egg
@@ -44,6 +46,6 @@ connect_egg() {
 	 << "; cannot parent layer " << _layer->_number << " properly.\n";
 	 << "; 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());
 }
 }
 
 

+ 1 - 0
pandatool/src/lwoegg/cLwoPolygons.cxx

@@ -11,6 +11,7 @@
 
 
 #include <lwoPolygonTags.h>
 #include <lwoPolygonTags.h>
 #include <lwoTags.h>
 #include <lwoTags.h>
+#include <eggData.h>
 #include <eggPolygon.h>
 #include <eggPolygon.h>
 #include <eggPoint.h>
 #include <eggPoint.h>
 #include <deg_2_rad.h>
 #include <deg_2_rad.h>

+ 0 - 22
pandatool/src/lwoegg/lwoToEggConverter.I

@@ -2,25 +2,3 @@
 // Created by:  drose (25Apr01)
 // 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;
-}

+ 76 - 4
pandatool/src/lwoegg/lwoToEggConverter.cxx

@@ -9,6 +9,7 @@
 #include "cLwoPolygons.h"
 #include "cLwoPolygons.h"
 #include "cLwoSurface.h"
 #include "cLwoSurface.h"
 
 
+#include <eggData.h>
 #include <lwoHeader.h>
 #include <lwoHeader.h>
 #include <lwoLayer.h>
 #include <lwoLayer.h>
 #include <lwoPoints.h>
 #include <lwoPoints.h>
@@ -16,6 +17,7 @@
 #include <lwoVertexMap.h>
 #include <lwoVertexMap.h>
 #include <lwoTags.h>
 #include <lwoTags.h>
 #include <lwoPolygonTags.h>
 #include <lwoPolygonTags.h>
+#include <lwoInputFile.h>
 
 
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -24,14 +26,13 @@
 //  Description: 
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 LwoToEggConverter::
 LwoToEggConverter::
-LwoToEggConverter(EggData &egg_data) : _egg_data(egg_data) {
+LwoToEggConverter() {
   _generic_layer = (CLwoLayer *)NULL;
   _generic_layer = (CLwoLayer *)NULL;
-  _error = false;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LwoToEggConverter::Destructor
 //     Function: LwoToEggConverter::Destructor
-//       Access: Public
+//       Access: Public, Virtual
 //  Description: 
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 LwoToEggConverter::
 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
 //     Function: LwoToEggConverter::convert_lwo
 //       Access: Public
 //       Access: Public
@@ -75,13 +142,18 @@ LwoToEggConverter::
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool LwoToEggConverter::
 bool LwoToEggConverter::
 convert_lwo(const LwoHeader *lwo_header) {
 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;
   _lwo_header = lwo_header;
 
 
   collect_lwo();
   collect_lwo();
   make_egg();
   make_egg();
   connect_egg();
   connect_egg();
 
 
-  _egg_data.remove_unused_vertices();
+  _egg_data->remove_unused_vertices();
 
 
   return !_error;
   return !_error;
 }
 }

+ 8 - 9
pandatool/src/lwoegg/lwoToEggConverter.h

@@ -8,8 +8,8 @@
 
 
 #include <pandatoolbase.h>
 #include <pandatoolbase.h>
 
 
+#include <somethingToEggConverter.h>
 #include <lwoHeader.h>
 #include <lwoHeader.h>
-#include <eggData.h>
 #include <pointerTo.h>
 #include <pointerTo.h>
 
 
 #include <vector>
 #include <vector>
@@ -27,15 +27,17 @@ class CLwoSurface;
 //               Reading and writing the egg and lwo structures is
 //               Reading and writing the egg and lwo structures is
 //               left to the user.
 //               left to the user.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-class LwoToEggConverter {
+class LwoToEggConverter : public SomethingToEggConverter {
 public:
 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);
   bool convert_lwo(const LwoHeader *lwo_header);
 
 
-  INLINE EggGroupNode *get_egg_root() const;
-  INLINE EggData &get_egg_data();
   CLwoLayer *get_layer(int number) const;
   CLwoLayer *get_layer(int number) const;
 
 
   CLwoSurface *get_surface(const string &name) const;
   CLwoSurface *get_surface(const string &name) const;
@@ -48,7 +50,6 @@ private:
   void slot_layer(int number);
   void slot_layer(int number);
   CLwoLayer *make_generic_layer();
   CLwoLayer *make_generic_layer();
 
 
-  EggData &_egg_data;
   CPT(LwoHeader) _lwo_header;
   CPT(LwoHeader) _lwo_header;
   
   
   CLwoLayer *_generic_layer;
   CLwoLayer *_generic_layer;
@@ -63,8 +64,6 @@ private:
 
 
   typedef map<string, CLwoSurface *> Surfaces;
   typedef map<string, CLwoSurface *> Surfaces;
   Surfaces _surfaces;
   Surfaces _surfaces;
-
-  bool _error;
 };
 };
 
 
 #include "lwoToEggConverter.I"
 #include "lwoToEggConverter.I"

+ 2 - 2
pandatool/src/pandatoolbase/Sources.pp

@@ -2,9 +2,9 @@
   #define TARGET pandatoolbase
   #define TARGET pandatoolbase
   
   
   #define SOURCES \
   #define SOURCES \
-    pandatoolbase.cxx pandatoolbase.h
+    pandatoolbase.cxx pandatoolbase.h pandatoolsymbols.h
 
 
   #define INSTALL_HEADERS \
   #define INSTALL_HEADERS \
-    pandatoolbase.h
+    pandatoolbase.h pandatoolsymbols.h
 
 
 #end ss_lib_target
 #end ss_lib_target

+ 1 - 0
pandatool/src/pandatoolbase/pandatoolbase.h

@@ -12,6 +12,7 @@
 #define PANDATOOLBASE_H
 #define PANDATOOLBASE_H
 
 
 #include <pandabase.h>
 #include <pandabase.h>
+#include "pandatoolsymbols.h"
 
 
 #endif
 #endif
 
 

+ 30 - 0
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

+ 1 - 3
pandatool/src/progbase/Sources.pp

@@ -1,12 +1,11 @@
 #begin ss_lib_target
 #begin ss_lib_target
   #define TARGET progbase
   #define TARGET progbase
   #define LOCAL_LIBS \
   #define LOCAL_LIBS \
-    pandatoolbase
+    converter pandatoolbase
   #define OTHER_LIBS \
   #define OTHER_LIBS \
     linmath:c putil:c express:c panda:m pystub dtool
     linmath:c putil:c express:c panda:m pystub dtool
 
 
   #define SOURCES \
   #define SOURCES \
-    distanceUnit.cxx distanceUnit.h \
     programBase.I programBase.cxx programBase.h \
     programBase.I programBase.cxx programBase.h \
     withOutputFile.cxx withOutputFile.h \
     withOutputFile.cxx withOutputFile.h \
     wordWrapStream.cxx \
     wordWrapStream.cxx \
@@ -14,7 +13,6 @@
     wordWrapStreamBuf.h
     wordWrapStreamBuf.h
 
 
   #define INSTALL_HEADERS \
   #define INSTALL_HEADERS \
-    distanceUnit.h \
     programBase.I programBase.h \
     programBase.I programBase.h \
     withOutputFile.h \
     withOutputFile.h \
     wordWrapStream.h wordWrapStreamBuf.I \
     wordWrapStream.h wordWrapStreamBuf.I \

+ 1 - 2
pandatool/src/progbase/programBase.h

@@ -8,8 +8,7 @@
 
 
 #include <pandatoolbase.h>
 #include <pandatoolbase.h>
 
 
-#include "distanceUnit.h"
-
+#include <distanceUnit.h>
 #include <filename.h>
 #include <filename.h>
 #include <vector_string.h>
 #include <vector_string.h>
 
 

+ 18 - 0
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

+ 47 - 0
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 <fltToEggConverter.h>
+#include <lwoToEggConverter.h>
+
+#include <dconfig.h>
+#include <loaderFileTypeRegistry.h>
+#include <eggData.h>
+
+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));
+}

+ 17 - 0
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 <pandatoolbase.h>
+
+#include <dconfig.h>
+
+ConfigureDecl(config_ptloader, EXPCL_PANDAEGG, EXPTP_PANDAEGG);
+
+extern EXPCL_PTLOADER void init_libptloader();
+
+#endif

+ 84 - 0
pandatool/src/ptloader/loaderFileTypePandatool.cxx

@@ -0,0 +1,84 @@
+// Filename: loaderFileTypePandatool.cxx
+// Created by:  drose (26Apr01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "loaderFileTypePandatool.h"
+
+#include <somethingToEggConverter.h>
+#include <config_util.h>
+#include <load_egg_file.h>
+#include <eggData.h>
+
+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();
+}

+ 55 - 0
pandatool/src/ptloader/loaderFileTypePandatool.h

@@ -0,0 +1,55 @@
+// Filename: loaderFileTypePandatool.h
+// Created by:  drose (20Jun00)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef LOADERFILETYPEPANDATOOL_H
+#define LOADERFILETYPEPANDATOOL_H
+
+#include <pandatoolbase.h>
+
+#include <loaderFileType.h>
+
+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
+