31 FadeLODNode(
const std::string &name) :
36 _fade_time = lod_fade_time;
37 _fade_bin_name = lod_fade_bin_name;
38 _fade_bin_draw_order = lod_fade_bin_draw_order;
39 _fade_state_override = lod_fade_state_override;
49 _fade_time = copy._fade_time;
50 _fade_bin_name = copy._fade_bin_name;
51 _fade_bin_draw_order = copy._fade_bin_draw_order;
52 _fade_state_override = copy._fade_state_override;
85 if (!support_fade_lod) {
90 return show_switches_cull_callback(trav, data);
93 consider_verify_lods(trav, data);
96 NodePath this_np = data.get_node_path();
106 ldata->_fade_mode = FadeLODNodeData::FM_solid;
107 ldata->_fade_out = -1;
108 ldata->_fade_in = compute_child(trav, data);
109 camera->set_aux_scene_data(this_np, ldata);
115 if (ldata->_fade_mode == FadeLODNodeData::FM_solid) {
118 int index = compute_child(trav, data);
119 if (index != ldata->_fade_in) {
121 if (index >= 0 && ldata->_fade_in >= 0 &&
125 ldata->_fade_mode = FadeLODNodeData::FM_less_detail;
129 ldata->_fade_mode = FadeLODNodeData::FM_more_detail;
136 ldata->_fade_out = ldata->_fade_in;
137 ldata->_fade_in = index;
141 if (ldata->_fade_mode != FadeLODNodeData::FM_solid) {
144 PN_stdfloat elapsed = now - ldata->_fade_start;
146 if (elapsed >= _fade_time) {
148 ldata->_fade_mode = FadeLODNodeData::FM_solid;
151 PN_stdfloat half_fade_time = _fade_time * 0.5f;
153 int in_child = ldata->_fade_in;
154 int out_child = ldata->_fade_out;
156 if (ldata->_fade_mode == FadeLODNodeData::FM_less_detail) {
159 elapsed = _fade_time - elapsed;
161 in_child = out_child;
165 nassertr(elapsed >= 0.0f && elapsed <= _fade_time,
false);
167 if (elapsed < half_fade_time) {
172 if (child !=
nullptr) {
174 next_data_out._state =
175 next_data_out._state->compose(get_fade_1_old_state());
182 if (child !=
nullptr) {
185 PN_stdfloat in_alpha = elapsed / half_fade_time;
186 next_data_in._state =
187 next_data_in._state->compose(get_fade_1_new_state(in_alpha));
197 if (child !=
nullptr) {
199 next_data_in._state =
200 next_data_in._state->compose(get_fade_2_new_state());
207 if (child !=
nullptr) {
210 PN_stdfloat out_alpha = 1.0f - (elapsed - half_fade_time) / half_fade_time;
211 next_data_out._state =
212 next_data_out._state->compose(get_fade_2_old_state(out_alpha));
221 if (ldata->_fade_mode == FadeLODNodeData::FM_solid) {
224 int index = ldata->_fade_in;
227 if (child !=
nullptr) {
244 output(std::ostream &out)
const {
245 LODNode::output(out);
246 out <<
" fade time: " << _fade_time;
255 _fade_bin_name = name;
256 _fade_bin_draw_order = draw_order;
257 _fade_1_new_state.clear();
258 _fade_2_old_state.clear();
268 _fade_state_override =
override;
269 _fade_1_old_state.clear();
270 _fade_1_new_state.clear();
271 _fade_2_old_state.clear();
272 _fade_2_new_state.clear();
280 get_fade_1_old_state() {
281 if (_fade_1_old_state ==
nullptr) {
282 _fade_1_old_state = RenderState::make_empty();
285 return _fade_1_old_state;
293 get_fade_1_new_state(PN_stdfloat in_alpha) {
294 if (_fade_1_new_state ==
nullptr) {
295 _fade_1_new_state = RenderState::make
296 (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
297 CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
298 DepthOffsetAttrib::make(),
299 _fade_state_override);
302 LVecBase4 alpha_scale(1.0f, 1.0f, 1.0f, in_alpha);
303 return _fade_1_new_state->compose
304 (RenderState::make(ColorScaleAttrib::make(alpha_scale)));
312 get_fade_2_old_state(PN_stdfloat out_alpha) {
313 if (_fade_2_old_state ==
nullptr) {
314 _fade_2_old_state = RenderState::make
315 (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
316 DepthWriteAttrib::make(DepthWriteAttrib::M_off),
317 CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
318 _fade_state_override);
321 LVecBase4 alpha_scale(1.0f, 1.0f, 1.0f, out_alpha);
322 return _fade_2_old_state->compose
323 (RenderState::make(ColorScaleAttrib::make(alpha_scale)));
331 get_fade_2_new_state() {
332 if (_fade_2_new_state ==
nullptr) {
333 _fade_2_new_state = RenderState::make
334 (DepthOffsetAttrib::make(),
335 _fade_state_override);
338 return _fade_2_new_state;
370 node->fillin(scan, manager);
381 LODNode::fillin(scan, manager);
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Base class for objects that can be written to and read from Bam files.
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 ...
set_fade_state_override
Specifies the override value that is applied to the state changes necessary to apply the fade effect.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
CPT(RenderState) FadeLODNode
Returns a RenderState for rendering the old element during first half of fade.
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 std::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...
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
get_num_children
Returns the number of child nodes this node has.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Camera * get_camera_node() const
Returns the camera used to render the scene.
get_aux_scene_data
Returns the AuxSceneData associated with the indicated NodePath, or NULL if nothing is associated.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SceneSetup * get_scene() const
Returns the SceneSetup object.
A class to retrieve the individual data elements previously stored in a Datagram.
get_child
Returns the nth child node of this node.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_out
Returns the "out" distance of the indicated switch range.
static void register_with_read_factory()
Tells the BamReader how to create objects of type LODNode.