[Bf-blender-cvs] [99847cd6423] master: OBJ: Use filename as the default object name

Jesse Yurkovich noreply at git.blender.org
Tue Jun 7 08:32:49 CEST 2022


Commit: 99847cd642385105e06a486200d377a682b597a0
Author: Jesse Yurkovich
Date:   Mon Jun 6 22:34:06 2022 -0700
Branches: master
https://developer.blender.org/rB99847cd642385105e06a486200d377a682b597a0

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 c7990028312..a627e7261e3 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
@@ -343,9 +343,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 48990975416..235e9ac77e6 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