sceneGraphReducer.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Filename: sceneGraphReducer.h
  2. // Created by: drose (14Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef SCENEGRAPHREDUCER_H
  19. #define SCENEGRAPHREDUCER_H
  20. #include "pandabase.h"
  21. #include "transformState.h"
  22. #include "renderAttrib.h"
  23. #include "renderState.h"
  24. #include "accumulatedAttribs.h"
  25. #include "geomTransformer.h"
  26. #include "typedObject.h"
  27. #include "pointerTo.h"
  28. class PandaNode;
  29. ///////////////////////////////////////////////////////////////////
  30. // Class : SceneGraphReducer
  31. // Description : An interface for simplifying ("flattening") scene
  32. // graphs by eliminating unneeded nodes and collapsing
  33. // out unneeded state changes and transforms.
  34. //
  35. // This class is designed so that it may be inherited
  36. // from and specialized, if needed, to fine-tune the
  37. // flattening behavior, but normally the default
  38. // behavior is sufficient.
  39. ////////////////////////////////////////////////////////////////////
  40. class EXPCL_PANDA SceneGraphReducer {
  41. PUBLISHED:
  42. INLINE SceneGraphReducer();
  43. INLINE ~SceneGraphReducer();
  44. enum AttribTypes {
  45. TT_transform = 0x001,
  46. TT_color = 0x002,
  47. TT_color_scale = 0x004,
  48. TT_tex_matrix = 0x008,
  49. TT_other = 0x010,
  50. };
  51. INLINE void apply_attribs(PandaNode *node, int attrib_types = ~0);
  52. INLINE void apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs,
  53. int attrib_types, GeomTransformer &transformer);
  54. int flatten(PandaNode *root, bool combine_siblings);
  55. protected:
  56. void r_apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs,
  57. int attrib_types, GeomTransformer &transformer);
  58. int r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
  59. bool combine_siblings);
  60. int flatten_siblings(PandaNode *parent_node);
  61. bool consider_child(PandaNode *grandparent_node,
  62. PandaNode *parent_node, PandaNode *child_node);
  63. bool consider_siblings(PandaNode *parent_node, PandaNode *child1,
  64. PandaNode *child2);
  65. bool do_flatten_child(PandaNode *grandparent_node,
  66. PandaNode *parent_node, PandaNode *child_node);
  67. PandaNode *do_flatten_siblings(PandaNode *parent_node,
  68. PandaNode *child1, PandaNode *child2);
  69. PT(PandaNode) collapse_nodes(PandaNode *node1, PandaNode *node2,
  70. bool siblings);
  71. void choose_name(PandaNode *preserve, PandaNode *source1,
  72. PandaNode *source2);
  73. private:
  74. GeomTransformer _transformer;
  75. };
  76. #include "sceneGraphReducer.I"
  77. #endif