Panda3D

eggGroup.h

00001 // Filename: eggGroup.h
00002 // Created by:  drose (16Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef EGGGROUP_H
00016 #define EGGGROUP_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "eggGroupNode.h"
00021 #include "eggRenderMode.h"
00022 #include "eggTransform.h"
00023 #include "eggVertex.h"
00024 #include "eggSwitchCondition.h"
00025 #include "pt_EggVertex.h"
00026 
00027 #include "luse.h"
00028 #include "collideMask.h"
00029 #include "vector_string.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : EggGroup
00033 // Description : The main glue of the egg hierarchy, this corresponds
00034 //               to the <Group>, <Instance>, and <Joint> type nodes.
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDAEGG EggGroup : public EggGroupNode, public EggRenderMode, public EggTransform {
00037 PUBLISHED:
00038   typedef pmap<PT_EggVertex, double> VertexRef;
00039   typedef pmap<string, string> TagData;
00040 
00041   // These bits are all stored somewhere in _flags.
00042   enum GroupType {
00043     // The bits here must correspond to those in Flags, below.
00044     GT_invalid               = -1,
00045     GT_group                 = 0x00000000,
00046     GT_instance              = 0x00000001,
00047     GT_joint                 = 0x00000002,
00048   };
00049   enum DCSType {
00050     // The bits here must correspond to those in Flags2, below.
00051     DC_unspecified           = 0x00000000,
00052     DC_none                  = 0x00000010,
00053     DC_local                 = 0x00000020,
00054     DC_net                   = 0x00000030,
00055     DC_no_touch              = 0x00000040,
00056     DC_default               = 0x00000050,
00057   };
00058   enum BillboardType {
00059     // The bits here must correspond to those in Flags, below.
00060     BT_none                  = 0x00000000,
00061     BT_axis                  = 0x00000020,
00062     BT_point_camera_relative = 0x00000040,
00063     BT_point_world_relative  = 0x00000080,
00064   };
00065   enum CollisionSolidType {
00066     // The bits here must correspond to those in Flags, below, and
00067     // they must fit within F_cs_type.
00068     CST_none                 = 0x00000000,
00069     CST_plane                = 0x00010000,
00070     CST_polygon              = 0x00020000,
00071     CST_polyset              = 0x00030000,
00072     CST_sphere               = 0x00040000,
00073     CST_tube                 = 0x00050000,
00074     CST_inv_sphere           = 0x00060000,
00075     CST_floor_mesh           = 0x00080000,
00076   };
00077   enum CollideFlags {
00078     // The bits here must correspond to those in Flags, below, and
00079     // they must fit within F_collide_flags.
00080     CF_none                  = 0x00000000,
00081     CF_descend               = 0x00100000,
00082     CF_event                 = 0x00200000,
00083     CF_keep                  = 0x00400000,
00084     CF_solid                 = 0x00800000,
00085     CF_center                = 0x01000000,
00086     CF_turnstile             = 0x02000000,
00087     CF_level                 = 0x04000000,
00088     CF_intangible            = 0x08000000,
00089   };
00090 
00091   enum DartType {
00092     // The bits here must correspond to those in Flags, below.
00093     DT_none                  = 0x00000000,
00094     DT_structured            = 0x10000000,
00095     DT_sync                  = 0x20000000,
00096     DT_nosync                = 0x30000000,
00097     DT_default               = 0x40000000,
00098   };
00099 
00100 
00101   // These correspond to ColorBlendAttrib::Mode (but not numerically).
00102   enum BlendMode {
00103     BM_unspecified,
00104     BM_none,
00105     BM_add,
00106     BM_subtract,
00107     BM_inv_subtract,
00108     BM_min,
00109     BM_max
00110   };
00111 
00112   // These correspond to ColorBlendAttrib::Operand (but not numerically).
00113   enum BlendOperand {
00114     BO_unspecified,
00115     BO_zero,
00116     BO_one,
00117     BO_incoming_color,
00118     BO_one_minus_incoming_color,
00119     BO_fbuffer_color,
00120     BO_one_minus_fbuffer_color,
00121     BO_incoming_alpha,
00122     BO_one_minus_incoming_alpha,
00123     BO_fbuffer_alpha,
00124     BO_one_minus_fbuffer_alpha,
00125     BO_constant_color,
00126     BO_one_minus_constant_color,
00127     BO_constant_alpha,
00128     BO_one_minus_constant_alpha,
00129     BO_incoming_color_saturate,
00130     BO_color_scale,
00131     BO_one_minus_color_scale,
00132     BO_alpha_scale,
00133     BO_one_minus_alpha_scale,
00134   };
00135 
00136   EggGroup(const string &name = "");
00137   EggGroup(const EggGroup &copy);
00138   EggGroup &operator = (const EggGroup &copy);
00139   ~EggGroup();
00140 
00141   virtual void write(ostream &out, int indent_level) const;
00142   void write_billboard_flags(ostream &out, int indent_level) const;
00143   void write_collide_flags(ostream &out, int indent_level) const;
00144   void write_model_flags(ostream &out, int indent_level) const;
00145   void write_switch_flags(ostream &out, int indent_level) const;
00146   void write_object_types(ostream &out, int indent_level) const;
00147   void write_decal_flags(ostream &out, int indent_level) const;
00148   void write_tags(ostream &out, int indent_level) const;
00149   void write_render_mode(ostream &out, int indent_level) const;
00150 
00151   virtual bool is_joint() const;
00152 
00153   virtual EggRenderMode *determine_alpha_mode();
00154   virtual EggRenderMode *determine_depth_write_mode();
00155   virtual EggRenderMode *determine_depth_test_mode();
00156   virtual EggRenderMode *determine_visibility_mode();
00157   virtual EggRenderMode *determine_depth_offset();
00158   virtual EggRenderMode *determine_draw_order();
00159   virtual EggRenderMode *determine_bin();
00160   virtual bool determine_indexed();
00161   virtual bool determine_decal();
00162 
00163   void set_group_type(GroupType type);
00164   INLINE GroupType get_group_type() const;
00165   INLINE bool is_instance_type() const;
00166 
00167   INLINE void set_billboard_type(BillboardType type);
00168   INLINE BillboardType get_billboard_type() const;
00169 
00170   INLINE void set_billboard_center(const LPoint3d &billboard_center);
00171   INLINE void clear_billboard_center();
00172   INLINE bool has_billboard_center() const;
00173   INLINE const LPoint3d &get_billboard_center() const;
00174 
00175   INLINE void set_cs_type(CollisionSolidType type);
00176   INLINE CollisionSolidType get_cs_type() const;
00177 
00178   INLINE void set_collide_flags(int flags);
00179   INLINE CollideFlags get_collide_flags() const;
00180 
00181   INLINE void set_collision_name(const string &collision_name);
00182   INLINE void clear_collision_name();
00183   INLINE bool has_collision_name() const;
00184   INLINE const string &get_collision_name() const;
00185 
00186   INLINE void set_dcs_type(DCSType type);
00187   INLINE DCSType get_dcs_type() const;
00188   INLINE bool has_dcs_type() const;
00189 
00190   INLINE void set_dart_type(DartType type);
00191   INLINE DartType get_dart_type() const;
00192 
00193   INLINE void set_switch_flag(bool flag);
00194   INLINE bool get_switch_flag() const;
00195 
00196   INLINE void set_switch_fps(double fps);
00197   INLINE double get_switch_fps() const;
00198 
00199   INLINE void add_object_type(const string &object_type);
00200   INLINE void clear_object_types();
00201   INLINE int get_num_object_types() const;
00202   INLINE string get_object_type(int index) const;
00203   MAKE_SEQ(get_object_types, get_num_object_types, get_object_type);
00204   bool has_object_type(const string &object_type) const;
00205   bool remove_object_type(const string &object_type);
00206 
00207   INLINE void set_model_flag(bool flag);
00208   INLINE bool get_model_flag() const;
00209 
00210   INLINE void set_texlist_flag(bool flag);
00211   INLINE bool get_texlist_flag() const;
00212 
00213   INLINE void set_nofog_flag(bool flag);
00214   INLINE bool get_nofog_flag() const;
00215 
00216   INLINE void set_decal_flag(bool flag);
00217   INLINE bool get_decal_flag() const;
00218 
00219   INLINE void set_direct_flag(bool flag);
00220   INLINE bool get_direct_flag() const;
00221 
00222   INLINE void set_portal_flag(bool flag);
00223   INLINE bool get_portal_flag() const;
00224 
00225   INLINE void set_polylight_flag(bool flag);
00226   INLINE bool get_polylight_flag() const;
00227 
00228   INLINE void set_indexed_flag(bool flag);
00229   INLINE void clear_indexed_flag();
00230   INLINE bool has_indexed_flag() const;
00231   INLINE bool get_indexed_flag() const;
00232 
00233   INLINE void set_collide_mask(CollideMask mask);
00234   INLINE void clear_collide_mask();
00235   INLINE bool has_collide_mask() const;
00236   INLINE CollideMask get_collide_mask() const;
00237 
00238   INLINE void set_from_collide_mask(CollideMask mask);
00239   INLINE void clear_from_collide_mask();
00240   INLINE bool has_from_collide_mask() const;
00241   INLINE CollideMask get_from_collide_mask() const;
00242 
00243   INLINE void set_into_collide_mask(CollideMask mask);
00244   INLINE void clear_into_collide_mask();
00245   INLINE bool has_into_collide_mask() const;
00246   INLINE CollideMask get_into_collide_mask() const;
00247 
00248   INLINE void set_blend_mode(BlendMode blend_mode);
00249   INLINE BlendMode get_blend_mode() const;
00250   INLINE void set_blend_operand_a(BlendOperand blend_operand_a);
00251   INLINE BlendOperand get_blend_operand_a() const;
00252   INLINE void set_blend_operand_b(BlendOperand blend_operand_b);
00253   INLINE BlendOperand get_blend_operand_b() const;
00254   INLINE void set_blend_color(const Colorf &blend_color);
00255   INLINE void clear_blend_color();
00256   INLINE bool has_blend_color() const;
00257   INLINE const Colorf &get_blend_color() const;
00258 
00259   INLINE void set_lod(const EggSwitchCondition &lod);
00260   INLINE void clear_lod();
00261   INLINE bool has_lod() const;
00262   INLINE const EggSwitchCondition &get_lod() const;
00263 
00264   INLINE void set_tag(const string &key, const string &value);
00265   INLINE string get_tag(const string &key) const;
00266   INLINE bool has_tag(const string &key) const;
00267   INLINE void clear_tag(const string &key);
00268 
00269   INLINE const EggTransform &get_default_pose() const;
00270   INLINE EggTransform &modify_default_pose();
00271   INLINE void set_default_pose(const EggTransform &transform);
00272   INLINE void clear_default_pose();
00273 
00274   INLINE void set_scroll_u(const double u_speed);
00275   INLINE void set_scroll_v(const double v_speed);
00276   INLINE void set_scroll_r(const double r_speed);
00277   INLINE double get_scroll_u() const;
00278   INLINE double get_scroll_v() const;
00279   INLINE double get_scroll_r() const;
00280 
00281   INLINE bool has_scrolling_uvs();
00282 
00283 public:
00284   INLINE TagData::const_iterator tag_begin() const;
00285   INLINE TagData::const_iterator tag_end() const;
00286   INLINE TagData::size_type tag_size() const;
00287 
00288 PUBLISHED:
00289   void ref_vertex(EggVertex *vert, double membership = 1.0);
00290   void unref_vertex(EggVertex *vert);
00291   void unref_all_vertices();
00292   double get_vertex_membership(const EggVertex *vert) const;
00293   void set_vertex_membership(EggVertex *vert, double membership);
00294   void steal_vrefs(EggGroup *other);
00295 
00296 public:
00297   INLINE VertexRef::const_iterator vref_begin() const;
00298   INLINE VertexRef::const_iterator vref_end() const;
00299   INLINE VertexRef::size_type vref_size() const;
00300 
00301 PUBLISHED:
00302 #ifndef NDEBUG
00303   void test_vref_integrity() const;
00304 #else
00305   void test_vref_integrity() const { }
00306 #endif  // NDEBUG
00307 
00308   void add_group_ref(EggGroup *group);
00309   int get_num_group_refs() const;
00310   EggGroup *get_group_ref(int n) const;
00311   MAKE_SEQ(get_group_refs, get_num_group_refs, get_group_ref);
00312   void remove_group_ref(int n);
00313   void clear_group_refs();
00314 
00315   static GroupType string_group_type(const string &strval);
00316   static DartType string_dart_type(const string &strval);
00317   static DCSType string_dcs_type(const string &strval);
00318   static BillboardType string_billboard_type(const string &strval);
00319   static CollisionSolidType string_cs_type(const string &strval);
00320   static CollideFlags string_collide_flags(const string &strval);
00321   static BlendMode string_blend_mode(const string &strval);
00322   static BlendOperand string_blend_operand(const string &strval);
00323 
00324 public:
00325   virtual EggTransform *as_transform();
00326 
00327 protected:
00328   void write_vertex_ref(ostream &out, int indent_level) const;
00329   virtual bool egg_start_parse_body();
00330   virtual void adjust_under();
00331   virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
00332                            CoordinateSystem to_cs);
00333   virtual void r_flatten_transforms();
00334 
00335   virtual void transform_changed();
00336 
00337 private:
00338 
00339   enum Flags {
00340     F_group_type             = 0x00000003,
00341 
00342     F_billboard_type         = 0x000000e0,
00343     F_switch_flag            = 0x00000100,
00344     F_model_flag             = 0x00000400,
00345     F_texlist_flag           = 0x00000800,
00346     F_nofog_flag             = 0x00001000,
00347     F_decal_flag             = 0x00002000,
00348     F_direct_flag            = 0x00004000,
00349     F_cs_type                = 0x000f0000,
00350     F_collide_flags          = 0x0ff00000,
00351     F_dart_type              = 0xf0000000,
00352   };
00353   enum Flags2 {
00354     F2_collide_mask          = 0x00000001,
00355     F2_from_collide_mask     = 0x00000002,
00356     F2_into_collide_mask     = 0x00000004,
00357     F2_billboard_center      = 0x00000008,
00358 
00359     F2_dcs_type              = 0x00000070,
00360     F2_portal_flag           = 0x00000080,
00361     F2_polylight_flag        = 0x00000100,
00362     F2_indexed_flag          = 0x00000200,
00363     F2_has_indexed_flag      = 0x00000400,
00364 
00365     F2_has_blend_color       = 0x00000800,
00366   };
00367 
00368   int _flags;
00369   int _flags2;
00370   CollideMask _collide_mask, _from_collide_mask, _into_collide_mask;
00371   BlendMode _blend_mode;
00372   BlendOperand _blend_operand_a;
00373   BlendOperand _blend_operand_b;
00374   Colorf _blend_color;
00375   LPoint3d _billboard_center;
00376   vector_string _object_types;
00377   string _collision_name;
00378   double _fps;
00379   PT(EggSwitchCondition) _lod;
00380   TagData _tag_data;
00381 
00382   double _u_speed;
00383   double _v_speed;
00384   double _r_speed;
00385 
00386   // This is the <DefaultPose> entry for a <Joint>.  It is not the
00387   // <Transform> entry (that is stored via inheritance, in the
00388   // EggTransform class we inherit from).
00389   EggTransform _default_pose;
00390 
00391   VertexRef _vref;
00392 
00393   typedef pvector< PT(EggGroup) > GroupRefs;
00394   GroupRefs _group_refs;
00395 
00396 
00397 public:
00398 
00399   static TypeHandle get_class_type() {
00400     return _type_handle;
00401   }
00402   static void init_type() {
00403     EggGroupNode::init_type();
00404     EggRenderMode::init_type();
00405     register_type(_type_handle, "EggGroup",
00406                   EggGroupNode::get_class_type(),
00407                   EggRenderMode::get_class_type());
00408   }
00409   virtual TypeHandle get_type() const {
00410     return get_class_type();
00411   }
00412   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00413 
00414 private:
00415   static TypeHandle _type_handle;
00416 };
00417 
00418 ostream &operator << (ostream &out, EggGroup::GroupType t);
00419 ostream &operator << (ostream &out, EggGroup::DartType t);
00420 ostream &operator << (ostream &out, EggGroup::DCSType t);
00421 ostream &operator << (ostream &out, EggGroup::BillboardType t);
00422 ostream &operator << (ostream &out, EggGroup::CollisionSolidType t);
00423 ostream &operator << (ostream &out, EggGroup::CollideFlags t);
00424 ostream &operator << (ostream &out, EggGroup::BlendMode t);
00425 ostream &operator << (ostream &out, EggGroup::BlendOperand t);
00426 
00427 
00428 #include "eggGroup.I"
00429 
00430 #endif
00431 
 All Classes Functions Variables Enumerations