forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlodNode.I
More file actions
523 lines (474 loc) · 17.8 KB
/
lodNode.I
File metadata and controls
523 lines (474 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
// Filename: lodNode.I
// Created by: drose (06Mar02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: LODNode::Constructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE LODNode::
LODNode(const string &name) :
PandaNode(name)
{
set_cull_callback();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Copy Constructor
// Access: Protected
// Description:
////////////////////////////////////////////////////////////////////
INLINE LODNode::
LODNode(const LODNode ©) :
PandaNode(copy),
_cycler(copy._cycler)
{
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::add_switch
// Access: Published
// Description: Adds a switch range to the LODNode. This implies
// that the corresponding child node has been parented
// to the node.
//
// The sense of in vs. out distances is as if the object
// were coming towards you from far away: it switches
// "in" at the far distance, and switches "out" at the
// close distance. Thus, "in" should be larger than
// "out".
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
add_switch(PN_stdfloat in, PN_stdfloat out) {
nassertv(in >= out);
CDWriter cdata(_cycler);
cdata->_switch_vector.push_back(Switch(in, out));
cdata->check_limits();
if (cdata->_num_shown != 0) {
mark_internal_bounds_stale();
}
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::set_switch
// Access: Published
// Description: Changes the switching range of a particular child of
// the LODNode. See add_switch().
////////////////////////////////////////////////////////////////////
INLINE bool LODNode::
set_switch(int index, PN_stdfloat in, PN_stdfloat out) {
nassertr(in >= out, false);
CDWriter cdata(_cycler);
nassertr(index >= 0 && index < (int)cdata->_switch_vector.size(), false);
cdata->_switch_vector[index].set_range(in, out);
cdata->check_limits();
if (cdata->_num_shown != 0) {
mark_internal_bounds_stale();
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::clear_switches
// Access: Published
// Description: Removes the set of switching ranges for the LODNode,
// presumably in conjunction with removing all of its
// children. See add_switch().
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
clear_switches() {
CDWriter cdata(_cycler);
cdata->_switch_vector.clear();
cdata->_lowest = 0;
cdata->_highest = 0;
if (cdata->_num_shown != 0) {
mark_internal_bounds_stale();
}
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_num_switches
// Access: Published
// Description: Returns the number of switch ranges added to the
// LODNode. This should correspond to the number of
// children of the node in order for the LODNode to
// function correctly.
////////////////////////////////////////////////////////////////////
INLINE int LODNode::
get_num_switches() const {
CDReader cdata(_cycler);
return cdata->_switch_vector.size();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_lod_scale
// Access: Published
// Description: Returns the multiplier for lod distances
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat LODNode::
get_lod_scale() const {
CDReader cdata(_cycler);
return cdata->_lod_scale;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::set_lod_scale
// Access: Published
// Description: Sets the multiplier for lod distances. A higher
// value means you'll see farther switchs than normal
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
set_lod_scale(PN_stdfloat value) {
CDWriter cdata(_cycler);
cdata->_lod_scale = value;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_in
// Access: Published
// Description: Returns the "in" distance of the indicated switch
// range. This should be larger than the "out" distance
// of the same range.
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat LODNode::
get_in(int index) const {
CDReader cdata(_cycler);
nassertr(index >= 0 && index < (int)cdata->_switch_vector.size(), 0.0);
return cdata->_switch_vector[index].get_in();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_out
// Access: Published
// Description: Returns the "out" distance of the indicated switch
// range. This should be smaller than the "in" distance
// of the same range.
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat LODNode::
get_out(int index) const {
CDReader cdata(_cycler);
nassertr(index >= 0 && index < (int)cdata->_switch_vector.size(), 0.0);
return cdata->_switch_vector[index].get_out();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_lowest_switch
// Access: Published
// Description: Returns the index number of the child with the lowest
// level of detail; that is, the one that is designed to
// be seen from the farthest away. This is usually the
// first child, but it is not necessarily so.
////////////////////////////////////////////////////////////////////
INLINE int LODNode::
get_lowest_switch() const {
CDReader cdata(_cycler);
return cdata->_lowest;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_highest_switch
// Access: Published
// Description: Returns the index number of the child with the highest
// level of detail; that is, the one that is designed to
// be seen from the closest to the camera. This is
// usually the last child, but it is not necessarily so.
////////////////////////////////////////////////////////////////////
INLINE int LODNode::
get_highest_switch() const {
CDReader cdata(_cycler);
return cdata->_highest;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::force_switch
// Access: Published
// Description: Forces the LODNode to show the indicated level
// instead of the level that would normally be shown
// based on the distance from the camera.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
force_switch(int index) {
CDWriter cdata(_cycler);
cdata->_force_switch = index;
cdata->_got_force_switch = true;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::clear_force_switch
// Access: Published
// Description: Undoes the effect of a previous call to
// force_switch() and releases the LODNode to once again
// display the normal level.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
clear_force_switch() {
CDWriter cdata(_cycler);
cdata->_got_force_switch = false;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::set_center
// Access: Published
// Description: Specifies the center of the LOD. This is the point
// that is compared to the camera (in camera space) to
// determine the particular LOD that should be chosen.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
set_center(const LPoint3 ¢er) {
CDWriter cdata(_cycler);
cdata->_center = center;
if (cdata->_num_shown != 0) {
mark_internal_bounds_stale();
}
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::get_center
// Access: Published
// Description: Returns the center of the LOD. This is the point
// that is compared to the camera (in camera space) to
// determine the particular LOD that should be chosen.
////////////////////////////////////////////////////////////////////
INLINE const LPoint3 &LODNode::
get_center() const {
CDReader cdata(_cycler);
return cdata->_center;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::is_any_shown
// Access: Published
// Description: Returns true if any switch has been shown with
// show_switch(), indicating the LODNode is in debug
// show mode; or false if it is in the normal mode.
////////////////////////////////////////////////////////////////////
INLINE bool LODNode::
is_any_shown() const {
CDReader cdata(_cycler);
return (cdata->_num_shown != 0);
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::consider_verify_lods
// Access: Protected
// Description: To be called internally when the node is rendered,
// this will raise an assertion if verify-lods is
// configured true, and verify_child_bounds() returns
// false.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::
consider_verify_lods(CullTraverser *trav, CullTraverserData &data) {
#ifndef NDEBUG
if (verify_lods) {
do_auto_verify_lods(trav, data);
}
#endif // NDEBUG
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::CData::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE LODNode::CData::
CData() :
_center(0.0f, 0.0f, 0.0f),
_lowest(0),
_highest(0),
_got_force_switch(false),
_force_switch(0),
_num_shown(0),
_lod_scale(1)
{
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::CData::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE LODNode::CData::
CData(const LODNode::CData ©) :
_center(copy._center),
_switch_vector(copy._switch_vector),
_lowest(copy._lowest),
_highest(copy._highest),
_bounds_seq(UpdateSeq::old()),
_got_force_switch(copy._got_force_switch),
_force_switch(copy._force_switch),
_num_shown(copy._num_shown),
_lod_scale(copy._lod_scale)
{
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE LODNode::Switch::
Switch(PN_stdfloat in, PN_stdfloat out) :
_shown(false),
_bounds_seq(UpdateSeq::old()),
_verify_ok(false)
{
set_range(in, out);
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::get_in
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat LODNode::Switch::
get_in() const {
return _in;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::get_out
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat LODNode::Switch::
get_out() const {
return _out;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::set_range
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
set_range(PN_stdfloat in, PN_stdfloat out) {
_in = in;
_out = out;
clear_ring_viz();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::in_range
// Access: Public
// Description: Returns true if the indicated distance is within the
// range for the LOD.
////////////////////////////////////////////////////////////////////
INLINE bool LODNode::Switch::
in_range(PN_stdfloat dist) const {
return (dist >= _out && dist < _in);
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::in_range_2
// Access: Public
// Description: Returns true if the indicated distance squared is
// within the range for the LOD. (The distance value is
// understood to be the square of the distance from the
// camera to the object.)
////////////////////////////////////////////////////////////////////
INLINE bool LODNode::Switch::
in_range_2(PN_stdfloat dist2) const {
return (dist2 >= _out * _out && dist2 < _in * _in);
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::rescale
// Access: Public
// Description: Scales the switching distances by the indicated factor.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
rescale(PN_stdfloat factor) {
_in *= factor;
_out *= factor;
clear_ring_viz();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::is_shown
// Access: Public
// Description: Returns true if show() has been called.
////////////////////////////////////////////////////////////////////
INLINE bool LODNode::Switch::
is_shown() const {
return _shown;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::show
// Access: Public
// Description: Shows this ring in debug mode using the indicated
// color.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
show(const LColor &color) {
_shown = true;
_show_color = color;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::hide
// Access: Public
// Description: Undoes a previous call to show().
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
hide() {
_shown = false;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::get_ring_viz
// Access: Public
// Description: Returns a PandaNode suitable for rendering the ring
// associated with this switch.
////////////////////////////////////////////////////////////////////
INLINE PandaNode *LODNode::Switch::
get_ring_viz() const {
if (_ring_viz.is_null()) {
((Switch *)this)->compute_ring_viz();
}
return _ring_viz;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::get_spindle_viz
// Access: Public
// Description: Returns a PandaNode suitable for rendering the center
// spindle of the LODNode, in the color of this switch.
////////////////////////////////////////////////////////////////////
INLINE PandaNode *LODNode::Switch::
get_spindle_viz() const {
if (_spindle_viz.is_null()) {
((Switch *)this)->compute_spindle_viz();
}
return _spindle_viz;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::get_viz_model_state
// Access: Public
// Description: Returns a RenderState suitable for drawing the
// visible children of this switch level when the
// show_switch() debugging mode is enabled.
////////////////////////////////////////////////////////////////////
INLINE const RenderState *LODNode::Switch::
get_viz_model_state() const {
if (_viz_model_state.is_null()) {
((Switch *)this)->compute_viz_model_state();
}
return _viz_model_state;
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::write_datagram
// Access: Public
// Description: Writes the contents of the Switch out to the
// datagram, presumably in preparation to writing to a
// Bam file.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
write_datagram(Datagram &destination) const {
destination.add_stdfloat(_in);
destination.add_stdfloat(_out);
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::read_datagram
// Access: Public
// Description: Reads the contents of the Switch from the datagram,
// presumably in response to reading a Bam file.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
read_datagram(DatagramIterator &source) {
_in = source.get_stdfloat();
_out = source.get_stdfloat();
}
////////////////////////////////////////////////////////////////////
// Function: LODNode::Switch::clear_ring_viz
// Access: Private
// Description: Resets the internal cache values for the ring and
// spindle viz, and related pointers, for the
// set_switch() debugging mode.
////////////////////////////////////////////////////////////////////
INLINE void LODNode::Switch::
clear_ring_viz() {
_ring_viz.clear();
_spindle_viz.clear();
_viz_model_state.clear();
_bounds_seq = UpdateSeq::old();
}