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