Panda3D
 All Classes Functions Variables Enumerations
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_occluder_flag(bool flag);
00226   INLINE bool get_occluder_flag() const;
00227 
00228   INLINE void set_polylight_flag(bool flag);
00229   INLINE bool get_polylight_flag() const;
00230 
00231   INLINE void set_indexed_flag(bool flag);
00232   INLINE void clear_indexed_flag();
00233   INLINE bool has_indexed_flag() const;
00234   INLINE bool get_indexed_flag() const;
00235 
00236   INLINE void set_collide_mask(CollideMask mask);
00237   INLINE void clear_collide_mask();
00238   INLINE bool has_collide_mask() const;
00239   INLINE CollideMask get_collide_mask() const;
00240 
00241   INLINE void set_from_collide_mask(CollideMask mask);
00242   INLINE void clear_from_collide_mask();
00243   INLINE bool has_from_collide_mask() const;
00244   INLINE CollideMask get_from_collide_mask() const;
00245 
00246   INLINE void set_into_collide_mask(CollideMask mask);
00247   INLINE void clear_into_collide_mask();
00248   INLINE bool has_into_collide_mask() const;
00249   INLINE CollideMask get_into_collide_mask() const;
00250 
00251   INLINE void set_blend_mode(BlendMode blend_mode);
00252   INLINE BlendMode get_blend_mode() const;
00253   INLINE void set_blend_operand_a(BlendOperand blend_operand_a);
00254   INLINE BlendOperand get_blend_operand_a() const;
00255   INLINE void set_blend_operand_b(BlendOperand blend_operand_b);
00256   INLINE BlendOperand get_blend_operand_b() const;
00257   INLINE void set_blend_color(const LColor &blend_color);
00258   INLINE void clear_blend_color();
00259   INLINE bool has_blend_color() const;
00260   INLINE const LColor &get_blend_color() const;
00261 
00262   INLINE void set_lod(const EggSwitchCondition &lod);
00263   INLINE void clear_lod();
00264   INLINE bool has_lod() const;
00265   INLINE const EggSwitchCondition &get_lod() const;
00266 
00267   INLINE void set_tag(const string &key, const string &value);
00268   INLINE string get_tag(const string &key) const;
00269   INLINE bool has_tag(const string &key) const;
00270   INLINE void clear_tag(const string &key);
00271 
00272   INLINE const EggTransform &get_default_pose() const;
00273   INLINE EggTransform &modify_default_pose();
00274   INLINE void set_default_pose(const EggTransform &transform);
00275   INLINE void clear_default_pose();
00276 
00277   INLINE void set_scroll_u(const double u_speed);
00278   INLINE void set_scroll_v(const double v_speed);
00279   INLINE void set_scroll_r(const double r_speed);
00280   INLINE double get_scroll_u() const;
00281   INLINE double get_scroll_v() const;
00282   INLINE double get_scroll_r() const;
00283 
00284   INLINE bool has_scrolling_uvs();
00285 
00286 public:
00287   INLINE TagData::const_iterator tag_begin() const;
00288   INLINE TagData::const_iterator tag_end() const;
00289   INLINE TagData::size_type tag_size() const;
00290 
00291 PUBLISHED:
00292   void ref_vertex(EggVertex *vert, double membership = 1.0);
00293   void unref_vertex(EggVertex *vert);
00294   void unref_all_vertices();
00295   double get_vertex_membership(const EggVertex *vert) const;
00296   void set_vertex_membership(EggVertex *vert, double membership);
00297   void steal_vrefs(EggGroup *other);
00298 
00299 public:
00300   INLINE VertexRef::const_iterator vref_begin() const;
00301   INLINE VertexRef::const_iterator vref_end() const;
00302   INLINE VertexRef::size_type vref_size() const;
00303 
00304 PUBLISHED:
00305 #ifdef _DEBUG
00306   void test_vref_integrity() const;
00307 #else
00308   void test_vref_integrity() const { }
00309 #endif  // _DEBUG
00310 
00311   void add_group_ref(EggGroup *group);
00312   int get_num_group_refs() const;
00313   EggGroup *get_group_ref(int n) const;
00314   MAKE_SEQ(get_group_refs, get_num_group_refs, get_group_ref);
00315   void remove_group_ref(int n);
00316   void clear_group_refs();
00317 
00318   static GroupType string_group_type(const string &strval);
00319   static DartType string_dart_type(const string &strval);
00320   static DCSType string_dcs_type(const string &strval);
00321   static BillboardType string_billboard_type(const string &strval);
00322   static CollisionSolidType string_cs_type(const string &strval);
00323   static CollideFlags string_collide_flags(const string &strval);
00324   static BlendMode string_blend_mode(const string &strval);
00325   static BlendOperand string_blend_operand(const string &strval);
00326 
00327 public:
00328   virtual EggTransform *as_transform();
00329 
00330 protected:
00331   void write_vertex_ref(ostream &out, int indent_level) const;
00332   virtual bool egg_start_parse_body();
00333   virtual void adjust_under();
00334   virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
00335                            CoordinateSystem to_cs);
00336   virtual void r_flatten_transforms();
00337 
00338   virtual void transform_changed();
00339 
00340 private:
00341 
00342   enum Flags {
00343     F_group_type             = 0x00000003,
00344 
00345     F_billboard_type         = 0x000000e0,
00346     F_switch_flag            = 0x00000100,
00347     F_model_flag             = 0x00000400,
00348     F_texlist_flag           = 0x00000800,
00349     F_nofog_flag             = 0x00001000,
00350     F_decal_flag             = 0x00002000,
00351     F_direct_flag            = 0x00004000,
00352     F_cs_type                = 0x000f0000,
00353     F_collide_flags          = 0x0ff00000,
00354     F_dart_type              = 0xf0000000,
00355   };
00356   enum Flags2 {
00357     F2_collide_mask          = 0x00000001,
00358     F2_from_collide_mask     = 0x00000002,
00359     F2_into_collide_mask     = 0x00000004,
00360     F2_billboard_center      = 0x00000008,
00361 
00362     F2_dcs_type              = 0x00000070,
00363     F2_portal_flag           = 0x00000080,
00364     F2_polylight_flag        = 0x00000100,
00365     F2_indexed_flag          = 0x00000200,
00366     F2_has_indexed_flag      = 0x00000400,
00367     F2_has_blend_color       = 0x00000800,
00368     F2_occluder_flag         = 0x00001000,
00369   };
00370 
00371   int _flags;
00372   int _flags2;
00373   CollideMask _collide_mask, _from_collide_mask, _into_collide_mask;
00374   BlendMode _blend_mode;
00375   BlendOperand _blend_operand_a;
00376   BlendOperand _blend_operand_b;
00377   LColor _blend_color;
00378   LPoint3d _billboard_center;
00379   vector_string _object_types;
00380   string _collision_name;
00381   double _fps;
00382   PT(EggSwitchCondition) _lod;
00383   TagData _tag_data;
00384 
00385   double _u_speed;
00386   double _v_speed;
00387   double _r_speed;
00388 
00389   // This is the <DefaultPose> entry for a <Joint>.  It is not the
00390   // <Transform> entry (that is stored via inheritance, in the
00391   // EggTransform class we inherit from).
00392   EggTransform _default_pose;
00393 
00394   VertexRef _vref;
00395 
00396   typedef pvector< PT(EggGroup) > GroupRefs;
00397   GroupRefs _group_refs;
00398 
00399 
00400 public:
00401 
00402   static TypeHandle get_class_type() {
00403     return _type_handle;
00404   }
00405   static void init_type() {
00406     EggGroupNode::init_type();
00407     EggRenderMode::init_type();
00408     register_type(_type_handle, "EggGroup",
00409                   EggGroupNode::get_class_type(),
00410                   EggRenderMode::get_class_type());
00411   }
00412   virtual TypeHandle get_type() const {
00413     return get_class_type();
00414   }
00415   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00416 
00417 private:
00418   static TypeHandle _type_handle;
00419 };
00420 
00421 ostream &operator << (ostream &out, EggGroup::GroupType t);
00422 ostream &operator << (ostream &out, EggGroup::DartType t);
00423 ostream &operator << (ostream &out, EggGroup::DCSType t);
00424 ostream &operator << (ostream &out, EggGroup::BillboardType t);
00425 ostream &operator << (ostream &out, EggGroup::CollisionSolidType t);
00426 ostream &operator << (ostream &out, EggGroup::CollideFlags t);
00427 ostream &operator << (ostream &out, EggGroup::BlendMode t);
00428 ostream &operator << (ostream &out, EggGroup::BlendOperand t);
00429 
00430 
00431 #include "eggGroup.I"
00432 
00433 #endif
00434 
 All Classes Functions Variables Enumerations