Panda3D
eggGroup.h
1 // Filename: eggGroup.h
2 // Created by: drose (16Jan99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EGGGROUP_H
16 #define EGGGROUP_H
17 
18 #include "pandabase.h"
19 
20 #include "eggGroupNode.h"
21 #include "eggRenderMode.h"
22 #include "eggTransform.h"
23 #include "eggVertex.h"
24 #include "eggSwitchCondition.h"
25 #include "pt_EggVertex.h"
26 
27 #include "luse.h"
28 #include "collideMask.h"
29 #include "vector_string.h"
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : EggGroup
33 // Description : The main glue of the egg hierarchy, this corresponds
34 // to the <Group>, <Instance>, and <Joint> type nodes.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDAEGG EggGroup : public EggGroupNode, public EggRenderMode, public EggTransform {
37 PUBLISHED:
40 
41  // These bits are all stored somewhere in _flags.
42  enum GroupType {
43  // The bits here must correspond to those in Flags, below.
44  GT_invalid = -1,
45  GT_group = 0x00000000,
46  GT_instance = 0x00000001,
47  GT_joint = 0x00000002,
48  };
49  enum DCSType {
50  // The bits here must correspond to those in Flags2, below.
51  DC_unspecified = 0x00000000,
52  DC_none = 0x00000010,
53  DC_local = 0x00000020,
54  DC_net = 0x00000030,
55  DC_no_touch = 0x00000040,
56  DC_default = 0x00000050,
57  };
58  enum BillboardType {
59  // The bits here must correspond to those in Flags, below.
60  BT_none = 0x00000000,
61  BT_axis = 0x00000020,
62  BT_point_camera_relative = 0x00000040,
63  BT_point_world_relative = 0x00000080,
64  };
65  enum CollisionSolidType {
66  // The bits here must correspond to those in Flags, below, and
67  // they must fit within F_cs_type.
68  CST_none = 0x00000000,
69  CST_plane = 0x00010000,
70  CST_polygon = 0x00020000,
71  CST_polyset = 0x00030000,
72  CST_sphere = 0x00040000,
73  CST_tube = 0x00050000,
74  CST_inv_sphere = 0x00060000,
75  CST_box = 0x00070000,
76  CST_floor_mesh = 0x00080000,
77  };
78  enum CollideFlags {
79  // The bits here must correspond to those in Flags, below, and
80  // they must fit within F_collide_flags.
81  CF_none = 0x00000000,
82  CF_descend = 0x00100000,
83  CF_event = 0x00200000,
84  CF_keep = 0x00400000,
85  CF_solid = 0x00800000,
86  CF_center = 0x01000000,
87  CF_turnstile = 0x02000000,
88  CF_level = 0x04000000,
89  CF_intangible = 0x08000000,
90  };
91 
92  enum DartType {
93  // The bits here must correspond to those in Flags, below.
94  DT_none = 0x00000000,
95  DT_structured = 0x10000000,
96  DT_sync = 0x20000000,
97  DT_nosync = 0x30000000,
98  DT_default = 0x40000000,
99  };
100 
101 
102  // These correspond to ColorBlendAttrib::Mode (but not numerically).
103  enum BlendMode {
104  BM_unspecified,
105  BM_none,
106  BM_add,
107  BM_subtract,
108  BM_inv_subtract,
109  BM_min,
110  BM_max
111  };
112 
113  // These correspond to ColorBlendAttrib::Operand (but not numerically).
114  enum BlendOperand {
115  BO_unspecified,
116  BO_zero,
117  BO_one,
118  BO_incoming_color,
119  BO_one_minus_incoming_color,
120  BO_fbuffer_color,
121  BO_one_minus_fbuffer_color,
122  BO_incoming_alpha,
123  BO_one_minus_incoming_alpha,
124  BO_fbuffer_alpha,
125  BO_one_minus_fbuffer_alpha,
126  BO_constant_color,
127  BO_one_minus_constant_color,
128  BO_constant_alpha,
129  BO_one_minus_constant_alpha,
130  BO_incoming_color_saturate,
131  BO_color_scale,
132  BO_one_minus_color_scale,
133  BO_alpha_scale,
134  BO_one_minus_alpha_scale,
135  };
136 
137  EggGroup(const string &name = "");
138  EggGroup(const EggGroup &copy);
139  EggGroup &operator = (const EggGroup &copy);
140  ~EggGroup();
141 
142  virtual void write(ostream &out, int indent_level) const;
143  void write_billboard_flags(ostream &out, int indent_level) const;
144  void write_collide_flags(ostream &out, int indent_level) const;
145  void write_model_flags(ostream &out, int indent_level) const;
146  void write_switch_flags(ostream &out, int indent_level) const;
147  void write_object_types(ostream &out, int indent_level) const;
148  void write_decal_flags(ostream &out, int indent_level) const;
149  void write_tags(ostream &out, int indent_level) const;
150  void write_render_mode(ostream &out, int indent_level) const;
151 
152  virtual bool is_joint() const;
153 
160  virtual EggRenderMode *determine_bin();
161  virtual bool determine_indexed();
162  virtual bool determine_decal();
163 
164  void set_group_type(GroupType type);
165  INLINE GroupType get_group_type() const;
166  INLINE bool is_instance_type() const;
167 
168  INLINE void set_billboard_type(BillboardType type);
169  INLINE BillboardType get_billboard_type() const;
170 
171  INLINE void set_billboard_center(const LPoint3d &billboard_center);
172  INLINE void clear_billboard_center();
173  INLINE bool has_billboard_center() const;
174  INLINE const LPoint3d &get_billboard_center() const;
175 
176  INLINE void set_cs_type(CollisionSolidType type);
177  INLINE CollisionSolidType get_cs_type() const;
178 
179  INLINE void set_collide_flags(int flags);
180  INLINE CollideFlags get_collide_flags() const;
181 
182  INLINE void set_collision_name(const string &collision_name);
183  INLINE void clear_collision_name();
184  INLINE bool has_collision_name() const;
185  INLINE const string &get_collision_name() const;
186 
187  INLINE void set_dcs_type(DCSType type);
188  INLINE DCSType get_dcs_type() const;
189  INLINE bool has_dcs_type() const;
190 
191  INLINE void set_dart_type(DartType type);
192  INLINE DartType get_dart_type() const;
193 
194  INLINE void set_switch_flag(bool flag);
195  INLINE bool get_switch_flag() const;
196 
197  INLINE void set_switch_fps(double fps);
198  INLINE double get_switch_fps() const;
199 
200  INLINE void add_object_type(const string &object_type);
201  INLINE void clear_object_types();
202  INLINE int get_num_object_types() const;
203  INLINE string get_object_type(int index) const;
204  MAKE_SEQ(get_object_types, get_num_object_types, get_object_type);
205  bool has_object_type(const string &object_type) const;
206  bool remove_object_type(const string &object_type);
207 
208  INLINE void set_model_flag(bool flag);
209  INLINE bool get_model_flag() const;
210 
211  INLINE void set_texlist_flag(bool flag);
212  INLINE bool get_texlist_flag() const;
213 
214  INLINE void set_nofog_flag(bool flag);
215  INLINE bool get_nofog_flag() const;
216 
217  INLINE void set_decal_flag(bool flag);
218  INLINE bool get_decal_flag() const;
219 
220  INLINE void set_direct_flag(bool flag);
221  INLINE bool get_direct_flag() const;
222 
223  INLINE void set_portal_flag(bool flag);
224  INLINE bool get_portal_flag() const;
225 
226  INLINE void set_occluder_flag(bool flag);
227  INLINE bool get_occluder_flag() const;
228 
229  INLINE void set_polylight_flag(bool flag);
230  INLINE bool get_polylight_flag() const;
231 
232  INLINE void set_indexed_flag(bool flag);
233  INLINE void clear_indexed_flag();
234  INLINE bool has_indexed_flag() const;
235  INLINE bool get_indexed_flag() const;
236 
237  INLINE void set_collide_mask(CollideMask mask);
238  INLINE void clear_collide_mask();
239  INLINE bool has_collide_mask() const;
240  INLINE CollideMask get_collide_mask() const;
241 
242  INLINE void set_from_collide_mask(CollideMask mask);
243  INLINE void clear_from_collide_mask();
244  INLINE bool has_from_collide_mask() const;
245  INLINE CollideMask get_from_collide_mask() const;
246 
247  INLINE void set_into_collide_mask(CollideMask mask);
248  INLINE void clear_into_collide_mask();
249  INLINE bool has_into_collide_mask() const;
250  INLINE CollideMask get_into_collide_mask() const;
251 
252  INLINE void set_blend_mode(BlendMode blend_mode);
253  INLINE BlendMode get_blend_mode() const;
254  INLINE void set_blend_operand_a(BlendOperand blend_operand_a);
255  INLINE BlendOperand get_blend_operand_a() const;
256  INLINE void set_blend_operand_b(BlendOperand blend_operand_b);
257  INLINE BlendOperand get_blend_operand_b() const;
258  INLINE void set_blend_color(const LColor &blend_color);
259  INLINE void clear_blend_color();
260  INLINE bool has_blend_color() const;
261  INLINE const LColor &get_blend_color() const;
262 
263  INLINE void set_lod(const EggSwitchCondition &lod);
264  INLINE void clear_lod();
265  INLINE bool has_lod() const;
266  INLINE const EggSwitchCondition &get_lod() const;
267 
268  INLINE void set_tag(const string &key, const string &value);
269  INLINE string get_tag(const string &key) const;
270  INLINE bool has_tag(const string &key) const;
271  INLINE void clear_tag(const string &key);
272 
273  INLINE const EggTransform &get_default_pose() const;
274  INLINE EggTransform &modify_default_pose();
275  INLINE void set_default_pose(const EggTransform &transform);
276  INLINE void clear_default_pose();
277 
278  INLINE void set_scroll_u(const double u_speed);
279  INLINE void set_scroll_v(const double v_speed);
280  INLINE void set_scroll_w(const double w_speed);
281  INLINE void set_scroll_r(const double r_speed);
282  INLINE double get_scroll_u() const;
283  INLINE double get_scroll_v() const;
284  INLINE double get_scroll_w() const;
285  INLINE double get_scroll_r() const;
286 
287  INLINE bool has_scrolling_uvs();
288 
289 public:
290  INLINE TagData::const_iterator tag_begin() const;
291  INLINE TagData::const_iterator tag_end() const;
292  INLINE TagData::size_type tag_size() const;
293 
294 PUBLISHED:
295  void ref_vertex(EggVertex *vert, double membership = 1.0);
296  void unref_vertex(EggVertex *vert);
297  void unref_all_vertices();
298  double get_vertex_membership(const EggVertex *vert) const;
299  void set_vertex_membership(EggVertex *vert, double membership);
300  void steal_vrefs(EggGroup *other);
301 
302 public:
303  INLINE VertexRef::const_iterator vref_begin() const;
304  INLINE VertexRef::const_iterator vref_end() const;
305  INLINE VertexRef::size_type vref_size() const;
306 
307 PUBLISHED:
308 #ifdef _DEBUG
309  void test_vref_integrity() const;
310 #else
311  void test_vref_integrity() const { }
312 #endif // _DEBUG
313 
314  void add_group_ref(EggGroup *group);
315  int get_num_group_refs() const;
316  EggGroup *get_group_ref(int n) const;
317  MAKE_SEQ(get_group_refs, get_num_group_refs, get_group_ref);
318  void remove_group_ref(int n);
319  void clear_group_refs();
320 
321  static GroupType string_group_type(const string &strval);
322  static DartType string_dart_type(const string &strval);
323  static DCSType string_dcs_type(const string &strval);
324  static BillboardType string_billboard_type(const string &strval);
325  static CollisionSolidType string_cs_type(const string &strval);
326  static CollideFlags string_collide_flags(const string &strval);
327  static BlendMode string_blend_mode(const string &strval);
328  static BlendOperand string_blend_operand(const string &strval);
329 
330 public:
331  virtual EggTransform *as_transform();
332 
333 protected:
334  void write_vertex_ref(ostream &out, int indent_level) const;
335  virtual bool egg_start_parse_body();
336  virtual void adjust_under();
337  virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
338  CoordinateSystem to_cs);
339  virtual void r_flatten_transforms();
340 
341  virtual void transform_changed();
342 
343 private:
344 
345  enum Flags {
346  F_group_type = 0x00000003,
347 
348  F_billboard_type = 0x000000e0,
349  F_switch_flag = 0x00000100,
350  F_model_flag = 0x00000400,
351  F_texlist_flag = 0x00000800,
352  F_nofog_flag = 0x00001000,
353  F_decal_flag = 0x00002000,
354  F_direct_flag = 0x00004000,
355  F_cs_type = 0x000f0000,
356  F_collide_flags = 0x0ff00000,
357  F_dart_type = 0xf0000000,
358  };
359  enum Flags2 {
360  F2_collide_mask = 0x00000001,
361  F2_from_collide_mask = 0x00000002,
362  F2_into_collide_mask = 0x00000004,
363  F2_billboard_center = 0x00000008,
364 
365  F2_dcs_type = 0x00000070,
366  F2_portal_flag = 0x00000080,
367  F2_polylight_flag = 0x00000100,
368  F2_indexed_flag = 0x00000200,
369  F2_has_indexed_flag = 0x00000400,
370  F2_has_blend_color = 0x00000800,
371  F2_occluder_flag = 0x00001000,
372  };
373 
374  int _flags;
375  int _flags2;
376  CollideMask _collide_mask, _from_collide_mask, _into_collide_mask;
377  BlendMode _blend_mode;
378  BlendOperand _blend_operand_a;
379  BlendOperand _blend_operand_b;
380  LColor _blend_color;
381  LPoint3d _billboard_center;
382  vector_string _object_types;
383  string _collision_name;
384  double _fps;
385  PT(EggSwitchCondition) _lod;
386  TagData _tag_data;
387 
388  double _u_speed;
389  double _v_speed;
390  double _w_speed;
391  double _r_speed;
392 
393  // This is the <DefaultPose> entry for a <Joint>. It is not the
394  // <Transform> entry (that is stored via inheritance, in the
395  // EggTransform class we inherit from).
396  EggTransform _default_pose;
397 
398  VertexRef _vref;
399 
401  GroupRefs _group_refs;
402 
403 
404 public:
405 
406  static TypeHandle get_class_type() {
407  return _type_handle;
408  }
409  static void init_type() {
410  EggGroupNode::init_type();
411  EggRenderMode::init_type();
412  register_type(_type_handle, "EggGroup",
413  EggGroupNode::get_class_type(),
414  EggRenderMode::get_class_type());
415  }
416  virtual TypeHandle get_type() const {
417  return get_class_type();
418  }
419  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
420 
421 private:
422  static TypeHandle _type_handle;
423 };
424 
425 ostream &operator << (ostream &out, EggGroup::GroupType t);
426 ostream &operator << (ostream &out, EggGroup::DartType t);
427 ostream &operator << (ostream &out, EggGroup::DCSType t);
428 ostream &operator << (ostream &out, EggGroup::BillboardType t);
429 ostream &operator << (ostream &out, EggGroup::CollisionSolidType t);
430 ostream &operator << (ostream &out, EggGroup::CollideFlags t);
431 ostream &operator << (ostream &out, EggGroup::BlendMode t);
432 ostream &operator << (ostream &out, EggGroup::BlendOperand t);
433 
434 
435 #include "eggGroup.I"
436 
437 #endif
438 
virtual bool determine_indexed()
Walks back up the hierarchy, looking for an EggGroup at this level or above that has the "indexed" sc...
Definition: eggNode.cxx:228
virtual void write(ostream &out, int indent_level) const
Writes the group and all of its children to the indicated output stream in Egg format.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
virtual EggRenderMode * determine_draw_order()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:190
virtual EggRenderMode * determine_depth_test_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:136
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:36
This class stores miscellaneous rendering properties that is associated with geometry, and which may be set on the geometry primitive level, on the group above it, or indirectly via a texture.
Definition: eggRenderMode.h:36
virtual EggTransform * as_transform()
Returns this object cross-cast to an EggTransform pointer, if it inherits from EggTransform, or NULL if it does not.
Definition: eggObject.cxx:183
virtual bool determine_decal()
Walks back up the hierarchy, looking for an EggGroup at this level or above that has the "decal" flag...
Definition: eggNode.cxx:248
virtual EggRenderMode * determine_visibility_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:154
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
virtual EggRenderMode * determine_depth_write_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:118
virtual EggRenderMode * determine_alpha_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:100
virtual bool is_joint() const
Returns true if this particular node represents a <Joint> entry or not.
Definition: eggNode.cxx:75
virtual EggRenderMode * determine_bin()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:208
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual EggRenderMode * determine_depth_offset()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Definition: eggNode.cxx:172
This corresponds to a <SwitchCondition> entry within a group.
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
Definition: eggTransform.h:33