00001 // Filename: sequenceNode.cxx 00002 // Created by: drose (06Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "pandabase.h" 00016 #include "sequenceNode.h" 00017 #include "cullTraverser.h" 00018 00019 TypeHandle SequenceNode::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: SequenceNode::Copy Constructor 00023 // Access: Protected 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 SequenceNode:: 00027 SequenceNode(const SequenceNode ©) : 00028 SelectiveChildNode(copy), 00029 AnimInterface(copy) 00030 { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: SequenceNode::get_num_frames 00035 // Access: Published, Virtual 00036 // Description: Returns the number of frames in the animation. This 00037 // is a property of the animation and may not be 00038 // directly adjusted by the user (although it may change 00039 // without warning with certain kinds of animations, 00040 // since this is a virtual method that may be 00041 // overridden). 00042 //////////////////////////////////////////////////////////////////// 00043 int SequenceNode:: 00044 get_num_frames() const { 00045 return get_num_children(); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: SequenceNode::safe_to_combine 00050 // Access: Public, Virtual 00051 // Description: Returns true if it is generally safe to combine this 00052 // particular kind of PandaNode with other kinds of 00053 // PandaNodes of compatible type, adding children or 00054 // whatever. For instance, an LODNode should not be 00055 // combined with any other PandaNode, because its set of 00056 // children is meaningful. 00057 //////////////////////////////////////////////////////////////////// 00058 bool SequenceNode:: 00059 safe_to_combine() const { 00060 return false; 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: SequenceNode::safe_to_combine_children 00065 // Access: Public, Virtual 00066 // Description: Returns true if it is generally safe to combine the 00067 // children of this PandaNode with each other. For 00068 // instance, an LODNode's children should not be 00069 // combined with each other, because the set of children 00070 // is meaningful. 00071 //////////////////////////////////////////////////////////////////// 00072 bool SequenceNode:: 00073 safe_to_combine_children() const { 00074 return false; 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: SequenceNode::make_copy 00079 // Access: Public, Virtual 00080 // Description: Returns a newly-allocated Node that is a shallow copy 00081 // of this one. It will be a different Node pointer, 00082 // but its internal data may or may not be shared with 00083 // that of the original Node. 00084 //////////////////////////////////////////////////////////////////// 00085 PandaNode *SequenceNode:: 00086 make_copy() const { 00087 return new SequenceNode(*this); 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: SequenceNode::cull_callback 00092 // Access: Public, Virtual 00093 // Description: This function will be called during the cull 00094 // traversal to perform any additional operations that 00095 // should be performed at cull time. This may include 00096 // additional manipulation of render state or additional 00097 // visible/invisible decisions, or any other arbitrary 00098 // operation. 00099 // 00100 // Note that this function will *not* be called unless 00101 // set_cull_callback() is called in the constructor of 00102 // the derived class. It is necessary to call 00103 // set_cull_callback() to indicated that we require 00104 // cull_callback() to be called. 00105 // 00106 // By the time this function is called, the node has 00107 // already passed the bounding-volume test for the 00108 // viewing frustum, and the node's transform and state 00109 // have already been applied to the indicated 00110 // CullTraverserData object. 00111 // 00112 // The return value is true if this node should be 00113 // visible, or false if it should be culled. 00114 //////////////////////////////////////////////////////////////////// 00115 bool SequenceNode:: 00116 cull_callback(CullTraverser *, CullTraverserData &) { 00117 select_child(get_frame()); 00118 return true; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: SequenceNode::get_first_visible_child 00123 // Access: Public, Virtual 00124 // Description: Returns the index number of the first visible child 00125 // of this node, or a number >= get_num_children() if 00126 // there are no visible children of this node. This is 00127 // called during the cull traversal, but only if 00128 // has_selective_visibility() has already returned true. 00129 // See has_selective_visibility(). 00130 //////////////////////////////////////////////////////////////////// 00131 int SequenceNode:: 00132 get_first_visible_child() const { 00133 return get_frame(); 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function: SequenceNode::has_single_child_visibility 00138 // Access: Public, Virtual 00139 // Description: Should be overridden by derived classes to return 00140 // true if this kind of node has the special property 00141 // that just one of its children is visible at any given 00142 // time, and furthermore that the particular visible 00143 // child can be determined without reference to any 00144 // external information (such as a camera). At present, 00145 // only SequenceNodes and SwitchNodes fall into this 00146 // category. 00147 // 00148 // If this function returns true, get_visible_child() 00149 // can be called to return the index of the 00150 // currently-visible child. 00151 //////////////////////////////////////////////////////////////////// 00152 bool SequenceNode:: 00153 has_single_child_visibility() const { 00154 return true; 00155 } 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: SequenceNode::get_visible_child 00159 // Access: Public, Virtual 00160 // Description: Returns the index number of the currently visible 00161 // child of this node. This is only meaningful if 00162 // has_single_child_visibility() has returned true. 00163 //////////////////////////////////////////////////////////////////// 00164 int SequenceNode:: 00165 get_visible_child() const { 00166 return get_frame(); 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: SequenceNode::output 00171 // Access: Published, Virtual 00172 // Description: 00173 //////////////////////////////////////////////////////////////////// 00174 void SequenceNode:: 00175 output(ostream &out) const { 00176 out << get_type() << " " << get_name() << ": "; 00177 AnimInterface::output(out); 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function: SequenceNode::register_with_read_factory 00182 // Access: Public, Static 00183 // Description: Tells the BamReader how to create objects of type 00184 // SequenceNode. 00185 //////////////////////////////////////////////////////////////////// 00186 void SequenceNode:: 00187 register_with_read_factory() { 00188 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: SequenceNode::write_datagram 00193 // Access: Public, Virtual 00194 // Description: Writes the contents of this object to the datagram 00195 // for shipping out to a Bam file. 00196 //////////////////////////////////////////////////////////////////// 00197 void SequenceNode:: 00198 write_datagram(BamWriter *manager, Datagram &dg) { 00199 SelectiveChildNode::write_datagram(manager, dg); 00200 AnimInterface::write_datagram(manager, dg); 00201 } 00202 00203 //////////////////////////////////////////////////////////////////// 00204 // Function: SequenceNode::make_from_bam 00205 // Access: Protected, Static 00206 // Description: This function is called by the BamReader's factory 00207 // when a new object of type SequenceNode is encountered 00208 // in the Bam file. It should create the SequenceNode 00209 // and extract its information from the file. 00210 //////////////////////////////////////////////////////////////////// 00211 TypedWritable *SequenceNode:: 00212 make_from_bam(const FactoryParams ¶ms) { 00213 SequenceNode *node = new SequenceNode(""); 00214 DatagramIterator scan; 00215 BamReader *manager; 00216 00217 parse_params(params, scan, manager); 00218 node->fillin(scan, manager); 00219 00220 return node; 00221 } 00222 00223 //////////////////////////////////////////////////////////////////// 00224 // Function: SequenceNode::fillin 00225 // Access: Protected 00226 // Description: This internal function is called by make_from_bam to 00227 // read in all of the relevant data from the BamFile for 00228 // the new SequenceNode. 00229 //////////////////////////////////////////////////////////////////// 00230 void SequenceNode:: 00231 fillin(DatagramIterator &scan, BamReader *manager) { 00232 SelectiveChildNode::fillin(scan, manager); 00233 AnimInterface::fillin(scan, manager); 00234 }