Panda3D
Loading...
Searching...
No Matches
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
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
41class EggNode;
42class EggBin;
43class EggTable;
44class EggNurbsCurve;
45class EggNurbsSurface;
46class EggPrimitive;
47class EggPolygon;
48class EggMaterial;
49class RenderRelation;
50class CollisionSolid;
51class CollisionNode;
52class CollisionPlane;
54class PortalNode;
55class OccluderNode;
56class PolylightNode;
57class EggRenderState;
58class 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 */
67class EXPCL_PANDA_EGG2PG EggLoader {
68public:
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
82private:
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
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
258public:
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
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...
Converts an EggGroup hierarchy, beginning with a group with <Dart> set, to a character node with join...
A node in the scene graph that can hold any number of CollisionSolids.
The abstract base class for all things that can collide with other things in the world,...
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition pointerTo.h:144
This class keeps track of all the state we must make note of during the graph traversal,...
A type of group node that holds related subnodes.
Definition eggBin.h:26
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition eggData.h:37
A base class for nodes in the hierarchy that are not leaf nodes.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition eggGroup.h:34
Converts an egg data structure, possibly read from an egg file but not necessarily,...
Definition eggLoader.h:67
A base class for things that may be directly added into the egg hierarchy.
Definition eggNode.h:36
A parametric NURBS curve.
A parametric NURBS surface.
A single polygon.
Definition eggPolygon.h:24
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
This class is used within this package only to record the render state that should be assigned to eac...
This corresponds to a.
Definition eggTable.h:27
Defines a texture map that may be applied to geometry.
Definition eggTexture.h:30
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
A collection of vertices.
A node that holds Geom objects, renderable pieces of geometry.
Definition geomNode.h:34
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
This describes the structure of a single array within a Geom data.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
Encodes a string name in a hash table, mapping it to a pointer.
A node in the scene graph that can hold an occluder polygon, which must be a rectangle.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
A PolylightNode.
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
Definition portalNode.h:30
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Defines the properties of a named stage of the multitexture pipeline.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition texture.h:72
This structure collects together the different combinations of transforms and blend amounts used by a...
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL set.
Definition pset.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.