Panda3D

geomNode.I

00001 // Filename: geomNode.I
00002 // Created by:  drose (23Feb02)
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 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: GeomNode::set_preserved
00018 //       Access: Published
00019 //  Description: Sets the "preserved" flag.  When this is true, the
00020 //               GeomNode will be left untouched by any flatten
00021 //               operations.
00022 ////////////////////////////////////////////////////////////////////
00023 INLINE void GeomNode::
00024 set_preserved(bool value) {
00025   _preserved = value;
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: GeomNode::get_preserved
00030 //       Access: Published
00031 //  Description: Returns the "preserved" flag.  When this is true, the
00032 //               GeomNode will be left untouched by any flatten
00033 //               operations.
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE bool GeomNode::
00036 get_preserved() const {
00037   return _preserved;
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: GeomNode::get_num_geoms
00042 //       Access: Published
00043 //  Description: Returns the number of geoms in the node.
00044 ////////////////////////////////////////////////////////////////////
00045 INLINE int GeomNode::
00046 get_num_geoms() const {
00047   CDReader cdata(_cycler);
00048   return cdata->get_geoms()->size();
00049 }
00050 
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: GeomNode::get_geom
00054 //       Access: Published
00055 //  Description: Returns the nth geom of the node.  This object should
00056 //               not be modified, since the same object might be
00057 //               shared between multiple different GeomNodes, but see
00058 //               modify_geom().
00059 ////////////////////////////////////////////////////////////////////
00060 INLINE CPT(Geom) GeomNode::
00061 get_geom(int n) const {
00062   CDReader cdata(_cycler);
00063   CPT(GeomList) geoms = cdata->get_geoms();
00064   nassertr(n >= 0 && n < (int)geoms->size(), NULL);
00065   return (*geoms)[n]._geom.get_read_pointer();
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: GeomNode::modify_geom
00070 //       Access: Published
00071 //  Description: Returns the nth geom of the node, suitable for
00072 //               modifying it.  If the nth Geom has multiple reference
00073 //               counts to it, reassigns it to an identical copy
00074 //               first, and returns the new copy--this provides a
00075 //               "copy on write" that ensures that the Geom that is
00076 //               returned is unique to this GeomNode and is not shared
00077 //               with any other GeomNodes.
00078 //
00079 //               Note that if this method is called in a downstream
00080 //               stage (for instance, during cull or draw), then it
00081 //               will propagate the new list of Geoms upstream all the
00082 //               way to pipeline stage 0, which may step on changes
00083 //               that were made independently in pipeline stage 0.
00084 //               Use with caution.
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE PT(Geom) GeomNode::
00087 modify_geom(int n) {
00088   CDWriter cdata(_cycler, true);
00089   PT(GeomList) geoms = cdata->modify_geoms();
00090   nassertr(n >= 0 && n < (int)geoms->size(), NULL);
00091   mark_internal_bounds_stale();
00092   return (*geoms)[n]._geom.get_write_pointer();
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: GeomNode::get_geom_state
00097 //       Access: Published
00098 //  Description: Returns the RenderState associated with the nth geom
00099 //               of the node.  This is just the RenderState directly
00100 //               associated with the Geom; the actual state in which
00101 //               the Geom is rendered will also be affected by
00102 //               RenderStates that appear on the scene graph in nodes
00103 //               above this GeomNode.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE const RenderState *GeomNode::
00106 get_geom_state(int n) const {
00107   CDReader cdata(_cycler);
00108   CPT(GeomList) geoms = cdata->get_geoms();
00109   nassertr(n >= 0 && n < (int)geoms->size(), NULL);
00110   return (*geoms)[n]._state;
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: GeomNode::set_geom_state
00115 //       Access: Published
00116 //  Description: Changes the RenderState associated with the nth geom
00117 //               of the node.  This is just the RenderState directly
00118 //               associated with the Geom; the actual state in which
00119 //               the Geom is rendered will also be affected by
00120 //               RenderStates that appear on the scene graph in nodes
00121 //               above this GeomNode.
00122 //
00123 //               Note that if this method is called in a downstream
00124 //               stage (for instance, during cull or draw), then it
00125 //               will propagate the new list of Geoms upstream all the
00126 //               way to pipeline stage 0, which may step on changes
00127 //               that were made independently in pipeline stage 0.
00128 //               Use with caution.
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE void GeomNode::
00131 set_geom_state(int n, const RenderState *state) {
00132   CDWriter cdata(_cycler, true);
00133   PT(GeomList) geoms = cdata->modify_geoms();
00134   nassertv(n >= 0 && n < (int)geoms->size());
00135   (*geoms)[n]._state = state;
00136 }
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //     Function: GeomNode::remove_geom
00140 //       Access: Published
00141 //  Description: Removes the nth geom from the node.
00142 ////////////////////////////////////////////////////////////////////
00143 INLINE void GeomNode::
00144 remove_geom(int n) {
00145   CDWriter cdata(_cycler);
00146   PT(GeomList) geoms = cdata->modify_geoms();
00147   nassertv(n >= 0 && n < (int)geoms->size());
00148 
00149   geoms->erase(geoms->begin() + n);
00150   mark_internal_bounds_stale();
00151 }
00152 
00153 ////////////////////////////////////////////////////////////////////
00154 //     Function: GeomNode::remove_all_geoms
00155 //       Access: Published
00156 //  Description: Removes all the geoms from the node at once.
00157 ////////////////////////////////////////////////////////////////////
00158 INLINE void GeomNode::
00159 remove_all_geoms() {
00160   CDWriter cdata(_cycler);
00161   cdata->set_geoms(new GeomList);
00162   mark_internal_bounds_stale();
00163 }
00164 
00165 ////////////////////////////////////////////////////////////////////
00166 //     Function: GeomNode::get_default_collide_mask
00167 //       Access: Published, Static
00168 //  Description: Returns the default into_collide_mask assigned to new
00169 //               GeomNodes.
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE CollideMask GeomNode::
00172 get_default_collide_mask() {
00173   return default_geom_node_collide_mask;
00174 }
00175 
00176 ////////////////////////////////////////////////////////////////////
00177 //     Function: GeomNode::count_name
00178 //       Access: Private
00179 //  Description: Increments the count for the indicated InternalName.
00180 ////////////////////////////////////////////////////////////////////
00181 INLINE void GeomNode::
00182 count_name(GeomNode::NameCount &name_count, const InternalName *name) {
00183   pair<NameCount::iterator, bool> result = 
00184     name_count.insert(NameCount::value_type(name, 1));
00185   if (!result.second) {
00186     (*result.first).second++;
00187   }
00188 }
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: GeomNode::get_name_count
00192 //       Access: Private
00193 //  Description: Returns the count for the indicated InternalName.
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE int GeomNode::
00196 get_name_count(const GeomNode::NameCount &name_count, const InternalName *name) {
00197   NameCount::const_iterator ni;
00198   ni = name_count.find(name);
00199   if (ni != name_count.end()) {
00200     return (*ni).second;
00201   }
00202   return 0;
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: GeomNode::get_geoms
00207 //       Access: Published
00208 //  Description: Returns an object that can be used to walk through
00209 //               the list of geoms of the node.  When you intend to
00210 //               visit multiple geoms, using this is slightly
00211 //               faster than calling get_geom() directly on the
00212 //               GeomNode, since this object avoids reopening the
00213 //               PipelineCycler each time.
00214 //
00215 //               This object also protects you from self-modifying
00216 //               loops (e.g. adding or removing geoms during
00217 //               traversal), since a virtual copy of the geoms is
00218 //               made ahead of time.  The virtual copy is fast--it is
00219 //               a form of copy-on-write, so the list is not actually
00220 //               copied unless it is modified during the traversal.
00221 ////////////////////////////////////////////////////////////////////
00222 INLINE GeomNode::Geoms GeomNode::
00223 get_geoms(Thread *current_thread) const {
00224   CDReader cdata(_cycler, current_thread);
00225   return Geoms(cdata);
00226 }
00227 
00228 ////////////////////////////////////////////////////////////////////
00229 //     Function: GeomNode::GeomEntry::Constructor
00230 //       Access: Public
00231 //  Description:
00232 ////////////////////////////////////////////////////////////////////
00233 INLINE GeomNode::GeomEntry::
00234 GeomEntry(Geom *geom, const RenderState *state) :
00235   _geom(geom),
00236   _state(state)
00237 {
00238 }
00239 
00240 ////////////////////////////////////////////////////////////////////
00241 //     Function: GeomNode::CData::Constructor
00242 //       Access: Public
00243 //  Description:
00244 ////////////////////////////////////////////////////////////////////
00245 INLINE GeomNode::CData::
00246 CData() :
00247   _geoms(new GeomNode::GeomList)
00248 {
00249 }
00250 
00251 ////////////////////////////////////////////////////////////////////
00252 //     Function: GeomNode::CData::get_geoms
00253 //       Access: Public
00254 //  Description: Returns a read-only pointer to the _geoms list.
00255 ////////////////////////////////////////////////////////////////////
00256 INLINE CPT(GeomNode::GeomList) GeomNode::CData::
00257 get_geoms() const {
00258   return _geoms.get_read_pointer();
00259 }
00260 
00261 ////////////////////////////////////////////////////////////////////
00262 //     Function: GeomNode::CData::modify_geoms
00263 //       Access: Public
00264 //  Description: Returns a modifiable, unique pointer to the _geoms
00265 //               list.
00266 ////////////////////////////////////////////////////////////////////
00267 INLINE PT(GeomNode::GeomList) GeomNode::CData::
00268 modify_geoms() {
00269   return _geoms.get_write_pointer();
00270 }
00271 
00272 ////////////////////////////////////////////////////////////////////
00273 //     Function: GeomNode::CData::set_geoms
00274 //       Access: Public
00275 //  Description: Replaces the _geoms list with a new list.
00276 ////////////////////////////////////////////////////////////////////
00277 INLINE void GeomNode::CData::
00278 set_geoms(GeomNode::GeomList *geoms) {
00279   _geoms = geoms;
00280 }
00281 
00282 ////////////////////////////////////////////////////////////////////
00283 //     Function: GeomNode::Geoms::Constructor
00284 //       Access: Public
00285 //  Description:
00286 ////////////////////////////////////////////////////////////////////
00287 INLINE GeomNode::Geoms::
00288 Geoms() {
00289 }
00290 
00291 ////////////////////////////////////////////////////////////////////
00292 //     Function: GeomNode::Geoms::Constructor
00293 //       Access: Public
00294 //  Description:
00295 ////////////////////////////////////////////////////////////////////
00296 INLINE GeomNode::Geoms::
00297 Geoms(const GeomNode::CData *cdata) :
00298   _geoms(cdata->get_geoms())
00299 {
00300 }
00301 
00302 ////////////////////////////////////////////////////////////////////
00303 //     Function: GeomNode::Geoms::Copy Constructor
00304 //       Access: Public
00305 //  Description:
00306 ////////////////////////////////////////////////////////////////////
00307 INLINE GeomNode::Geoms::
00308 Geoms(const GeomNode::Geoms &copy) :
00309   _geoms(copy._geoms)
00310 {
00311 }
00312 
00313 ////////////////////////////////////////////////////////////////////
00314 //     Function: GeomNode::Geoms::Copy Assignment Operator
00315 //       Access: Public
00316 //  Description:
00317 ////////////////////////////////////////////////////////////////////
00318 INLINE void GeomNode::Geoms::
00319 operator = (const GeomNode::Geoms &copy) {
00320   _geoms = copy._geoms;
00321 }
00322 
00323 ////////////////////////////////////////////////////////////////////
00324 //     Function: GeomNode::Geoms::get_num_geoms
00325 //       Access: Public
00326 //  Description: Returns the number of geoms of the node.
00327 ////////////////////////////////////////////////////////////////////
00328 INLINE int GeomNode::Geoms::
00329 get_num_geoms() const {
00330   nassertr(!_geoms.is_null(), 0);
00331   return _geoms->size();
00332 }
00333 
00334 ////////////////////////////////////////////////////////////////////
00335 //     Function: GeomNode::Geoms::get_geom
00336 //       Access: Public
00337 //  Description: Returns the nth geom of the node.  This object should
00338 //               not be modified, since the same object might be
00339 //               shared between multiple different GeomNodes.
00340 ////////////////////////////////////////////////////////////////////
00341 INLINE CPT(Geom) GeomNode::Geoms::
00342 get_geom(int n) const {
00343   nassertr(!_geoms.is_null(), NULL);
00344   nassertr(n >= 0 && n < (int)_geoms->size(), NULL);
00345   return (*_geoms)[n]._geom.get_read_pointer();
00346 }
00347 
00348 ////////////////////////////////////////////////////////////////////
00349 //     Function: GeomNode::Geoms::get_geom_state
00350 //       Access: Public
00351 //  Description: Returns the RenderState associated with the nth geom
00352 //               of the node.  This is just the RenderState directly
00353 //               associated with the Geom; the actual state in which
00354 //               the Geom is rendered will also be affected by
00355 //               RenderStates that appear on the scene graph in nodes
00356 //               above this GeomNode.
00357 ////////////////////////////////////////////////////////////////////
00358 INLINE const RenderState *GeomNode::Geoms::
00359 get_geom_state(int n) const {
00360   nassertr(!_geoms.is_null(), NULL);
00361   nassertr(n >= 0 && n < (int)_geoms->size(), NULL);
00362   return (*_geoms)[n]._state;
00363 }
 All Classes Functions Variables Enumerations