Browse Source

fix bug with losing the color in certain normal/color combinations

David Rose 20 năm trước cách đây
mục cha
commit
2d5ecf1cab
1 tập tin đã thay đổi với 16 bổ sung2 xóa
  1. 16 2
      panda/src/egg/eggPrimitive.cxx

+ 16 - 2
panda/src/egg/eggPrimitive.cxx

@@ -352,9 +352,23 @@ unify_attributes(EggPrimitive::Shading shading) {
     shading = get_shading();
   }
 
-  // Not having a color is implicitly white.
+  // Does the primitive have an explicit color?
   if (!has_color() && shading != S_overall) {
-    set_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
+    if (shading != S_per_vertex) {
+      // If there is no color set, first we check the vertices.  If the
+      // vertices have a color, we inherit the color from there.
+      iterator pi;
+      for (pi = begin(); pi != end() && !has_color(); ++pi) {
+        EggVertex *vertex = (*pi);
+        if (vertex->has_color()) {
+          set_color(vertex->get_color());
+        }
+      }
+    }
+    if (!has_color()) {
+      // If we still don't have a color, the implicit color is white.
+      set_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
+    }
   }
 
   switch (shading) {