[Bf-blender-cvs] [581604d17ab] blender-v3.2-release: OBJ: Use filename as the default object name

Jesse Yurkovich noreply at git.blender.org
Wed Jun 22 13:03:02 CEST 2022


Commit: 581604d17ab7dad152a55fe555f0c68f9cf75219
Author: Jesse Yurkovich
Date:   Mon Jun 6 22:34:06 2022 -0700
Branches: blender-v3.2-release
https://developer.blender.org/rB581604d17ab7dad152a55fe555f0c68f9cf75219

OBJ: Use filename as the default object name

To match the existing Python .obj importer, and to make it easier for
the user to determine which object is which, use the filename for the
default object name instead of "New object".

Differential Revision: https://developer.blender.org/D15133

===================================================================

M	source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
M	source/blender/io/wavefront_obj/tests/obj_importer_tests.cc

===================================================================

diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
index c069093ac06..f1c9959cae5 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
@@ -342,9 +342,14 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
     return;
   }
 
+  /* Use the filename as the default name given to the initial object. */
+  char ob_name[FILE_MAXFILE];
+  BLI_strncpy(ob_name, BLI_path_basename(import_params_.filepath), FILE_MAXFILE);
+  BLI_path_extension_replace(ob_name, FILE_MAXFILE, "");
+
   VertexIndexOffset offsets;
   Geometry *curr_geom = create_geometry(
-      nullptr, GEOM_MESH, "", r_global_vertices, r_all_geometries, offsets);
+      nullptr, GEOM_MESH, ob_name, r_global_vertices, r_all_geometries, offsets);
 
   /* State variables: once set, they remain the same for the remaining
    * elements in the object. */
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 3d34fb6f9c6..e959f71fffb 100644
--- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
@@ -133,7 +133,7 @@ TEST_F(obj_importer_test, import_cube)
 {
   Expectation expect[] = {
       {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
-      {"OBNew object",
+      {"OBcube",
        OB_MESH,
        8,
        12,
@@ -168,7 +168,7 @@ TEST_F(obj_importer_test, import_nurbs)
 {
   Expectation expect[] = {
       {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
-      {"OBNew object",
+      {"OBnurbs",
        OB_CURVES_LEGACY,
        12,
        0,
@@ -184,7 +184,7 @@ TEST_F(obj_importer_test, import_nurbs_curves)
 {
   Expectation expect[] = {
       {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
-      {"OBNew object", OB_CURVES_LEGACY, 4, 0, 4, 0, float3(2, -2, 0), float3(-2, -2, 0)},
+      {"OBnurbs_curves", OB_CURVES_LEGACY, 4, 0, 4, 0, float3(2, -2, 0), float3(-2, -2, 0)},
       {"OBNurbsCurveDiffWeights",
        OB_CURVES_LEGACY,
        4,
@@ -211,7 +211,7 @@ TEST_F(obj_importer_test, import_nurbs_cyclic)
 {
   Expectation expect[] = {
       {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
-      {"OBNew object",
+      {"OBnurbs_cyclic",
        OB_CURVES_LEGACY,
        31,
        0,
@@ -262,7 +262,7 @@ TEST_F(obj_importer_test, import_materials)
 {
   Expectation expect[] = {
       {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
-      {"OBNew object", OB_MESH, 8, 12, 6, 24, float3(-1, -1, 1), float3(1, -1, -1)},
+      {"OBmaterials", OB_MESH, 8, 12, 6, 24, float3(-1, -1, 1), float3(1, -1, -1)},
   };
   import_and_check("materials.obj", expect, std::size(expect), 4);
 }



More information about the Bf-blender-cvs mailing list