00001 // Filename: modelNode.cxx 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "modelNode.h" 00020 00021 #include "bamReader.h" 00022 #include "datagram.h" 00023 #include "datagramIterator.h" 00024 00025 TypeHandle ModelNode::_type_handle; 00026 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: ModelNode::make_copy 00030 // Access: Public, Virtual 00031 // Description: Returns a newly-allocated Node that is a shallow copy 00032 // of this one. It will be a different Node pointer, 00033 // but its internal data may or may not be shared with 00034 // that of the original Node. 00035 //////////////////////////////////////////////////////////////////// 00036 PandaNode *ModelNode:: 00037 make_copy() const { 00038 return new ModelNode(*this); 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: ModelNode::safe_to_flatten 00043 // Access: Public, Virtual 00044 // Description: Returns true if it is generally safe to flatten out 00045 // this particular kind of Node by duplicating 00046 // instances, false otherwise (for instance, a Camera 00047 // cannot be safely flattened, because the Camera 00048 // pointer itself is meaningful). 00049 //////////////////////////////////////////////////////////////////// 00050 bool ModelNode:: 00051 safe_to_flatten() const { 00052 return false; 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: ModelNode::safe_to_transform 00057 // Access: Public, Virtual 00058 // Description: Returns true if it is generally safe to transform 00059 // this particular kind of Node by calling the xform() 00060 // method, false otherwise. For instance, it's usually 00061 // a bad idea to attempt to xform a Character. 00062 //////////////////////////////////////////////////////////////////// 00063 bool ModelNode:: 00064 safe_to_transform() const { 00065 return _preserve_transform == PT_none; 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: ModelNode::safe_to_modify_transform 00070 // Access: Public, Virtual 00071 // Description: Returns true if it is safe to automatically adjust 00072 // the transform on this kind of node. Usually, this is 00073 // only a bad idea if the user expects to find a 00074 // particular transform on the node. 00075 // 00076 // ModelNodes with the preserve_transform flag set are 00077 // presently the only kinds of nodes that should not 00078 // have their transform even adjusted. 00079 //////////////////////////////////////////////////////////////////// 00080 bool ModelNode:: 00081 safe_to_modify_transform() const { 00082 return _preserve_transform != PT_local; 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: ModelNode::safe_to_combine 00087 // Access: Public, Virtual 00088 // Description: Returns true if it is generally safe to combine this 00089 // particular kind of PandaNode with other kinds of 00090 // PandaNodes, adding children or whatever. For 00091 // instance, an LODNode should not be combined with any 00092 // other PandaNode, because its set of children is 00093 // meaningful. 00094 //////////////////////////////////////////////////////////////////// 00095 bool ModelNode:: 00096 safe_to_combine() const { 00097 return false; 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: ModelNode::preserve_name 00102 // Access: Public, Virtual 00103 // Description: Returns true if the node's name has extrinsic meaning 00104 // and must be preserved across a flatten operation, 00105 // false otherwise. 00106 //////////////////////////////////////////////////////////////////// 00107 bool ModelNode:: 00108 preserve_name() const { 00109 return true; 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: ModelNode::register_with_read_factory 00114 // Access: Public, Static 00115 // Description: Tells the BamReader how to create objects of type 00116 // ModelNode. 00117 //////////////////////////////////////////////////////////////////// 00118 void ModelNode:: 00119 register_with_read_factory() { 00120 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: ModelNode::write_datagram 00125 // Access: Public, Virtual 00126 // Description: Writes the contents of this object to the datagram 00127 // for shipping out to a Bam file. 00128 //////////////////////////////////////////////////////////////////// 00129 void ModelNode:: 00130 write_datagram(BamWriter *manager, Datagram &dg) { 00131 PandaNode::write_datagram(manager, dg); 00132 dg.add_uint8((int)_preserve_transform); 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: ModelNode::make_from_bam 00137 // Access: Protected, Static 00138 // Description: This function is called by the BamReader's factory 00139 // when a new object of type ModelNode is encountered 00140 // in the Bam file. It should create the ModelNode 00141 // and extract its information from the file. 00142 //////////////////////////////////////////////////////////////////// 00143 TypedWritable *ModelNode:: 00144 make_from_bam(const FactoryParams ¶ms) { 00145 ModelNode *node = new ModelNode(""); 00146 DatagramIterator scan; 00147 BamReader *manager; 00148 00149 parse_params(params, scan, manager); 00150 node->fillin(scan, manager); 00151 00152 return node; 00153 } 00154 00155 //////////////////////////////////////////////////////////////////// 00156 // Function: ModelNode::fillin 00157 // Access: Protected 00158 // Description: This internal function is called by make_from_bam to 00159 // read in all of the relevant data from the BamFile for 00160 // the new ModelNode. 00161 //////////////////////////////////////////////////////////////////// 00162 void ModelNode:: 00163 fillin(DatagramIterator &scan, BamReader *manager) { 00164 PandaNode::fillin(scan, manager); 00165 00166 _preserve_transform = (PreserveTransform)scan.get_uint8(); 00167 }