Panda3D
 All Classes Functions Variables Enumerations
eggLoader.h
1 // Filename: eggLoader.h
2 // Created by: drose (26Feb02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EGGLOADER_H
16 #define EGGLOADER_H
17 
18 #include "pandabase.h"
19 
20 #include "deferredNodeProperty.h"
21 #include "eggData.h"
22 #include "eggTexture.h"
23 #include "pt_EggTexture.h"
24 #include "eggGroup.h"
25 #include "eggMaterial.h"
26 #include "pt_EggMaterial.h"
27 #include "eggVertexPool.h"
28 #include "texture.h"
29 #include "pandaNode.h"
30 #include "pointerTo.h"
31 #include "lmatrix.h"
32 #include "indirectCompareTo.h"
33 #include "textureAttrib.h"
34 #include "textureStage.h"
35 #include "texGenAttrib.h"
36 #include "colorBlendAttrib.h"
37 #include "eggTransform.h"
38 #include "geomVertexData.h"
39 #include "geomPrimitive.h"
40 #include "bamCacheRecord.h"
41 
42 class EggNode;
43 class EggBin;
44 class EggTable;
45 class EggNurbsCurve;
46 class EggNurbsSurface;
47 class EggPrimitive;
48 class EggPolygon;
49 class EggMaterial;
50 class RenderRelation;
51 class CollisionSolid;
52 class CollisionNode;
53 class CollisionPlane;
54 class CollisionPolygon;
55 class PortalNode;
56 class OccluderNode;
57 class PolylightNode;
58 class EggRenderState;
59 class CharacterMaker;
60 
61 
62 ////////////////////////////////////////////////////////////////////
63 // Class : EggLoader
64 // Description : Converts an egg data structure, possibly read from an
65 // egg file but not necessarily, into a scene graph
66 // suitable for rendering.
67 //
68 // This class isn't exported from this package.
69 ////////////////////////////////////////////////////////////////////
70 class EggLoader {
71 public:
72  EggLoader();
73  EggLoader(const EggData *data);
74 
75  void build_graph();
76  void reparent_decals();
77  void start_sequences();
78 
79  void make_polyset(EggBin *egg_bin, PandaNode *parent,
80  const LMatrix4d *transform, bool is_dynamic,
81  CharacterMaker *character_maker);
82 
83  CPT(TransformState) make_transform(const EggTransform *egg_transform);
84 
85 private:
86  class TextureDef {
87  public:
88  CPT(RenderAttrib) _texture;
89  PT(TextureStage) _stage;
90  const EggTexture *_egg_tex;
91  };
92 
93  // This structure is used internally in setup_bucket().
97 
98  // This structure is returned by setup_bucket().
100 
101  // This is used by make_primitive().
102  class PrimitiveUnifier {
103  public:
104  INLINE PrimitiveUnifier(const GeomPrimitive *prim);
105  INLINE bool operator < (const PrimitiveUnifier &other) const;
106 
107  TypeHandle _type;
108  GeomPrimitive::ShadeModel _shade_model;
109  };
112 
113  void show_normals(EggVertexPool *vertex_pool, GeomNode *geom_node);
114 
115  void make_nurbs_curve(EggNurbsCurve *egg_curve, PandaNode *parent,
116  const LMatrix4d &mat);
117  void make_old_nurbs_curve(EggNurbsCurve *egg_curve, PandaNode *parent,
118  const LMatrix4d &mat);
119  void make_nurbs_surface(EggNurbsSurface *egg_surface, PandaNode *parent,
120  const LMatrix4d &mat);
121 
122  void load_textures();
123  bool load_texture(TextureDef &def, EggTexture *egg_tex);
124  void apply_texture_attributes(Texture *tex, const EggTexture *egg_tex);
125  Texture::CompressionMode convert_compression_mode(EggTexture::CompressionMode compression_mode) const;
126  SamplerState::WrapMode convert_wrap_mode(EggTexture::WrapMode wrap_mode) const;
127  PT(TextureStage) make_texture_stage(const EggTexture *egg_tex);
128 
129  void separate_switches(EggNode *egg_node);
130  void emulate_bface(EggNode *egg_node);
131 
132  PandaNode *make_node(EggNode *egg_node, PandaNode *parent);
133  PandaNode *make_node(EggBin *egg_bin, PandaNode *parent);
134  PandaNode *make_polyset(EggBin *egg_bin, PandaNode *parent);
135  PandaNode *make_lod(EggBin *egg_bin, PandaNode *parent);
136  PandaNode *make_node(EggGroup *egg_group, PandaNode *parent);
137  PandaNode *create_group_arc(EggGroup *egg_group, PandaNode *parent,
138  PandaNode *node);
139  PandaNode *make_node(EggTable *egg_table, PandaNode *parent);
140  PandaNode *make_node(EggGroupNode *egg_group, PandaNode *parent);
141 
142  void check_for_polysets(EggGroup *egg_group, bool &all_polysets,
143  bool &any_hidden);
144  PT(GeomVertexData) make_vertex_data
145  (const EggRenderState *render_state, EggVertexPool *vertex_pool,
146  EggNode *primitive_home, const LMatrix4d &transform, TransformBlendTable *blend_table,
147  bool is_dynamic, CharacterMaker *character_maker, bool ignore_color);
148  PT(TransformBlendTable) make_blend_table
149  (EggVertexPool *vertex_bool, EggNode *primitive_home,
150  CharacterMaker *character_maker);
151  void record_morph
152  (GeomVertexArrayFormat *array_format,
153  CharacterMaker *character_maker, const string &morph_name,
154  InternalName *column_name, int num_components);
155 
156  void make_primitive(const EggRenderState *render_state,
157  EggPrimitive *egg_prim,
158  UniquePrimitives &unique_primitives,
159  Primitives &primitives,
160  bool has_overall_color, const LColor &overall_color);
161 
162  void set_portal_polygon(EggGroup *egg_group, PortalNode *pnode);
163  void set_occluder_polygon(EggGroup *egg_group, OccluderNode *pnode);
164  PT(EggPolygon) find_first_polygon(EggGroup *egg_group);
165 
166  bool make_sphere(EggGroup *start_group, EggGroup::CollideFlags flags,
167  LPoint3 &center, PN_stdfloat &radius, LColor &color);
168 
169  bool make_box(EggGroup *start_group, EggGroup::CollideFlags flags,
170  LPoint3 &min_p, LPoint3 &max_p, LColor &color);
171 
172  void make_collision_solids(EggGroup *start_group, EggGroup *egg_group,
173  CollisionNode *cnode);
174  void make_collision_plane(EggGroup *egg_group, CollisionNode *cnode,
175  EggGroup::CollideFlags flags);
176  void make_collision_polygon(EggGroup *egg_group, CollisionNode *cnode,
177  EggGroup::CollideFlags flags);
178  void make_collision_polyset(EggGroup *egg_group, CollisionNode *cnode,
179  EggGroup::CollideFlags flags);
180  void make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode,
181  EggGroup::CollideFlags flags);
182  void make_collision_box(EggGroup *egg_group, CollisionNode *cnode,
183  EggGroup::CollideFlags flags);
184  void make_collision_inv_sphere(EggGroup *egg_group, CollisionNode *cnode,
185  EggGroup::CollideFlags flags);
186  void make_collision_tube(EggGroup *egg_group, CollisionNode *cnode,
187  EggGroup::CollideFlags flags);
188  void make_collision_floor_mesh(EggGroup *egg_group, CollisionNode *cnode,
189  EggGroup::CollideFlags flags);
190  void apply_collision_flags(CollisionSolid *solid,
191  EggGroup::CollideFlags flags);
192  EggGroup *find_collision_geometry(EggGroup *egg_group,
193  EggGroup::CollideFlags flags);
194  CollisionPlane *create_collision_plane(EggPolygon *egg_poly,
195  EggGroup *parent_group);
196  void create_collision_polygons(CollisionNode *cnode, EggPolygon *egg_poly,
197  EggGroup *parent_group,
198  EggGroup::CollideFlags flags);
199 
200  void create_collision_floor_mesh(CollisionNode *cnode,
201  EggGroup *parent_group,
202  EggGroup::CollideFlags flags);
203 
204  void apply_deferred_nodes(PandaNode *node, const DeferredNodeProperty &prop);
205  bool expand_all_object_types(EggNode *egg_node);
206  bool expand_object_types(EggGroup *egg_group, const pset<string> &expanded,
207  const pvector<string> &expanded_history);
208  bool do_expand_object_type(EggGroup *egg_group, const pset<string> &expanded,
209  const pvector<string> &expanded_history,
210  const string &object_type);
211 
212  static TextureStage::CombineMode
213  get_combine_mode(const EggTexture *egg_tex,
214  EggTexture::CombineChannel channel);
215 
216  static TextureStage::CombineSource
217  get_combine_source(const EggTexture *egg_tex,
218  EggTexture::CombineChannel channel, int n);
219 
220  static TextureStage::CombineOperand
221  get_combine_operand(const EggTexture *egg_tex,
222  EggTexture::CombineChannel channel, int n);
223 
224  static ColorBlendAttrib::Mode
225  get_color_blend_mode(EggGroup::BlendMode mode);
226 
227  static ColorBlendAttrib::Operand
228  get_color_blend_operand(EggGroup::BlendOperand operand);
229 
231  Textures _textures;
232 
234  Materials _materials;
235  Materials _materials_bface;
236 
238  Groups _groups;
239 
241  ExtraNodes _decals;
242  ExtraNodes _sequences;
243 
244  class VertexPoolTransform {
245  public:
246  bool operator < (const VertexPoolTransform &other) const;
247  PT(EggVertexPool) _vertex_pool;
248  BakeInUVs _bake_in_uvs;
249  LMatrix4d _transform;
250  };
252  VertexPoolData _vertex_pool_data;
253 
255  TransformStates _transform_states;
256 
257  DeferredNodes _deferred_nodes;
258 
259 public:
260  PT(PandaNode) _root;
261  PT(EggData) _data;
262  PT(BamCacheRecord) _record;
263  bool _error;
264 
265  CharacterMaker * _dynamic_override_char_maker;
266  bool _dynamic_override;
267 
268 
269  friend class EggRenderState;
270  friend class PandaNode;
271 };
272 
273 #include "eggLoader.I"
274 
275 #endif
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
This class keeps track of all the state we must make note of during the graph traversal, but cannot apply immediately.
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
A node in the scene graph that can hold an occluder polygon, which must be a rectangle.
Definition: occluderNode.h:35
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
This class is used within this package only to record the render state that should be assigned to eac...
The main glue of the egg hierarchy, this corresponds to the &lt;Group&gt;, &lt;Instance&gt;, and &lt;Joint&gt; type nod...
Definition: eggGroup.h:36
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
Definition: portalNode.h:34
void start_sequences()
Starts all of the SequenceNodes we created looping.
Definition: eggLoader.cxx:302
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A PolylightNode.
Definition: polylightNode.h:31
A parametric NURBS curve.
Definition: eggNurbsCurve.h:28
A single polygon.
Definition: eggPolygon.h:26
This corresponds to a.
Definition: eggTable.h:31
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:33
A parametric NURBS surface.
void reparent_decals()
For each node representing a decal base geometry (i.e.
Definition: eggLoader.cxx:237
This structure collects together the different combinations of transforms and blend amounts used by a...
Converts an EggGroup hierarchy, beginning with a group with &lt;Dart&gt; set, to a character node with join...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:38
A collection of vertices.
Definition: eggVertexPool.h:46
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
void make_polyset(EggBin *egg_bin, PandaNode *parent, const LMatrix4d *transform, bool is_dynamic, CharacterMaker *character_maker)
Creates a polyset–that is, a Geom–from the primitives that have already been grouped into a bin...
Definition: eggLoader.cxx:321
This represents the &lt;Transform&gt; entry of a group or texture node: a list of component transform opera...
Definition: eggTransform.h:33
Converts an egg data structure, possibly read from an egg file but not necessarily, into a scene graph suitable for rendering.
Definition: eggLoader.h:70
A type of group node that holds related subnodes.
Definition: eggBin.h:30