Panda3D
geoMipTerrain.I
1 // Filename: geoMipTerrain.I
2 // Created by: rdb (29Jun07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "config_grutil.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: GeoMipTerrain::Constructor
19 // Access: Published
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 INLINE GeoMipTerrain::
23 GeoMipTerrain(const string &name) {
24  _root = NodePath(name);
25  _root_flattened = false;
26  _xsize = 0;
27  _ysize = 0;
28  _block_size = 16;
29  _max_level = 4; // Always log(_block_size) / log(2.0)
30  _min_level = 0;
31  _factor = 100.0;
32  _near = 16.0;
33  _far = 128.0;
34  _use_near_far = false;
35  _has_color_map = false;
36  PT(PandaNode) tmpnode = new PandaNode("tmp_focal");
37  _auto_flatten = AFM_off;
38  _focal_point = NodePath(tmpnode);
39  _focal_is_temporary = true;
40  _is_dirty = true;
41  _bruteforce = false;
42  _stitching = false;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: GeoMipTerrain::Destructor
47 // Access: Published
48 // Description: This will not remove the terrain node itself.
49 // To have the terrain itself also deleted, please
50 // call remove_node() prior to destruction.
51 ////////////////////////////////////////////////////////////////////
52 INLINE GeoMipTerrain::
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: GeoMipTerrain::heightfield
58 // Access: Published
59 // Description: Returns a reference to the heightfield (a PNMImage)
60 // contained inside GeoMipTerrain. You can use
61 // the reference to alter the heightfield.
62 ////////////////////////////////////////////////////////////////////
65  return _heightfield;
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: GeoMipTerrain::color_map
70 // Access: Published
71 // Description: Returns a reference to the color map (a PNMImage)
72 // contained inside GeoMipTerrain. You can use
73 // the reference to alter the color map.
74 ////////////////////////////////////////////////////////////////////
77  return _color_map;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: GeoMipTerrain::set_bruteforce
82 // Access: Published
83 // Description: Sets a boolean specifying whether the terrain will
84 // be rendered bruteforce. If the terrain is rendered
85 // bruteforce, there will be no Level of Detail, and
86 // the update() call will only update the
87 // terrain if it is marked dirty.
88 ////////////////////////////////////////////////////////////////////
89 INLINE void GeoMipTerrain::
90 set_bruteforce(bool bf) {
91  if (bf == true && _bruteforce == false) {
92  _is_dirty = true;
93  }
94  _bruteforce = bf;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: GeoMipTerrain::get_bruteforce
99 // Access: Published
100 // Description: Returns a boolean whether the terrain is rendered
101 // bruteforce or not. See set_bruteforce for more
102 // information.
103 ////////////////////////////////////////////////////////////////////
104 INLINE bool GeoMipTerrain::
106  return _bruteforce;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: GeoMipTerrain::set_auto_flatten
111 // Access: Private
112 // Description: The terrain can be automatically flattened (using
113 // flatten_light, flatten_medium, or flatten_strong)
114 // after each update. This only affects future
115 // updates, it doesn't flatten the current terrain.
116 ////////////////////////////////////////////////////////////////////
117 INLINE void GeoMipTerrain::
118 set_auto_flatten(int mode) {
119  _auto_flatten = mode;
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: GeoMipTerrain::set_focal_point
124 // Access: Published
125 // Description: Sets the focal point. GeoMipTerrain generates
126 // high-resolution terrain around the focal point, and
127 // progressively lower and lower resolution terrain
128 // as you get farther away. If a point is supplied
129 // and not a NodePath, make sure it's relative to
130 // the terrain. Only the x and y coordinates of
131 // the focal point are taken in respect.
132 ////////////////////////////////////////////////////////////////////
133 INLINE void GeoMipTerrain::
134 set_focal_point(double x, double y) {
135  if (!_focal_is_temporary) {
136  PT(PandaNode) tmpnode = new PandaNode("tmp_focal");
137  _focal_point = NodePath(tmpnode);
138  }
139  _focal_point.set_pos(_root, x, y, 0);
140  _focal_is_temporary = true;
141 }
142 INLINE void GeoMipTerrain::
143 set_focal_point(const LPoint2d &fp) {
144  set_focal_point(fp.get_x(), fp.get_y());
145 }
146 INLINE void GeoMipTerrain::
147 set_focal_point(const LPoint2f &fp) {
148  set_focal_point(double(fp.get_x()), double(fp.get_y()));
149 }
150 INLINE void GeoMipTerrain::
151 set_focal_point(const LPoint3d &fp) {
152  set_focal_point(fp.get_x(), fp.get_y());
153 }
154 INLINE void GeoMipTerrain::
155 set_focal_point(const LPoint3f &fp) {
156  set_focal_point(double(fp.get_x()), double(fp.get_y()));
157 }
158 INLINE void GeoMipTerrain::
159 set_focal_point(NodePath fp) {
160  if (_focal_is_temporary) {
161  _focal_point.remove_node();
162  }
163  _focal_point = fp;
164  _focal_is_temporary = false;
165 }
166 
167 ////////////////////////////////////////////////////////////////////
168 // Function: GeoMipTerrain::get_focal_point
169 // Access: Published
170 // Description: Returns the focal point, as a NodePath.
171 // If you have set it to be just a point, it will
172 // return an empty node at the focal position.
173 ////////////////////////////////////////////////////////////////////
176  return _focal_point;
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: GeoMipTerrain::get_root
181 // Access: Published
182 // Description: Returns the root of the terrain. This is a
183 // single PandaNode to which all the rest of the
184 // terrain is parented. The generate and update
185 // operations replace the nodes which are parented
186 // to this root, but they don't replace this root
187 // itself.
188 ////////////////////////////////////////////////////////////////////
190 get_root() const {
191  return _root;
192 }
193 
194 ////////////////////////////////////////////////////////////////////
195 // Function: GeoMipTerrain::set_min_level
196 // Access: Published
197 // Description: Sets the minimum level of detail at which blocks
198 // may be generated by generate() or update().
199 // The default value is 0, which is the highest
200 // quality. This value is also taken in respect when
201 // generating the terrain bruteforce.
202 ////////////////////////////////////////////////////////////////////
203 INLINE void GeoMipTerrain::
204 set_min_level(unsigned short minlevel) {
205  _min_level = minlevel;
206 }
207 
208 ////////////////////////////////////////////////////////////////////
209 // Function: GeoMipTerrain::get_min_level
210 // Access: Published
211 // Description: Gets the minimum level of detail at which blocks
212 // may be generated by generate() or update().
213 // The default value is 0, which is the highest
214 // quality.
215 ////////////////////////////////////////////////////////////////////
216 INLINE unsigned short GeoMipTerrain::
218  return _min_level;
219 }
220 
221 ////////////////////////////////////////////////////////////////////
222 // Function: GeoMipTerrain::get_max_level
223 // Access: Published
224 // Description: Returns the highest level possible for this block
225 // size. When a block is at this level, it will be
226 // the worst quality possible.
227 ////////////////////////////////////////////////////////////////////
228 INLINE unsigned short GeoMipTerrain::
230  return _max_level;
231 }
232 
233 ////////////////////////////////////////////////////////////////////
234 // Function: GeoMipTerrain::get_block_size
235 // Access: Published
236 // Description: Gets the block size.
237 ////////////////////////////////////////////////////////////////////
238 INLINE unsigned short GeoMipTerrain::
240  return _block_size;
241 }
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: GeoMipTerrain::set_block_size
245 // Access: Published
246 // Description: Sets the block size. If it is not a power of two,
247 // the closest power of two is used.
248 ////////////////////////////////////////////////////////////////////
249 INLINE void GeoMipTerrain::
250 set_block_size(unsigned short newbs) {
251  if (is_power_of_two(newbs)) {
252  _block_size = newbs;
253  } else {
254  if (is_power_of_two(newbs - 1)) {
255  _block_size = newbs - 1;
256  } else {
257  if (is_power_of_two(newbs + 1)) {
258  _block_size = newbs + 1;
259  } else {
260  _block_size = (unsigned short) pow(2.0,
261  floor(log((double) newbs) / log(2.0) + 0.5));
262  }
263  }
264  }
265  _max_level = (unsigned short) (log((double) _block_size) / log(2.0));
266  _is_dirty = true;
267 }
268 
269 ////////////////////////////////////////////////////////////////////
270 // Function: GeoMipTerrain::is_dirty
271 // Access: Published
272 // Description: Returns a bool indicating whether the terrain is
273 // marked 'dirty', that means the terrain has to be
274 // regenerated on the next update() call, because
275 // for instance the heightfield has changed.
276 // Once the terrain has been regenerated, the dirty
277 // flag automatically gets reset internally.
278 ////////////////////////////////////////////////////////////////////
279 INLINE bool GeoMipTerrain::
281  return _is_dirty;
282 }
283 
284 ////////////////////////////////////////////////////////////////////
285 // Function: GeoMipTerrain::set_factor
286 // Access: Published
287 // Description: DEPRECATED method. Use set_near/far instead.
288 // Sets the quality factor at which blocks must be
289 // generated. The higher this level, the better
290 // quality the terrain will be, but more expensive
291 // to render. A value of 0 makes the terrain the
292 // lowest quality possible, depending on blocksize.
293 // The default value is 100.
294 ////////////////////////////////////////////////////////////////////
295 INLINE void GeoMipTerrain::
296 set_factor(PN_stdfloat factor) {
297  grutil_cat.debug() << "Using deprecated method set_factor, use set_near and set_far instead!\n";
298  _use_near_far = false;
299  _factor = factor;
300 }
301 
302 ////////////////////////////////////////////////////////////////////
303 // Function: GeoMipTerrain::set_near_far
304 // Access: Published
305 // Description: Sets the near and far LOD distances in one call.
306 ////////////////////////////////////////////////////////////////////
307 INLINE void GeoMipTerrain::
308 set_near_far(double input_near, double input_far) {
309  _use_near_far = true;
310  _near = input_near;
311  _far = input_far;
312 }
313 
314 ////////////////////////////////////////////////////////////////////
315 // Function: GeoMipTerrain::set_near
316 // Access: Published
317 // Description: Sets the near LOD distance, at which the terrain
318 // will be rendered at highest quality.
319 // This distance is in the terrain's coordinate space!
320 ////////////////////////////////////////////////////////////////////
321 INLINE void GeoMipTerrain::
322 set_near(double input_near) {
323  _use_near_far = true;
324  _near = input_near;
325 }
326 
327 ////////////////////////////////////////////////////////////////////
328 // Function: GeoMipTerrain::set_far
329 // Access: Published
330 // Description: Sets the far LOD distance, at which the terrain
331 // will be rendered at lowest quality.
332 // This distance is in the terrain's coordinate space!
333 ////////////////////////////////////////////////////////////////////
334 INLINE void GeoMipTerrain::
335 set_far(double input_far) {
336  _use_near_far = true;
337  _far = input_far;
338 }
339 
340 ////////////////////////////////////////////////////////////////////
341 // Function: GeoMipTerrain::get_far
342 // Access: Published
343 // Description: Returns the far LOD distance in the terrain coordinate
344 // space
345 ////////////////////////////////////////////////////////////////////
346 INLINE double GeoMipTerrain::
348  return _far;
349 }
350 
351 ////////////////////////////////////////////////////////////////////
352 // Function: GeoMipTerrain::get_near
353 // Access: Published
354 // Description: Returns the near LOD distance in the terrain coordinate
355 // space
356 ////////////////////////////////////////////////////////////////////
357 INLINE double GeoMipTerrain::
359  return _near;
360 }
361 
362 ////////////////////////////////////////////////////////////////////
363 // Function: GeoMipTerrain::get_flatten_mode
364 // Access: Published
365 // Description: Returns the automatic-flatten mode (e.g., off,
366 // flatten_light, flatten_medium, or flatten_strong)
367 ////////////////////////////////////////////////////////////////////
368 INLINE int GeoMipTerrain::
370  return _auto_flatten;
371 }
372 
373 ////////////////////////////////////////////////////////////////////
374 // Function: GeoMipTerrain::get_block_node_path
375 // Access: Published
376 // Description: Returns the NodePath of the specified block.
377 // If auto-flatten is enabled and the node is
378 // getting removed during the flattening process,
379 // it will still return a NodePath with the
380 // appropriate terrain chunk, but it will be in
381 // a temporary scenegraph.
382 // Please note that this returns a const object and
383 // you can not modify the node. Modify the heightfield
384 // instead.
385 ////////////////////////////////////////////////////////////////////
386 INLINE const NodePath GeoMipTerrain::
387 get_block_node_path(unsigned short mx, unsigned short my) {
388  nassertr(mx < _blocks.size(), NodePath::fail());
389  nassertr(my < _blocks[mx].size(), NodePath::fail());
390  return _blocks[mx][my];
391 }
392 
393 ////////////////////////////////////////////////////////////////////
394 // Function: GeoMipTerrain::get_block_from_pos
395 // Access: Published
396 // Description: Gets the coordinates of the block at the specified
397 // position. This position must be relative to the
398 // terrain, not to render. Returns an array containing
399 // two values: the block x and the block y coords.
400 // If the positions are out of range, the closest
401 // block is taken.
402 // Note that the VecBase returned does not represent
403 // a vector, position, or rotation, but it contains
404 // the block index of the block which you can use
405 // in GeoMipTerrain::get_block_node_path.
406 ////////////////////////////////////////////////////////////////////
408 get_block_from_pos(double x, double y) {
409  if (x < 0) x = 0;
410  if (y < 0) y = 0;
411  if (x > _xsize - 1) x = _xsize - 1;
412  if (y > _ysize - 1) y = _ysize - 1;
413  x = floor(x / _block_size);
414  y = floor(y / _block_size);
415  return LVecBase2(x, y);
416 }
417 ////////////////////////////////////////////////////////////////////
418 // Function: GeoMipTerrain::lod_decide
419 // Access: Private
420 // Description: Calculates the level for the given mipmap.
421 ////////////////////////////////////////////////////////////////////
422 INLINE unsigned short GeoMipTerrain::
423 lod_decide(unsigned short mx, unsigned short my) {
424  PN_stdfloat cx = mx;
425  PN_stdfloat cy = my;
426  cx = (cx * _block_size + _block_size / 2) * _root.get_sx();
427  cy = (cy * _block_size + _block_size / 2) * _root.get_sy();
428  PN_stdfloat d;
429  if (_use_near_far) {
430  d = sqrt(pow(_focal_point.get_x(_root) - cx, 2) +
431  pow(_focal_point.get_y(_root) - cy, 2));
432  if (d < _near) {
433  return 0;
434  } else if (d > _far) {
435  return _max_level;
436  } else {
437  return (unsigned short)((d - _near) / (_far - _near) * _max_level * (1.0 - (_min_level / _max_level)) + _min_level);
438  }
439  } else {
440  if (_factor > 0.0) {
441  d = sqrt(pow(_focal_point.get_x(_root) - cx, 2) +
442  pow(_focal_point.get_y(_root) - cy, 2)) / _factor;
443  } else {
444  d = _max_level;
445  }
446  return short(floor(d));
447  }
448 }
449 
450 ////////////////////////////////////////////////////////////////////
451 // Function: GeoMipTerrain::set_heightfield
452 // Access: Published
453 // Description: Loads the specified heightmap image file into
454 // the heightfield. Returns true if succeeded, or
455 // false if an error has occured.
456 // If the heightmap is not a power of two plus one,
457 // it is scaled up using a gaussian filter.
458 ////////////////////////////////////////////////////////////////////
459 INLINE bool GeoMipTerrain::
460 set_heightfield(const PNMImage &image) {
461  if (image.get_color_space() == CS_sRGB) {
462  // Probably a mistaken metadata setting on the file.
463  grutil_cat.warning()
464  << "Heightfield image is specified to have sRGB color space!\n"
465  "Panda applies gamma correction, which will probably cause "
466  "it to produce incorrect results.\n";
467  }
468 
469  // Before we apply anything, validate the size.
470  if (is_power_of_two(image.get_x_size() - 1) &&
471  is_power_of_two(image.get_y_size() - 1)) {
472  _heightfield = image;
473  _is_dirty = true;
474  _xsize = _heightfield.get_x_size();
475  _ysize = _heightfield.get_y_size();
476  return true;
477  } else {
478  grutil_cat.error()
479  << "Specified image does not have a power-of-two-plus-one size!\n";
480  }
481  return false;
482 }
483 
484 ////////////////////////////////////////////////////////////////////
485 // Function: GeoMipTerrain::set_color_map
486 // Access: Published
487 // Description: Loads the specified image as color map. The next
488 // time generate() is called, the terrain is painted
489 // with this color map using the vertex color column.
490 // Returns a boolean indicating whether the operation
491 // has succeeded.
492 ////////////////////////////////////////////////////////////////////
493 INLINE bool GeoMipTerrain::
494 set_color_map(const Filename &filename, PNMFileType *ftype) {
495  if (_color_map.read(filename, ftype)) {
496  _is_dirty = true;
497  _has_color_map = true;
498  return true;
499  }
500  return false;
501 }
502 
503 INLINE bool GeoMipTerrain::
504 set_color_map(const PNMImage &image) {
505  _color_map.copy_from(image);
506  _is_dirty = true;
507  _has_color_map = true;
508  return true;
509 }
510 
511 INLINE bool GeoMipTerrain::
512 set_color_map(const Texture *tex) {
513  tex->store(_color_map);
514  _is_dirty = true;
515  return true;
516 }
517 
518 INLINE bool GeoMipTerrain::
519 set_color_map(const string &path) {
520  return set_color_map(Filename(path));
521 }
522 
523 ////////////////////////////////////////////////////////////////////
524 // Function: GeoMipTerrain::has_color_map
525 // Access: Published
526 // Description: Returns whether a color map has been set.
527 ////////////////////////////////////////////////////////////////////
528 INLINE bool GeoMipTerrain::
529 has_color_map() const {
530  return _has_color_map;
531 }
532 
533 ////////////////////////////////////////////////////////////////////
534 // Function: GeoMipTerrain::clear_color_map
535 // Access: Published
536 // Description: Clears the color map.
537 ////////////////////////////////////////////////////////////////////
538 INLINE void GeoMipTerrain::
540  if (_has_color_map) {
541  _color_map.clear();
542  _has_color_map = false;
543  }
544 }
545 
546 ////////////////////////////////////////////////////////////////////
547 // Function: GeoMipTerrain::set_border_stitching
548 // Access: Published
549 // Description: If this value is true, the LOD level at the
550 // borders of the terrain will be 0. This is useful
551 // if you have multiple terrains attached and you
552 // want to stitch them together, to fix seams.
553 // This setting also has effect when bruteforce is
554 // enabled, although in that case you are probably
555 // better off with setting the minlevels to the same
556 // value.
557 ////////////////////////////////////////////////////////////////////
558 INLINE void GeoMipTerrain::
559 set_border_stitching(bool stitching) {
560  if (stitching && !_stitching) {
561  _is_dirty = true;
562  }
563  _stitching = stitching;
564 }
565 
566 ////////////////////////////////////////////////////////////////////
567 // Function: GeoMipTerrain::get_stitching
568 // Access: Published
569 // Description: Returns the current stitching setting. False by
570 // default, unless set_stitching has been set.
571 ////////////////////////////////////////////////////////////////////
572 INLINE bool GeoMipTerrain::
574  return _stitching;
575 }
576 
577 ////////////////////////////////////////////////////////////////////
578 // Function: GeoMipTerrain::get_pixel_value
579 // Access: Private
580 // Description: Get the elevation at a certain pixel of the image.
581 // This function does NOT linearly interpolate.
582 // For that, use GeoMipTerrain::get_elevation() instead.
583 ////////////////////////////////////////////////////////////////////
584 INLINE double GeoMipTerrain::
585 get_pixel_value(int x, int y) {
586  x = max(min(x,int(_xsize-1)),0);
587  y = max(min(y,int(_ysize-1)),0);
588  if (_heightfield.is_grayscale()) {
589  return double(_heightfield.get_bright(x, y));
590  } else {
591  return double(_heightfield.get_red(x, y))
592  + double(_heightfield.get_green(x, y)) / 256.0
593  + double(_heightfield.get_blue(x, y)) / 65536.0;
594  }
595 }
596 INLINE double GeoMipTerrain::
597 get_pixel_value(unsigned short mx, unsigned short my, int x, int y) {
598  nassertr_always(mx < (_xsize - 1) / _block_size, false);
599  nassertr_always(my < (_ysize - 1) / _block_size, false);
600  return get_pixel_value(mx * _block_size + x, (_ysize - 1) -
601  (my * _block_size + y));
602 }
603 
604 ////////////////////////////////////////////////////////////////////
605 // Function: GeoMipTerrain::get_normal
606 // Access: Published
607 // Description: Fetches the terrain normal at (x,y), where the input
608 // coordinate is specified in pixels. This ignores the
609 // current LOD level and instead provides an
610 // accurate number.
611 // Terrain scale is NOT taken into account! To get
612 // accurate normals, please divide it by the
613 // terrain scale and normalize it again!
614 ////////////////////////////////////////////////////////////////////
616 get_normal(unsigned short mx, unsigned short my, int x, int y) {
617  nassertr_always(mx < (_xsize - 1) / _block_size, false);
618  nassertr_always(my < (_ysize - 1) / _block_size, false);
619  return get_normal(mx * _block_size + x, (_ysize - 1) -
620  (my * _block_size + y));
621 }
622 
623 ////////////////////////////////////////////////////////////////////
624 // Function: GeoMipTerrain::is_power_of_two
625 // Access: Private
626 // Description: Returns a bool whether the given int i is a
627 // power of two or not.
628 ////////////////////////////////////////////////////////////////////
629 INLINE bool GeoMipTerrain::
630 is_power_of_two(unsigned int i) {
631  return !((i - 1) & i);
632 }
633 
634 ////////////////////////////////////////////////////////////////////
635 // Function: GeoMipTerrain::f_part
636 // Access: Private
637 // Description: Returns the part of the number right of the
638 // floating-point.
639 ////////////////////////////////////////////////////////////////////
640 INLINE float GeoMipTerrain::
641 f_part(float i) {
642  return i - floor(i);
643 }
644 INLINE double GeoMipTerrain::
645 f_part(double i) {
646  return i - floor(i);
647 }
648 
649 ////////////////////////////////////////////////////////////////////
650 // Function: GeoMipTerrain::sfav
651 // Access: Private
652 // Description: Used to calculate vertex numbers. Only to
653 // be used internally.
654 ////////////////////////////////////////////////////////////////////
655 INLINE int GeoMipTerrain::
656 sfav(int n, int powlevel, int mypowlevel) {
657  double t = n - 1;
658  t /= pow(2.0, powlevel - mypowlevel);
659  t = double(int(t > 0.0 ? t + 0.5 : t - 0.5));
660  t *= pow(2.0, powlevel - mypowlevel);
661  return int(t);
662 }
663 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
bool is_dirty()
Returns a bool indicating whether the terrain is marked &#39;dirty&#39;, that means the terrain has to be reg...
void set_factor(PN_stdfloat factor)
DEPRECATED method.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
ColorSpace get_color_space() const
Returns the color space in which the image is encoded.
Definition: pnmImage.I:296
bool read(const Filename &filename, PNMFileType *type=NULL, bool report_unknown_type=true)
Reads the indicated image filename.
Definition: pnmImage.cxx:245
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
float get_blue(int x, int y) const
Returns the blue component color at the indicated pixel.
Definition: pnmImage.I:913
bool set_color_map(const Filename &filename, PNMFileType *type=NULL)
Loads the specified image as color map.
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
const NodePath get_block_node_path(unsigned short mx, unsigned short my)
Returns the NodePath of the specified block.
PNMImage & heightfield()
Returns a reference to the heightfield (a PNMImage) contained inside GeoMipTerrain.
Definition: geoMipTerrain.I:64
unsigned short get_min_level()
Gets the minimum level of detail at which blocks may be generated by generate() or update()...
double get_far()
Returns the far LOD distance in the terrain coordinate space.
bool store(PNMImage &pnmimage) const
Saves the texture to the indicated PNMImage, but does not write it to disk.
Definition: texture.I:472
void set_bruteforce(bool bf)
Sets a boolean specifying whether the terrain will be rendered bruteforce.
Definition: geoMipTerrain.I:90
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a two-component point in space.
Definition: lpoint2.h:424
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
PNMImage & color_map()
Returns a reference to the color map (a PNMImage) contained inside GeoMipTerrain. ...
Definition: geoMipTerrain.I:76
~GeoMipTerrain()
This will not remove the terrain node itself.
Definition: geoMipTerrain.I:53
unsigned short get_block_size()
Gets the block size.
int get_y_size() const
Returns the number of pixels in the Y direction.
int get_x_size() const
Returns the number of pixels in the X direction.
float get_red(int x, int y) const
Returns the red component color at the indicated pixel.
Definition: pnmImage.I:889
double get_near()
Returns the near LOD distance in the terrain coordinate space.
void set_near_far(double input_near, double input_far)
Sets the near and far LOD distances in one call.
bool has_color_map() const
Returns whether a color map has been set.
static NodePath fail()
Creates a NodePath with the ET_fail error type set.
Definition: nodePath.I:185
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
float get_green(int x, int y) const
Returns the green component color at the indicated pixel.
Definition: pnmImage.I:901
bool get_bruteforce()
Returns a boolean whether the terrain is rendered bruteforce or not.
void clear_color_map()
Clears the color map.
unsigned short get_max_level()
Returns the highest level possible for this block size.
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
LVector3 get_normal(int x, int y)
Fetches the terrain normal at (x, y), where the input coordinate is specified in pixels.
bool get_border_stitching()
Returns the current stitching setting.
void set_border_stitching(bool stitching)
If this value is true, the LOD level at the borders of the terrain will be 0.
int get_flatten_mode()
Returns the automatic-flatten mode (e.g., off, flatten_light, flatten_medium, or flatten_strong) ...
bool set_heightfield(const Filename &filename, PNMFileType *type=NULL)
Loads the specified heightmap image file into the heightfield.
void set_near(double input_near)
Sets the near LOD distance, at which the terrain will be rendered at highest quality.
void set_auto_flatten(int mode)
The terrain can be automatically flattened (using flatten_light, flatten_medium, or flatten_strong) a...
void clear()
Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc).
Definition: pnmImage.cxx:50
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
Definition: nodePath.cxx:757
void set_block_size(unsigned short newbs)
Sets the block size.
void set_far(double input_far)
Sets the far LOD distance, at which the terrain will be rendered at lowest quality.
static bool is_grayscale(ColorType color_type)
This static variant of is_grayscale() returns true if the indicated image type represents a grayscale...
void copy_from(const PNMImage &copy)
Makes this image become a copy of the other image.
Definition: pnmImage.cxx:111
This is a two-component point in space.
Definition: lpoint2.h:92
NodePath get_root() const
Returns the root of the terrain.
float get_bright(int x, int y) const
Returns the linear brightness of the given xel, as a linearized float in the range 0...
Definition: pnmImage.I:1020
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
LVecBase2 get_block_from_pos(double x, double y)
Gets the coordinates of the block at the specified position.
void set_min_level(unsigned short minlevel)
Sets the minimum level of detail at which blocks may be generated by generate() or update()...
NodePath get_focal_point() const
Returns the focal point, as a NodePath.