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  LPoint3 &min_p, LPoint3 &max_p, LColor &color);
168 
169  void make_collision_solids(EggGroup *start_group, EggGroup *egg_group,
170  CollisionNode *cnode);
171  void make_collision_plane(EggGroup *egg_group, CollisionNode *cnode,
172  EggGroup::CollideFlags flags);
173  void make_collision_polygon(EggGroup *egg_group, CollisionNode *cnode,
174  EggGroup::CollideFlags flags);
175  void make_collision_polyset(EggGroup *egg_group, CollisionNode *cnode,
176  EggGroup::CollideFlags flags);
177  void make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode,
178  EggGroup::CollideFlags flags);
179  void make_collision_box(EggGroup *egg_group, CollisionNode *cnode,
180  EggGroup::CollideFlags flags);
181  void make_collision_inv_sphere(EggGroup *egg_group, CollisionNode *cnode,
182  EggGroup::CollideFlags flags);
183  void make_collision_capsule(EggGroup *egg_group, CollisionNode *cnode,
184  EggGroup::CollideFlags flags);
185  void make_collision_floor_mesh(EggGroup *egg_group, CollisionNode *cnode,
186  EggGroup::CollideFlags flags);
187  void apply_collision_flags(CollisionSolid *solid,
188  EggGroup::CollideFlags flags);
189  EggGroup *find_collision_geometry(EggGroup *egg_group,
190  EggGroup::CollideFlags flags);
191  CollisionPlane *create_collision_plane(EggPolygon *egg_poly,
192  EggGroup *parent_group);
193  void create_collision_polygons(CollisionNode *cnode, EggPolygon *egg_poly,
194  EggGroup *parent_group,
195  EggGroup::CollideFlags flags);
196 
197  void create_collision_floor_mesh(CollisionNode *cnode,
198  EggGroup *parent_group,
199  EggGroup::CollideFlags flags);
200 
201  void apply_deferred_nodes(PandaNode *node, const DeferredNodeProperty &prop);
202  bool expand_all_object_types(EggNode *egg_node);
203  bool expand_object_types(EggGroup *egg_group, const pset<std::string> &expanded,
204  const pvector<std::string> &expanded_history);
205  bool do_expand_object_type(EggGroup *egg_group, const pset<std::string> &expanded,
206  const pvector<std::string> &expanded_history,
207  const std::string &object_type);
208 
209  static TextureStage::CombineMode
210  get_combine_mode(const EggTexture *egg_tex,
211  EggTexture::CombineChannel channel);
212 
213  static TextureStage::CombineSource
214  get_combine_source(const EggTexture *egg_tex,
215  EggTexture::CombineChannel channel, int n);
216 
217  static TextureStage::CombineOperand
218  get_combine_operand(const EggTexture *egg_tex,
219  EggTexture::CombineChannel channel, int n);
220 
221  static ColorBlendAttrib::Mode
222  get_color_blend_mode(EggGroup::BlendMode mode);
223 
224  static ColorBlendAttrib::Operand
225  get_color_blend_operand(EggGroup::BlendOperand operand);
226 
228  Textures _textures;
229 
230  typedef pmap<CPT_EggMaterial, CPT(RenderAttrib) > Materials;
231  Materials _materials;
232  Materials _materials_bface;
233 
234  typedef pmap<PT(EggGroup), PT(PandaNode) > Groups;
235  Groups _groups;
236 
238  ExtraNodes _decals;
239  ExtraNodes _sequences;
240 
241  class VertexPoolTransform {
242  public:
243  bool operator < (const VertexPoolTransform &other) const;
244  PT(EggVertexPool) _vertex_pool;
245  BakeInUVs _bake_in_uvs;
246  LMatrix4d _transform;
247  };
248  typedef pmap<VertexPoolTransform, PT(GeomVertexData) > VertexPoolData;
249  VertexPoolData _vertex_pool_data;
250 
251  typedef pmap<LMatrix4, CPT(TransformState) > TransformStates;
252  TransformStates _transform_states;
253 
254  DeferredNodes _deferred_nodes;
255 
256 public:
257  PT(PandaNode) _root;
258  PT(EggData) _data;
259  PT(BamCacheRecord) _record;
260  bool _error;
261 
262  CharacterMaker * _dynamic_override_char_maker;
263  bool _dynamic_override;
264 
265 
266  friend class EggRenderState;
267  friend class PandaNode;
268 };
269 
270 #include "eggLoader.I"
271 
272 #endif
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition: eggPrimitive.h:47
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
Indicates a coordinate-system transform on vertices.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
This class keeps track of all the state we must make note of during the graph traversal,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:46
The abstract base class for all things that can collide with other things in the world,...
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:56
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition: eggData.h:37
A node in the scene graph that can hold an occluder polygon, which must be a rectangle.
Definition: occluderNode.h:31
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
This class is used within this package only to record the render state that should be assigned to eac...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:34
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
Definition: portalNode.h:30
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A PolylightNode.
Definition: polylightNode.h:29
A parametric NURBS curve.
Definition: eggNurbsCurve.h:26
A single polygon.
Definition: eggPolygon.h:24
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
This corresponds to a.
Definition: eggTable.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:35
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:30
A parametric NURBS surface.
This describes the structure of a single array within a Geom data.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition: pointerTo.h:144
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This structure collects together the different combinations of transforms and blend amounts used by a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Converts an EggGroup hierarchy, beginning with a group with <Dart> set, to a character node with join...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:35
A collection of vertices.
Definition: eggVertexPool.h:41
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
Definition: eggTransform.h:29
Converts an egg data structure, possibly read from an egg file but not necessarily,...
Definition: eggLoader.h:67
A type of group node that holds related subnodes.
Definition: eggBin.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.