[Bf-blender-cvs] [89f0fedb5cf] blender-v3.3-release: Fix T97769: new OBJ exporter does not replace spaces in object names
Aras Pranckevicius
noreply at git.blender.org
Wed Aug 3 08:50:17 CEST 2022
Commit: 89f0fedb5cfcde8d2d29f4cf08f3cfa194c375b2
Author: Aras Pranckevicius
Date: Wed Aug 3 09:49:56 2022 +0300
Branches: blender-v3.3-release
https://developer.blender.org/rB89f0fedb5cfcde8d2d29f4cf08f3cfa194c375b2
Fix T97769: new OBJ exporter does not replace spaces in object names
The Python based exporter was replacing spaces with underscores
in object/group names, mostly to handle cases where names could begin
or end with spaces. The new exporter was not doing that. Note: spaces
in material names were already handled by the new exporter.
Fixes T97769. Updated test coverage expectations; one of the test
files has an object with a space in the name.
===================================================================
M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
===================================================================
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
index 731587bfcea..36a9cf1b9ae 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
@@ -179,13 +179,19 @@ void OBJWriter::write_mtllib_name(const StringRefNull mtl_filepath) const
fh.write_to_file(outfile_);
}
+static void spaces_to_underscores(std::string &r_name)
+{
+ std::replace(r_name.begin(), r_name.end(), ' ', '_');
+}
+
void OBJWriter::write_object_name(FormatHandler<eFileType::OBJ> &fh,
const OBJMesh &obj_mesh_data) const
{
- const char *object_name = obj_mesh_data.get_object_name();
+ std::string object_name = obj_mesh_data.get_object_name();
+ spaces_to_underscores(object_name);
if (export_params_.export_object_groups) {
- const std::string object_name = obj_mesh_data.get_object_name();
- const char *mesh_name = obj_mesh_data.get_object_mesh_name();
+ std::string mesh_name = obj_mesh_data.get_object_mesh_name();
+ spaces_to_underscores(mesh_name);
fh.write<eOBJSyntaxElement::object_group>(object_name + "_" + mesh_name);
return;
}
@@ -389,7 +395,8 @@ void OBJWriter::write_poly_elements(FormatHandler<eFileType::OBJ> &fh,
mat_name = MATERIAL_GROUP_DISABLED;
}
if (export_params_.export_material_groups) {
- const std::string object_name = obj_mesh_data.get_object_name();
+ std::string object_name = obj_mesh_data.get_object_name();
+ spaces_to_underscores(object_name);
fh.write<eOBJSyntaxElement::object_group>(object_name + "_" + mat_name);
}
buf.write<eOBJSyntaxElement::poly_usemtl>(mat_name);
diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
index 4055d892332..339f672c3e0 100644
--- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
@@ -290,7 +290,7 @@ TEST_F(obj_importer_test, import_nurbs_mesh)
{
Expectation expect[] = {
{"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
- {"OBTorus Knot",
+ {"OBTorus_Knot",
OB_MESH,
108,
108,
More information about the Bf-blender-cvs
mailing list