2
0

pandaNode.I 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. // Filename: pandaNode.I
  2. // Created by: drose (20Feb02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, 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://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: PandaNode::DownConnection::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE PandaNode::DownConnection::
  24. DownConnection(PandaNode *child, int sort) :
  25. _child(child),
  26. _sort(sort)
  27. {
  28. }
  29. ////////////////////////////////////////////////////////////////////
  30. // Function: PandaNode::DownConnection::operator <
  31. // Access: Public
  32. // Description: Provides a partial ordering on the children of a node
  33. // so that they are ranked first in sort order, and then
  34. // (by virtue of the ordered_vector) in the order they
  35. // were added.
  36. ////////////////////////////////////////////////////////////////////
  37. INLINE bool PandaNode::DownConnection::
  38. operator < (const DownConnection &other) const {
  39. return _sort < other._sort;
  40. }
  41. ////////////////////////////////////////////////////////////////////
  42. // Function: PandaNode::DownConnection::get_child
  43. // Access: Public
  44. // Description:
  45. ////////////////////////////////////////////////////////////////////
  46. INLINE PandaNode *PandaNode::DownConnection::
  47. get_child() const {
  48. return _child;
  49. }
  50. ////////////////////////////////////////////////////////////////////
  51. // Function: PandaNode::DownConnection::set_child
  52. // Access: Public
  53. // Description: This is only called by PandaNode::replace_child().
  54. ////////////////////////////////////////////////////////////////////
  55. INLINE void PandaNode::DownConnection::
  56. set_child(PandaNode *child) {
  57. _child = child;
  58. }
  59. ////////////////////////////////////////////////////////////////////
  60. // Function: PandaNode::DownConnection::get_sort
  61. // Access: Public
  62. // Description:
  63. ////////////////////////////////////////////////////////////////////
  64. INLINE int PandaNode::DownConnection::
  65. get_sort() const {
  66. return _sort;
  67. }
  68. ////////////////////////////////////////////////////////////////////
  69. // Function: PandaNode::UpConnection::Constructor
  70. // Access: Public
  71. // Description:
  72. ////////////////////////////////////////////////////////////////////
  73. INLINE PandaNode::UpConnection::
  74. UpConnection(PandaNode *parent) :
  75. _parent(parent)
  76. {
  77. }
  78. ////////////////////////////////////////////////////////////////////
  79. // Function: PandaNode::UpConnection::operator <
  80. // Access: Public
  81. // Description: Sorts the up connections of a node by pointer. This
  82. // is different from the down connections of a node,
  83. // which are sorted by the specified _sort number. This
  84. // makes it easy to locate a particular parent of a node
  85. // by pointer, or to test for a parent-child
  86. // relationship given two node pointers.
  87. ////////////////////////////////////////////////////////////////////
  88. INLINE bool PandaNode::UpConnection::
  89. operator < (const UpConnection &other) const {
  90. return _parent < other._parent;
  91. }
  92. ////////////////////////////////////////////////////////////////////
  93. // Function: PandaNode::UpConnection::get_parent
  94. // Access: Public
  95. // Description:
  96. ////////////////////////////////////////////////////////////////////
  97. INLINE PandaNode *PandaNode::UpConnection::
  98. get_parent() const {
  99. return _parent;
  100. }
  101. ////////////////////////////////////////////////////////////////////
  102. // Function: PandaNode::CData::Constructor
  103. // Access: Public
  104. // Description:
  105. ////////////////////////////////////////////////////////////////////
  106. INLINE PandaNode::CData::
  107. CData() {
  108. _state = RenderState::make_empty();
  109. _effects = RenderEffects::make_empty();
  110. _transform = TransformState::make_identity();
  111. _prev_transform = TransformState::make_identity();
  112. _draw_mask = DrawMask::all_on();
  113. _net_collide_mask = CollideMask::all_off();
  114. _fixed_internal_bound = false;
  115. }
  116. ////////////////////////////////////////////////////////////////////
  117. // Function: PandaNode::CData::Copy Constructor
  118. // Access: Public
  119. // Description:
  120. ////////////////////////////////////////////////////////////////////
  121. INLINE PandaNode::CData::
  122. CData(const PandaNode::CData &copy) :
  123. _down(copy._down),
  124. _stashed(copy._stashed),
  125. _up(copy._up),
  126. _paths(copy._paths),
  127. _state(copy._state),
  128. _effects(copy._effects),
  129. _transform(copy._transform),
  130. _prev_transform(copy._prev_transform),
  131. _tag_data(copy._tag_data),
  132. _draw_mask(copy._draw_mask),
  133. _fixed_internal_bound(copy._fixed_internal_bound)
  134. {
  135. _net_collide_mask = CollideMask::all_off();
  136. }
  137. ////////////////////////////////////////////////////////////////////
  138. // Function: PandaNode::Children::Constructor
  139. // Access: Public
  140. // Description:
  141. ////////////////////////////////////////////////////////////////////
  142. INLINE PandaNode::Children::
  143. Children(const PandaNode::CDReader &cdata) :
  144. _cdata(cdata)
  145. {
  146. }
  147. ////////////////////////////////////////////////////////////////////
  148. // Function: PandaNode::Children::Copy Constructor
  149. // Access: Public
  150. // Description:
  151. ////////////////////////////////////////////////////////////////////
  152. INLINE PandaNode::Children::
  153. Children(const PandaNode::Children &copy) :
  154. _cdata(copy._cdata)
  155. {
  156. }
  157. ////////////////////////////////////////////////////////////////////
  158. // Function: PandaNode::Children::Copy Assignment Operator
  159. // Access: Public
  160. // Description:
  161. ////////////////////////////////////////////////////////////////////
  162. INLINE void PandaNode::Children::
  163. operator = (const PandaNode::Children &copy) {
  164. _cdata = copy._cdata;
  165. }
  166. ////////////////////////////////////////////////////////////////////
  167. // Function: PandaNode::Children::get_num_children
  168. // Access: Public
  169. // Description: Returns the number of children of the node.
  170. ////////////////////////////////////////////////////////////////////
  171. INLINE int PandaNode::Children::
  172. get_num_children() const {
  173. return _cdata->_down.size();
  174. }
  175. ////////////////////////////////////////////////////////////////////
  176. // Function: PandaNode::Children::get_child
  177. // Access: Public
  178. // Description: Returns the nth child of the node.
  179. ////////////////////////////////////////////////////////////////////
  180. INLINE PandaNode *PandaNode::Children::
  181. get_child(int n) const {
  182. nassertr(n >= 0 && n < (int)_cdata->_down.size(), NULL);
  183. return _cdata->_down[n].get_child();
  184. }
  185. ////////////////////////////////////////////////////////////////////
  186. // Function: PandaNode::ChildrenCopy::Copy Constructor
  187. // Access: Public
  188. // Description:
  189. ////////////////////////////////////////////////////////////////////
  190. INLINE PandaNode::ChildrenCopy::
  191. ChildrenCopy(const PandaNode::ChildrenCopy &copy) :
  192. _list(copy._list)
  193. {
  194. }
  195. ////////////////////////////////////////////////////////////////////
  196. // Function: PandaNode::ChildrenCopy::Copy Assignment Operator
  197. // Access: Public
  198. // Description:
  199. ////////////////////////////////////////////////////////////////////
  200. INLINE void PandaNode::ChildrenCopy::
  201. operator = (const PandaNode::ChildrenCopy &copy) {
  202. _list = copy._list;
  203. }
  204. ////////////////////////////////////////////////////////////////////
  205. // Function: PandaNode::ChildrenCopy::get_num_children
  206. // Access: Public
  207. // Description: Returns the number of children of the node.
  208. ////////////////////////////////////////////////////////////////////
  209. INLINE int PandaNode::ChildrenCopy::
  210. get_num_children() const {
  211. return _list.size();
  212. }
  213. ////////////////////////////////////////////////////////////////////
  214. // Function: PandaNode::ChildrenCopy::get_child
  215. // Access: Public
  216. // Description: Returns the nth child of the node.
  217. ////////////////////////////////////////////////////////////////////
  218. INLINE PandaNode *PandaNode::ChildrenCopy::
  219. get_child(int n) const {
  220. nassertr(n >= 0 && n < (int)_list.size(), NULL);
  221. return _list[n];
  222. }
  223. ////////////////////////////////////////////////////////////////////
  224. // Function: PandaNode::get_num_parents
  225. // Access: Published
  226. // Description: Returns the number of parent nodes this node has. If
  227. // this number is greater than 1, the node has been
  228. // multiply instanced. The order of the parent nodes is
  229. // not meaningful and is not related to the order in
  230. // which the node was instanced to them.
  231. ////////////////////////////////////////////////////////////////////
  232. INLINE int PandaNode::
  233. get_num_parents() const {
  234. CDReader cdata(_cycler);
  235. return cdata->_up.size();
  236. }
  237. ////////////////////////////////////////////////////////////////////
  238. // Function: PandaNode::get_parent
  239. // Access: Published
  240. // Description: Returns the nth parent node of this node. See
  241. // get_num_parents().
  242. ////////////////////////////////////////////////////////////////////
  243. INLINE PandaNode *PandaNode::
  244. get_parent(int n) const {
  245. CDReader cdata(_cycler);
  246. nassertr(n >= 0 && n < (int)cdata->_up.size(), NULL);
  247. return cdata->_up[n].get_parent();
  248. }
  249. ////////////////////////////////////////////////////////////////////
  250. // Function: PandaNode::find_parent
  251. // Access: Published
  252. // Description: Returns the index of the indicated parent node, if it
  253. // is a parent, or -1 if it is not.
  254. ////////////////////////////////////////////////////////////////////
  255. INLINE int PandaNode::
  256. find_parent(PandaNode *node) const {
  257. CDReader cdata(_cycler);
  258. Up::const_iterator ui = cdata->_up.find(UpConnection(node));
  259. if (ui == cdata->_up.end()) {
  260. return -1;
  261. }
  262. return ui - cdata->_up.begin();
  263. }
  264. ////////////////////////////////////////////////////////////////////
  265. // Function: PandaNode::get_num_children
  266. // Access: Published
  267. // Description: Returns the number of child nodes this node has. The
  268. // order of the child nodes *is* meaningful and is based
  269. // on the sort number that was passed to add_child(),
  270. // and also on the order in which the nodes were added.
  271. ////////////////////////////////////////////////////////////////////
  272. INLINE int PandaNode::
  273. get_num_children() const {
  274. CDReader cdata(_cycler);
  275. return cdata->_down.size();
  276. }
  277. ////////////////////////////////////////////////////////////////////
  278. // Function: PandaNode::get_child
  279. // Access: Published
  280. // Description: Returns the nth child node of this node. See
  281. // get_num_children().
  282. ////////////////////////////////////////////////////////////////////
  283. INLINE PandaNode *PandaNode::
  284. get_child(int n) const {
  285. CDReader cdata(_cycler);
  286. nassertr(n >= 0 && n < (int)cdata->_down.size(), NULL);
  287. return cdata->_down[n].get_child();
  288. }
  289. ////////////////////////////////////////////////////////////////////
  290. // Function: PandaNode::get_child_sort
  291. // Access: Published
  292. // Description: Returns the sort index of the nth child node of this
  293. // node (that is, the number that was passed to
  294. // add_child()). See get_num_children().
  295. ////////////////////////////////////////////////////////////////////
  296. INLINE int PandaNode::
  297. get_child_sort(int n) const {
  298. CDReader cdata(_cycler);
  299. nassertr(n >= 0 && n < (int)cdata->_down.size(), -1);
  300. return cdata->_down[n].get_sort();
  301. }
  302. ////////////////////////////////////////////////////////////////////
  303. // Function: PandaNode::stash_child
  304. // Access: Published
  305. // Description: Stashes the indicated child node. This removes the
  306. // child from the list of active children and puts it on
  307. // a special list of stashed children. This child node
  308. // no longer contributes to the bounding volume of the
  309. // PandaNode, and is not visited in normal traversals.
  310. // It is invisible and uncollidable. The child may
  311. // later be restored by calling unstash_child().
  312. //
  313. // This function returns true if the child node was
  314. // successfully stashed, or false if it was not a child
  315. // of the node in the first place (e.g. it was
  316. // previously stashed).
  317. ////////////////////////////////////////////////////////////////////
  318. INLINE bool PandaNode::
  319. stash_child(PandaNode *child_node) {
  320. int child_index = find_child(child_node);
  321. if (child_index < 0) {
  322. return false;
  323. }
  324. stash_child(child_index);
  325. return true;
  326. }
  327. ////////////////////////////////////////////////////////////////////
  328. // Function: PandaNode::unstash_child
  329. // Access: Published
  330. // Description: Returns the indicated stashed node to normal child
  331. // status. This removes the child from the list of
  332. // stashed children and puts it on the normal list of
  333. // active children. This child node once again
  334. // contributes to the bounding volume of the PandaNode,
  335. // and will be visited in normal traversals. It is
  336. // visible and collidable.
  337. //
  338. // This function returns true if the child node was
  339. // successfully stashed, or false if it was not a child
  340. // of the node in the first place (e.g. it was
  341. // previously stashed).
  342. ////////////////////////////////////////////////////////////////////
  343. INLINE bool PandaNode::
  344. unstash_child(PandaNode *child_node) {
  345. int stashed_index = find_stashed(child_node);
  346. if (stashed_index < 0) {
  347. return false;
  348. }
  349. unstash_child(stashed_index);
  350. return true;
  351. }
  352. ////////////////////////////////////////////////////////////////////
  353. // Function: PandaNode::get_num_stashed
  354. // Access: Published
  355. // Description: Returns the number of stashed nodes this node has.
  356. // These are former children of the node that have been
  357. // moved to the special stashed list via stash_child().
  358. ////////////////////////////////////////////////////////////////////
  359. INLINE int PandaNode::
  360. get_num_stashed() const {
  361. CDReader cdata(_cycler);
  362. return cdata->_stashed.size();
  363. }
  364. ////////////////////////////////////////////////////////////////////
  365. // Function: PandaNode::get_stashed
  366. // Access: Published
  367. // Description: Returns the nth stashed node of this node. See
  368. // get_num_stashed().
  369. ////////////////////////////////////////////////////////////////////
  370. INLINE PandaNode *PandaNode::
  371. get_stashed(int n) const {
  372. CDReader cdata(_cycler);
  373. nassertr(n >= 0 && n < (int)cdata->_stashed.size(), NULL);
  374. return cdata->_stashed[n].get_child();
  375. }
  376. ////////////////////////////////////////////////////////////////////
  377. // Function: PandaNode::get_stashed_sort
  378. // Access: Published
  379. // Description: Returns the sort index of the nth stashed node of this
  380. // node (that is, the number that was passed to
  381. // add_child()). See get_num_stashed().
  382. ////////////////////////////////////////////////////////////////////
  383. INLINE int PandaNode::
  384. get_stashed_sort(int n) const {
  385. CDReader cdata(_cycler);
  386. nassertr(n >= 0 && n < (int)cdata->_stashed.size(), -1);
  387. return cdata->_stashed[n].get_sort();
  388. }
  389. ////////////////////////////////////////////////////////////////////
  390. // Function: PandaNode::set_attrib
  391. // Access: Published
  392. // Description: Adds the indicated render attribute to the scene
  393. // graph on this node. This attribute will now apply to
  394. // this node and everything below. If there was already
  395. // an attribute of the same type, it is replaced.
  396. ////////////////////////////////////////////////////////////////////
  397. INLINE void PandaNode::
  398. set_attrib(const RenderAttrib *attrib, int override) {
  399. CDWriter cdata(_cycler);
  400. cdata->_state = cdata->_state->add_attrib(attrib, override);
  401. }
  402. ////////////////////////////////////////////////////////////////////
  403. // Function: PandaNode::get_attrib
  404. // Access: Published
  405. // Description: Returns the render attribute of the indicated type,
  406. // if it is defined on the node, or NULL if it is not.
  407. // This checks only what is set on this particular node
  408. // level, and has nothing to do with what render
  409. // attributes may be inherited from parent nodes.
  410. ////////////////////////////////////////////////////////////////////
  411. INLINE const RenderAttrib *PandaNode::
  412. get_attrib(TypeHandle type) const {
  413. CDReader cdata(_cycler);
  414. int index = cdata->_state->find_attrib(type);
  415. if (index >= 0) {
  416. return cdata->_state->get_attrib(index);
  417. }
  418. return NULL;
  419. }
  420. ////////////////////////////////////////////////////////////////////
  421. // Function: PandaNode::has_attrib
  422. // Access: Published
  423. // Description: Returns true if there is a render attribute of the
  424. // indicated type defined on this node, or false if
  425. // there is not.
  426. ////////////////////////////////////////////////////////////////////
  427. INLINE bool PandaNode::
  428. has_attrib(TypeHandle type) const {
  429. CDReader cdata(_cycler);
  430. int index = cdata->_state->find_attrib(type);
  431. return (index >= 0);
  432. }
  433. ////////////////////////////////////////////////////////////////////
  434. // Function: PandaNode::clear_attrib
  435. // Access: Published
  436. // Description: Removes the render attribute of the given type from
  437. // this node. This node, and the subgraph below, will
  438. // now inherit the indicated render attribute from the
  439. // nodes above this one.
  440. ////////////////////////////////////////////////////////////////////
  441. INLINE void PandaNode::
  442. clear_attrib(TypeHandle type) {
  443. CDWriter cdata(_cycler);
  444. cdata->_state = cdata->_state->remove_attrib(type);
  445. }
  446. ////////////////////////////////////////////////////////////////////
  447. // Function: PandaNode::set_effect
  448. // Access: Published
  449. // Description: Adds the indicated render effect to the scene
  450. // graph on this node. If there was already an effect
  451. // of the same type, it is replaced.
  452. ////////////////////////////////////////////////////////////////////
  453. INLINE void PandaNode::
  454. set_effect(const RenderEffect *effect) {
  455. CDWriter cdata(_cycler);
  456. cdata->_effects = cdata->_effects->add_effect(effect);
  457. }
  458. ////////////////////////////////////////////////////////////////////
  459. // Function: PandaNode::get_effect
  460. // Access: Published
  461. // Description: Returns the render effect of the indicated type,
  462. // if it is defined on the node, or NULL if it is not.
  463. ////////////////////////////////////////////////////////////////////
  464. INLINE const RenderEffect *PandaNode::
  465. get_effect(TypeHandle type) const {
  466. CDReader cdata(_cycler);
  467. int index = cdata->_effects->find_effect(type);
  468. if (index >= 0) {
  469. return cdata->_effects->get_effect(index);
  470. }
  471. return NULL;
  472. }
  473. ////////////////////////////////////////////////////////////////////
  474. // Function: PandaNode::has_effect
  475. // Access: Published
  476. // Description: Returns true if there is a render effect of the
  477. // indicated type defined on this node, or false if
  478. // there is not.
  479. ////////////////////////////////////////////////////////////////////
  480. INLINE bool PandaNode::
  481. has_effect(TypeHandle type) const {
  482. CDReader cdata(_cycler);
  483. int index = cdata->_effects->find_effect(type);
  484. return (index >= 0);
  485. }
  486. ////////////////////////////////////////////////////////////////////
  487. // Function: PandaNode::clear_effect
  488. // Access: Published
  489. // Description: Removes the render effect of the given type from
  490. // this node.
  491. ////////////////////////////////////////////////////////////////////
  492. INLINE void PandaNode::
  493. clear_effect(TypeHandle type) {
  494. CDWriter cdata(_cycler);
  495. cdata->_effects = cdata->_effects->remove_effect(type);
  496. }
  497. ////////////////////////////////////////////////////////////////////
  498. // Function: PandaNode::set_state
  499. // Access: Published
  500. // Description: Sets the complete RenderState that will be applied to
  501. // all nodes at this level and below. (The actual state
  502. // that will be applied to lower nodes is based on the
  503. // composition of RenderStates from above this node as
  504. // well). This completely replaces whatever has been
  505. // set on this node via repeated calls to set_attrib().
  506. ////////////////////////////////////////////////////////////////////
  507. INLINE void PandaNode::
  508. set_state(const RenderState *state) {
  509. CDWriter cdata(_cycler);
  510. cdata->_state = state;
  511. }
  512. ////////////////////////////////////////////////////////////////////
  513. // Function: PandaNode::get_state
  514. // Access: Published
  515. // Description: Returns the complete RenderState that will be applied
  516. // to all nodes at this level and below, as set on this
  517. // node. This returns only the RenderState set on this
  518. // particular node, and has nothing to do with state
  519. // that might be inherited from above.
  520. ////////////////////////////////////////////////////////////////////
  521. INLINE const RenderState *PandaNode::
  522. get_state() const {
  523. CDReader cdata(_cycler);
  524. return cdata->_state;
  525. }
  526. ////////////////////////////////////////////////////////////////////
  527. // Function: PandaNode::clear_state
  528. // Access: Published
  529. // Description: Resets this node to leave the render state alone.
  530. // Nodes at this level and below will once again inherit
  531. // their render state unchanged from the nodes above
  532. // this level.
  533. ////////////////////////////////////////////////////////////////////
  534. INLINE void PandaNode::
  535. clear_state() {
  536. CDWriter cdata(_cycler);
  537. cdata->_state = RenderState::make_empty();
  538. }
  539. ////////////////////////////////////////////////////////////////////
  540. // Function: PandaNode::set_effects
  541. // Access: Published
  542. // Description: Sets the complete RenderEffects that will be applied
  543. // this node. This completely replaces whatever has
  544. // been set on this node via repeated calls to
  545. // set_attrib().
  546. ////////////////////////////////////////////////////////////////////
  547. INLINE void PandaNode::
  548. set_effects(const RenderEffects *effects) {
  549. CDWriter cdata(_cycler);
  550. cdata->_effects = effects;
  551. }
  552. ////////////////////////////////////////////////////////////////////
  553. // Function: PandaNode::get_effects
  554. // Access: Published
  555. // Description: Returns the complete RenderEffects that will be
  556. // applied to this node.
  557. ////////////////////////////////////////////////////////////////////
  558. INLINE const RenderEffects *PandaNode::
  559. get_effects() const {
  560. CDReader cdata(_cycler);
  561. return cdata->_effects;
  562. }
  563. ////////////////////////////////////////////////////////////////////
  564. // Function: PandaNode::clear_effects
  565. // Access: Published
  566. // Description: Resets this node to have no render effects.
  567. ////////////////////////////////////////////////////////////////////
  568. INLINE void PandaNode::
  569. clear_effects() {
  570. CDWriter cdata(_cycler);
  571. cdata->_effects = RenderEffects::make_empty();
  572. }
  573. ////////////////////////////////////////////////////////////////////
  574. // Function: PandaNode::set_transform
  575. // Access: Published
  576. // Description: Sets the transform that will be applied to this node
  577. // and below. This defines a new coordinate space at
  578. // this point in the scene graph and below.
  579. ////////////////////////////////////////////////////////////////////
  580. INLINE void PandaNode::
  581. set_transform(const TransformState *transform) {
  582. CDWriter cdata(_cycler);
  583. cdata->_transform = transform;
  584. mark_bound_stale();
  585. transform_changed();
  586. }
  587. ////////////////////////////////////////////////////////////////////
  588. // Function: PandaNode::get_transform
  589. // Access: Published
  590. // Description: Returns the transform that has been set on this
  591. // particular node. This is not the net transform from
  592. // the root, but simply the transform on this particular
  593. // node.
  594. ////////////////////////////////////////////////////////////////////
  595. INLINE const TransformState *PandaNode::
  596. get_transform() const {
  597. CDReader cdata(_cycler);
  598. return cdata->_transform;
  599. }
  600. ////////////////////////////////////////////////////////////////////
  601. // Function: PandaNode::clear_transform
  602. // Access: Published
  603. // Description: Resets the transform on this node to the identity
  604. // transform.
  605. ////////////////////////////////////////////////////////////////////
  606. INLINE void PandaNode::
  607. clear_transform() {
  608. CDWriter cdata(_cycler);
  609. cdata->_transform = TransformState::make_identity();
  610. mark_bound_stale();
  611. transform_changed();
  612. }
  613. ////////////////////////////////////////////////////////////////////
  614. // Function: PandaNode::set_prev_transform
  615. // Access: Published
  616. // Description: Sets the transform that represents this node's
  617. // "previous" position, one frame ago, for the purposes
  618. // of detecting motion for accurate collision
  619. // calculations.
  620. ////////////////////////////////////////////////////////////////////
  621. INLINE void PandaNode::
  622. set_prev_transform(const TransformState *transform) {
  623. CDWriter cdata(_cycler);
  624. cdata->_prev_transform = transform;
  625. }
  626. ////////////////////////////////////////////////////////////////////
  627. // Function: PandaNode::get_prev_transform
  628. // Access: Published
  629. // Description: Returns the transform that has been set as this
  630. // node's "previous" position. See
  631. // set_prev_transform().
  632. ////////////////////////////////////////////////////////////////////
  633. INLINE const TransformState *PandaNode::
  634. get_prev_transform() const {
  635. CDReader cdata(_cycler);
  636. return cdata->_prev_transform;
  637. }
  638. ////////////////////////////////////////////////////////////////////
  639. // Function: PandaNode::reset_prev_transform
  640. // Access: Published
  641. // Description: Resets the "previous" transform on this node to be
  642. // the same as the current transform. This is not the
  643. // same as clearing it to identity.
  644. ////////////////////////////////////////////////////////////////////
  645. INLINE void PandaNode::
  646. reset_prev_transform() {
  647. CDWriter cdata(_cycler);
  648. cdata->_prev_transform = cdata->_transform;
  649. }
  650. ////////////////////////////////////////////////////////////////////
  651. // Function: PandaNode::set_tag
  652. // Access: Published
  653. // Description: Associates a user-defined value with a user-defined
  654. // key which is stored on the node. This value has no
  655. // meaning to Panda; but it is stored indefinitely on
  656. // the node until it is requested again.
  657. //
  658. // Each unique key stores a different string value.
  659. // There is no effective limit on the number of
  660. // different keys that may be stored or on the length of
  661. // any one key's value.
  662. ////////////////////////////////////////////////////////////////////
  663. INLINE void PandaNode::
  664. set_tag(const string &key, const string &value) {
  665. CDWriter cdata(_cycler);
  666. cdata->_tag_data[key] = value;
  667. }
  668. ////////////////////////////////////////////////////////////////////
  669. // Function: PandaNode::get_tag
  670. // Access: Published
  671. // Description: Retrieves the user-defined value that was previously
  672. // set on this node for the particular key, if any. If
  673. // no value has been previously set, returns the empty
  674. // string.
  675. ////////////////////////////////////////////////////////////////////
  676. INLINE string PandaNode::
  677. get_tag(const string &key) const {
  678. CDReader cdata(_cycler);
  679. TagData::const_iterator ti;
  680. ti = cdata->_tag_data.find(key);
  681. if (ti != cdata->_tag_data.end()) {
  682. return (*ti).second;
  683. }
  684. return string();
  685. }
  686. ////////////////////////////////////////////////////////////////////
  687. // Function: PandaNode::has_tag
  688. // Access: Published
  689. // Description: Returns true if a value has been defined on this node
  690. // for the particular key (even if that value is the
  691. // empty string), or false if no value has been set.
  692. ////////////////////////////////////////////////////////////////////
  693. INLINE bool PandaNode::
  694. has_tag(const string &key) const {
  695. CDReader cdata(_cycler);
  696. TagData::const_iterator ti;
  697. ti = cdata->_tag_data.find(key);
  698. return (ti != cdata->_tag_data.end());
  699. }
  700. ////////////////////////////////////////////////////////////////////
  701. // Function: PandaNode::clear_tag
  702. // Access: Published
  703. // Description: Removes the value defined for this key on this
  704. // particular node. After a call to clear_tag(),
  705. // has_tag() will return false for the indicated key.
  706. ////////////////////////////////////////////////////////////////////
  707. INLINE void PandaNode::
  708. clear_tag(const string &key) {
  709. CDWriter cdata(_cycler);
  710. cdata->_tag_data.erase(key);
  711. }
  712. ////////////////////////////////////////////////////////////////////
  713. // Function: PandaNode::ls
  714. // Access: Published
  715. // Description: Lists all the nodes at and below the current path
  716. // hierarchically.
  717. ////////////////////////////////////////////////////////////////////
  718. INLINE void PandaNode::
  719. ls(ostream &out, int indent_level) const {
  720. r_list_descendants(out, indent_level);
  721. }
  722. ////////////////////////////////////////////////////////////////////
  723. // Function: PandaNode::set_draw_mask
  724. // Access: Published
  725. // Description: Sets the hide/show bits of this particular node.
  726. //
  727. // During the cull traversal, a node is not visited if
  728. // none of its draw mask bits intersect with the
  729. // camera's draw mask bits. These masks can be used to
  730. // selectively hide and show different parts of the
  731. // scene graph from different cameras that are otherwise
  732. // viewing the same scene. See
  733. // Camera::set_camera_mask().
  734. ////////////////////////////////////////////////////////////////////
  735. INLINE void PandaNode::
  736. set_draw_mask(DrawMask mask) {
  737. CDWriter cdata(_cycler);
  738. cdata->_draw_mask = mask;
  739. }
  740. ////////////////////////////////////////////////////////////////////
  741. // Function: PandaNode::get_draw_mask
  742. // Access: Published
  743. // Description: Returns the hide/show bits of this particular node.
  744. // See set_draw_mask().
  745. ////////////////////////////////////////////////////////////////////
  746. INLINE DrawMask PandaNode::
  747. get_draw_mask() const {
  748. CDReader cdata(_cycler);
  749. return cdata->_draw_mask;
  750. }
  751. ////////////////////////////////////////////////////////////////////
  752. // Function: PandaNode::get_net_collide_mask
  753. // Access: Published
  754. // Description: Returns the union of all into_collide_mask() values
  755. // set at CollisionNodes at this level and below.
  756. ////////////////////////////////////////////////////////////////////
  757. INLINE CollideMask PandaNode::
  758. get_net_collide_mask() const {
  759. // Call get_bound() first to ensure the mask is recomputed.
  760. BoundedObject::get_bound();
  761. CDReader cdata(_cycler);
  762. return cdata->_net_collide_mask;
  763. }
  764. ////////////////////////////////////////////////////////////////////
  765. // Function: PandaNode::set_bound
  766. // Access: Published
  767. // Description: Sets the type of the external bounding volume that is
  768. // placed around this node and all of its children.
  769. ////////////////////////////////////////////////////////////////////
  770. INLINE void PandaNode::
  771. set_bound(BoundingVolumeType type) {
  772. CDWriter cdata(_cycler);
  773. cdata->_fixed_internal_bound = false;
  774. BoundedObject::set_bound(type);
  775. }
  776. ////////////////////////////////////////////////////////////////////
  777. // Function: PandaNode::set_bound
  778. // Access: Published
  779. // Description: Resets the internal bounding volume so that it is the
  780. // indicated volume. The external bounding volume as
  781. // returned by get_bound() (which includes all of the
  782. // node's children) will be adjusted to include this
  783. // internal volume.
  784. ////////////////////////////////////////////////////////////////////
  785. INLINE void PandaNode::
  786. set_bound(const BoundingVolume &volume) {
  787. CDWriter cdata(_cycler);
  788. cdata->_fixed_internal_bound = true;
  789. _internal_bound.set_bound(volume);
  790. changed_internal_bound();
  791. }
  792. ////////////////////////////////////////////////////////////////////
  793. // Function: PandaNode::get_bound
  794. // Access: Published
  795. // Description: Returns the node's external bounding volume. This is
  796. // the bounding volume around the node and all of its
  797. // children.
  798. ////////////////////////////////////////////////////////////////////
  799. INLINE const BoundingVolume &PandaNode::
  800. get_bound() const {
  801. return BoundedObject::get_bound();
  802. }
  803. ////////////////////////////////////////////////////////////////////
  804. // Function: PandaNode::get_internal_bound
  805. // Access: Published
  806. // Description: Returns the node's internal bounding volume. This is
  807. // the bounding volume around the node alone, without
  808. // including children.
  809. ////////////////////////////////////////////////////////////////////
  810. INLINE const BoundingVolume &PandaNode::
  811. get_internal_bound() const {
  812. CDReader cdata(_cycler);
  813. if (!cdata->_fixed_internal_bound &&
  814. (is_bound_stale() || _internal_bound.is_bound_stale())) {
  815. ((PandaNode *)this)->recompute_internal_bound();
  816. }
  817. return _internal_bound.get_bound();
  818. }
  819. ////////////////////////////////////////////////////////////////////
  820. // Function: PandaNode::changed_internal_bound
  821. // Access: Protected
  822. // Description: Should be called whenever you adjust the
  823. // _internal_bound member, to force the external
  824. // bounding volume to be recomputed.
  825. ////////////////////////////////////////////////////////////////////
  826. INLINE void PandaNode::
  827. changed_internal_bound() {
  828. BoundedObject::mark_bound_stale();
  829. }
  830. ////////////////////////////////////////////////////////////////////
  831. // Function: PandaNode::add_net_collide_mask
  832. // Access: Protected
  833. // Description: Adds the indicated bits into the net_collide_mask for
  834. // this node. This is normally called only by
  835. // CollisionNode::recompute_bound().
  836. ////////////////////////////////////////////////////////////////////
  837. INLINE void PandaNode::
  838. add_net_collide_mask(CollideMask mask) {
  839. CDWriter cdata(_cycler);
  840. cdata->_net_collide_mask |= mask;
  841. }
  842. ////////////////////////////////////////////////////////////////////
  843. // Function: PandaNode::get_children
  844. // Access: Public
  845. // Description: Returns an object that can be used to walk through
  846. // the list of children of the node. When you intend to
  847. // visit multiple children, using this is slightly
  848. // faster than calling get_child() directly on the
  849. // PandaNode, since this object keeps the PipelineCycler
  850. // open the whole time.
  851. //
  852. // However, this object does not protect you from
  853. // self-modifying loops (e.g. adding or removing
  854. // children during traversal).
  855. ////////////////////////////////////////////////////////////////////
  856. INLINE PandaNode::Children PandaNode::
  857. get_children() const {
  858. CDReader cdata(_cycler);
  859. return Children(cdata);
  860. }
  861. ////////////////////////////////////////////////////////////////////
  862. // Function: PandaNode::get_children_copy
  863. // Access: Public
  864. // Description: Returns an object that can be used to walk through
  865. // the list of children of the node. Unlike
  866. // get_children(), this function actually returns an
  867. // object that protects you from self-modifying loops,
  868. // because it makes and returns a copy of the complete
  869. // children list.
  870. ////////////////////////////////////////////////////////////////////
  871. INLINE PandaNode::ChildrenCopy PandaNode::
  872. get_children_copy() const {
  873. CDReader cdata(_cycler);
  874. return ChildrenCopy(cdata);
  875. }