sequenceNode.cxx 8.5 KB

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