Commit: 8339dd66477ad2f872c18c6578bc0a1139d3b818
Author: Ankit Meel
Date: Thu Aug 6 15:04:36 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB8339dd66477ad2f872c18c6578bc0a1139d3b818
Replace std::string_view with StringRef.
Add comments.
===================================================================
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mtl.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_importer.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 631aa4229b4..1d667e22db1 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
@@ -69,7 +69,7 @@ static void split_line_key_rest(std::string_view line, string
&r_line_key, strin
if (r_rest_line.empty()) {
return;
}
- /* Remove the initial space. */
+ /* Remove the space between line key and the data after it. */
r_rest_line.erase(0, 1);
}
@@ -166,6 +166,9 @@ static bool create_raw_curve(std::unique_ptr<OBJRawObject>
*raw_object)
return true;
}
+/**
+ * Open OBJ file at the path given in import parameters.
+ */
OBJParser::OBJParser(const OBJImportParams &import_params) :
import_params_(import_params)
{
obj_file_.open(import_params_.filepath);
@@ -199,6 +202,7 @@ void
OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
fprintf(stderr, "Cannot read from file:%s.\n", import_params_.filepath);
return;
}
+
string line;
/* Non owning raw pointer to the unique_ptr to a raw object.
* Needed to update object data in the same while loop. */
@@ -395,20 +399,20 @@ void
OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
else if (line_key == "usemtl") {
(*curr_ob)->material_name_.append(rest_line);
}
- else if (line_key == "#") {
- /* This is a comment. */
- }
}
}
/**
- * Return a list of all material library filepaths referenced by in the OBJ
file.
+ * Return a list of all material library filepaths referenced by the OBJ file.
*/
Span<std::string> OBJParser::mtl_libraries() const
{
return mtl_libraries_;
}
+/**
+ * Open material library file.
+ */
MTLParser::MTLParser(StringRef mtl_library, StringRef obj_filepath) :
mtl_library_(mtl_library)
{
char obj_file_dir[FILE_MAXDIR];
@@ -470,7 +474,7 @@ void MTLParser::parse_and_store(Map<string, MTLMaterial>
&mtl_materials)
/* Image Textures. */
else if (line_key.find("map_") != string::npos) {
if (!curr_mtlmat->texture_maps.contains_as(line_key)) {
- /* No supported map_xx found. */
+ /* No supported texture map found. */
continue;
}
tex_map_XX &tex_map = curr_mtlmat->texture_maps.lookup(line_key);
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
index ad2dfe09ad7..e4b04f71f7a 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
@@ -193,13 +193,14 @@ void OBJMeshFromRaw::create_uv_verts()
void OBJMeshFromRaw::create_materials(Main *bmain, const Map<std::string,
MTLMaterial> &materials)
{
for (const Map<std::string, MTLMaterial>::Item &curr_mat :
materials.items()) {
- Material *mat = BKE_material_add(bmain, curr_mat.key.c_str());
- mat->use_nodes = true;
- ShaderNodetreeWrap mat_wrap{bmain, curr_mat.value};
- mat->nodetree = mat_wrap.get_nodetree();
BKE_object_material_slot_add(bmain, mesh_object_.get());
+ Material *mat = BKE_material_add(bmain, curr_mat.key.c_str());
BKE_object_material_assign(
bmain, mesh_object_.get(), mat, mesh_object_.get()->totcol,
BKE_MAT_ASSIGN_USERPREF);
+
+ ShaderNodetreeWrap mat_wrap{bmain, curr_mat.value};
+ mat->use_nodes = true;
+ mat->nodetree = mat_wrap.get_nodetree();
}
}
} // namespace blender::io::obj
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 17d43a3ab24..0f43d3b0403 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
@@ -73,11 +73,9 @@ static void set_property_of_socket(eNodeSocketDatatype
property_type,
}
}
-static std::string replace_all_occurences(std::string_view path,
- std::string_view to_remove,
- std::string_view to_add)
+static std::string replace_all_occurences(StringRef path, StringRef to_remove,
StringRef to_add)
{
- std::string clean_path{path};
+ std::string clean_path{path.data()};
while (true) {
std::string::size_type pos = clean_path.find(to_remove);
if (pos == std::string::npos) {
@@ -91,7 +89,7 @@ static std::string replace_all_occurences(std::string_view
path,
/**
* Load image for Image Texture node.
*/
-static void set_img_filepath(Main *bmain, std::string_view value, bNode
*r_node)
+static void set_img_filepath(Main *bmain, StringRef value, bNode *r_node)
{
BLI_assert(r_node);
Image *tex_image = BKE_image_load(bmain, value.data());
@@ -130,6 +128,9 @@ ShaderNodetreeWrap::ShaderNodetreeWrap(Main *bmain, const
MTLMaterial &mtl_mat)
nodeSetActive(nodetree_.get(), shader_output_.get());
}
+/**
+ * Assert if caller hasn't acquired nodetree. Memory is managed by
`unique_ptr`s.
+ */
ShaderNodetreeWrap::~ShaderNodetreeWrap()
{
if (nodetree_) {
@@ -177,6 +178,9 @@ void ShaderNodetreeWrap::link_sockets(unique_node_ptr
from_node,
static_cast<void>(from_node.release());
}
+/**
+ * Set values of sockets in p-BSDF node of the nodetree.
+ */
void ShaderNodetreeWrap::set_bsdf_socket_values()
{
set_property_of_socket(SOCK_FLOAT, "Specular", {mtl_mat_->Ns}, bsdf_.get());
@@ -188,6 +192,10 @@ void ShaderNodetreeWrap::set_bsdf_socket_values()
set_property_of_socket(SOCK_RGBA, "Emission", {mtl_mat_->Ke, 3},
bsdf_.get());
}
+/**
+ * Create image texture, vector and normal mapping nodes from MTL materials
and link the
+ * nodes to p-BSDF node.
+ */
void ShaderNodetreeWrap::add_image_textures(Main *bmain)
{
for (const Map<std::string, tex_map_XX>::Item texture_map :
mtl_mat_->texture_maps.items()) {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
index 8d3b33ed408..078381b9d75 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
@@ -122,6 +122,10 @@ const std::string &OBJRawObject::group() const
return nurbs_element_.group_;
}
+/**
+ * Return a reference to the texture map corresponding to the given ID
+ * Caller must ensure that the lookup key given exists in the Map.
+ */
tex_map_XX &MTLMaterial::tex_map_of_type(StringRef map_string)
{
return texture_maps.lookup_as(map_string);
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
b/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
index 455635bf522..a0ef6ca4217 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
@@ -125,7 +125,7 @@ void importer_main(bContext *C, const OBJImportParams
&import_params)
MTLParser mtl_parser{mtl_library, import_params.filepath};
mtl_parser.parse_and_store(materials);
}
- obj_parser.print_obj_data(list_of_objects, global_vertices);
+ // obj_parser.print_obj_data(list_of_objects, global_vertices);
raw_to_blender_objects(bmain, scene, list_of_objects, global_vertices,
materials);
}
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs