Ver código fonte

add set_vis_blend()

David Rose 13 anos atrás
pai
commit
306bb1ff42

+ 43 - 0
panda/src/pnmimage/pfmFile.I

@@ -592,6 +592,49 @@ get_vis_2d() const {
   return _vis_2d;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::set_vis_blend
+//       Access: Published
+//  Description: Specifies a blending map--a grayscale image--that
+//               will be applied to the vertex color during
+//               generate_vis_mesh() and generate_vis_points().  The
+//               image size must exactly match the mesh size of the
+//               PfmFile.
+//
+//               Ownership of the pointer is not kept by the PfmFile;
+//               it is your responsibility to ensure it does not
+//               destruct during the lifetime of the PfmFile (or at
+//               least not before your subsequent call to
+//               generate_vis_mesh()).
+////////////////////////////////////////////////////////////////////
+INLINE void PfmFile::
+set_vis_blend(const PNMImage *vis_blend) {
+  _vis_blend = vis_blend;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::set_vis_blend
+//       Access: Published
+//  Description: Removes the blending map set by a prior call to
+//               set_vis_blend().
+////////////////////////////////////////////////////////////////////
+INLINE void PfmFile::
+clear_vis_blend() {
+  _vis_blend = NULL;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::get_vis_blend
+//       Access: Published
+//  Description: Returns the blending map set by the most recent call
+//               to set_vis_blend(), or NULL if there is no blending
+//               map in effect.
+////////////////////////////////////////////////////////////////////
+INLINE const PNMImage *PfmFile::
+get_vis_blend() const {
+  return _vis_blend;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::get_table
 //       Access: Public

+ 27 - 1
panda/src/pnmimage/pfmFile.cxx

@@ -45,6 +45,7 @@ PfmFile() {
   _has_point = has_point_noop;
   _vis_inverse = false;
   _vis_2d = false;
+  _vis_blend = NULL;
   clear();
 }
 
@@ -62,7 +63,8 @@ PfmFile(const PfmFile &copy) :
   _no_data_value(copy._no_data_value),
   _has_point(copy._has_point),
   _vis_inverse(copy._vis_inverse),
-  _vis_2d(copy._vis_2d)
+  _vis_2d(copy._vis_2d),
+  _vis_blend(copy._vis_blend)
 {
 }
 
@@ -81,6 +83,7 @@ operator = (const PfmFile &copy) {
   _has_point = copy._has_point;
   _vis_inverse = copy._vis_inverse;
   _vis_2d = copy._vis_2d;
+  _vis_blend = copy._vis_blend;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -94,6 +97,7 @@ clear() {
   _y_size = 0;
   _scale = 1.0;
   _num_channels = 3;
+  _vis_blend = NULL;
   _table.clear();
   clear_no_data_value();
 }
@@ -110,6 +114,7 @@ clear(int x_size, int y_size, int num_channels) {
   _y_size = y_size;
   _scale = 1.0;
   _num_channels = num_channels;
+  _vis_blend = NULL;
 
   _table.clear();
   int size = _x_size * _y_size * _num_channels;
@@ -2149,6 +2154,11 @@ build_auto_vis_columns(VisColumns &vis_columns, bool for_points) const {
     // We need an additional texcoord column for the flat texcoords.
     add_vis_column(vis_columns, CT_texcoord2, CT_texcoord2, _flat_texcoord_name);
   }
+
+  if (_vis_blend != (PNMImage *)NULL) {
+    // The blend map, if specified, also gets applied to the vertices.
+    add_vis_column(vis_columns, CT_blend1, CT_blend1, InternalName::get_color());
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -2196,6 +2206,12 @@ make_array_format(const VisColumns &vis_columns) const {
       numeric_type = GeomEnums::NT_float32;
       contents = GeomEnums::C_vector;
       break;
+
+    case CT_blend1:
+      num_components = 4;
+      numeric_type = GeomEnums::NT_uint8;
+      contents = GeomEnums::C_color;
+      break;
     }
     nassertr(num_components != 0, NULL);
     
@@ -2394,6 +2410,16 @@ add_data(const PfmFile &file, GeomVertexWriter &vwriter, int xi, int yi, bool re
       vwriter.set_data3f(n);
     }
     break;
+
+  case CT_blend1:
+    {
+      const PNMImage *vis_blend = file.get_vis_blend();
+      if (vis_blend != NULL) {
+        double gray = vis_blend->get_gray(xi, yi);
+        vwriter.set_data3d(gray, gray, gray);
+      }
+    }
+    break;
   }
 }
 

+ 6 - 0
panda/src/pnmimage/pfmFile.h

@@ -123,6 +123,10 @@ PUBLISHED:
   INLINE void set_vis_2d(bool vis_2d);
   INLINE bool get_vis_2d() const;
 
+  INLINE void set_vis_blend(const PNMImage *vis_blend);
+  INLINE void clear_vis_blend();
+  INLINE const PNMImage *get_vis_blend() const;
+
   enum ColumnType {
     CT_texcoord2,
     CT_texcoord3,
@@ -130,6 +134,7 @@ PUBLISHED:
     CT_vertex2,
     CT_vertex3,
     CT_normal3,
+    CT_blend1,
   };
   void clear_vis_columns();
   void add_vis_column(ColumnType source, ColumnType target,
@@ -223,6 +228,7 @@ private:
   bool _vis_inverse;
   PT(InternalName) _flat_texcoord_name;
   bool _vis_2d;
+  const PNMImage *_vis_blend;
 
   VisColumns _vis_columns;