00001 // Filename: builderBucket.cxx 00002 // Created by: drose (10Sep97) 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 00020 #include "builderAttrib.h" 00021 #include "builderBucket.h" 00022 #include "builderFuncs.h" 00023 #include "builderMisc.h" 00024 #include "geomNode.h" 00025 00026 00027 BuilderBucket *BuilderBucket::_default_bucket = NULL; 00028 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: BuilderBucket::Constructor 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 BuilderBucket:: 00036 BuilderBucket() { 00037 _node = NULL; 00038 (*this) = (*get_default_bucket()); 00039 } 00040 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: BuilderBucket::Copy constructor 00044 // Access: Public 00045 // Description: 00046 //////////////////////////////////////////////////////////////////// 00047 BuilderBucket:: 00048 BuilderBucket(const BuilderBucket ©) { 00049 _node = NULL; 00050 (*this) = copy; 00051 } 00052 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: BuilderBucket::Copy assignment operator 00056 // Access: Public 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 BuilderBucket &BuilderBucket:: 00060 operator = (const BuilderBucket ©) { 00061 ((BuilderProperties &)*this) = (BuilderProperties &)copy; 00062 00063 // setGState(copy._state); 00064 set_name(copy.get_name()); 00065 set_coords(copy._coords); 00066 set_normals(copy._normals); 00067 set_texcoords(copy._texcoords); 00068 set_colors(copy._colors); 00069 00070 _node = copy._node; 00071 _drawBin = copy._drawBin; 00072 _drawOrder = copy._drawOrder; 00073 00074 _state = copy._state; 00075 00076 return *this; 00077 } 00078 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: BuilderBucket::Destructor 00082 // Access: Public, Virtual 00083 // Description: 00084 //////////////////////////////////////////////////////////////////// 00085 BuilderBucket:: 00086 ~BuilderBucket() { 00087 } 00088 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: BuilderBucket::make_copy 00092 // Access: Public, Virtual 00093 // Description: Allocates and returns a new copy of this object. If 00094 // you are subclassing from BuilderBucket, you must 00095 // redefine this to return an instance of your new 00096 // subclass, because the Builder will call this function 00097 // to get its own copy. 00098 //////////////////////////////////////////////////////////////////// 00099 BuilderBucket *BuilderBucket:: 00100 make_copy() const { 00101 return new BuilderBucket(*this); 00102 } 00103 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: BuilderBucket::make_geom_node 00107 // Access: Public, Virtual 00108 // Description: Called by the builder when it is time to create a new 00109 // GeomNode. This function should allocate and return a 00110 // new GeomNode suitable for adding geometry to. You 00111 // may redefine it to return a subclass of GeomNode, or 00112 // to do some initialization to the node. 00113 //////////////////////////////////////////////////////////////////// 00114 GeomNode *BuilderBucket:: 00115 make_geom_node() { 00116 return new GeomNode(""); 00117 } 00118 00119 //////////////////////////////////////////////////////////////////// 00120 // Function: BuilderBucket::done_geom 00121 // Access: Public, Virtual 00122 // Description: Called after all the geometry has been added to the 00123 // Geom. This is just a hook for the user to redefine 00124 // to do any post-processing that may be desired on the 00125 // geometry. It may deallocate it and return a new 00126 // copy. If it returns NULL, the geom is discarded. 00127 //////////////////////////////////////////////////////////////////// 00128 Geom *BuilderBucket:: 00129 done_geom(Geom *geom) { 00130 return geom; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: BuilderBucket::add_attrib 00135 // Access: Public 00136 // Description: A convenience function to add the indicated render 00137 // attribute to the bucket's state. 00138 //////////////////////////////////////////////////////////////////// 00139 void BuilderBucket:: 00140 add_attrib(const RenderAttrib *attrib) { 00141 _state = _state->add_attrib(attrib); 00142 } 00143 00144 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: BuilderBucket::Ordering operator 00148 // Access: Public, Virtual 00149 // Description: Defines an arbitrary ordering among different 00150 // buckets, and groups identical buckets together. 00151 // (Buckets a and b are identical if !(a < b) and !(b < 00152 // a).) 00153 // 00154 // The actual order between different buckets is 00155 // arbitrary and largely irrelevant, so long as it is 00156 // consistent. That is, if (a < b) and (b < c), it must 00157 // also be true that (a < c). Also, if (a < b), it 00158 // cannot be true that (b < a). 00159 //////////////////////////////////////////////////////////////////// 00160 bool BuilderBucket:: 00161 operator < (const BuilderBucket &other) const { 00162 if (get_name() != other.get_name()) { 00163 return get_name() < other.get_name(); 00164 } 00165 00166 if (_node != other._node) { 00167 return _node < other._node; 00168 } 00169 00170 if (_coords != other._coords) 00171 return _coords < other._coords; 00172 if (_normals != other._normals) 00173 return _normals < other._normals; 00174 if (_texcoords != other._texcoords) 00175 return _texcoords < other._texcoords; 00176 if (_colors != other._colors) 00177 return _colors < other._colors; 00178 00179 if (_drawBin != other._drawBin) 00180 return _drawBin < other._drawBin; 00181 if (_drawOrder != other._drawOrder) 00182 return _drawOrder < other._drawOrder; 00183 00184 if (_state != other._state) { 00185 return _state < other._state; 00186 } 00187 00188 return BuilderProperties::operator < (other); 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: BuilderBucket::output 00193 // Access: Public, Virtual 00194 // Description: Formats the bucket for output in some sensible way. 00195 //////////////////////////////////////////////////////////////////// 00196 void BuilderBucket:: 00197 output(ostream &out) const { 00198 out << "Bucket \"" << get_name() << "\""; 00199 00200 if (_node != (PandaNode *)NULL) { 00201 out << " attached to " << *_node << "\n"; 00202 } 00203 out << "\n"; 00204 00205 00206 if (_coords != (Vertexf *)NULL) { 00207 out << "_coords = " << (void *)_coords << "\n"; 00208 } 00209 00210 if (_normals != (Normalf *)NULL) { 00211 out << "_normals = " << (void *)_normals << "\n"; 00212 } 00213 00214 if (_texcoords != (TexCoordf *)NULL) { 00215 out << "_texcoords = " << (void *)_texcoords << "\n"; 00216 } 00217 00218 if (_colors != (Colorf *)NULL) { 00219 out << "_colors = " << (void *)_colors << "\n"; 00220 } 00221 00222 if (_drawBin != -1) { 00223 out << "_drawBin = " << _drawBin << "\n"; 00224 } 00225 00226 if (_drawOrder != 0) { 00227 out << "_drawOrder = " << _drawOrder << "\n"; 00228 } 00229 00230 if (!_state->is_empty()) { 00231 out << *_state << "\n"; 00232 } 00233 00234 BuilderProperties::output(out); 00235 } 00236 00237 00238 //////////////////////////////////////////////////////////////////// 00239 // Function: BuilderBucket::private Constructor 00240 // Access: Private 00241 // Description: This special constructor is used only to initialize 00242 // the _default_bucket pointer. It sets up the initial 00243 // defaults. The normal constructor copies from this 00244 // instance. 00245 //////////////////////////////////////////////////////////////////// 00246 BuilderBucket:: 00247 BuilderBucket(int) { 00248 _node = NULL; 00249 00250 _drawBin = -1; 00251 _drawOrder = 0; 00252 00253 // From BuilderProperties 00254 _mesh = true; 00255 _retesselate_coplanar = true; 00256 _show_tstrips = false; 00257 _show_qsheets = false; 00258 _show_quads = false; 00259 _show_normals = false; 00260 _normal_color.set(1.0, 0.0, 0.0, 1.0); 00261 _normal_scale = 1.0; 00262 _subdivide_polys = true; 00263 _coplanar_threshold = 0.01; 00264 00265 _unroll_fans = true; 00266 _consider_fans = true; 00267 _max_tfan_angle = 40.0; 00268 _min_tfan_tris = 0; 00269 00270 _state = RenderState::make_empty(); 00271 }