46 _compose_transforms =
false;
47 _flt_units = DU_invalid;
56 _compose_transforms(copy._compose_transforms)
64 ~FltToEggConverter() {
114 nout <<
"Reading " << filename <<
"\n";
115 FltError result = header->read_flt(filename);
116 if (result != FE_ok) {
117 nout <<
"Unable to read: " << result <<
"\n";
121 header->check_version();
123 _flt_units = header->get_units();
144 if (_egg_data->get_coordinate_system() == CS_default) {
145 _egg_data->set_coordinate_system(CS_zup_right);
149 _flt_header = flt_header;
153 _egg_data->add_child(_main_egg_vpool.p());
161 state._egg_parent = _egg_data;
162 convert_record(_flt_header, state);
164 if (_main_egg_vpool->empty()) {
167 _egg_data->remove_child(_main_egg_vpool.p());
179 void FltToEggConverter::
182 _main_egg_vpool.clear();
189 void FltToEggConverter::
193 for (
int i = 0; i < num_children; i++) {
195 dispatch_record(child, state);
203 void FltToEggConverter::
205 if (flt_record->
is_of_type(FltLOD::get_class_type())) {
206 convert_lod(DCAST(
FltLOD, flt_record), state);
208 }
else if (flt_record->
is_of_type(FltGroup::get_class_type())) {
209 convert_group(DCAST(
FltGroup, flt_record), state);
211 }
else if (flt_record->
is_of_type(FltObject::get_class_type())) {
212 convert_object(DCAST(
FltObject, flt_record), state);
214 }
else if (flt_record->
is_of_type(FltFace::get_class_type())) {
215 convert_face(DCAST(
FltFace, flt_record), state);
217 }
else if (flt_record->
is_of_type(FltExternalReference::get_class_type())) {
221 }
else if (flt_record->
is_of_type(FltBeadID::get_class_type())) {
222 convert_bead_id(DCAST(
FltBeadID, flt_record), state);
224 }
else if (flt_record->
is_of_type(FltBead::get_class_type())) {
225 convert_bead(DCAST(
FltBead, flt_record), state);
228 convert_record(flt_record, state);
235 void FltToEggConverter::
241 (flt_lod->_switch_in, flt_lod->_switch_out,
242 LPoint3d(flt_lod->_center_x, flt_lod->_center_y, flt_lod->_center_z),
243 flt_lod->_transition_range);
244 egg_group->set_lod(lod);
247 parse_comment(flt_lod, egg_group);
250 next_state._egg_parent = egg_group;
251 convert_record(flt_lod, next_state);
257 void FltToEggConverter::
262 if ((flt_group->_flags & FltGroup::F_forward_animation) != 0) {
264 egg_group->set_switch_flag(
true);
265 egg_group->set_switch_fps(24.0);
269 parse_comment(flt_group, egg_group);
274 next_state._egg_parent = egg_group;
275 convert_record(flt_group, next_state);
281 void FltToEggConverter::
287 parse_comment(flt_object, egg_group);
290 next_state._flt_object = flt_object;
291 next_state._egg_parent = egg_group;
292 convert_record(flt_object, next_state);
298 void FltToEggConverter::
300 nout <<
"Don't know how to convert beads of type " << flt_bead->get_type()
306 parse_comment(flt_bead, egg_group);
309 next_state._egg_parent = egg_group;
310 convert_record(flt_bead, next_state);
316 void FltToEggConverter::
318 nout <<
"Don't know how to convert beads of type " << flt_bead->get_type()
324 parse_comment(flt_bead, egg_group);
327 next_state._egg_parent = egg_group;
328 convert_record(flt_bead, next_state);
334 void FltToEggConverter::
337 switch (flt_face->_draw_type) {
338 case FltGeometry::DT_omni_light:
339 case FltGeometry::DT_uni_light:
340 case FltGeometry::DT_bi_light:
360 for (
int i = 0; i < num_children && vlist ==
nullptr; i++) {
362 if (child->
is_of_type(FltVertexList::get_class_type())) {
367 if (vlist !=
nullptr) {
368 int num_vertices = vlist->get_num_vertices();
369 for (
int i = 0; i < num_vertices; i++) {
370 FltVertex *flt_vertex = vlist->get_vertex(i);
371 vertices.push_back(make_egg_vertex(flt_vertex));
375 setup_geometry(flt_face, state, egg_prim, _main_egg_vpool, vertices);
381 void FltToEggConverter::
396 void FltToEggConverter::
404 flt_geom->_billboard_type);
408 next_state._egg_parent = egg_parent;
411 convert_subfaces(flt_geom, next_state);
414 next_state._egg_parent->add_child(egg_prim);
417 EggVertices::const_iterator vi;
419 bool use_vertex_color =
true;
420 bool keep_normals =
true;
421 switch (flt_geom->_light_mode) {
422 case FltGeometry::LM_face_no_normal:
423 use_vertex_color =
false;
424 keep_normals =
false;
427 case FltGeometry::LM_vertex_no_normal:
428 use_vertex_color =
true;
429 keep_normals =
false;
432 case FltGeometry::LM_face_with_normal:
433 use_vertex_color =
false;
437 case FltGeometry::LM_vertex_with_normal:
438 use_vertex_color =
true;
443 LColor face_color = flt_geom->
get_color();
445 if (state._flt_object !=
nullptr) {
448 PN_stdfloat alpha = 1.0 - (state._flt_object->_transparency / 65535.0);
449 face_color[3] *= alpha;
452 egg_prim->set_color(face_color);
458 if (flt_geom->_texwhite) {
461 use_vertex_color =
false;
465 if (use_vertex_color) {
468 egg_prim->clear_color();
471 for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
473 if (vertex->has_color()) {
474 LColor vertex_color = vertex->
get_color();
475 vertex_color[3] = face_color[3];
476 vertex->set_color(vertex_color);
481 vertex->set_color(face_color);
489 for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
490 (*vi)->clear_color();
496 for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
497 (*vi)->clear_normal();
501 if (flt_geom->_draw_type == FltGeometry::DT_solid_no_cull) {
506 for (vi = vertices.begin(); vi != vertices.end(); ++vi) {
511 parse_comment(flt_geom, egg_prim);
522 void FltToEggConverter::
525 if (num_subfaces == 0) {
533 state._egg_parent = egg_group;
535 egg_group->set_decal_flag(
true);
540 egg_group = decal_group;
543 next_state._egg_parent = decal_group;
545 for (
int i = 0; i < num_subfaces; i++) {
547 dispatch_record(subface, next_state);
556 bool FltToEggConverter::
566 bool FltToEggConverter::
568 return parse_comment(flt_bead->
get_comment(),
"anonymous", egg_node);
576 bool FltToEggConverter::
587 bool FltToEggConverter::
588 parse_comment(
const string &comment,
const string &name,
590 if (comment.empty()) {
596 static const string egg_str =
"<egg>";
600 while (p < comment.length() &&
601 cmp_nocase(comment.substr(p, 5), egg_str) != 0) {
605 if (p >= comment.length()) {
612 while (p < comment.length() && isspace(comment[p])) {
615 if (p >= comment.length() || comment[p] !=
'{') {
616 nout <<
"No opening brace in comment for " 625 size_t q = comment.length() - 1;
626 while (q > p && comment[q] !=
'}') {
630 nout <<
"No closing brace in comment for " 636 string egg_syntax = comment.substr(p, q - p);
639 nout <<
"Syntax error in comment for " 653 PT_EggVertex FltToEggConverter::
654 make_egg_vertex(
const FltVertex *flt_vertex) {
656 egg_vertex->
set_pos(flt_vertex->_pos);
658 if (flt_vertex->_has_normal) {
659 egg_vertex->set_normal(LCAST(
double, flt_vertex->_normal));
662 if (flt_vertex->_has_uv) {
663 egg_vertex->set_uv(LCAST(
double, flt_vertex->_uv));
667 egg_vertex->set_color(flt_vertex->
get_color());
677 PT_EggTexture FltToEggConverter::
678 make_egg_texture(
const FltTexture *flt_texture) {
679 Textures::const_iterator ti;
680 ti = _textures.find(flt_texture);
681 if (ti != _textures.end()) {
687 string tref_name = format_string(flt_texture->_pattern_index);
690 PT_EggTexture egg_texture =
new EggTexture(tref_name, filename);
692 _textures.insert(Textures::value_type(flt_texture, egg_texture));
696 switch (flt_texture->_min_filter) {
697 case FltTexture::MN_point:
698 egg_texture->set_minfilter(EggTexture::FT_nearest);
701 case FltTexture::MN_bilinear:
702 egg_texture->set_minfilter(EggTexture::FT_linear);
705 case FltTexture::MN_mipmap_point:
706 egg_texture->set_minfilter(EggTexture::FT_nearest_mipmap_nearest);
709 case FltTexture::MN_mipmap_linear:
710 egg_texture->set_minfilter(EggTexture::FT_nearest_mipmap_linear);
713 case FltTexture::MN_mipmap_bilinear:
714 egg_texture->set_minfilter(EggTexture::FT_linear_mipmap_nearest);
717 case FltTexture::MN_mipmap_trilinear:
718 case FltTexture::MN_OB_mipmap:
719 egg_texture->set_minfilter(EggTexture::FT_linear_mipmap_linear);
722 case FltTexture::MN_bicubic:
723 case FltTexture::MN_bilinear_gequal:
724 case FltTexture::MN_bilinear_lequal:
725 case FltTexture::MN_bicubic_gequal:
726 case FltTexture::MN_bicubic_lequal:
731 switch (flt_texture->_mag_filter) {
732 case FltTexture::MG_point:
733 egg_texture->set_magfilter(EggTexture::FT_nearest);
736 case FltTexture::MG_bilinear:
737 egg_texture->set_magfilter(EggTexture::FT_linear);
740 case FltTexture::MG_bicubic:
741 case FltTexture::MG_sharpen:
742 case FltTexture::MG_add_detail:
743 case FltTexture::MG_modulate_detail:
744 case FltTexture::MG_bilinear_gequal:
745 case FltTexture::MG_bilinear_lequal:
746 case FltTexture::MG_bicubic_gequal:
747 case FltTexture::MG_bicubic_lequal:
752 switch (flt_texture->_repeat) {
753 case FltTexture::RT_repeat:
754 egg_texture->set_wrap_mode(EggTexture::WM_repeat);
757 case FltTexture::RT_clamp:
758 egg_texture->set_wrap_mode(EggTexture::WM_clamp);
762 switch (flt_texture->_repeat_u) {
763 case FltTexture::RT_repeat:
764 egg_texture->set_wrap_u(EggTexture::WM_repeat);
767 case FltTexture::RT_clamp:
768 egg_texture->set_wrap_u(EggTexture::WM_clamp);
772 switch (flt_texture->_repeat_v) {
773 case FltTexture::RT_repeat:
774 egg_texture->set_wrap_v(EggTexture::WM_repeat);
777 case FltTexture::RT_clamp:
778 egg_texture->set_wrap_v(EggTexture::WM_clamp);
782 switch (flt_texture->_env_type) {
783 case FltTexture::ET_modulate:
784 egg_texture->set_env_type(EggTexture::ET_modulate);
787 case FltTexture::ET_decal:
788 egg_texture->set_env_type(EggTexture::ET_decal);
791 case FltTexture::ET_blend:
792 case FltTexture::ET_color:
797 switch (flt_texture->_internal_format) {
798 case FltTexture::IF_default:
801 case FltTexture::IF_i_12a_4:
802 case FltTexture::IF_ia_12:
803 case FltTexture::IF_ia_8:
804 egg_texture->set_format(EggTexture::F_luminance_alpha);
807 case FltTexture::IF_rgb_5:
808 egg_texture->set_format(EggTexture::F_rgb5);
811 case FltTexture::IF_rgba_4:
812 egg_texture->set_format(EggTexture::F_rgba4);
816 case FltTexture::IF_rgba_8:
817 egg_texture->set_format(EggTexture::F_rgba8);
820 case FltTexture::IF_rgba_12:
821 egg_texture->set_format(EggTexture::F_rgba12);
824 case FltTexture::IF_i_16:
825 if (flt_texture->_intensity_is_alpha) {
826 egg_texture->set_format(EggTexture::F_alpha);
828 egg_texture->set_format(EggTexture::F_luminance);
832 case FltTexture::IF_rgb_12:
833 egg_texture->set_format(EggTexture::F_rgb12);
837 parse_comment(flt_texture, egg_texture);
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
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.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for any of a broad family of flt beads that include an ID.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Filename get_texture_filename() const
Returns the name of the texture image file.
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true),...
void set_pos(double pos)
Sets the vertex position.
A base class for nodes in the hierarchy that are not leaf nodes.
int get_num_children() const
Returns the number of child records of this record.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a texture map that may be applied to geometry.
The main grouping bead of the flt file.
bool handle_external_reference(EggGroupNode *egg_parent, const Filename &ref_filename)
Handles an external reference in the source file.
void set_texture(EggTexture *texture)
Replaces the current list of textures with the indicated texture.
set_bface_flag
Sets the backfacing flag of the polygon.
A base class for any of a broad family of flt records that represent particular beads in the hierarch...
This class supervises the construction of an EggData structure from the data represented by the FltHe...
LColor get_color() const
Returns the color set on this particular attribute.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_color() const
Returns true if the vertex has a primary color indicated, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for both FltFace and FltMesh, which are two different kinds of geometric primiti...
A single point, or a collection of points as defined by a single <PointLight> entry.
bool has_color() const
Returns true if the face has a primary color indicated, false otherwise.
bool parse_egg(const std::string &egg_syntax)
Parses the egg syntax given in the indicate string as if it had been read from the egg file within th...
virtual std::string get_name() const
Returns the English name of the file type this converter supports.
This keeps track of relevant things about the traversal as we walk through the flt hierarchy.
DistanceUnit
This enumerated type lists all the kinds of units we're likely to come across in model conversion pro...
This is our own Panda specialization on the default STL vector.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
const std::string & get_comment() const
Retrieves the comment for this record, or empty string if the record has no comment.
virtual DistanceUnit get_input_units()
This may be called after convert_file() has been called and returned true, indicating a successful co...
FltRecord * get_subface(int n) const
Returns the nth subface of this record.
void clear_error()
Resets the error flag to the no-error state.
A list of vertices, typically added as a child of a face bead.
Represents a single texture in the texture palette.
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The base class for all kinds of records in a MultiGen OpenFlight file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggGroupNode * get_synthetic_group(const std::string &name, const FltBead *transform_bead, FltGeometry::BillboardType type=FltGeometry::BT_none)
Sometimes it is necessary to synthesize a group within a particular EggGroup, for instance to insert ...
Represents a single vertex in the vertex palette.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An external reference to another flt file (possibly to a specific bead within the flt file).
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::string get_extension() const
Returns the common extension of the file type this converter supports.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The main objecting bead of the flt file.
bool convert_flt(const FltHeader *flt_header)
Fills up the egg_data structure according to the indicated lwo structure.
FltRecord * get_child(int n) const
Returns the nth child of this record.
Filename get_ref_filename() const
Returns the name of the referenced file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
LColor get_color() const
Returns the primary color of the face, as a four-component value (including alpha as the transparency...
A base class for things that may be directly added into the egg hierarchy.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
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.
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
LColor get_color() const
If has_color() indicates true, returns the color of the vertex, as a four- component value.
bool has_texture() const
Returns true if the face has a texture applied, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A Level-of-Detail record.
This is a base class for a family of converter classes that manage a conversion from some file type t...
FltTexture * get_texture() const
Returns the texture applied to this face, or NULL if no texture was applied.
const std::string & get_id() const
Returns the id (name) of this particular bead.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
A collection of vertices.
EggVertex * add_vertex(EggVertex *vertex)
Adds the indicated vertex to the end of the primitive's list of vertices, and returns it.
A SwitchCondition that switches the levels-of-detail based on distance from the camera's eyepoint.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_transform(const FltBead *flt_bead, EggGroup *egg_group)
Sets up the group to reflect the transform indicated by the given record, if any.
int get_num_subfaces() const
Returns the number of subface records of this record.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.