Panda3D
 All Classes Functions Variables Enumerations
sequenceNode.cxx
1 // Filename: sequenceNode.cxx
2 // Created by: drose (06Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pandabase.h"
16 #include "sequenceNode.h"
17 #include "cullTraverser.h"
18 
19 TypeHandle SequenceNode::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: SequenceNode::Copy Constructor
23 // Access: Protected
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 SequenceNode::
27 SequenceNode(const SequenceNode &copy) :
28  SelectiveChildNode(copy),
29  AnimInterface(copy)
30 {
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: SequenceNode::get_num_frames
35 // Access: Published, Virtual
36 // Description: Returns the number of frames in the animation. This
37 // is a property of the animation and may not be
38 // directly adjusted by the user (although it may change
39 // without warning with certain kinds of animations,
40 // since this is a virtual method that may be
41 // overridden).
42 ////////////////////////////////////////////////////////////////////
44 get_num_frames() const {
45  return get_num_children();
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: SequenceNode::safe_to_combine
50 // Access: Public, Virtual
51 // Description: Returns true if it is generally safe to combine this
52 // particular kind of PandaNode with other kinds of
53 // PandaNodes of compatible type, adding children or
54 // whatever. For instance, an LODNode should not be
55 // combined with any other PandaNode, because its set of
56 // children is meaningful.
57 ////////////////////////////////////////////////////////////////////
58 bool SequenceNode::
59 safe_to_combine() const {
60  return false;
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: SequenceNode::safe_to_combine_children
65 // Access: Public, Virtual
66 // Description: Returns true if it is generally safe to combine the
67 // children of this PandaNode with each other. For
68 // instance, an LODNode's children should not be
69 // combined with each other, because the set of children
70 // is meaningful.
71 ////////////////////////////////////////////////////////////////////
72 bool SequenceNode::
74  return false;
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: SequenceNode::make_copy
79 // Access: Public, Virtual
80 // Description: Returns a newly-allocated Node that is a shallow copy
81 // of this one. It will be a different Node pointer,
82 // but its internal data may or may not be shared with
83 // that of the original Node.
84 ////////////////////////////////////////////////////////////////////
86 make_copy() const {
87  return new SequenceNode(*this);
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: SequenceNode::cull_callback
92 // Access: Public, Virtual
93 // Description: This function will be called during the cull
94 // traversal to perform any additional operations that
95 // should be performed at cull time. This may include
96 // additional manipulation of render state or additional
97 // visible/invisible decisions, or any other arbitrary
98 // operation.
99 //
100 // Note that this function will *not* be called unless
101 // set_cull_callback() is called in the constructor of
102 // the derived class. It is necessary to call
103 // set_cull_callback() to indicated that we require
104 // cull_callback() to be called.
105 //
106 // By the time this function is called, the node has
107 // already passed the bounding-volume test for the
108 // viewing frustum, and the node's transform and state
109 // have already been applied to the indicated
110 // CullTraverserData object.
111 //
112 // The return value is true if this node should be
113 // visible, or false if it should be culled.
114 ////////////////////////////////////////////////////////////////////
115 bool SequenceNode::
117  select_child(get_frame());
118  return true;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: SequenceNode::get_first_visible_child
123 // Access: Public, Virtual
124 // Description: Returns the index number of the first visible child
125 // of this node, or a number >= get_num_children() if
126 // there are no visible children of this node. This is
127 // called during the cull traversal, but only if
128 // has_selective_visibility() has already returned true.
129 // See has_selective_visibility().
130 ////////////////////////////////////////////////////////////////////
131 int SequenceNode::
133  return get_frame();
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: SequenceNode::has_single_child_visibility
138 // Access: Public, Virtual
139 // Description: Should be overridden by derived classes to return
140 // true if this kind of node has the special property
141 // that just one of its children is visible at any given
142 // time, and furthermore that the particular visible
143 // child can be determined without reference to any
144 // external information (such as a camera). At present,
145 // only SequenceNodes and SwitchNodes fall into this
146 // category.
147 //
148 // If this function returns true, get_visible_child()
149 // can be called to return the index of the
150 // currently-visible child.
151 ////////////////////////////////////////////////////////////////////
152 bool SequenceNode::
154  return true;
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: SequenceNode::get_visible_child
159 // Access: Public, Virtual
160 // Description: Returns the index number of the currently visible
161 // child of this node. This is only meaningful if
162 // has_single_child_visibility() has returned true.
163 ////////////////////////////////////////////////////////////////////
164 int SequenceNode::
166  return get_frame();
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: SequenceNode::output
171 // Access: Published, Virtual
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 void SequenceNode::
175 output(ostream &out) const {
176  out << get_type() << " " << get_name() << ": ";
177  AnimInterface::output(out);
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: SequenceNode::register_with_read_factory
182 // Access: Public, Static
183 // Description: Tells the BamReader how to create objects of type
184 // SequenceNode.
185 ////////////////////////////////////////////////////////////////////
186 void SequenceNode::
188  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: SequenceNode::write_datagram
193 // Access: Public, Virtual
194 // Description: Writes the contents of this object to the datagram
195 // for shipping out to a Bam file.
196 ////////////////////////////////////////////////////////////////////
197 void SequenceNode::
200  AnimInterface::write_datagram(manager, dg);
201 }
202 
203 ////////////////////////////////////////////////////////////////////
204 // Function: SequenceNode::make_from_bam
205 // Access: Protected, Static
206 // Description: This function is called by the BamReader's factory
207 // when a new object of type SequenceNode is encountered
208 // in the Bam file. It should create the SequenceNode
209 // and extract its information from the file.
210 ////////////////////////////////////////////////////////////////////
211 TypedWritable *SequenceNode::
212 make_from_bam(const FactoryParams &params) {
213  SequenceNode *node = new SequenceNode("");
214  DatagramIterator scan;
215  BamReader *manager;
216 
217  parse_params(params, scan, manager);
218  node->fillin(scan, manager);
219 
220  return node;
221 }
222 
223 ////////////////////////////////////////////////////////////////////
224 // Function: SequenceNode::fillin
225 // Access: Protected
226 // Description: This internal function is called by make_from_bam to
227 // read in all of the relevant data from the BamFile for
228 // the new SequenceNode.
229 ////////////////////////////////////////////////////////////////////
230 void SequenceNode::
231 fillin(DatagramIterator &scan, BamReader *manager) {
232  SelectiveChildNode::fillin(scan, manager);
233  AnimInterface::fillin(scan, manager);
234 }
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
static void register_with_read_factory()
Tells the BamReader how to create objects of type SequenceNode.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:4164
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual int get_num_frames() const
Returns the number of frames in the animation.
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
A node that automatically cycles through rendering each one of its children according to its frame ra...
Definition: sequenceNode.h:29
A base class for nodes like LODNode and SequenceNode that select only one visible child at a time...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is the fundamental interface for things that have a play/loop/stop type interface for frame-base...
Definition: animInterface.h:39
virtual int get_visible_child() const
Returns the index number of the currently visible child of this node.
int get_frame() const
Returns the current integer frame number.
virtual int get_first_visible_child() const
Returns the index number of the first visible child of this node, or a number &gt;= get_num_children() i...
int get_num_children(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of child nodes this node has.
Definition: pandaNode.I:68
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
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 ...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.