Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2022-08-01 17:29:52 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2022-08-01 17:29:52 +0300
commitbe0449cfcae25ff64540e3859232481826f675fb (patch)
tree80f663b543f27c97e39f6265ea119abc512b6c6a /source/blender/io
parent49bccd7740622d287f82e4c9b73bfc81d9a22584 (diff)
parent3393b7137e247383477eb38d938239fbb9221680 (diff)
Merge branch 'master' into sculpt_curve_collisionssculpt_curve_collisions
Diffstat (limited to 'source/blender/io')
-rw-r--r--source/blender/io/collada/BCAnimationCurve.cpp2
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc19
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_import_mtl.cc2
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc6
-rw-r--r--source/blender/io/wavefront_obj/tests/obj_importer_tests.cc63
5 files changed, 82 insertions, 10 deletions
diff --git a/source/blender/io/collada/BCAnimationCurve.cpp b/source/blender/io/collada/BCAnimationCurve.cpp
index 04a7a81c0a6..fe90dc5d5fa 100644
--- a/source/blender/io/collada/BCAnimationCurve.cpp
+++ b/source/blender/io/collada/BCAnimationCurve.cpp
@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2008 Blender Foundation. All rights reserved. */
+#include "RNA_path.h"
+
#include "BCAnimationCurve.h"
BCAnimationCurve::BCAnimationCurve()
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 a32fd90594d..8594603867f 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
@@ -13,6 +13,7 @@
#include "obj_import_file_reader.hh"
#include "obj_import_string_utils.hh"
+#include <algorithm>
#include <charconv>
namespace blender::io::obj {
@@ -394,6 +395,23 @@ static bool parse_keyword(const char *&p, const char *end, StringRef keyword)
return true;
}
+/* Special case: if there were no faces/edges in any geometries,
+ * treat all the vertices as a point cloud. */
+static void use_all_vertices_if_no_faces(Geometry *geom,
+ const Vector<std::unique_ptr<Geometry>> &all_geometries,
+ const GlobalVertices &global_vertices)
+{
+ if (!global_vertices.vertices.is_empty() && geom && geom->geom_type_ == GEOM_MESH) {
+ if (std::all_of(
+ all_geometries.begin(), all_geometries.end(), [](const std::unique_ptr<Geometry> &g) {
+ return g->get_vertex_count() == 0;
+ })) {
+ geom->track_vertex_index(0);
+ geom->track_vertex_index(global_vertices.vertices.size() - 1);
+ }
+ }
+}
+
void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
GlobalVertices &r_global_vertices)
{
@@ -571,6 +589,7 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
buffer_offset = left_size;
}
+ use_all_vertices_if_no_faces(curr_geom, r_all_geometries, r_global_vertices);
add_default_mtl_library();
}
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
index 60e419728f3..f7685ba0b7b 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
@@ -65,7 +65,7 @@ static bool load_texture_image_at_path(Main *bmain,
bNode *r_node,
const std::string &path)
{
- Image *tex_image = BKE_image_load(bmain, path.c_str());
+ Image *tex_image = BKE_image_load_exists(bmain, path.c_str());
if (!tex_image) {
fprintf(stderr, "Cannot load image file: '%s'\n", path.c_str());
return false;
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
index 9a457167fca..7e282b164b0 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
@@ -41,12 +41,14 @@ void fixup_line_continuations(char *p, char *end)
while (true) {
/* Find next backslash, if any. */
char *backslash = std::find(p, end, '\\');
- if (backslash == end)
+ if (backslash == end) {
break;
+ }
/* Skip over possible whitespace right after it. */
p = backslash + 1;
- while (p < end && is_whitespace(*p) && *p != '\n')
+ while (p < end && is_whitespace(*p) && *p != '\n') {
++p;
+ }
/* If then we have a newline, turn both backslash
* and the newline into regular spaces. */
if (p < end && *p == '\n') {
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 c59269f5a7d..ecf1243fa86 100644
--- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
@@ -47,7 +47,8 @@ class obj_importer_test : public BlendfileLoadingBaseTest {
void import_and_check(const char *path,
const Expectation *expect,
size_t expect_count,
- int expect_mat_count)
+ int expect_mat_count,
+ int expect_image_count = 0)
{
if (!blendfile_load("io_tests/blend_geometry/all_quads.blend")) {
ADD_FAILURE();
@@ -132,12 +133,12 @@ class obj_importer_test : public BlendfileLoadingBaseTest {
DEG_OBJECT_ITER_END;
EXPECT_EQ(object_index, expect_count);
- /* Count number of materials. */
- int mat_count = 0;
- LISTBASE_FOREACH (ID *, id, &bfile->main->materials) {
- ++mat_count;
- }
+ /* Check number of materials & textures. */
+ const int mat_count = BLI_listbase_count(&bfile->main->materials);
EXPECT_EQ(mat_count, expect_mat_count);
+
+ const int ima_count = BLI_listbase_count(&bfile->main->images);
+ EXPECT_EQ(ima_count, expect_image_count);
}
};
@@ -306,7 +307,45 @@ TEST_F(obj_importer_test, import_materials)
{"OBCube", 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);
+ import_and_check("materials.obj", expect, std::size(expect), 4, 1);
+}
+
+TEST_F(obj_importer_test, import_cubes_with_textures_rel)
+{
+ Expectation expect[] = {
+ {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
+ {"OBCube4Tex",
+ OB_MESH,
+ 8,
+ 12,
+ 6,
+ 24,
+ float3(1, 1, -1),
+ float3(-1, -1, 1),
+ float3(0, 1, 0),
+ float2(0.9935f, 0.0020f)},
+ {"OBCubeTiledTex",
+ OB_MESH,
+ 8,
+ 12,
+ 6,
+ 24,
+ float3(4, 1, -1),
+ float3(2, -1, 1),
+ float3(0, 1, 0),
+ float2(0.9935f, 0.0020f)},
+ {"OBCubeTiledTexFromAnotherFolder",
+ OB_MESH,
+ 8,
+ 12,
+ 6,
+ 24,
+ float3(7, 1, -1),
+ float3(5, -1, 1),
+ float3(0, 1, 0),
+ float2(0.9935f, 0.0020f)},
+ };
+ import_and_check("cubes_with_textures_rel.obj", expect, std::size(expect), 3, 4);
}
TEST_F(obj_importer_test, import_faces_invalid_or_with_holes)
@@ -664,4 +703,14 @@ TEST_F(obj_importer_test, import_cubes_vertex_colors_mrgb)
import_and_check("cubes_vertex_colors_mrgb.obj", expect, std::size(expect), 0);
}
+TEST_F(obj_importer_test, import_vertices)
+{
+ Expectation expect[] = {
+ {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
+ /* Loose vertices without faces or edges. */
+ {"OBCube.001", OB_MESH, 8, 0, 0, 0, float3(1, 1, -1), float3(-1, 1, 1)},
+ };
+ import_and_check("vertices.obj", expect, std::size(expect), 0);
+}
+
} // namespace blender::io::obj