diff --git a/pandatool/src/flt/fltBeadID.cxx b/pandatool/src/flt/fltBeadID.cxx index f3d39c21aa..91a4ddbc26 100644 --- a/pandatool/src/flt/fltBeadID.cxx +++ b/pandatool/src/flt/fltBeadID.cxx @@ -123,7 +123,15 @@ build_record(FltRecordWriter &writer) const { FltError FltBeadID:: write_ancillary(FltRecordWriter &writer) const { if (_id.length() > 7) { - Datagram dc(_id); + + // Although the manual mentions nothing of this, it is essential + // that the length of the record be a multiple of 4 bytes. + string id = _id; + while ((id.length() % 4) != 0) { + id += '\0'; + } + Datagram dc(id); + FltError result = writer.write_record(FO_long_id, dc); if (result != FE_ok) { return result; diff --git a/pandatool/src/fltegg/fltToEggConverter.cxx b/pandatool/src/fltegg/fltToEggConverter.cxx index 0eacb3dccf..54e7ac787e 100644 --- a/pandatool/src/fltegg/fltToEggConverter.cxx +++ b/pandatool/src/fltegg/fltToEggConverter.cxx @@ -106,32 +106,42 @@ convert_record(const FltRecord *flt_record, FltToEggLevelState &state) { for (int i = 0; i < num_children; i++) { const FltRecord *child = flt_record->get_child(i); + dispatch_record(child, state); + } +} - if (child->is_of_type(FltLOD::get_class_type())) { - convert_lod(DCAST(FltLOD, child), state); - - } else if (child->is_of_type(FltGroup::get_class_type())) { - convert_group(DCAST(FltGroup, child), state); - - } else if (child->is_of_type(FltObject::get_class_type())) { - convert_object(DCAST(FltObject, child), state); - - } else if (child->is_of_type(FltFace::get_class_type())) { - convert_face(DCAST(FltFace, child), state); - - } else if (child->is_of_type(FltExternalReference::get_class_type())) { - convert_ext_ref(DCAST(FltExternalReference, child), state); - - // Fallbacks. - } else if (child->is_of_type(FltBeadID::get_class_type())) { - convert_bead_id(DCAST(FltBeadID, child), state); - - } else if (child->is_of_type(FltBead::get_class_type())) { - convert_bead(DCAST(FltBead, child), state); - - } else { - convert_record(child, state); - } +//////////////////////////////////////////////////////////////////// +// Function: FltToEggConverter::dispatch_record +// Access: Private +// Description: Determines what kind of record this is and calls the +// appropriate convert function. +//////////////////////////////////////////////////////////////////// +void FltToEggConverter:: +dispatch_record(const FltRecord *flt_record, FltToEggLevelState &state) { + if (flt_record->is_of_type(FltLOD::get_class_type())) { + convert_lod(DCAST(FltLOD, flt_record), state); + + } else if (flt_record->is_of_type(FltGroup::get_class_type())) { + convert_group(DCAST(FltGroup, flt_record), state); + + } else if (flt_record->is_of_type(FltObject::get_class_type())) { + convert_object(DCAST(FltObject, flt_record), state); + + } else if (flt_record->is_of_type(FltFace::get_class_type())) { + convert_face(DCAST(FltFace, flt_record), state); + + } else if (flt_record->is_of_type(FltExternalReference::get_class_type())) { + convert_ext_ref(DCAST(FltExternalReference, flt_record), state); + + // Fallbacks. + } else if (flt_record->is_of_type(FltBeadID::get_class_type())) { + convert_bead_id(DCAST(FltBeadID, flt_record), state); + + } else if (flt_record->is_of_type(FltBead::get_class_type())) { + convert_bead(DCAST(FltBead, flt_record), state); + + } else { + convert_record(flt_record, state); } } @@ -323,10 +333,19 @@ setup_geometry(const FltGeometry *flt_geom, FltToEggLevelState &state, EggPrimitive *egg_prim, EggVertexPool *egg_vpool, const FltToEggConverter::EggVertices &vertices) { - // Add the primitive to its appropriate parent. + // Determine what the appropriate parent will be. EggGroupNode *egg_parent = state.get_synthetic_group(flt_geom->get_id(), flt_geom->get_transform()); - egg_parent->add_child(egg_prim); + + // Create a new state to reflect the new parent. + FltToEggLevelState next_state(state); + next_state._egg_parent = egg_parent; + + // Check for decals onto the primitive. + convert_subfaces(flt_geom, next_state); + + // Add the primitive to its new home. + next_state._egg_parent->add_child(egg_prim); // Now examine the vertices. EggVertices::const_iterator vi; @@ -414,6 +433,47 @@ setup_geometry(const FltGeometry *flt_geom, FltToEggLevelState &state, parse_comment(flt_geom, egg_prim); } +//////////////////////////////////////////////////////////////////// +// Function: FltToEggConverter::convert_subfaces +// Access: Public +// Description: Records all of the subfaces of the indicated group as +// coplanar polygons (i.e. decals) of the group. +// +// If coplanar polygons exist, the state is modified so +// that _egg_parent is the new group to which the base +// polygons should be added. Therefore, subfaces should +// be defined before the ordinary children are +// processed. +//////////////////////////////////////////////////////////////////// +void FltToEggConverter:: +convert_subfaces(const FltRecord *flt_record, FltToEggLevelState &state) { + int num_subfaces = flt_record->get_num_subfaces(); + if (num_subfaces == 0) { + // No subfaces. + return; + } + + // Create a new group to contain the base polygons. + EggGroup *egg_group = new EggGroup("decal_base"); + state._egg_parent->add_child(egg_group); + state._egg_parent = egg_group; + + egg_group->set_decal_flag(true); + + // Now create a nested group to hold the decals. + EggGroup *decal_group = new EggGroup("decals"); + egg_group->add_child(decal_group); + egg_group = decal_group; + + FltToEggLevelState next_state(state); + next_state._egg_parent = decal_group; + + for (int i = 0; i < num_subfaces; i++) { + const FltRecord *subface = flt_record->get_subface(i); + dispatch_record(subface, next_state); + } +} + //////////////////////////////////////////////////////////////////// // Function: FltToEggConverter::set_transform // Access: Private @@ -563,5 +623,8 @@ make_egg_texture(const FltTexture *flt_texture) { PT(EggTexture) egg_texture = new EggTexture(tref_name, filename); _textures.insert(Textures::value_type(flt_texture, egg_texture)); + + ////*** Texture properties. + return egg_texture; } diff --git a/pandatool/src/fltegg/fltToEggConverter.h b/pandatool/src/fltegg/fltToEggConverter.h index eb388b11ca..ef018b80d8 100644 --- a/pandatool/src/fltegg/fltToEggConverter.h +++ b/pandatool/src/fltegg/fltToEggConverter.h @@ -54,6 +54,7 @@ private: typedef vector< PT(EggVertex) > EggVertices; void convert_record(const FltRecord *flt_record, FltToEggLevelState &state); + void dispatch_record(const FltRecord *flt_record, FltToEggLevelState &state); void convert_lod(const FltLOD *flt_lod, FltToEggLevelState &state); void convert_group(const FltGroup *flt_group, FltToEggLevelState &state); void convert_object(const FltObject *flt_object, FltToEggLevelState &state); @@ -66,6 +67,8 @@ private: EggPrimitive *egg_prim, EggVertexPool *egg_vpool, const EggVertices &vertices); + void convert_subfaces(const FltRecord *flt_record, FltToEggLevelState &state); + void set_transform(const FltBead *flt_bead, EggGroup *egg_group); bool parse_comment(const FltBeadID *flt_bead, EggNode *egg_node); bool parse_comment(const FltRecord *flt_record, const string &name,