Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
434abe118b
2 changed files with 40 additions and 35 deletions
  1. 27 20
      pandatool/src/flt/fltGeometry.cxx
  2. 13 15
      pandatool/src/fltegg/fltToEggConverter.cxx

+ 27 - 20
pandatool/src/flt/fltGeometry.cxx

@@ -45,44 +45,51 @@ FltGeometry(FltHeader *header) : FltBeadID(header) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FltGeometry::get_color
 //     Function: FltGeometry::get_color
 //       Access: Public
 //       Access: Public
-//  Description: If has_color() indicates true, returns the primary
-//               color of the face, as a four-component value
-//               (including alpha as the transparency channel).
+//  Description: Returns the primary color of the face, as a
+//               four-component value (including alpha as the
+//               transparency channel).
+//
+//               If has_color() is false, the result is white, but
+//               still reflects the transparency correctly.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 Colorf FltGeometry::
 Colorf FltGeometry::
 get_color() const {
 get_color() const {
-  nassertr(has_color(), Colorf(0.0, 0.0, 0.0, 0.0));
+  Colorf color;
 
 
-  if (_texwhite && has_texture()) {
+  if (!has_color() || (_texwhite && has_texture())) {
     // Force this one white.
     // Force this one white.
-    return Colorf(1.0, 1.0, 1.0, 1.0 - (_transparency / 65535.0));
-  }
+    color.set(1.0, 1.0, 1.0, 1.0);
 
 
-  if (has_material()) {
+  } else if (has_material()) {
     // If we have a material, that replaces the color.
     // If we have a material, that replaces the color.
     FltMaterial *material = get_material();
     FltMaterial *material = get_material();
-    return Colorf(material->_diffuse[0],
-		  material->_diffuse[1],
-		  material->_diffuse[2],
-		  1.0 - (_transparency / 65535.0));
+    color.set(material->_diffuse[0],
+	      material->_diffuse[1],
+	      material->_diffuse[2],
+	      material->_alpha);
+  } else {
+    RGBColorf rgb =
+      _header->get_rgb(_color_index, (_flags & F_packed_color) != 0,
+		       _packed_color);
+    color.set(rgb[0], rgb[1], rgb[2], 1.0);
   }
   }
 
 
-  return _header->get_color(_color_index, (_flags & F_packed_color) != 0,
-			    _packed_color, _transparency);
+  // Modify the whole thing by our transparency.
+  float alpha = 1.0 - (_transparency / 65535.0);
+  color[3] *= alpha;
+
+  return color;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FltGeometry::get_rgb
 //     Function: FltGeometry::get_rgb
 //       Access: Public
 //       Access: Public
-//  Description: If has_color() indicates true, returns the primary
-//               color of the face, as a three-component value
-//               ignoring transparency.
+//  Description: Returns the primary color of the face, as a
+//               three-component value ignoring transparency.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 RGBColorf FltGeometry::
 RGBColorf FltGeometry::
 get_rgb() const {
 get_rgb() const {
-  nassertr(has_color(), RGBColorf(0.0, 0.0, 0.0));
-
-  if (_texwhite && has_texture()) {
+  if (!has_color() || (_texwhite && has_texture())) {
     // Force this one white.
     // Force this one white.
     return RGBColorf(1.0, 1.0, 1.0);
     return RGBColorf(1.0, 1.0, 1.0);
   }
   }

+ 13 - 15
pandatool/src/fltegg/fltToEggConverter.cxx

@@ -360,30 +360,28 @@ setup_geometry(const FltGeometry *flt_geom, FltToEggLevelState &state,
     break;
     break;
   }
   }
 
 
+  Colorf face_color = flt_geom->get_color();
+
+  if (state._flt_object != (FltObject *)NULL) {
+    // If we have a FltObject above us, it might also specify a
+    // transparency.  This combines with our existing transparency.
+    float alpha = 1.0 - (state._flt_object->_transparency / 65535.0);
+    face_color[3] *= alpha;
+  }
+
+  egg_prim->set_color(face_color);
+
   if (flt_geom->has_texture()) {
   if (flt_geom->has_texture()) {
     // If the geometry has a texture, apply it.
     // If the geometry has a texture, apply it.
     egg_prim->set_texture(make_egg_texture(flt_geom->get_texture()));
     egg_prim->set_texture(make_egg_texture(flt_geom->get_texture()));
 
 
     if (flt_geom->_texwhite) {
     if (flt_geom->_texwhite) {
       // If the geometry should be colored white under the texture,
       // If the geometry should be colored white under the texture,
-      // then eliminate any explicit color; the egg loader will
-      // implicitly color it white.
-      egg_prim->clear_color();
+      // then eliminate vertex colors.
       use_vertex_color = false;
       use_vertex_color = false;
     }
     }
   }
   }
 
 
-  // Get the alpha value based on the object's "transparency".
-  double a = 1.0 - (flt_geom->_transparency / 65536.0);
-  Colorf face_color;
-  
-  if (flt_geom->has_color()) {
-    // And make sure to set the transparency correctly.
-    face_color = flt_geom->get_color();
-    face_color[3] = a;
-    egg_prim->set_color(face_color);
-  }
-
   if (use_vertex_color) {
   if (use_vertex_color) {
     // If we're to use vertex color instead of the face color, remove
     // If we're to use vertex color instead of the face color, remove
     // the face color to eliminate any ambiguity.
     // the face color to eliminate any ambiguity.
@@ -395,7 +393,7 @@ setup_geometry(const FltGeometry *flt_geom, FltToEggLevelState &state,
       EggVertex *vertex = (*vi);
       EggVertex *vertex = (*vi);
       if (vertex->has_color()) {
       if (vertex->has_color()) {
 	Colorf vertex_color = vertex->get_color();
 	Colorf vertex_color = vertex->get_color();
-	vertex_color[3] = a;
+	vertex_color[3] = face_color[3];
 	vertex->set_color(vertex_color);
 	vertex->set_color(vertex_color);
       } else {
       } else {
 	if (flt_geom->has_color()) {
 	if (flt_geom->has_color()) {