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