diff --git a/pandatool/src/xfile/Sources.pp b/pandatool/src/xfile/Sources.pp index e51db8f7ec..23db78bd5c 100644 --- a/pandatool/src/xfile/Sources.pp +++ b/pandatool/src/xfile/Sources.pp @@ -15,15 +15,14 @@ #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] \ - xFileMaker.cxx xFileMaker.h - #define SOURCES \ $[SOURCES] \ eggToX.cxx eggToX.h @@ -44,15 +43,14 @@ #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] \ - xFileToEggConverter.cxx xFileToEggConverter.h - #define SOURCES \ $[SOURCES] \ xFileToEgg.cxx xFileToEgg.h diff --git a/pandatool/src/xfile/eggToX.cxx b/pandatool/src/xfile/eggToX.cxx index 515eb17bfc..89717d6eb9 100644 --- a/pandatool/src/xfile/eggToX.cxx +++ b/pandatool/src/xfile/eggToX.cxx @@ -24,7 +24,7 @@ // Description: //////////////////////////////////////////////////////////////////// EggToX:: -EggToX() : EggToSomething("DirectX", "x") { +EggToX() : EggToSomething("DirectX", ".x") { set_program_description ("This program reads an Egg file and outputs an equivalent, " "or nearly equivalent, DirectX-style .x file. Only simple " diff --git a/pandatool/src/xfile/xFileMaker.cxx b/pandatool/src/xfile/xFileMaker.cxx index 094dbd938b..828a7ada5b 100644 --- a/pandatool/src/xfile/xFileMaker.cxx +++ b/pandatool/src/xfile/xFileMaker.cxx @@ -19,6 +19,7 @@ #include "xFileMaker.h" #include "xFileMesh.h" #include "xFileMaterial.h" +#include "xFileTemplates.h" #include "notify.h" #include "eggGroupNode.h" @@ -34,10 +35,6 @@ #include "string_utils.h" #include "datagram.h" -// This must be included only in exactly one .cxx file, since -// including defines the structure! -#include - //////////////////////////////////////////////////////////////////// // Function: XFileMaker::Constructor // Access: Public @@ -79,7 +76,7 @@ open(const Filename &filename) { } // Register our templates. - hr = _dx_file->RegisterTemplates(D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES); + hr = _dx_file->RegisterTemplates(D3DRM_XTEMPLATES, d3drm_xtemplates_length); if (hr != DXFILE_OK) { nout << "Unable to register templates.\n"; return false; @@ -152,7 +149,7 @@ add_tree(EggData &egg_data) { int num_bins = pmaker.make_bins(&egg_data); // And now we're ready to traverse the egg hierarchy. - return add_node(&egg_data, NULL); + return recurse_nodes(&egg_data, NULL); } //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/xfile/xFileMaterial.cxx b/pandatool/src/xfile/xFileMaterial.cxx index 94077f9324..0771f0405f 100644 --- a/pandatool/src/xfile/xFileMaterial.cxx +++ b/pandatool/src/xfile/xFileMaterial.cxx @@ -17,11 +17,10 @@ //////////////////////////////////////////////////////////////////// #include "xFileMaterial.h" +#include "xFileToEggConverter.h" #include "eggMaterial.h" #include "eggTexture.h" -#include "eggMaterialCollection.h" -#include "eggTextureCollection.h" #include "eggPrimitive.h" #include "datagram.h" @@ -101,14 +100,12 @@ set_from_egg(EggPrimitive *egg_prim) { // indicated egg primitive. //////////////////////////////////////////////////////////////////// void XFileMaterial:: -apply_to_egg(EggPrimitive *egg_prim, - EggTextureCollection &textures, - EggMaterialCollection &materials) { +apply_to_egg(EggPrimitive *egg_prim, XFileToEggConverter *converter) { // Is there a texture? if (_has_texture) { - EggTexture temp("", _texture); - EggTexture *egg_tex = - textures.create_unique_texture(temp, ~EggTexture::E_tref_name); + Filename texture = converter->convert_texture_path(_texture); + EggTexture temp("", texture); + EggTexture *egg_tex = converter->create_unique_texture(temp); egg_prim->set_texture(egg_tex); } @@ -127,8 +124,7 @@ apply_to_egg(EggPrimitive *egg_prim, temp.set_emit(Colorf(_emissive_color[0], _emissive_color[1], _emissive_color[2], 1.0)); } - EggMaterial *egg_mat = - materials.create_unique_material(temp, ~EggMaterial::E_mref_name); + EggMaterial *egg_mat = converter->create_unique_material(temp); egg_prim->set_material(egg_mat); } diff --git a/pandatool/src/xfile/xFileMaterial.h b/pandatool/src/xfile/xFileMaterial.h index 7ffcda1cfd..dd52eb42d1 100644 --- a/pandatool/src/xfile/xFileMaterial.h +++ b/pandatool/src/xfile/xFileMaterial.h @@ -24,9 +24,8 @@ #include "filename.h" class EggPrimitive; -class EggTextureCollection; -class EggMaterialCollection; class Datagram; +class XFileToEggConverter; //////////////////////////////////////////////////////////////////// // Class : XFileMaterial @@ -39,9 +38,7 @@ public: ~XFileMaterial(); void set_from_egg(EggPrimitive *egg_prim); - void apply_to_egg(EggPrimitive *egg_prim, - EggTextureCollection &textures, - EggMaterialCollection &materials); + void apply_to_egg(EggPrimitive *egg_prim, XFileToEggConverter *converter); int compare_to(const XFileMaterial &other) const; diff --git a/pandatool/src/xfile/xFileMesh.cxx b/pandatool/src/xfile/xFileMesh.cxx index 3ba268f7fd..61da1246d0 100644 --- a/pandatool/src/xfile/xFileMesh.cxx +++ b/pandatool/src/xfile/xFileMesh.cxx @@ -254,9 +254,7 @@ add_material(XFileMaterial *material) { // node. //////////////////////////////////////////////////////////////////// bool XFileMesh:: -create_polygons(EggGroupNode *egg_parent, - EggTextureCollection &textures, - EggMaterialCollection &materials) { +create_polygons(EggGroupNode *egg_parent, XFileToEggConverter *converter) { EggVertexPool *vpool = new EggVertexPool(get_name()); egg_parent->add_child(vpool); Faces::const_iterator fi; @@ -308,9 +306,8 @@ create_polygons(EggGroupNode *egg_parent, int material_index = face->_material_index; if (material_index >= 0 && material_index < (int)_materials.size()) { XFileMaterial *material = _materials[material_index]; - material->apply_to_egg(egg_poly, textures, materials); + material->apply_to_egg(egg_poly, converter); } - } return true; diff --git a/pandatool/src/xfile/xFileMesh.h b/pandatool/src/xfile/xFileMesh.h index 307e6ea253..2d760f3888 100644 --- a/pandatool/src/xfile/xFileMesh.h +++ b/pandatool/src/xfile/xFileMesh.h @@ -30,12 +30,11 @@ class XFileVertex; class XFileNormal; class XFileMaterial; class XFileFace; +class XFileToEggConverter; class EggGroupNode; class EggVertex; class EggPolygon; class EggPrimitive; -class EggTextureCollection; -class EggMaterialCollection; class Datagram; //////////////////////////////////////////////////////////////////// @@ -59,8 +58,7 @@ public: int add_material(XFileMaterial *material); bool create_polygons(EggGroupNode *egg_parent, - EggTextureCollection &textures, - EggMaterialCollection &materials); + XFileToEggConverter *converter); bool has_normals() const; bool has_colors() const; diff --git a/pandatool/src/xfile/xFileTemplates.cxx b/pandatool/src/xfile/xFileTemplates.cxx new file mode 100644 index 0000000000..4b3ae2968d --- /dev/null +++ b/pandatool/src/xfile/xFileTemplates.cxx @@ -0,0 +1,27 @@ +// Filename: xFileTemplates.cxx +// Created by: drose (21Jun01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "xFileTemplates.h" + +// This must be included only in exactly one .cxx file, since +// including defines the structure! +#include + +const int d3drm_xtemplates_length = D3DRM_XTEMPLATE_BYTES; + + diff --git a/pandatool/src/xfile/xFileTemplates.h b/pandatool/src/xfile/xFileTemplates.h new file mode 100644 index 0000000000..23a7ee5ff6 --- /dev/null +++ b/pandatool/src/xfile/xFileTemplates.h @@ -0,0 +1,40 @@ +// Filename: xFileTemplates.h +// Created by: drose (21Jun01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef XFILETEMPLATES_H +#define XFILETEMPLATES_H + +//////////////////////////////////////////////////////////////////// +// +// This file exists to get an external handle to the table defined in +// the Windows header file rmxftmpl.h. Since the table is actually +// defined in the Windows header file, we can't include that header +// file in multiple .cxx files, or we'll define the table multiple +// times. +// +// Unfortunately, the length of the table is defined within that +// header file with a #define, so there's no way to extern *that*. +// Instead, we define our own variable that references the length. +// +//////////////////////////////////////////////////////////////////// + +extern unsigned char D3DRM_XTEMPLATES[]; +extern const int d3drm_xtemplates_length; + +#endif + diff --git a/pandatool/src/xfile/xFileToEgg.cxx b/pandatool/src/xfile/xFileToEgg.cxx index 85196b523a..027a4e2de4 100644 --- a/pandatool/src/xfile/xFileToEgg.cxx +++ b/pandatool/src/xfile/xFileToEgg.cxx @@ -32,7 +32,7 @@ XFileToEgg() : add_transform_options(); add_texture_path_options(); add_rel_dir_options(); - add_search_path_options(false); + add_search_path_options(true); set_program_description ("This program converts DirectX retained-mode (.x) files to egg. This " diff --git a/pandatool/src/xfile/xFileToEggConverter.cxx b/pandatool/src/xfile/xFileToEggConverter.cxx index 08830278a9..14b980a7b1 100644 --- a/pandatool/src/xfile/xFileToEggConverter.cxx +++ b/pandatool/src/xfile/xFileToEggConverter.cxx @@ -19,13 +19,13 @@ #include "xFileToEggConverter.h" #include "xFileMesh.h" #include "xFileMaterial.h" +#include "xFileTemplates.h" + #include "eggData.h" #include "eggGroup.h" #include "datagram.h" - -// This must be included only in exactly one .cxx file, since -// including defines the structure! -#include +#include "eggMaterialCollection.h" +#include "eggTextureCollection.h" //////////////////////////////////////////////////////////////////// @@ -119,7 +119,7 @@ convert_file(const Filename &filename) { } // Register our templates. - hr = _dx_file->RegisterTemplates(D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES); + hr = _dx_file->RegisterTemplates(D3DRM_XTEMPLATES, d3drm_xtemplates_length); if (hr != DXFILE_OK) { nout << "Unable to register templates.\n"; return false; @@ -154,6 +154,30 @@ close() { } } +//////////////////////////////////////////////////////////////////// +// Function: XFileToEggConverter::create_unique_texture +// Access: Public +// Description: Returns an EggTexture pointer whose properties match +// that of the the given EggTexture, except for the tref +// name. +//////////////////////////////////////////////////////////////////// +EggTexture *XFileToEggConverter:: +create_unique_texture(const EggTexture ©) { + return _textures.create_unique_texture(copy, ~EggTexture::E_tref_name); +} + +//////////////////////////////////////////////////////////////////// +// Function: XFileToEggConverter::create_unique_material +// Access: Public +// Description: Returns an EggMaterial pointer whose properties match +// that of the the given EggMaterial, except for the mref +// name. +//////////////////////////////////////////////////////////////////// +EggMaterial *XFileToEggConverter:: +create_unique_material(const EggMaterial ©) { + return _materials.create_unique_material(copy, ~EggMaterial::E_mref_name); +} + //////////////////////////////////////////////////////////////////// // Function: XFileToEggConverter::get_toplevel // Access: Private @@ -312,7 +336,7 @@ convert_mesh(LPDIRECTXFILEDATA obj, EggGroupNode *egg_parent) { return false; } - if (!mesh.create_polygons(egg_parent, _textures, _materials)) { + if (!mesh.create_polygons(egg_parent, this)) { return false; } diff --git a/pandatool/src/xfile/xFileToEggConverter.h b/pandatool/src/xfile/xFileToEggConverter.h index a0963af7e1..c7b613dc09 100644 --- a/pandatool/src/xfile/xFileToEggConverter.h +++ b/pandatool/src/xfile/xFileToEggConverter.h @@ -35,6 +35,8 @@ class EggGroupNode; class Datagram; class XFileMesh; class XFileMaterial; +class EggTexture; +class EggMaterial; //////////////////////////////////////////////////////////////////// // Class : XFileToEggConverter @@ -54,6 +56,9 @@ public: virtual bool convert_file(const Filename &filename); void close(); + EggTexture *create_unique_texture(const EggTexture ©); + EggMaterial *create_unique_material(const EggMaterial ©); + private: bool get_toplevel(); bool convert_object(LPDIRECTXFILEOBJECT obj, EggGroupNode *egg_parent);