Panda3D
Loading...
Searching...
No Matches
sequenceNode.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file sequenceNode.cxx
10 * @author drose
11 * @date 2002-03-06
12 */
13
14#include "pandabase.h"
15#include "sequenceNode.h"
16#include "cullTraverser.h"
17
18TypeHandle SequenceNode::_type_handle;
19
20/**
21 *
22 */
23SequenceNode::
24SequenceNode(const SequenceNode &copy) :
26 AnimInterface(copy)
27{
28}
29
30/**
31 * Returns the number of frames in the animation. This is a property of the
32 * animation and may not be directly adjusted by the user (although it may
33 * change without warning with certain kinds of animations, since this is a
34 * virtual method that may be overridden).
35 */
37get_num_frames() const {
38 return get_num_children();
39}
40
41/**
42 * Returns true if it is generally safe to combine this particular kind of
43 * PandaNode with other kinds of PandaNodes of compatible type, adding
44 * children or whatever. For instance, an LODNode should not be combined with
45 * any other PandaNode, because its set of children is meaningful.
46 */
48safe_to_combine() const {
49 return false;
50}
51
52/**
53 * Returns true if it is generally safe to combine the children of this
54 * PandaNode with each other. For instance, an LODNode's children should not
55 * be combined with each other, because the set of children is meaningful.
56 */
59 return false;
60}
61
62/**
63 * Returns a newly-allocated Node that is a shallow copy of this one. It will
64 * be a different Node pointer, but its internal data may or may not be shared
65 * with that of the original Node.
66 */
68make_copy() const {
69 return new SequenceNode(*this);
70}
71
72/**
73 * This function will be called during the cull traversal to perform any
74 * additional operations that should be performed at cull time. This may
75 * include additional manipulation of render state or additional
76 * visible/invisible decisions, or any other arbitrary operation.
77 *
78 * Note that this function will *not* be called unless set_cull_callback() is
79 * called in the constructor of the derived class. It is necessary to call
80 * set_cull_callback() to indicated that we require cull_callback() to be
81 * called.
82 *
83 * By the time this function is called, the node has already passed the
84 * bounding-volume test for the viewing frustum, and the node's transform and
85 * state have already been applied to the indicated CullTraverserData object.
86 *
87 * The return value is true if this node should be visible, or false if it
88 * should be culled.
89 */
92 select_child(get_frame());
93 return true;
94}
95
96/**
97 * Returns the index number of the first visible child of this node, or a
98 * number >= get_num_children() if there are no visible children of this node.
99 * This is called during the cull traversal, but only if
100 * has_selective_visibility() has already returned true. See
101 * has_selective_visibility().
102 */
105 return get_frame();
106}
107
108/**
109 * Should be overridden by derived classes to return true if this kind of node
110 * has the special property that just one of its children is visible at any
111 * given time, and furthermore that the particular visible child can be
112 * determined without reference to any external information (such as a
113 * camera). At present, only SequenceNodes and SwitchNodes fall into this
114 * category.
115 *
116 * If this function returns true, get_visible_child() can be called to return
117 * the index of the currently-visible child.
118 */
121 return true;
122}
123
124/**
125 * Returns the index number of the currently visible child of this node. This
126 * is only meaningful if has_single_child_visibility() has returned true.
127 */
129get_visible_child() const {
130 return get_frame();
131}
132
133/**
134 *
135 */
136void SequenceNode::
137output(std::ostream &out) const {
138 out << get_type() << " " << get_name() << ": ";
139 AnimInterface::output(out);
140}
141
142/**
143 * Tells the BamReader how to create objects of type SequenceNode.
144 */
147 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
148}
149
150/**
151 * Writes the contents of this object to the datagram for shipping out to a
152 * Bam file.
153 */
155write_datagram(BamWriter *manager, Datagram &dg) {
157 AnimInterface::write_datagram(manager, dg);
158}
159
160/**
161 * This function is called by the BamReader's factory when a new object of
162 * type SequenceNode is encountered in the Bam file. It should create the
163 * SequenceNode and extract its information from the file.
164 */
165TypedWritable *SequenceNode::
166make_from_bam(const FactoryParams &params) {
167 SequenceNode *node = new SequenceNode("");
168 DatagramIterator scan;
169 BamReader *manager;
170
171 parse_params(params, scan, manager);
172 node->fillin(scan, manager);
173
174 return node;
175}
176
177/**
178 * This internal function is called by make_from_bam to read in all of the
179 * relevant data from the BamFile for the new SequenceNode.
180 */
181void SequenceNode::
182fillin(DatagramIterator &scan, BamReader *manager) {
183 SelectiveChildNode::fillin(scan, manager);
184 AnimInterface::fillin(scan, manager);
185}
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
This is the fundamental interface for things that have a play/loop/stop type interface for frame-base...
get_frame
Returns the current integer frame number.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
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 ...
Definition datagram.h:38
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.
Definition factory.I:73
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
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_num_children
Returns the number of child nodes this node has.
Definition pandaNode.h:124
A base class for nodes like LODNode and SequenceNode that select only one visible child at a time.
A node that automatically cycles through rendering each one of its children according to its frame ra...
virtual int get_num_frames() const
Returns the number of frames in the animation.
virtual bool safe_to_combine_children() const
Returns true if it is generally safe to combine the children of this PandaNode with each other.
virtual bool has_single_child_visibility() const
Should be overridden by derived classes to return true if this kind of node has the special property ...
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 int get_first_visible_child() const
Returns the index number of the first visible child of this node, or a number >= get_num_children() i...
virtual int get_visible_child() const
Returns the index number of the currently visible child 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...
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
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 SequenceNode.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
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.