OBJ Export: Update 'bitflag smoothgroup' to also consider boundary vertices.

Previous code would consider two different face groups sharing no common
edges as fully isolated from each other, and could assign them the same
bitflag facegroup value.

Following FBX recent option to export these bitflags smoothgroups (!135646),
also consider that two different face groups are connected if they only share
common vertices, and assign them different bitflags values.

NOTE: This seems to be the expected behavior in major DCCs actually
using smoothgroups, only considering boundary edges create groups that
generate broken shading when imported by these tools.

NOTE: The 'unique integer identifers' option is kept for OBJ exporter,
as such OBJ files are also found on internet, depending on which app
generated them.

Pull Request: https://projects.blender.org/blender/blender/pulls/135998
This commit is contained in:
Bastien Montagne
2025-03-18 10:04:38 +01:00
committed by Bastien Montagne
parent d6da557358
commit b87b58b07e
2 changed files with 13 additions and 7 deletions

View File

@@ -335,7 +335,7 @@ void WM_OT_obj_export(wmOperatorType *ot)
"export_normals",
true,
"Export Normals",
"Export per-face normals if the face is flat-shaded, per-face-per-loop "
"Export per-face normals if the face is flat-shaded, per-face-corner "
"normals if smooth-shaded");
RNA_def_boolean(ot->srna, "export_colors", false, "Export Colors", "Export per-vertex colors");
RNA_def_boolean(ot->srna,
@@ -386,14 +386,20 @@ void WM_OT_obj_export(wmOperatorType *ot)
"Export Vertex Groups",
"Export the name of the vertex group of a face. It is approximated "
"by choosing the vertex group with the most members among the vertices of a face");
RNA_def_boolean(ot->srna,
"export_smooth_groups",
false,
"Export Smooth Groups",
"Generate smooth groups identifiers for each group of smooth faces, as "
"unique integer values by default");
RNA_def_boolean(
ot->srna,
"export_smooth_groups",
"smooth_group_bitflags",
false,
"Export Smooth Groups",
"Every smooth-shaded face is assigned group \"1\" and every flat-shaded face \"off\"");
RNA_def_boolean(
ot->srna, "smooth_group_bitflags", false, "Generate Bitflags for Smooth Groups", "");
"Bitflags Smooth Groups",
"If exporting smoothgroups, generate 'bitflags' values for the groups, instead of "
"unique integer values. The same bitflag value can be re-used for different groups of "
"smooth faces, as long as they have no common sharp edges or vertices");
/* Only show `.obj` or `.mtl` files by default. */
prop = RNA_def_string(ot->srna, "filter_glob", "*.obj;*.mtl", 0, "Extension Filter", "");

View File

@@ -214,7 +214,7 @@ void OBJMesh::calc_smooth_groups(const bool use_bitflags)
export_mesh_->corner_verts(),
sharp_edges,
sharp_faces,
false,
true,
&tot_smooth_groups_);
}
else {