Ver Fonte

String loading, and made it a TypedObject

rdb há 17 anos atrás
pai
commit
902fc40742

+ 7 - 20
panda/src/grutil/geoMipTerrain.I

@@ -1,6 +1,6 @@
 // Filename: geoMipTerrain.I
 // Created by:  pro-rsoft (29jun07)
-// Last updated by: pro-rsoft (03mar08)
+// Last updated by: pro-rsoft (24sep08)
 //
 ////////////////////////////////////////////////////////////////////
 //
@@ -463,25 +463,8 @@ set_heightfield(const PNMImage &image) {
   return true;
 }
 INLINE bool GeoMipTerrain::
-set_heightfield(const Texture *tex) {
-  _heightfield = PNMImage(
-            max(3, (int) pow(2.0, ceil(log(float(max(2, tex->get_x_size() - 1)))
-                                                           / log(2.0))) + 1),
-            max(3, (int) pow(2.0, ceil(log(float(max(2, tex->get_y_size() - 1)))
-                                                           / log(2.0))) + 1));
-  PNMImage image;
-  tex->store(image);
-  // Make sure not to apply gaussian when it's already the right size
-  if (_heightfield.get_x_size() == image.get_x_size() &&
-      _heightfield.get_y_size() == image.get_y_size()) {
-    _heightfield.copy_from(image);
-  } else {
-    _heightfield.gaussian_filter_from(1.0, image);
-  }
-  _is_dirty = true;
-  _xsize = _heightfield.get_x_size();
-  _ysize = _heightfield.get_y_size();
-  return true;
+set_heightfield(const string &path) {
+  set_heightfield(Filename(path));
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -515,6 +498,10 @@ set_color_map(const Texture *tex) {
   _is_dirty = true;
   return true;
 }
+INLINE bool GeoMipTerrain::
+set_color_map(const string &path) {
+  set_heightfield(Filename(path));
+}
 
 ////////////////////////////////////////////////////////////////////
 //     Function: GeoMipTerrain::has_color_map

+ 3 - 1
panda/src/grutil/geoMipTerrain.cxx

@@ -1,6 +1,6 @@
 // Filename: geoMipTerrain.cxx
 // Created by:  pro-rsoft (29jun07)
-// Last updated by: pro-rsoft (20sep08)
+// Last updated by: pro-rsoft (25sep08)
 //
 ////////////////////////////////////////////////////////////////////
 //
@@ -30,6 +30,8 @@
 
 #include "collideMask.h"
 
+TypeHandle GeoMipTerrain::_type_handle;
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GeoMipTerrain::generate_block
 //       Access: Private

+ 24 - 7
panda/src/grutil/geoMipTerrain.h

@@ -1,6 +1,6 @@
 // Filename: geoMipTerrain.h
 // Created by:  pro-rsoft (29jun07)
-// Last updated by: pro-rsoft (20sep08)
+// Last updated by: pro-rsoft (25sep08)
 //
 ////////////////////////////////////////////////////////////////////
 //
@@ -37,9 +37,8 @@
 //               information about the GeoMipMapping algoritm, see
 //               this paper, written by Willem H. de Boer:
 //               http://flipcode.com/articles/article_geomipmaps.pdf
-//               
 ////////////////////////////////////////////////////////////////////
-class EXPCL_PANDA_GRUTIL GeoMipTerrain {
+class EXPCL_PANDA_GRUTIL GeoMipTerrain : public TypedObject {
 PUBLISHED:
   INLINE GeoMipTerrain(const string &name);
   INLINE ~GeoMipTerrain();
@@ -48,12 +47,13 @@ PUBLISHED:
   INLINE bool set_heightfield(const Filename &filename,
                                     PNMFileType *type = NULL);
   INLINE bool set_heightfield(const PNMImage &image);
-  INLINE bool set_heightfield(const Texture *image);
+  INLINE bool set_heightfield(const string &path);
   INLINE PNMImage &color_map();
   INLINE bool set_color_map(const Filename &filename,
                                   PNMFileType *type = NULL);
   INLINE bool set_color_map(const PNMImage &image);
   INLINE bool set_color_map(const Texture *image);
+  INLINE bool set_color_map(const string &path);
   INLINE bool has_color_map();
   INLINE void clear_color_map();
   double get_elevation(double x, double y);
@@ -98,9 +98,9 @@ PUBLISHED:
   INLINE unsigned short get_min_level();
   INLINE bool is_dirty();
   INLINE void set_factor(float factor);
-  INLINE void set_near_far(double near, double far);
-  INLINE void set_near(double near);
-  INLINE void set_far(double far);
+  INLINE void set_near_far(double input_near, double input_far);
+  INLINE void set_near(double input_near);
+  INLINE void set_far(double input_far);
   INLINE const NodePath get_block_node_path(unsigned short mx,
                                             unsigned short my);
   INLINE LVecBase2f get_block_from_pos(double x, double y);
@@ -150,6 +150,23 @@ private:
   pvector<pvector<unsigned short> > _levels;
   pvector<pvector<unsigned short> > _old_levels;
   
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedObject::init_type();
+    register_type(_type_handle, "GeoMipTerrain",
+                  TypedObject::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+
 };
 
 #include "geoMipTerrain.I"