diff options
Diffstat (limited to 'source')
5 files changed, 21 insertions, 36 deletions
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 8e380e3f2bc..df15191916a 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -342,7 +342,7 @@ void WM_OT_obj_export(struct wmOperatorType *ot) "export_material_groups", false, "Export Material Groups", - "Append mesh name and material name to object name, separated by a '_'"); + "Generate an OBJ group for each part of a geometry using a different material"); RNA_def_boolean( ot->srna, "export_vertex_groups", 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 1668ce3269c..3f9fc3b1dbb 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 @@ -174,34 +174,14 @@ void OBJWriter::write_mtllib_name(const StringRefNull mtl_filepath) const fh.write_to_file(outfile_); } -void OBJWriter::write_object_group(FormatHandler<eFileType::OBJ> &fh, - const OBJMesh &obj_mesh_data) const -{ - /* "o object_name" is not mandatory. A valid .OBJ file may contain neither - * "o name" nor "g group_name". */ - BLI_assert(export_params_.export_object_groups); - if (!export_params_.export_object_groups) { - return; - } - const std::string object_name = obj_mesh_data.get_object_name(); - const char *object_mesh_name = obj_mesh_data.get_object_mesh_name(); - const char *object_material_name = obj_mesh_data.get_object_material_name(0); - if (export_params_.export_materials && export_params_.export_material_groups && - object_material_name) { - fh.write<eOBJSyntaxElement::object_group>(object_name + "_" + object_mesh_name + "_" + - object_material_name); - } - else { - fh.write<eOBJSyntaxElement::object_group>(object_name + "_" + object_mesh_name); - } -} - 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(); if (export_params_.export_object_groups) { - write_object_group(fh, obj_mesh_data); + const std::string object_name = obj_mesh_data.get_object_name(); + const char *mesh_name = obj_mesh_data.get_object_mesh_name(); + fh.write<eOBJSyntaxElement::object_group>(object_name + "_" + mesh_name); return; } fh.write<eOBJSyntaxElement::object_name>(object_name); @@ -363,13 +343,14 @@ void OBJWriter::write_poly_elements(FormatHandler<eFileType::OBJ> &fh, buf.write<eOBJSyntaxElement::poly_usemtl>(MATERIAL_GROUP_DISABLED); } else { - if (export_params_.export_object_groups) { - write_object_group(buf, obj_mesh_data); - } const char *mat_name = matname_fn(mat); if (!mat_name) { mat_name = MATERIAL_GROUP_DISABLED; } + if (export_params_.export_material_groups) { + const std::string object_name = obj_mesh_data.get_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/exporter/obj_export_file_writer.hh b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh index 50de8ad3282..96f7d434338 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh @@ -67,10 +67,6 @@ class OBJWriter : NonMovable, NonCopyable { */ void write_object_name(FormatHandler<eFileType::OBJ> &fh, const OBJMesh &obj_mesh_data) const; /** - * Write an object's group with mesh and/or material name appended conditionally. - */ - void write_object_group(FormatHandler<eFileType::OBJ> &fh, const OBJMesh &obj_mesh_data) const; - /** * Write file name of Material Library in .OBJ file. */ void write_mtllib_name(const StringRefNull mtl_filepath) const; diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc index 5be68565054..7d3e3cd84fd 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -203,11 +203,6 @@ const Material *OBJMesh::get_object_material(const int16_t mat_nr) const */ Object *obj = const_cast<Object *>(&export_object_eval_); const Material *r_mat = BKE_object_material_get(obj, mat_nr + 1); -#ifdef DEBUG - if (!r_mat) { - std::cerr << "Material not found for mat_nr = " << mat_nr << std::endl; - } -#endif return r_mat; } diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index e96a7d28561..b8fecfb25f3 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -511,4 +511,17 @@ TEST_F(obj_exporter_regression_test, all_objects) _export.params); } +TEST_F(obj_exporter_regression_test, all_objects_mat_groups) +{ + OBJExportParamsDefault _export; + _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; + _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.export_smooth_groups = true; + _export.params.export_material_groups = true; + compare_obj_export_to_golden("io_tests/blend_scene/all_objects.blend", + "io_tests/obj/all_objects_mat_groups.obj", + "io_tests/obj/all_objects_mat_groups.mtl", + _export.params); +} + } // namespace blender::io::obj |