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