35 set_program_brief(
"convert .egg geometry into compilable C tables");
36 set_program_description
37 (
"This program reads Egg files and outputs code that will almost " 38 "compile as a C or C++ program. You get to define the data structures " 39 "for the program after the fact; the program only generates tables " 40 "of vertices and polygons.");
48 "Generate a table of vertex positions.",
49 &EggToC::dispatch_none, &_vertices);
53 "Generate a table of UV's per each vertex.",
54 &EggToC::dispatch_none, &_uvs);
58 "Generate a table of normals per each vertex.",
59 &EggToC::dispatch_none, &_vertex_normals);
63 "Generate a table of colors per each vertex.",
64 &EggToC::dispatch_none, &_vertex_colors);
68 "Generate a table of polygons that index into the above tables.",
69 &EggToC::dispatch_none, &_polygons);
73 "Generate a table of normals per each polygon.",
74 &EggToC::dispatch_none, &_polygon_normals);
78 "Generate a table of colors per each polygon.",
79 &EggToC::dispatch_none, &_polygon_colors);
83 "Output only triangles by subdividing higher-order polygons.",
84 &EggToC::dispatch_none, &_triangulate_polygons);
92 nout <<
"Removing invalid primitives.\n";
93 int num_removed = _data->remove_invalid_primitives(
true);
94 nout <<
" (" << num_removed <<
" removed.)\n";
96 if (_triangulate_polygons) {
97 nout <<
"Triangulating polygons.\n";
98 int num_produced = _data->triangulate_polygons(~0);
99 nout <<
" (" << num_produced <<
" triangles produced.)\n";
102 _data->apply_texmats();
103 _data->flatten_transforms();
104 _data->remove_unused_vertices(
true);
113 <<
" * Generated by:\n" 118 _next_vpool_index = 0;
128 if (node->
is_of_type(EggVertexPool::get_class_type())) {
131 }
else if (node->
is_of_type(EggBin::get_class_type())) {
132 write_bin(DCAST(
EggBin, node));
134 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
137 EggGroupNode::const_iterator ci;
138 for (ci = group->begin(); ci != group->end(); ++ci) {
153 out <<
"/* Vertex pool index " << _next_vpool_index
154 <<
": " << vpool->get_name() <<
" */\n";
155 _vertex_pools[vpool] = _next_vpool_index;
159 out <<
"/* Vertex definition for " << vpool->get_name() <<
" */\n" 160 <<
"vertex vertices_" << vpool->get_name() <<
"[" << highest_index
162 for (i = 0; i < highest_index; i++) {
164 if (vert ==
nullptr) {
165 out <<
" vertex(), /* " << i <<
" */\n";
170 out <<
" vertex(" << p[0] <<
"), /* " << i <<
" */\n";
174 out <<
" vertex(" << p[0] <<
", " << p[1]
175 <<
"), /* " << i <<
" */\n";
179 out <<
" vertex(" << p[0] <<
", " << p[1] <<
", " << p[2]
180 <<
"), /* " << i <<
" */\n";
184 out <<
" vertex(" << p[0] <<
", " << p[1] <<
", " << p[2]
185 <<
", " << p[3] <<
"), /* " << i <<
" */\n";
189 out <<
" vertex(), /* error */\n";
197 out <<
"/* UV's for " << vpool->get_name() <<
" */\n" 198 <<
"uv uvs_" << vpool->get_name() <<
"[" << highest_index
200 for (i = 0; i < highest_index; i++) {
202 if (vert ==
nullptr || !vert->
has_uv()) {
203 out <<
" uv(), /* " << i <<
" */\n";
205 LTexCoordd uv = vert->
get_uv();
206 out <<
" uv(" << uv[0] <<
", " << uv[1]
207 <<
"), /* " << i <<
" */\n";
213 if (_vertex_normals) {
214 out <<
"/* Vertex normals for " << vpool->get_name() <<
" */\n" 215 <<
"normal normals_" << vpool->get_name() <<
"[" << highest_index
217 for (i = 0; i < highest_index; i++) {
219 if (vert ==
nullptr || !vert->has_normal()) {
220 out <<
" normal(), /* " << i <<
" */\n";
222 LNormald n = vert->get_normal();
223 out <<
" normal(" << n[0] <<
", " << n[1] <<
", " << n[2]
224 <<
"), /* " << i <<
" */\n";
230 if (_vertex_colors) {
231 out <<
"/* Vertex colors for " << vpool->get_name() <<
" */\n" 232 <<
"color colors_" << vpool->get_name() <<
"[" << highest_index
234 for (i = 0; i < highest_index; i++) {
236 if (vert ==
nullptr || !vert->has_color()) {
237 out <<
" color(), /* " << i <<
" */\n";
240 out <<
" color(" << c[0] <<
", " << c[1] <<
", " << c[2]
241 <<
", " << c[3] <<
"), /* " << i <<
" */\n";
255 string bin_name = bin->get_name();
256 if (bin_name.empty()) {
257 bin_name = format_string(_next_bin_index);
261 out <<
"/* Polygon group " << bin_name <<
" */\n";
263 size_t num_children = bin->size();
266 out <<
"/* Polygon definitions for " << bin_name <<
" */\n";
267 string prim_type =
"polygon";
268 if (_triangulate_polygons) {
269 prim_type =
"triangle";
272 out << prim_type <<
" polys_" << bin_name <<
"[" << num_children
275 if (_triangulate_polygons) {
276 out <<
" /* vpool index, vertex0, vertex1, vertex2 */\n";
278 out <<
" /* vpool index, num vertices, vertex0, vertex1, vertex2, ... */\n";
281 EggGroupNode::const_iterator ci;
282 size_t prim_index = 0;
283 for (ci = bin->begin(); ci != bin->end(); ++ci) {
285 if (!child->
is_of_type(EggPrimitive::get_class_type())) {
286 out <<
" " << prim_type <<
"(), /* error */\n";
290 int vpool_index = -1;
291 VertexPools::const_iterator pi = _vertex_pools.find(vpool);
292 if (pi != _vertex_pools.end()) {
293 vpool_index = (*pi).second;
296 out <<
" " << prim_type <<
"(" << vpool_index;
297 if (!_triangulate_polygons) {
298 out <<
", " << prim->size();
300 EggPrimitive::const_iterator vi;
301 for (vi = prim->begin(); vi != prim->end(); ++vi) {
305 out <<
"), /* " << prim_index <<
" */\n";
312 if (_polygon_normals) {
314 out <<
"/* Polygon normals for " << bin_name <<
" */\n";
315 out <<
"normal polys_" << bin_name <<
"[" << num_children
318 EggGroupNode::const_iterator ci;
319 size_t prim_index = 0;
320 for (ci = bin->begin(); ci != bin->end(); ++ci) {
322 if (!child->
is_of_type(EggPrimitive::get_class_type())) {
323 out <<
" normal(), /* error */\n";
326 if (!prim->has_normal()) {
327 out <<
" normal(), /* " << prim_index <<
" */\n";
329 LNormald n = prim->get_normal();
330 out <<
" normal(" << n[0] <<
", " << n[1] <<
", " << n[2]
331 <<
"), /* " << prim_index <<
" */\n";
339 if (_polygon_colors) {
341 out <<
"/* Polygon colors for " << bin_name <<
" */\n";
342 out <<
"color polys_" << bin_name <<
"[" << num_children
345 EggGroupNode::const_iterator ci;
346 size_t prim_index = 0;
347 for (ci = bin->begin(); ci != bin->end(); ++ci) {
349 if (!child->
is_of_type(EggPrimitive::get_class_type())) {
350 out <<
" color(), /* error */\n";
353 if (!prim->has_color()) {
354 out <<
" color(), /* " << prim_index <<
" */\n";
357 out <<
" color(" << c[0] <<
", " << c[1] <<
", " << c[2]
358 <<
", " << c[3] <<
"), /* " << prim_index <<
" */\n";
368 int main(
int argc,
char *argv[]) {
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_dimensions() const
Returns the number of dimensions the vertex uses.
void set_properties(int properties)
Sets the set of properties that determines which polygons are allowed to be grouped together into a s...
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
A base class for nodes in the hierarchy that are not leaf nodes.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
EggVertex * get_vertex(int index) const
Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that inde...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LColor get_color() const
Returns the color set on this particular attribute.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_index() const
Returns the index number of the vertex within its pool.
int get_highest_index() const
Returns the highest index number used by any vertex in the pool (except forward references).
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_exec_command() const
Returns the command that invoked this program, as a shell-friendly string, suitable for pasting into ...
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_pool
Returns the vertex pool associated with the vertices of the primitive, or NULL if the primitive has n...
This is the general base class for a file-converter program that reads some model file format and gen...
A base class for things that may be directly added into the egg hierarchy.
int make_bins(EggGroupNode *root_group)
The main entry point to EggBinMaker.
A specialization on EggBinMaker for making polysets that share the same basic rendering characteristi...
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout,...
A collection of vertices.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A type of group node that holds related subnodes.