eggGroup.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // Filename: eggGroup.h
  2. // Created by: drose (16Jan99)
  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. #ifndef EGGGROUP_H
  19. #define EGGGROUP_H
  20. #include "pandabase.h"
  21. #include "eggGroupNode.h"
  22. #include "eggRenderMode.h"
  23. #include "eggTransform3d.h"
  24. #include "eggVertex.h"
  25. #include "eggSwitchCondition.h"
  26. #include "pt_EggVertex.h"
  27. #include "luse.h"
  28. #include "collideMask.h"
  29. #include "vector_string.h"
  30. ////////////////////////////////////////////////////////////////////
  31. // Class : EggGroup
  32. // Description : The main glue of the egg hierarchy, this corresponds
  33. // to the <Group>, <Instance>, and <Joint> type nodes.
  34. ////////////////////////////////////////////////////////////////////
  35. class EXPCL_PANDAEGG EggGroup : public EggGroupNode, public EggRenderMode, public EggTransform3d {
  36. public:
  37. typedef pmap<PT_EggVertex, double> VertexRef;
  38. // These bits are all stored somewhere in _flags.
  39. enum GroupType {
  40. // The bits here must correspond to those in Flags, below.
  41. GT_invalid = -1,
  42. GT_group = 0x00000000,
  43. GT_instance = 0x00000001,
  44. GT_joint = 0x00000002,
  45. };
  46. enum DartType {
  47. // The bits here must correspond to those in Flags, below.
  48. DT_none = 0x00000000,
  49. DT_sync = 0x00000004,
  50. DT_nosync = 0x00000008,
  51. DT_default = 0x0000000c,
  52. };
  53. enum DCSType {
  54. // The bits here must correspond to those in Flags2, below.
  55. DC_none = 0x00000000,
  56. DC_local = 0x00000010,
  57. DC_net = 0x00000020,
  58. DC_default = 0x00000030,
  59. };
  60. enum BillboardType {
  61. // The bits here must correspond to those in Flags, below.
  62. BT_none = 0x00000000,
  63. BT_axis = 0x00000020,
  64. BT_point_camera_relative = 0x00000040,
  65. BT_point_world_relative = 0x00000080,
  66. };
  67. enum CollisionSolidType {
  68. // The bits here must correspond to those in Flags, below.
  69. CST_none = 0x00000000,
  70. CST_plane = 0x00010000,
  71. CST_polygon = 0x00020000,
  72. CST_polyset = 0x00030000,
  73. CST_sphere = 0x00040000,
  74. CST_inverse_sphere = 0x00050000,
  75. CST_geode = 0x00060000,
  76. };
  77. enum CollideFlags {
  78. // The bits here must correspond to those in Flags, below.
  79. CF_none = 0x00000000,
  80. CF_intangible = 0x00080000,
  81. CF_descend = 0x00100000,
  82. CF_event = 0x00200000,
  83. CF_keep = 0x00400000,
  84. CF_solid = 0x00800000,
  85. CF_center = 0x01000000,
  86. CF_turnstile = 0x02000000,
  87. };
  88. EggGroup(const string &name = "");
  89. EggGroup(const EggGroup &copy);
  90. EggGroup &operator = (const EggGroup &copy);
  91. ~EggGroup();
  92. virtual void write(ostream &out, int indent_level) const;
  93. virtual bool is_joint() const;
  94. virtual EggRenderMode *determine_alpha_mode();
  95. virtual EggRenderMode *determine_depth_write_mode();
  96. virtual EggRenderMode *determine_depth_test_mode();
  97. virtual EggRenderMode *determine_draw_order();
  98. virtual EggRenderMode *determine_bin();
  99. void set_group_type(GroupType type);
  100. INLINE GroupType get_group_type() const;
  101. INLINE bool is_instance_type() const;
  102. INLINE void set_billboard_type(BillboardType type);
  103. INLINE BillboardType get_billboard_type() const;
  104. INLINE void set_billboard_center(const LPoint3d &billboard_center);
  105. INLINE void clear_billboard_center();
  106. INLINE bool has_billboard_center() const;
  107. INLINE const LPoint3d &get_billboard_center() const;
  108. INLINE void set_cs_type(CollisionSolidType type);
  109. INLINE CollisionSolidType get_cs_type() const;
  110. INLINE void set_collide_flags(int flags);
  111. INLINE CollideFlags get_collide_flags() const;
  112. INLINE void set_collision_name(const string &collision_name);
  113. INLINE void clear_collision_name();
  114. INLINE bool has_collision_name() const;
  115. INLINE const string &get_collision_name() const;
  116. INLINE void set_dcs_type(DCSType type);
  117. INLINE DCSType get_dcs_type() const;
  118. INLINE void set_dart_type(DartType type);
  119. INLINE DartType get_dart_type() const;
  120. INLINE void set_switch_flag(bool flag);
  121. INLINE bool get_switch_flag() const;
  122. INLINE void set_switch_fps(double fps);
  123. INLINE double get_switch_fps() const;
  124. INLINE void add_object_type(const string &object_type);
  125. INLINE void clear_object_types();
  126. INLINE int get_num_object_types() const;
  127. INLINE string get_object_type(int index) const;
  128. bool has_object_type(const string &object_type) const;
  129. bool remove_object_type(const string &object_type);
  130. INLINE void set_model_flag(bool flag);
  131. INLINE bool get_model_flag() const;
  132. INLINE void set_texlist_flag(bool flag);
  133. INLINE bool get_texlist_flag() const;
  134. INLINE void set_nofog_flag(bool flag);
  135. INLINE bool get_nofog_flag() const;
  136. INLINE void set_decal_flag(bool flag);
  137. INLINE bool get_decal_flag() const;
  138. INLINE void set_direct_flag(bool flag);
  139. INLINE bool get_direct_flag() const;
  140. INLINE void set_collide_mask(CollideMask mask);
  141. INLINE void clear_collide_mask();
  142. INLINE bool has_collide_mask() const;
  143. INLINE CollideMask get_collide_mask() const;
  144. INLINE void set_from_collide_mask(CollideMask mask);
  145. INLINE void clear_from_collide_mask();
  146. INLINE bool has_from_collide_mask() const;
  147. INLINE CollideMask get_from_collide_mask() const;
  148. INLINE void set_into_collide_mask(CollideMask mask);
  149. INLINE void clear_into_collide_mask();
  150. INLINE bool has_into_collide_mask() const;
  151. INLINE CollideMask get_into_collide_mask() const;
  152. INLINE void set_lod(const EggSwitchCondition &lod);
  153. INLINE void clear_lod();
  154. INLINE bool has_lod() const;
  155. INLINE const EggSwitchCondition &get_lod() const;
  156. void ref_vertex(EggVertex *vert, double membership = 1.0);
  157. void unref_vertex(EggVertex *vert);
  158. void unref_all_vertices();
  159. double get_vertex_membership(const EggVertex *vert) const;
  160. INLINE VertexRef::const_iterator vref_begin() const;
  161. INLINE VertexRef::const_iterator vref_end() const;
  162. INLINE VertexRef::size_type vref_size() const;
  163. #ifndef NDEBUG
  164. void test_vref_integrity() const;
  165. #else
  166. void test_vref_integrity() const { }
  167. #endif // NDEBUG
  168. static GroupType string_group_type(const string &string);
  169. static DartType string_dart_type(const string &string);
  170. static DCSType string_dcs_type(const string &string);
  171. static BillboardType string_billboard_type(const string &string);
  172. static CollisionSolidType string_cs_type(const string &string);
  173. static CollideFlags string_collide_flags(const string &string);
  174. protected:
  175. void write_vertex_ref(ostream &out, int indent_level) const;
  176. virtual bool egg_start_parse_body();
  177. virtual void adjust_under();
  178. virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
  179. CoordinateSystem to_cs);
  180. virtual void r_flatten_transforms();
  181. virtual void transform_changed();
  182. private:
  183. enum Flags {
  184. F_group_type = 0x00000003,
  185. F_dart_type = 0x0000000c,
  186. F_billboard_type = 0x000000e0,
  187. F_switch_flag = 0x00000100,
  188. F_model_flag = 0x00000400,
  189. F_texlist_flag = 0x00000800,
  190. F_nofog_flag = 0x00001000,
  191. F_decal_flag = 0x00002000,
  192. F_direct_flag = 0x00004000,
  193. F_cs_type = 0x00070000,
  194. F_collide_flags = 0x03f80000,
  195. };
  196. enum Flags2 {
  197. F2_collide_mask = 0x00000001,
  198. F2_from_collide_mask = 0x00000002,
  199. F2_into_collide_mask = 0x00000004,
  200. F2_billboard_center = 0x00000008,
  201. F2_dcs_type = 0x00000030,
  202. };
  203. int _flags;
  204. int _flags2;
  205. CollideMask _collide_mask, _from_collide_mask, _into_collide_mask;
  206. LPoint3d _billboard_center;
  207. vector_string _object_types;
  208. string _collision_name;
  209. double _fps;
  210. PT(EggSwitchCondition) _lod;
  211. VertexRef _vref;
  212. public:
  213. static TypeHandle get_class_type() {
  214. return _type_handle;
  215. }
  216. static void init_type() {
  217. EggGroupNode::init_type();
  218. EggRenderMode::init_type();
  219. register_type(_type_handle, "EggGroup",
  220. EggGroupNode::get_class_type(),
  221. EggRenderMode::get_class_type());
  222. }
  223. virtual TypeHandle get_type() const {
  224. return get_class_type();
  225. }
  226. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  227. private:
  228. static TypeHandle _type_handle;
  229. };
  230. ostream &operator << (ostream &out, EggGroup::GroupType t);
  231. ostream &operator << (ostream &out, EggGroup::DartType t);
  232. ostream &operator << (ostream &out, EggGroup::DCSType t);
  233. ostream &operator << (ostream &out, EggGroup::BillboardType t);
  234. ostream &operator << (ostream &out, EggGroup::CollisionSolidType t);
  235. ostream &operator << (ostream &out, EggGroup::CollideFlags t);
  236. #include "eggGroup.I"
  237. #endif