Browse Source

various minor improvements

David Rose 24 years ago
parent
commit
c3ebf17c74

+ 5 - 0
panda/src/egg/eggMaterial.cxx

@@ -44,6 +44,11 @@ EggMaterial::
 EggMaterial(const EggMaterial &copy)
   : EggNode(copy),
     _diff(copy._diff),
+    _amb(copy._amb),
+    _emit(copy._emit),
+    _spec(copy._spec),
+    _shininess(copy._shininess),
+    _local(copy._local),
     _flags(copy._flags)
 {
 }

+ 16 - 9
panda/src/egg/eggNameUniquifier.cxx

@@ -69,14 +69,15 @@ uniquify(EggNode *node) {
     string name = filter_name(node);
 
     UsedNames &names = _categories[category];
-    bool inserted;
-    inserted = names.insert(UsedNames::value_type(name, node)).second;
-    if (!inserted) {
-      while (!inserted) {
-        _index++;
-        name = generate_name(node, category, _index);
-        inserted = names.insert(UsedNames::value_type(name, node)).second;
-      }
+    bool inserted = false;
+    if (!name.empty()) {
+      inserted = names.insert(UsedNames::value_type(name, node)).second;
+    }
+
+    while (!inserted) {
+      _index++;
+      name = generate_name(node, category, _index);
+      inserted = names.insert(UsedNames::value_type(name, node)).second;
     }
 
     node->set_name(name);
@@ -185,7 +186,13 @@ filter_name(EggNode *node) {
 ////////////////////////////////////////////////////////////////////
 string EggNameUniquifier::
 generate_name(EggNode *node, const string &category, int index) {
+  string name = filter_name(node);
+
   ostringstream str;
-  str << node->get_name() << "." << category << index;
+  if (name.empty()) {
+    str << category << index;
+  } else {
+    str << name << "." << category << index;
+  }
   return str.str();
 }

+ 74 - 10
panda/src/egg/eggPolysetMaker.cxx

@@ -19,6 +19,31 @@
 #include "eggPolysetMaker.h"
 #include "eggPolygon.h"
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggPolysetMaker::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+EggPolysetMaker::
+EggPolysetMaker() {
+  _properties = 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggPolysetMaker::set_properties
+//       Access: Public
+//  Description: Sets the set of properties that determines which
+//               polygons are allowed to be grouped together into a
+//               single polyset.  This is the bitwise 'or' of all the
+//               properties that matter.  If this is 0, all polygons
+//               (within a given group) will be lumped into a common
+//               polyset regardless of their properties.
+////////////////////////////////////////////////////////////////////
+void EggPolysetMaker::
+set_properties(int properties) {
+  _properties = properties;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggPolysetMaker::get_bin_number
 //       Access: Public, Virtual
@@ -46,20 +71,59 @@ sorts_less(int bin_number, const EggNode *a, const EggNode *b) {
   const EggPolygon *pa = DCAST(EggPolygon, a);
   const EggPolygon *pb = DCAST(EggPolygon, b);
 
-  if (pa->has_texture() != pb->has_texture()) {
-    return ((int)pa->has_texture() < (int)pb->has_texture());
+  if ((_properties & (P_has_texture | P_texture)) != 0) {
+    if (pa->has_texture() != pb->has_texture()) {
+      return ((int)pa->has_texture() < (int)pb->has_texture());
+    }
+  }
+  if ((_properties & (P_texture)) != 0) {
+    if (pa->has_texture()) {
+      return (pa->get_texture()->sorts_less_than(*pb->get_texture(), ~EggTexture::E_tref_name));
+    }
+  }
+  if ((_properties & (P_has_material | P_material)) != 0) {
+    if (pa->has_material() != pb->has_material()) {
+      return ((int)pa->has_material() < (int)pb->has_material());
+    }
+  }
+  if ((_properties & (P_material)) != 0) {
+    if (pa->has_material()) {
+      return (pa->get_material()->sorts_less_than(*pb->get_material(), ~EggMaterial::E_mref_name));
+    }
+  }
+  if ((_properties & (P_has_poly_color)) != 0) {
+    if (pa->has_color() != pb->has_color()) {
+      return ((int)pa->has_color() < (int)pb->has_color());
+    }
+  }
+  if ((_properties & (P_poly_color)) != 0) {
+    if (pa->get_color() != pb->get_color()) {
+      return (pa->get_color() < pb->get_color());
+    }
   }
-  if (pa->has_texture()) {
-    return (pa->get_texture()->sorts_less_than(*pb->get_texture(), ~EggTexture::E_tref_name));
+  if ((_properties & (P_has_poly_normal)) != 0) {
+    if (pa->has_normal() != pb->has_normal()) {
+      return ((int)pa->has_normal() < (int)pb->has_normal());
+    }
   }
-  if (pa->has_material() != pb->has_material()) {
-    return ((int)pa->has_material() < (int)pb->has_material());
+  if ((_properties & (P_has_vertex_normal)) != 0) {
+    bool pa_has_normal = pa->has_vertex_normal();
+    bool pb_has_normal = pb->has_vertex_normal();
+    if (pa_has_normal != pb_has_normal) {
+      return ((int)pa_has_normal < (int)pb_has_normal);
+    }
   }
-  if (pa->has_material()) {
-    return (pa->get_material()->sorts_less_than(*pb->get_material(), ~EggMaterial::E_mref_name));
+  if ((_properties & (P_has_vertex_color)) != 0) {
+    bool pa_has_color = pa->has_vertex_color();
+    bool pb_has_color = pb->has_vertex_color();
+    if (pa_has_color != pb_has_color) {
+      return ((int)pa_has_color < (int)pb_has_color);
+    }
   }
-  if (pa->get_bface_flag() != pb->get_bface_flag()) {
-    return ((int)pa->get_bface_flag() < (int)pb->get_bface_flag());
+  if ((_properties & (P_bface)) != 0) {
+    if (pa->get_bface_flag() != pb->get_bface_flag()) {
+      return ((int)pa->get_bface_flag() < (int)pb->get_bface_flag());
+    }
   }
 
   return false;

+ 20 - 1
panda/src/egg/eggPolysetMaker.h

@@ -37,7 +37,6 @@
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDAEGG EggPolysetMaker : public EggBinMaker {
 public:
-
   // The BinNumber serves to identify why a particular EggBin was
   // created.
   enum BinNumber {
@@ -45,11 +44,31 @@ public:
     BN_polyset,
   };
 
+  enum Properties {
+    P_has_texture        = 0x001,
+    P_texture            = 0x002,
+    P_has_material       = 0x004,
+    P_material           = 0x008,
+    P_has_poly_color     = 0x010,
+    P_poly_color         = 0x020,
+    P_has_poly_normal    = 0x040,
+    P_has_vertex_normal  = 0x080,
+    P_has_vertex_color   = 0x100,
+    P_bface              = 0x200,
+  };
+
+  EggPolysetMaker();
+  void set_properties(int properties);
+
+public:
   virtual int
   get_bin_number(const EggNode *node);
 
   virtual bool
   sorts_less(int bin_number, const EggNode *a, const EggNode *b);
+
+private:
+  int _properties;
 };
 
 

+ 34 - 0
panda/src/egg/eggPrimitive.cxx

@@ -130,6 +130,40 @@ determine_bin() {
   return EggNode::determine_bin();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggPrimitive::has_vertex_normal
+//       Access: Public
+//  Description: Returns true if any vertex on the primitive has a
+//               specific normal set, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool EggPrimitive::
+has_vertex_normal() const {
+  Vertices::const_iterator vi;
+  for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
+    if ((*vi)->has_normal()) {
+      return true;
+    }
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggPrimitive::has_vertex_color
+//       Access: Public
+//  Description: Returns true if any vertex on the primitive has a
+//               specific color set, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool EggPrimitive::
+has_vertex_color() const {
+  Vertices::const_iterator vi;
+  for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
+    if ((*vi)->has_color()) {
+      return true;
+    }
+  }
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggPrimitive::reverse_vertex_ordering
 //       Access: Public, Virtual

+ 3 - 0
panda/src/egg/eggPrimitive.h

@@ -87,6 +87,9 @@ public:
   INLINE void set_bface_flag(bool flag);
   INLINE bool get_bface_flag() const;
 
+  bool has_vertex_normal() const;
+  bool has_vertex_color() const;
+
   virtual void reverse_vertex_ordering();
   virtual bool cleanup();