Browse Source

added wrap mode

David Rose 24 years ago
parent
commit
9355785267

+ 43 - 0
pandatool/src/eggprogs/eggTextureCards.cxx

@@ -47,8 +47,15 @@ EggTextureCards() : EggWriter(true, true) {
      "Specifies the color of each polygon.  The default is white: 1,1,1,1.",
      "Specifies the color of each polygon.  The default is white: 1,1,1,1.",
      &EggTextureCards::dispatch_color, NULL, &_polygon_color[0]);
      &EggTextureCards::dispatch_color, NULL, &_polygon_color[0]);
 
 
+  add_option
+    ("wm", "[repeat | clamp]", 0,
+     "Indicates the wrap mode of the texture: either \"repeat\" or \"clamp\" "
+     "(or \"r\" or \"c\").  The default is to leave this unspecified.",
+     &EggTextureCards::dispatch_wrap_mode, NULL, &_wrap_mode);
+
   _polygon_geometry.set(-0.5, 0.5, -0.5, 0.5);
   _polygon_geometry.set(-0.5, 0.5, -0.5, 0.5);
   _polygon_color.set(1.0, 1.0, 1.0, 1.0);
   _polygon_color.set(1.0, 1.0, 1.0, 1.0);
+  _wrap_mode = EggTexture::WM_unspecified;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -76,6 +83,35 @@ handle_args(ProgramBase::Args &args) {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggTextureCards::dispatch_wrap_mode
+//       Access: Protected, Static
+//  Description: Standard dispatch function for an option that takes
+//               one parameter, which is to be interpreted as a
+//               WrapMode string.  The data pointer is to a WrapMode
+//               enum variable.
+////////////////////////////////////////////////////////////////////
+bool EggTextureCards::
+dispatch_wrap_mode(const string &opt, const string &arg, void *var) {
+  EggTexture::WrapMode *wmp = (EggTexture::WrapMode *)var;
+
+  *wmp = EggTexture::string_wrap_mode(arg);
+  if (*wmp == EggTexture::WM_unspecified) {
+    // An unknown string.  Let's check for our special cases.
+    if (arg == "r") {
+      *wmp = EggTexture::WM_repeat;
+    } else if (arg == "c") {
+      *wmp = EggTexture::WM_clamp;
+    } else {
+      nout << "Invalid wrap mode parameter for -" << opt << ": " 
+           << arg << "\n";
+      return false;
+    }
+  }
+
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: EggTextureCards::run
 //     Function: EggTextureCards::run
 //       Access: Public
 //       Access: Public
@@ -88,6 +124,12 @@ run() {
 
 
   EggGroup *group = new EggGroup();
   EggGroup *group = new EggGroup();
   _data.add_child(group);
   _data.add_child(group);
+
+  // Make the group a sequence, as a convenience.  If we view the
+  // egg file directly we can see all the tiles one at a time.
+  group->set_switch_flag(true);
+  group->set_switch_fps(2.0);
+
   EggVertexPool *vpool = new EggVertexPool("vpool");
   EggVertexPool *vpool = new EggVertexPool("vpool");
   group->add_child(vpool);
   group->add_child(vpool);
 
 
@@ -122,6 +164,7 @@ run() {
     string name = filename.get_basename_wo_extension();
     string name = filename.get_basename_wo_extension();
 
 
     EggTexture *tref = new EggTexture(name, filename);
     EggTexture *tref = new EggTexture(name, filename);
+    tref->set_wrap_mode(_wrap_mode);
     group->add_child(tref);
     group->add_child(tref);
 
 
     // Each polygon gets placed in its own sub-group.  This will make
     // Each polygon gets placed in its own sub-group.  This will make

+ 4 - 0
pandatool/src/eggprogs/eggTextureCards.h

@@ -9,6 +9,7 @@
 #include <pandatoolbase.h>
 #include <pandatoolbase.h>
 
 
 #include <eggWriter.h>
 #include <eggWriter.h>
+#include <eggTexture.h>
 #include <luse.h>
 #include <luse.h>
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -24,12 +25,15 @@ public:
 protected:
 protected:
   virtual bool handle_args(Args &args);
   virtual bool handle_args(Args &args);
 
 
+  static bool dispatch_wrap_mode(const string &opt, const string &arg, void *var);
+
 public:
 public:
   void run();
   void run();
 
 
   LVecBase4d _polygon_geometry;
   LVecBase4d _polygon_geometry;
   Colorf _polygon_color;
   Colorf _polygon_color;
   vector_string _texture_names;
   vector_string _texture_names;
+  EggTexture::WrapMode _wrap_mode;
 };
 };
 
 
 #endif
 #endif