15 #include "fadeLodNode.h" 16 #include "fadeLodNodeData.h" 17 #include "cullTraverserData.h" 18 #include "cullTraverser.h" 19 #include "clockObject.h" 20 #include "colorScaleAttrib.h" 21 #include "depthWriteAttrib.h" 22 #include "transparencyAttrib.h" 23 #include "cullBinAttrib.h" 24 #include "depthOffsetAttrib.h" 34 FadeLODNode(
const string &name) :
39 _fade_time = lod_fade_time;
40 _fade_bin_name = lod_fade_bin_name;
41 _fade_bin_draw_order = lod_fade_bin_draw_order;
42 _fade_state_override = lod_fade_state_override;
54 _fade_time = copy._fade_time;
55 _fade_bin_name = copy._fade_bin_name;
56 _fade_bin_draw_order = copy._fade_bin_draw_order;
57 _fade_state_override = copy._fade_state_override;
100 if (!support_fade_lod) {
105 return show_switches_cull_callback(trav, data);
108 consider_verify_lods(trav, data);
121 ldata->_fade_mode = FadeLODNodeData::FM_solid;
122 ldata->_fade_out = -1;
123 ldata->_fade_in = compute_child(trav, data);
124 camera->set_aux_scene_data(this_np, ldata);
130 if (ldata->_fade_mode == FadeLODNodeData::FM_solid) {
133 int index = compute_child(trav, data);
134 if (index != ldata->_fade_in) {
136 if (index >= 0 && ldata->_fade_in >= 0 &&
140 ldata->_fade_mode = FadeLODNodeData::FM_less_detail;
144 ldata->_fade_mode = FadeLODNodeData::FM_more_detail;
152 ldata->_fade_out = ldata->_fade_in;
153 ldata->_fade_in = index;
157 if (ldata->_fade_mode != FadeLODNodeData::FM_solid) {
160 PN_stdfloat elapsed = now - ldata->_fade_start;
162 if (elapsed >= _fade_time) {
164 ldata->_fade_mode = FadeLODNodeData::FM_solid;
167 PN_stdfloat half_fade_time = _fade_time * 0.5f;
169 int in_child = ldata->_fade_in;
170 int out_child = ldata->_fade_out;
172 if (ldata->_fade_mode == FadeLODNodeData::FM_less_detail) {
176 elapsed = _fade_time - elapsed;
178 in_child = out_child;
182 nassertr(elapsed >= 0.0f && elapsed <= _fade_time,
false);
184 if (elapsed < half_fade_time) {
192 next_data_out._state =
193 next_data_out._state->compose(get_fade_1_old_state());
203 PN_stdfloat in_alpha = elapsed / half_fade_time;
204 next_data_in._state =
205 next_data_in._state->compose(get_fade_1_new_state(in_alpha));
218 next_data_in._state =
219 next_data_in._state->compose(get_fade_2_new_state());
229 PN_stdfloat out_alpha = 1.0f - (elapsed - half_fade_time) / half_fade_time;
230 next_data_out._state =
231 next_data_out._state->compose(get_fade_2_old_state(out_alpha));
240 if (ldata->_fade_mode == FadeLODNodeData::FM_solid) {
243 int index = ldata->_fade_in;
265 output(ostream &out)
const {
266 LODNode::output(out);
267 out <<
" fade time: " << _fade_time;
279 _fade_bin_name = name;
280 _fade_bin_draw_order = draw_order;
281 _fade_1_new_state.clear();
282 _fade_2_old_state.clear();
295 _fade_state_override =
override;
296 _fade_1_old_state.clear();
297 _fade_1_new_state.clear();
298 _fade_2_old_state.clear();
299 _fade_2_new_state.clear();
309 get_fade_1_old_state() {
310 if (_fade_1_old_state == (
const RenderState *)NULL) {
311 _fade_1_old_state = RenderState::make_empty();
314 return _fade_1_old_state;
324 get_fade_1_new_state(PN_stdfloat in_alpha) {
325 if (_fade_1_new_state == (
const RenderState *)NULL) {
326 _fade_1_new_state = RenderState::make
327 (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
328 CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
329 DepthOffsetAttrib::make(),
330 _fade_state_override);
333 LVecBase4 alpha_scale(1.0f, 1.0f, 1.0f, in_alpha);
334 return _fade_1_new_state->compose
335 (RenderState::make(ColorScaleAttrib::make(alpha_scale)));
345 get_fade_2_old_state(PN_stdfloat out_alpha) {
346 if (_fade_2_old_state == (
const RenderState *)NULL) {
347 _fade_2_old_state = RenderState::make
348 (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
349 DepthWriteAttrib::make(DepthWriteAttrib::M_off),
350 CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
351 _fade_state_override);
354 LVecBase4 alpha_scale(1.0f, 1.0f, 1.0f, out_alpha);
355 return _fade_2_old_state->compose
356 (RenderState::make(ColorScaleAttrib::make(alpha_scale)));
366 get_fade_2_new_state() {
367 if (_fade_2_new_state == (
const RenderState *)NULL) {
368 _fade_2_new_state = RenderState::make
369 (DepthOffsetAttrib::make(),
370 _fade_state_override);
373 return _fade_2_new_state;
412 parse_params(params, scan, manager);
413 node->fillin(scan, manager);
427 LODNode::fillin(scan, manager);
This is a base class for a generic data structure that can be attached per-instance to the camera...
This is the data that is associated with a particular instance of the FadeLODNode for the scene graph...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
A basic node of the scene graph or data graph.
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
double get_expiration_time() const
Returns the frame_time at which this AuxSceneData object is currently scheduled to be removed from th...
void set_duration(double duration)
Specifies the minimum length in time, in seconds, to keep this AuxSceneData object around in the scen...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
int get_num_children(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of child nodes this node has.
Base class for objects that can be written to and read from Bam files.
PandaNode * get_child(int n, Thread *current_thread=Thread::get_current_thread()) const
Returns the nth child node of this node.
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PN_stdfloat get_out(int index) const
Returns the "out" distance of the indicated switch range.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
void traverse(const NodePath &root)
Begins the traversal from the indicated node.
double get_last_render_time() const
Returns the last time this object was used during traversal (according to set_last_render_time()).
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
void set_fade_bin(const string &name, int draw_order)
Specifies the cull bin and draw order that is assigned to the fading part of the geometry during a tr...
A Level-of-Detail node with alpha based switching.
void set_last_render_time(double render_time)
Should be called with the current frame_time each time the AuxSceneData is used during traversal...
NodePath get_node_path() const
Constructs and returns an actual NodePath that represents the same path we have just traversed...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Camera * get_camera_node() const
Returns the camera used to render the scene.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void set_fade_state_override(int override)
Specifies the override value that is applied to the state changes necessary to apply the fade effect...
AuxSceneData * get_aux_scene_data(const NodePath &node_path) const
Returns the AuxSceneData associated with the indicated NodePath, or NULL if nothing is associated...
This is the base class for all three-component vectors and points.
bool is_any_shown() const
Returns true if any switch has been shown with show_switch(), indicating the LODNode is in debug show...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
SceneSetup * get_scene() const
Returns the SceneSetup object.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
static void register_with_read_factory()
Tells the BamReader how to create objects of type LODNode.