sequenceNode.cxx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #include "pandabase.h"
  15. #include "sequenceNode.h"
  16. #include "cullTraverser.h"
  17. TypeHandle SequenceNode::_type_handle;
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: SequenceNode::Copy Constructor
  20. // Access: Protected
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. SequenceNode::
  24. SequenceNode(const SequenceNode &copy) :
  25. SelectiveChildNode(copy),
  26. AnimInterface(copy)
  27. {
  28. }
  29. ////////////////////////////////////////////////////////////////////
  30. // Function: SequenceNode::get_num_frames
  31. // Access: Published, Virtual
  32. // Description: Returns the number of frames in the animation. This
  33. // is a property of the animation and may not be
  34. // directly adjusted by the user (although it may change
  35. // without warning with certain kinds of animations,
  36. // since this is a virtual method that may be
  37. // overridden).
  38. ////////////////////////////////////////////////////////////////////
  39. int SequenceNode::
  40. get_num_frames() const {
  41. return get_num_children();
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: SequenceNode::safe_to_combine
  45. // Access: Public, Virtual
  46. // Description: Returns true if it is generally safe to combine this
  47. // particular kind of PandaNode with other kinds of
  48. // PandaNodes of compatible type, adding children or
  49. // whatever. For instance, an LODNode should not be
  50. // combined with any other PandaNode, because its set of
  51. // children is meaningful.
  52. ////////////////////////////////////////////////////////////////////
  53. bool SequenceNode::
  54. safe_to_combine() const {
  55. return false;
  56. }
  57. ////////////////////////////////////////////////////////////////////
  58. // Function: SequenceNode::safe_to_combine_children
  59. // Access: Public, Virtual
  60. // Description: Returns true if it is generally safe to combine the
  61. // children of this PandaNode with each other. For
  62. // instance, an LODNode's children should not be
  63. // combined with each other, because the set of children
  64. // is meaningful.
  65. ////////////////////////////////////////////////////////////////////
  66. bool SequenceNode::
  67. safe_to_combine_children() const {
  68. return false;
  69. }
  70. ////////////////////////////////////////////////////////////////////
  71. // Function: SequenceNode::make_copy
  72. // Access: Public, Virtual
  73. // Description: Returns a newly-allocated Node that is a shallow copy
  74. // of this one. It will be a different Node pointer,
  75. // but its internal data may or may not be shared with
  76. // that of the original Node.
  77. ////////////////////////////////////////////////////////////////////
  78. PandaNode *SequenceNode::
  79. make_copy() const {
  80. return new SequenceNode(*this);
  81. }
  82. ////////////////////////////////////////////////////////////////////
  83. // Function: SequenceNode::cull_callback
  84. // Access: Public, Virtual
  85. // Description: This function will be called during the cull
  86. // traversal to perform any additional operations that
  87. // should be performed at cull time. This may include
  88. // additional manipulation of render state or additional
  89. // visible/invisible decisions, or any other arbitrary
  90. // operation.
  91. //
  92. // Note that this function will *not* be called unless
  93. // set_cull_callback() is called in the constructor of
  94. // the derived class. It is necessary to call
  95. // set_cull_callback() to indicated that we require
  96. // cull_callback() to be called.
  97. //
  98. // By the time this function is called, the node has
  99. // already passed the bounding-volume test for the
  100. // viewing frustum, and the node's transform and state
  101. // have already been applied to the indicated
  102. // CullTraverserData object.
  103. //
  104. // The return value is true if this node should be
  105. // visible, or false if it should be culled.
  106. ////////////////////////////////////////////////////////////////////
  107. bool SequenceNode::
  108. cull_callback(CullTraverser *, CullTraverserData &) {
  109. select_child(get_frame());
  110. return true;
  111. }
  112. ////////////////////////////////////////////////////////////////////
  113. // Function: SequenceNode::has_single_child_visibility
  114. // Access: Public, Virtual
  115. // Description: Should be overridden by derived classes to return
  116. // true if this kind of node has the special property
  117. // that just one of its children is visible at any given
  118. // time, and furthermore that the particular visible
  119. // child can be determined without reference to any
  120. // external information (such as a camera). At present,
  121. // only SequenceNodes and SwitchNodes fall into this
  122. // category.
  123. //
  124. // If this function returns true, get_visible_child()
  125. // can be called to return the index of the
  126. // currently-visible child.
  127. ////////////////////////////////////////////////////////////////////
  128. bool SequenceNode::
  129. has_single_child_visibility() const {
  130. return true;
  131. }
  132. ////////////////////////////////////////////////////////////////////
  133. // Function: SequenceNode::output
  134. // Access: Published, Virtual
  135. // Description:
  136. ////////////////////////////////////////////////////////////////////
  137. void SequenceNode::
  138. output(ostream &out) const {
  139. out << get_type() << " " << get_name() << ": ";
  140. AnimInterface::output(out);
  141. }
  142. ////////////////////////////////////////////////////////////////////
  143. // Function: SequenceNode::register_with_read_factory
  144. // Access: Public, Static
  145. // Description: Tells the BamReader how to create objects of type
  146. // SequenceNode.
  147. ////////////////////////////////////////////////////////////////////
  148. void SequenceNode::
  149. register_with_read_factory() {
  150. BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
  151. }
  152. ////////////////////////////////////////////////////////////////////
  153. // Function: SequenceNode::write_datagram
  154. // Access: Public, Virtual
  155. // Description: Writes the contents of this object to the datagram
  156. // for shipping out to a Bam file.
  157. ////////////////////////////////////////////////////////////////////
  158. void SequenceNode::
  159. write_datagram(BamWriter *manager, Datagram &dg) {
  160. SelectiveChildNode::write_datagram(manager, dg);
  161. AnimInterface::write_datagram(manager, dg);
  162. }
  163. ////////////////////////////////////////////////////////////////////
  164. // Function: SequenceNode::make_from_bam
  165. // Access: Protected, Static
  166. // Description: This function is called by the BamReader's factory
  167. // when a new object of type SequenceNode is encountered
  168. // in the Bam file. It should create the SequenceNode
  169. // and extract its information from the file.
  170. ////////////////////////////////////////////////////////////////////
  171. TypedWritable *SequenceNode::
  172. make_from_bam(const FactoryParams &params) {
  173. SequenceNode *node = new SequenceNode("");
  174. DatagramIterator scan;
  175. BamReader *manager;
  176. parse_params(params, scan, manager);
  177. node->fillin(scan, manager);
  178. return node;
  179. }
  180. ////////////////////////////////////////////////////////////////////
  181. // Function: SequenceNode::fillin
  182. // Access: Protected
  183. // Description: This internal function is called by make_from_bam to
  184. // read in all of the relevant data from the BamFile for
  185. // the new SequenceNode.
  186. ////////////////////////////////////////////////////////////////////
  187. void SequenceNode::
  188. fillin(DatagramIterator &scan, BamReader *manager) {
  189. SelectiveChildNode::fillin(scan, manager);
  190. AnimInterface::fillin(scan, manager);
  191. }