31FadeLODNode(
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;
62 return new FadeLODNode(*
this);
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);
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) {
173 CullTraverserData next_data_out(data, child);
174 next_data_out._state =
175 next_data_out._state->compose(get_fade_1_old_state());
182 if (child !=
nullptr) {
183 CullTraverserData next_data_in(data, child);
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) {
198 CullTraverserData next_data_in(data, child);
199 next_data_in._state =
200 next_data_in._state->compose(get_fade_2_new_state());
207 if (child !=
nullptr) {
208 CullTraverserData next_data_out(data, child);
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) {
228 CullTraverserData next_data(data, child);
244output(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();
280get_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;
293get_fade_1_new_state(PN_stdfloat in_alpha) {
294 if (_fade_1_new_state ==
nullptr) {
299 _fade_state_override);
302 LVecBase4 alpha_scale(1.0f, 1.0f, 1.0f, in_alpha);
303 return _fade_1_new_state->compose
312get_fade_2_old_state(PN_stdfloat out_alpha) {
313 if (_fade_2_old_state ==
nullptr) {
318 _fade_state_override);
321 LVecBase4 alpha_scale(1.0f, 1.0f, 1.0f, out_alpha);
322 return _fade_2_old_state->compose
331get_fade_2_new_state() {
332 if (_fade_2_new_state ==
nullptr) {
335 _fade_state_override);
338 return _fade_2_new_state;
370 node->fillin(scan, manager);
381 LODNode::fillin(scan, manager);
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void set_last_render_time(double render_time)
Should be called with the current frame_time each time the AuxSceneData is used during traversal.
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...
double get_last_render_time() const
Returns the last time this object was used during traversal (according to set_last_render_time()).
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
set_aux_scene_data
Associates the indicated AuxSceneData object with the given NodePath, possibly replacing a previous d...
get_aux_scene_data
Returns the AuxSceneData associated with the indicated NodePath, or NULL if nothing is associated.
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
static ConstPointerTo< RenderAttrib > make(const LVecBase4 &scale)
Constructs a new ColorScaleAttrib object that indicates geometry should be scaled by the indicated fa...
static ConstPointerTo< RenderAttrib > make(const std::string &bin_name, int draw_order)
Constructs a new CullBinAttrib assigning geometry into the named bin.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
SceneSetup * get_scene() const
Returns the SceneSetup object.
void traverse(const NodePath &root)
Begins the traversal from the indicated node.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
static ConstPointerTo< RenderAttrib > make(int offset=1)
Constructs a new DepthOffsetAttrib object that indicates the relative amount of bias to write to the ...
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new DepthWriteAttrib object.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
This is the data that is associated with a particular instance of the FadeLODNode for the scene graph...
A Level-of-Detail node with alpha based switching.
set_fade_state_override
Specifies the override value that is applied to the state changes necessary to apply the fade effect.
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
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...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
static void register_with_read_factory()
Tells the BamReader how to create objects of type LODNode.
get_out
Returns the "out" distance of the indicated switch range.
bool is_any_shown() const
Returns true if any switch has been shown with show_switch(), indicating the LODNode is in debug show...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
get_child
Returns the nth child node of this node.
get_num_children
Returns the number of child nodes this node has.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
static ConstPointerTo< RenderState > make(const RenderAttrib *attrib, int override=0)
Returns a RenderState with one attribute set.
Camera * get_camera_node() const
Returns the camera used to render the scene.
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new TransparencyAttrib object.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.