Panda3D
 All Classes Functions Variables Enumerations
eggLoader.h
00001 // Filename: eggLoader.h
00002 // Created by:  drose (26Feb02)
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 EGGLOADER_H
00016 #define EGGLOADER_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "deferredNodeProperty.h"
00021 #include "eggData.h"
00022 #include "eggTexture.h"
00023 #include "pt_EggTexture.h"
00024 #include "eggGroup.h"
00025 #include "eggMaterial.h"
00026 #include "pt_EggMaterial.h"
00027 #include "eggVertexPool.h"
00028 #include "texture.h"
00029 #include "pandaNode.h"
00030 #include "pointerTo.h"
00031 #include "lmatrix.h"
00032 #include "indirectCompareTo.h"
00033 #include "textureAttrib.h"
00034 #include "textureStage.h"
00035 #include "texGenAttrib.h"
00036 #include "colorBlendAttrib.h"
00037 #include "eggTransform.h"
00038 #include "geomVertexData.h"
00039 #include "geomPrimitive.h"
00040 #include "bamCacheRecord.h"
00041 
00042 class EggNode;
00043 class EggBin;
00044 class EggTable;
00045 class EggNurbsCurve;
00046 class EggNurbsSurface;
00047 class EggPrimitive;
00048 class EggPolygon;
00049 class EggMaterial;
00050 class RenderRelation;
00051 class CollisionSolid;
00052 class CollisionNode;
00053 class CollisionPlane;
00054 class CollisionPolygon;
00055 class PortalNode;
00056 class OccluderNode;
00057 class PolylightNode;
00058 class EggRenderState;
00059 class CharacterMaker;
00060 
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //       Class : EggLoader
00064 // Description : Converts an egg data structure, possibly read from an
00065 //               egg file but not necessarily, into a scene graph
00066 //               suitable for rendering.
00067 //
00068 //               This class isn't exported from this package.
00069 ////////////////////////////////////////////////////////////////////
00070 class EggLoader {
00071 public:
00072   EggLoader();
00073   EggLoader(const EggData *data);
00074 
00075   void build_graph();
00076   void reparent_decals();
00077   void start_sequences();
00078 
00079   void make_polyset(EggBin *egg_bin, PandaNode *parent, 
00080                     const LMatrix4d *transform, bool is_dynamic,
00081                     CharacterMaker *character_maker);
00082 
00083   CPT(TransformState) make_transform(const EggTransform *egg_transform);
00084 
00085 private:
00086   class TextureDef {
00087   public:
00088     CPT(RenderAttrib) _texture;
00089     PT(TextureStage) _stage;
00090     const EggTexture *_egg_tex;
00091   };
00092 
00093   // This structure is used internally in setup_bucket().
00094   typedef pvector<const TextureDef *> TexMatTextures;
00095   typedef pmap<LMatrix3d, TexMatTextures> TexMatTransforms;
00096   typedef pmap<CPT(InternalName), TexMatTransforms> TexMats;
00097 
00098   // This structure is returned by setup_bucket().
00099   typedef pmap<CPT(InternalName), const EggTexture *> BakeInUVs;
00100 
00101   // This is used by make_primitive().
00102   class PrimitiveUnifier {
00103   public:
00104     INLINE PrimitiveUnifier(const GeomPrimitive *prim);
00105     INLINE bool operator < (const PrimitiveUnifier &other) const;
00106 
00107     TypeHandle _type;
00108     GeomPrimitive::ShadeModel _shade_model;
00109   };
00110   typedef pmap<PrimitiveUnifier, PT(GeomPrimitive) > UniquePrimitives;
00111   typedef pvector< PT(GeomPrimitive) > Primitives;
00112 
00113   void show_normals(EggVertexPool *vertex_pool, GeomNode *geom_node);  
00114 
00115   void make_nurbs_curve(EggNurbsCurve *egg_curve, PandaNode *parent,
00116                         const LMatrix4d &mat);
00117   void make_old_nurbs_curve(EggNurbsCurve *egg_curve, PandaNode *parent,
00118                             const LMatrix4d &mat);
00119   void make_nurbs_surface(EggNurbsSurface *egg_surface, PandaNode *parent,
00120                           const LMatrix4d &mat);
00121 
00122   void load_textures();
00123   bool load_texture(TextureDef &def, EggTexture *egg_tex);
00124   void apply_texture_attributes(Texture *tex, const EggTexture *egg_tex);
00125   Texture::CompressionMode convert_compression_mode(EggTexture::CompressionMode compression_mode) const;
00126   Texture::WrapMode convert_wrap_mode(EggTexture::WrapMode wrap_mode) const;
00127   PT(TextureStage) make_texture_stage(const EggTexture *egg_tex);
00128 
00129   void separate_switches(EggNode *egg_node);
00130   void emulate_bface(EggNode *egg_node);
00131 
00132   PandaNode *make_node(EggNode *egg_node, PandaNode *parent);
00133   PandaNode *make_node(EggBin *egg_bin, PandaNode *parent);
00134   PandaNode *make_polyset(EggBin *egg_bin, PandaNode *parent);
00135   PandaNode *make_lod(EggBin *egg_bin, PandaNode *parent);
00136   PandaNode *make_node(EggGroup *egg_group, PandaNode *parent);
00137   PandaNode *create_group_arc(EggGroup *egg_group, PandaNode *parent,
00138                                    PandaNode *node);
00139   PandaNode *make_node(EggTable *egg_table, PandaNode *parent);
00140   PandaNode *make_node(EggGroupNode *egg_group, PandaNode *parent);
00141 
00142   void check_for_polysets(EggGroup *egg_group, bool &all_polysets, 
00143                           bool &any_hidden);
00144   PT(GeomVertexData) make_vertex_data
00145   (const EggRenderState *render_state, EggVertexPool *vertex_pool, 
00146    EggNode *primitive_home, const LMatrix4d &transform, TransformBlendTable *blend_table,
00147    bool is_dynamic, CharacterMaker *character_maker, bool ignore_color);
00148   PT(TransformBlendTable) make_blend_table
00149   (EggVertexPool *vertex_bool, EggNode *primitive_home,
00150    CharacterMaker *character_maker);
00151   void record_morph
00152   (GeomVertexArrayFormat *array_format,
00153    CharacterMaker *character_maker, const string &morph_name, 
00154    InternalName *column_name, int num_components);
00155 
00156   void make_primitive(const EggRenderState *render_state, 
00157                       EggPrimitive *egg_prim, 
00158                       UniquePrimitives &unique_primitives,
00159                       Primitives &primitives,
00160                       bool has_overall_color, const LColor &overall_color);
00161 
00162   void set_portal_polygon(EggGroup *egg_group, PortalNode *pnode);
00163   void set_occluder_polygon(EggGroup *egg_group, OccluderNode *pnode);
00164   PT(EggPolygon) find_first_polygon(EggGroup *egg_group);
00165 
00166   bool make_sphere(EggGroup *start_group, EggGroup::CollideFlags flags,
00167                    LPoint3 &center, PN_stdfloat &radius, LColor &color);
00168 
00169   void make_collision_solids(EggGroup *start_group, EggGroup *egg_group,
00170                              CollisionNode *cnode);
00171   void make_collision_plane(EggGroup *egg_group, CollisionNode *cnode,
00172                             EggGroup::CollideFlags flags);
00173   void make_collision_polygon(EggGroup *egg_group, CollisionNode *cnode,
00174                               EggGroup::CollideFlags flags);
00175   void make_collision_polyset(EggGroup *egg_group, CollisionNode *cnode,
00176                               EggGroup::CollideFlags flags);
00177   void make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode,
00178                              EggGroup::CollideFlags flags);
00179   void make_collision_inv_sphere(EggGroup *egg_group, CollisionNode *cnode,
00180                                  EggGroup::CollideFlags flags);
00181   void make_collision_tube(EggGroup *egg_group, CollisionNode *cnode,
00182                            EggGroup::CollideFlags flags);
00183   void make_collision_floor_mesh(EggGroup *egg_group, CollisionNode *cnode,
00184                            EggGroup::CollideFlags flags);
00185   void apply_collision_flags(CollisionSolid *solid,
00186                              EggGroup::CollideFlags flags);
00187   EggGroup *find_collision_geometry(EggGroup *egg_group, 
00188                                     EggGroup::CollideFlags flags);
00189   CollisionPlane *create_collision_plane(EggPolygon *egg_poly,
00190                                          EggGroup *parent_group);
00191   void create_collision_polygons(CollisionNode *cnode, EggPolygon *egg_poly,
00192                                  EggGroup *parent_group,
00193                                  EggGroup::CollideFlags flags);
00194 
00195   void create_collision_floor_mesh(CollisionNode *cnode, 
00196                                  EggGroup *parent_group,
00197                                  EggGroup::CollideFlags flags);
00198 
00199   void apply_deferred_nodes(PandaNode *node, const DeferredNodeProperty &prop);
00200   bool expand_all_object_types(EggNode *egg_node);
00201   bool expand_object_types(EggGroup *egg_group, const pset<string> &expanded,
00202                            const pvector<string> &expanded_history);
00203   bool do_expand_object_type(EggGroup *egg_group, const pset<string> &expanded,
00204                              const pvector<string> &expanded_history,
00205                              const string &object_type);
00206 
00207   static TextureStage::CombineMode 
00208   get_combine_mode(const EggTexture *egg_tex, 
00209                    EggTexture::CombineChannel channel);
00210 
00211   static TextureStage::CombineSource
00212   get_combine_source(const EggTexture *egg_tex, 
00213                      EggTexture::CombineChannel channel, int n);
00214 
00215   static TextureStage::CombineOperand
00216   get_combine_operand(const EggTexture *egg_tex, 
00217                       EggTexture::CombineChannel channel, int n);
00218 
00219   static ColorBlendAttrib::Mode
00220   get_color_blend_mode(EggGroup::BlendMode mode);
00221 
00222   static ColorBlendAttrib::Operand
00223   get_color_blend_operand(EggGroup::BlendOperand operand);
00224 
00225   typedef pmap<PT_EggTexture, TextureDef> Textures;
00226   Textures _textures;
00227 
00228   typedef pmap<CPT_EggMaterial, CPT(RenderAttrib) > Materials;
00229   Materials _materials;
00230   Materials _materials_bface;
00231 
00232   typedef pmap<PT(EggGroup), PT(PandaNode) > Groups;
00233   Groups _groups;
00234 
00235   typedef pset<PandaNode *> ExtraNodes;
00236   ExtraNodes _decals;
00237   ExtraNodes _sequences;
00238 
00239   class VertexPoolTransform {
00240   public:
00241     bool operator < (const VertexPoolTransform &other) const;
00242     PT(EggVertexPool) _vertex_pool;
00243     BakeInUVs _bake_in_uvs;
00244     LMatrix4d _transform;
00245   };
00246   typedef pmap<VertexPoolTransform, PT(GeomVertexData) > VertexPoolData;
00247   VertexPoolData _vertex_pool_data;
00248 
00249   typedef pmap<LMatrix4, CPT(TransformState) > TransformStates;
00250   TransformStates _transform_states;
00251 
00252   DeferredNodes _deferred_nodes;
00253 
00254 public:
00255   PT(PandaNode) _root;
00256   PT(EggData) _data;
00257   PT(BamCacheRecord) _record;
00258   bool _error;
00259 
00260   CharacterMaker * _dynamic_override_char_maker;
00261   bool _dynamic_override;
00262 
00263 
00264   friend class EggRenderState;
00265   friend class PandaNode;
00266 };
00267 
00268 #include "eggLoader.I"
00269 
00270 #endif
 All Classes Functions Variables Enumerations