Browse Source

*** empty log message ***

David Rose 24 years ago
parent
commit
5eb03014e6

+ 7 - 1
pandatool/src/ptloader/Sources.pp

@@ -1,7 +1,7 @@
 #begin lib_target
   #define TARGET ptloader
   #define BUILDING_DLL BUILDING_PTLOADER
-  #define LOCAL_LIBS fltegg flt lwoegg lwo converter pandatoolbase
+  #define LOCAL_LIBS xfile fltegg flt lwoegg lwo converter pandatoolbase
   #define OTHER_LIBS \
     egg2sg:c builder:c egg:c pandaegg:m \
     mathutil:c linmath:c putil:c panda:m \
@@ -10,6 +10,12 @@
   #define UNIX_SYS_LIBS \
     m
 
+  #if $[HAVE_DX]
+    // To link in xfile, we need to also link in the DX libraries.
+    #define WIN_SYS_LIBS d3dxof.lib
+    #define USE_DX yes
+  #endif
+
   #define SOURCES \
     config_ptloader.cxx config_ptloader.h \
     loaderFileTypePandatool.cxx loaderFileTypePandatool.h

+ 16 - 7
pandatool/src/ptloader/config_ptloader.cxx

@@ -19,14 +19,18 @@
 #include "config_ptloader.h"
 #include "loaderFileTypePandatool.h"
 
-#include <config_lwo.h>
-#include <fltToEggConverter.h>
-#include <config_flt.h>
-#include <lwoToEggConverter.h>
+#include "config_lwo.h"
+#include "fltToEggConverter.h"
+#include "config_flt.h"
+#include "lwoToEggConverter.h"
 
-#include <dconfig.h>
-#include <loaderFileTypeRegistry.h>
-#include <eggData.h>
+#ifdef HAVE_DX
+#include "xFileToEggConverter.h"
+#endif
+
+#include "dconfig.h"
+#include "loaderFileTypeRegistry.h"
+#include "eggData.h"
 
 ConfigureDef(config_ptloader);
 
@@ -61,4 +65,9 @@ init_libptloader() {
   init_libflt();
   LwoToEggConverter *lwo = new LwoToEggConverter;
   reg->register_type(new LoaderFileTypePandatool(lwo));
+
+#ifdef HAVE_DX
+  XFileToEggConverter *xfile = new XFileToEggConverter;
+  reg->register_type(new LoaderFileTypePandatool(xfile));
+#endif
 }

+ 3 - 35
pandatool/src/xfile/Sources.pp

@@ -1,8 +1,8 @@
 #define DIRECTORY_IF_DX yes
 #define USE_DX yes
 
-#begin bin_target
-  #define TARGET egg2x
+#begin ss_lib_target
+  #define TARGET xfile
   #define LOCAL_LIBS eggbase progbase pandatoolbase
   #define OTHER_LIBS \
     egg:c pandaegg:m \
@@ -23,36 +23,4 @@
     xFileToEggConverter.cxx xFileToEggConverter.h \
     xFileVertex.cxx xFileVertex.h
 
-  #define SOURCES \
-    $[SOURCES] \
-    eggToX.cxx eggToX.h
-
-#end bin_target
-
-#begin bin_target
-  #define TARGET x2egg
-  #define LOCAL_LIBS converter eggbase progbase pandatoolbase
-  #define OTHER_LIBS \
-    egg:c pandaegg:m \
-    mathutil:c linmath:c putil:c panda:m \
-    express:c pandaexpress:m \
-    dtoolconfig dtool pystub \
-
-  #define WIN_SYS_LIBS \
-    d3dxof.lib
-
-  #define SOURCES \
-    xFileFace.cxx xFileFace.h \
-    xFileMaker.cxx xFileMaker.h \
-    xFileMaterial.cxx xFileMaterial.h \
-    xFileMesh.cxx xFileMesh.h \
-    xFileNormal.cxx xFileNormal.h \
-    xFileTemplates.cxx xFileTemplates.h \
-    xFileToEggConverter.cxx xFileToEggConverter.h \
-    xFileVertex.cxx xFileVertex.h
-
-  #define SOURCES \
-    $[SOURCES] \
-    xFileToEgg.cxx xFileToEgg.h
-
-#end bin_target
+#end ss_lib_target

+ 1 - 0
pandatool/src/xfile/xFileMaker.cxx

@@ -92,6 +92,7 @@ open(const Filename &filename) {
 
   // Save the templates we will use.
   static const GUID *temps[] = {
+    &mydef_TID_D3DRMHeader,
     &TID_D3DRMCoords2d,
     &TID_D3DRMVector,
     &TID_D3DRMColorRGBA,

+ 16 - 2
pandatool/src/xfile/xFileMaterial.cxx

@@ -211,13 +211,27 @@ void XFileMaterial::
 make_texture_data(Datagram &raw_data) {
   raw_data.clear();
 
+  // Convert the filename to an appropriate form for the X file.
+  string os_filename = _texture.to_os_specific();
+  // Now we have to double up the backslashes.
+  string filename;
+  for (string::const_iterator pi = os_filename.begin();
+       pi != os_filename.end();
+       ++pi) {
+    if ((*pi) == '\\') {
+      filename += '\\';
+      filename += '\\';
+    } else {
+      filename += (*pi);
+    }
+  }
+
   // Get a char * pointer to the texture filename, to pass into the
   // Microsoft DX file interface.  Unfortunately, we can't delete this
   // again, since it needs to live longer than the life of the
   // XFileMaterial object itself, so this becomes a memory leak
   // (unless the DX file interface frees it, but the documentation is
   // far from clear).  Too bad.
-  string filename = _texture.to_os_specific();
   char *filename_str = strdup(filename.c_str());
 
   // The Microsoft convention is to stuff a pointer into a four-byte
@@ -269,7 +283,7 @@ read_texture_data(const Datagram &raw_data) {
   // The Microsoft convention is to stuff a pointer into a four-byte
   // field.  Not terribly portable, but that's the interface.
   const char *ptr = (const char *)di.get_int32();
-  _texture = ptr;
+  _texture = Filename::from_os_specific(ptr);
   _has_texture = true;
 
   if (di.get_remaining_size() != 0) {

+ 7 - 0
pandatool/src/xfile/xFileTemplates.cxx

@@ -24,4 +24,11 @@
 
 const int d3drm_xtemplates_length = D3DRM_XTEMPLATE_BYTES;
 
+// I don't know what the official Windows way to declare this thing
+// is.  This is my way.  What a strange coding environment this is.
+#define DECLARE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+  const GUID name \
+      = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
 
+DECLARE_GUID(mydef_TID_D3DRMHeader,
+0x3d82ab43, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33);

+ 14 - 0
pandatool/src/xfile/xFileTemplates.h

@@ -19,6 +19,15 @@
 #ifndef XFILETEMPLATES_H
 #define XFILETEMPLATES_H
 
+#include "pandatoolbase.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <d3d.h>
+#include <dxfile.h>
+#include <rmxfguid.h>
+#undef WIN32_LEAN_AND_MEAN
+
 ////////////////////////////////////////////////////////////////////
 //
 // This file exists to get an external handle to the table defined in
@@ -36,5 +45,10 @@
 extern unsigned char D3DRM_XTEMPLATES[];
 extern const int d3drm_xtemplates_length;
 
+// For some reason, this definition does not appear in rmxfguid.h. 
+/* {3D82AB43-62DA-11cf-AB39-0020AF71E433} */
+DEFINE_GUID(mydef_TID_D3DRMHeader,
+0x3d82ab43, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33);
+
 #endif
 

+ 8 - 2
pandatool/src/xfile/xFileToEggConverter.cxx

@@ -27,7 +27,6 @@
 #include "eggMaterialCollection.h"
 #include "eggTextureCollection.h"
 
-
 ////////////////////////////////////////////////////////////////////
 //     Function: XFileToEggConverter::Constructor
 //       Access: Public
@@ -133,6 +132,10 @@ convert_file(const Filename &filename) {
     return false;
   }
 
+  if (_egg_data->get_coordinate_system() == CS_default) {
+    _egg_data->set_coordinate_system(CS_yup_left);
+  }
+
   return get_toplevel();
 }
 
@@ -249,7 +252,10 @@ convert_data_object(LPDIRECTXFILEDATA obj, EggGroupNode *egg_parent) {
     return false;
   }
 
-  if (*type == TID_D3DRMFrame) {
+  if (*type == mydef_TID_D3DRMHeader) {
+    // Quietly ignore headers.
+
+  } else if (*type == TID_D3DRMFrame) {
     if (!convert_frame(obj, egg_parent)) {
       return false;
     }

+ 36 - 0
pandatool/src/xfileprogs/Sources.pp

@@ -0,0 +1,36 @@
+#define DIRECTORY_IF_DX yes
+#define USE_DX yes
+
+#begin bin_target
+  #define TARGET egg2x
+  #define LOCAL_LIBS xfile eggbase progbase pandatoolbase
+  #define OTHER_LIBS \
+    egg:c pandaegg:m \
+    mathutil:c linmath:c putil:c panda:m \
+    express:c pandaexpress:m \
+    dtoolconfig dtool pystub \
+
+  #define WIN_SYS_LIBS \
+    d3dxof.lib
+
+  #define SOURCES \
+    eggToX.cxx eggToX.h
+
+#end bin_target
+
+#begin bin_target
+  #define TARGET x2egg
+  #define LOCAL_LIBS xfile converter eggbase progbase pandatoolbase
+  #define OTHER_LIBS \
+    egg:c pandaegg:m \
+    mathutil:c linmath:c putil:c panda:m \
+    express:c pandaexpress:m \
+    dtoolconfig dtool pystub \
+
+  #define WIN_SYS_LIBS \
+    d3dxof.lib
+
+  #define SOURCES \
+    xFileToEgg.cxx xFileToEgg.h
+
+#end bin_target

+ 0 - 0
pandatool/src/xfile/eggToX.cxx → pandatool/src/xfileprogs/eggToX.cxx


+ 0 - 0
pandatool/src/xfile/eggToX.h → pandatool/src/xfileprogs/eggToX.h


+ 0 - 0
pandatool/src/xfile/xFileToEgg.cxx → pandatool/src/xfileprogs/xFileToEgg.cxx


+ 0 - 0
pandatool/src/xfile/xFileToEgg.h → pandatool/src/xfileprogs/xFileToEgg.h