diff --git a/pandatool/src/ptloader/Sources.pp b/pandatool/src/ptloader/Sources.pp index d82a4c62a8..36e2203197 100644 --- a/pandatool/src/ptloader/Sources.pp +++ b/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 diff --git a/pandatool/src/ptloader/config_ptloader.cxx b/pandatool/src/ptloader/config_ptloader.cxx index 7b319d4d79..ed512a109f 100644 --- a/pandatool/src/ptloader/config_ptloader.cxx +++ b/pandatool/src/ptloader/config_ptloader.cxx @@ -19,14 +19,18 @@ #include "config_ptloader.h" #include "loaderFileTypePandatool.h" -#include -#include -#include -#include +#include "config_lwo.h" +#include "fltToEggConverter.h" +#include "config_flt.h" +#include "lwoToEggConverter.h" -#include -#include -#include +#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 } diff --git a/pandatool/src/xfile/Sources.pp b/pandatool/src/xfile/Sources.pp index 23db78bd5c..9fa953c7ec 100644 --- a/pandatool/src/xfile/Sources.pp +++ b/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 diff --git a/pandatool/src/xfile/xFileMaker.cxx b/pandatool/src/xfile/xFileMaker.cxx index 828a7ada5b..00f23b298e 100644 --- a/pandatool/src/xfile/xFileMaker.cxx +++ b/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, diff --git a/pandatool/src/xfile/xFileMaterial.cxx b/pandatool/src/xfile/xFileMaterial.cxx index 0771f0405f..c389b0331c 100644 --- a/pandatool/src/xfile/xFileMaterial.cxx +++ b/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) { diff --git a/pandatool/src/xfile/xFileTemplates.cxx b/pandatool/src/xfile/xFileTemplates.cxx index 4b3ae2968d..26cc20305c 100644 --- a/pandatool/src/xfile/xFileTemplates.cxx +++ b/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); diff --git a/pandatool/src/xfile/xFileTemplates.h b/pandatool/src/xfile/xFileTemplates.h index 23a7ee5ff6..1d27382645 100644 --- a/pandatool/src/xfile/xFileTemplates.h +++ b/pandatool/src/xfile/xFileTemplates.h @@ -19,6 +19,15 @@ #ifndef XFILETEMPLATES_H #define XFILETEMPLATES_H +#include "pandatoolbase.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#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 diff --git a/pandatool/src/xfile/xFileToEggConverter.cxx b/pandatool/src/xfile/xFileToEggConverter.cxx index 14b980a7b1..8420a19d0a 100644 --- a/pandatool/src/xfile/xFileToEggConverter.cxx +++ b/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; } diff --git a/pandatool/src/xfileprogs/Sources.pp b/pandatool/src/xfileprogs/Sources.pp new file mode 100644 index 0000000000..389ccf8af2 --- /dev/null +++ b/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 diff --git a/pandatool/src/xfile/eggToX.cxx b/pandatool/src/xfileprogs/eggToX.cxx similarity index 100% rename from pandatool/src/xfile/eggToX.cxx rename to pandatool/src/xfileprogs/eggToX.cxx diff --git a/pandatool/src/xfile/eggToX.h b/pandatool/src/xfileprogs/eggToX.h similarity index 100% rename from pandatool/src/xfile/eggToX.h rename to pandatool/src/xfileprogs/eggToX.h diff --git a/pandatool/src/xfile/xFileToEgg.cxx b/pandatool/src/xfileprogs/xFileToEgg.cxx similarity index 100% rename from pandatool/src/xfile/xFileToEgg.cxx rename to pandatool/src/xfileprogs/xFileToEgg.cxx diff --git a/pandatool/src/xfile/xFileToEgg.h b/pandatool/src/xfileprogs/xFileToEgg.h similarity index 100% rename from pandatool/src/xfile/xFileToEgg.h rename to pandatool/src/xfileprogs/xFileToEgg.h