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
This commit is contained in:
Jesse Yurkovich 2022-06-06 22:34:06 -07:00
parent b4d3ca624e
commit 99847cd642
Notes: blender-bot 2023-02-21 17:59:30 +01:00
Referenced by issue #98661, 3.2: Potential candidates for corrective releases
2 changed files with 11 additions and 6 deletions

View File

@ -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. */

View File

@ -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);
}