Commit: 491bd8b8bbc49b4d03cec6c97d2b2b5a475f0689
Author: Ankit Meel
Date: Mon Aug 17 12:16:20 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB491bd8b8bbc49b4d03cec6c97d2b2b5a475f0689
Move file open errors to constructors.
===================================================================
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mtl.cc
===================================================================
diff --git
a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 23528260259..834e4e1fa85 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -215,6 +215,7 @@ static Geometry *create_geometry(Geometry *const
prev_geometry,
return new_geometry();
}
if (new_type == GEOM_MESH) {
+ /* A Geometry created initially with a default name now found its name.
*/
prev_geometry->set_geometry_name(name);
return prev_geometry;
}
@@ -233,6 +234,9 @@ static Geometry *create_geometry(Geometry *const
prev_geometry,
return new_geometry();
}
+/**
+ * Whenever a new Geometry instance is created, index offsets should be
updated.
+ */
void IndexOffsets::update_index_offsets(const GlobalVertices &global_vertices)
{
index_offsets_[VERTEX_OFF] = global_vertices.vertices.size();
@@ -245,6 +249,10 @@ void IndexOffsets::update_index_offsets(const
GlobalVertices &global_vertices)
OBJParser::OBJParser(const OBJImportParams &import_params) :
import_params_(import_params)
{
obj_file_.open(import_params_.filepath);
+ if (!obj_file_.good()) {
+ fprintf(stderr, "Cannot read from OBJ file:%s.\n",
import_params_.filepath);
+ return;
+ }
}
/**
@@ -255,7 +263,6 @@ void
OBJParser::parse_and_store(Vector<std::unique_ptr<Geometry>> &all_geometrie
GlobalVertices &global_vertices)
{
if (!obj_file_.good()) {
- fprintf(stderr, "Cannot read from OBJ file:%s.\n",
import_params_.filepath);
return;
}
@@ -493,6 +500,9 @@ MTLParser::MTLParser(StringRef mtl_library, StringRefNull
obj_filepath)
BLI_path_join(mtl_file_path_, FILE_MAX, obj_file_dir, mtl_library.data(),
NULL);
BLI_split_dir_part(mtl_file_path_, mtl_dir_path_, FILE_MAXDIR);
mtl_file_.open(mtl_file_path_);
+ if (!mtl_file_.good()) {
+ fprintf(stderr, "Cannot read from MTL file:%s\n", mtl_file_path_);
+ }
}
/**
@@ -501,7 +511,7 @@ MTLParser::MTLParser(StringRef mtl_library, StringRefNull
obj_filepath)
void MTLParser::parse_and_store(Map<string, MTLMaterial> &mtl_materials)
{
if (!mtl_file_.good()) {
- fprintf(stderr, "Cannot read from MTL file:%s\n", mtl_file_path_);
+ return;
}
string line;
@@ -552,7 +562,8 @@ void MTLParser::parse_and_store(Map<string, MTLMaterial>
&mtl_materials)
else if (line_key == "illum") {
copy_string_to_int(rest_line, 2, current_mtlmaterial->illum);
}
- /* Image Textures. */
+
+ /* Parse image textures. */
else if (line_key.find("map_") != string::npos) {
if (!current_mtlmaterial->texture_maps.contains_as(string(line_key))) {
/* No supported texture map found. */
@@ -563,6 +574,7 @@ void MTLParser::parse_and_store(Map<string, MTLMaterial>
&mtl_materials)
Vector<string_view> str_map_xx_split{};
split_by_char(rest_line, ' ', str_map_xx_split);
+ /* TODO ankitm: use `skip_unsupported_options` for parsing this options
too. */
int64_t pos_o{str_map_xx_split.first_index_of_try("-o")};
if (pos_o != string::npos && pos_o + 3 < str_map_xx_split.size()) {
copy_string_to_float({str_map_xx_split[pos_o + 1],
diff --git
a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
index b27a1c492a6..f6b5f2c94c7 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
@@ -47,6 +47,9 @@ class OBJParser {
const GlobalVertices &global_vertices);
};
+/**
+ * All texture map options with number of arguments they accept.
+ */
class TextureMapOptions {
private:
Map<const std::string, int> tex_map_options;
@@ -67,6 +70,9 @@ class TextureMapOptions {
tex_map_options.add_new("-imfchan", 1);
}
+ /**
+ * All valid option strings.
+ */
Map<const std::string, int>::KeyIterator all_options() const
{
return tex_map_options.keys();
@@ -81,6 +87,9 @@ class TextureMapOptions {
class MTLParser {
private:
char mtl_file_path_[FILE_MAX];
+ /**
+ * Directory in which the MTL file is found.
+ */
char mtl_dir_path_[FILE_MAX];
std::ifstream mtl_file_;
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mtl.cc
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mtl.cc
index 2de4c762673..46ed228be87 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mtl.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mtl.cc
@@ -109,7 +109,9 @@ static bool set_img_filepath(Main *bmain, const tex_map_XX
&tex_map, bNode *r_no
fprintf(stderr, "Cannot load image file:'%s'\n", no_quote_path.data());
std::string no_underscore_path{replace_all_occurences(no_quote_path,
"_", " ")};
tex_image = BKE_image_load(nullptr, no_underscore_path.c_str());
- fprintf(stderr, "Cannot load image file:'%s'\n",
no_underscore_path.data());
+ if (!tex_image) {
+ fprintf(stderr, "Cannot load image file:'%s'\n",
no_underscore_path.data());
+ }
}
}
BLI_assert(tex_image);
@@ -208,6 +210,8 @@ void ShaderNodetreeWrap::set_bsdf_socket_values()
/**
* Create image texture, vector and normal mapping nodes from MTL materials
and link the
* nodes to p-BSDF node.
+ * Texture Coordinates -> Mapping -> Image Texture -> (optional) Normal Map ->
p-BSDF.
+ *
*/
void ShaderNodetreeWrap::add_image_textures(Main *bmain)
{
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs