[Bf-blender-cvs] [9e157283800] soc-2020-io-performance: Move MTLMaterial & float3_to_string to exporter files.
Ankit Meel
noreply at git.blender.org
Wed Sep 16 13:05:55 CEST 2020
Commit: 9e1572838007c5e7a0e69449ff4be05734293bc4
Author: Ankit Meel
Date: Wed Sep 16 16:09:02 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB9e1572838007c5e7a0e69449ff4be05734293bc4
Move MTLMaterial & float3_to_string to exporter files.
Keeping the branch in sync with D8754 and D8753.
===================================================================
M source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
M source/blender/io/wavefront_obj/intern/obj_export_mtl.hh
M source/blender/io/wavefront_obj/intern/obj_import_mtl.hh
M source/blender/io/wavefront_obj/intern/string_utils.cc
M source/blender/io/wavefront_obj/intern/string_utils.hh
===================================================================
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
index 90e3268447e..e5e4603f1cd 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
@@ -29,8 +29,6 @@
#include "obj_export_mesh.hh"
#include "obj_export_mtl.hh"
#include "obj_export_nurbs.hh"
-#include "obj_import_mtl.hh"
-#include "string_utils.hh"
namespace blender::io::obj {
@@ -424,6 +422,17 @@ void OBJWriter::update_index_offsets(const OBJMesh &obj_mesh_data)
/** \name MTL writers.
* \{ */
+/**
+ * Converts float3 to space-separated number string with no leading or trailing space.
+ * Only to be used in NON performance-critical code.
+ */
+static std::string float3_to_string(const float3 &numbers)
+{
+ std::ostringstream r_string;
+ r_string << numbers[0] << " " << numbers[1] << " " << numbers[2];
+ return r_string.str();
+};
+
/**
* Open the MTL file in append mode.
*/
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mtl.hh b/source/blender/io/wavefront_obj/intern/obj_export_mtl.hh
index 45101fd6f68..18069c93af3 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mtl.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mtl.hh
@@ -23,9 +23,76 @@
#pragma once
-#include "obj_import_mtl.hh"
+#include "BLI_float3.hh"
+#include "BLI_map.hh"
+#include "BLI_string_ref.hh"
+#include "BLI_vector.hh"
+
+#include "DNA_node_types.h"
+
+#include "obj_export_mesh.hh"
namespace blender::io::obj {
+
+/**
+ * Used for storing parameters for all kinds of texture maps from MTL file.
+ */
+struct tex_map_XX {
+ tex_map_XX(StringRef to_socket_id) : dest_socket_id(to_socket_id){};
+
+ const std::string dest_socket_id{};
+ float3 translation = {0.0f, 0.0f, 0.0f};
+ float3 scale = {1.0f, 1.0f, 1.0f};
+ /* Only Flat and Smooth projections are supported. */
+ int projection_type = SHD_PROJ_FLAT;
+ std::string image_path{};
+ std::string mtl_dir_path;
+};
+
+/**
+ * Container for storing material data read from MTL file, as well as
+ * to be written to MTL file.
+ */
+struct MTLMaterial {
+ MTLMaterial()
+ {
+ texture_maps.add("map_Kd", tex_map_XX("Base Color"));
+ texture_maps.add("map_Ks", tex_map_XX("Specular"));
+ texture_maps.add("map_Ns", tex_map_XX("Roughness"));
+ texture_maps.add("map_d", tex_map_XX("Alpha"));
+ texture_maps.add("map_refl", tex_map_XX("Metallic"));
+ texture_maps.add("map_Ke", tex_map_XX("Emission"));
+ texture_maps.add("map_Bump", tex_map_XX("Normal"));
+ }
+
+ /**
+ * 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 &tex_map_of_type(StringRef map_string)
+ {
+ {
+ BLI_assert(texture_maps.contains_as(map_string));
+ return texture_maps.lookup_as(map_string);
+ }
+ }
+
+ std::string name{};
+ /* Always check for negative values while importing or exporting. Use defaults if
+ * any value is negative. */
+ float Ns{-1.0f};
+ float3 Ka{-1.0f};
+ float3 Kd{-1.0f};
+ float3 Ks{-1.0f};
+ float3 Ke{-1.0f};
+ float Ni{-1.0f};
+ float d{-1.0f};
+ int illum{-1};
+ Map<const std::string, tex_map_XX> texture_maps;
+ /** Only used for Normal Map node: map_Bump. */
+ float map_Bump_strength{-1.0f};
+};
+
class MaterialWrap {
private:
const OBJMesh &obj_mesh_data_;
diff --git a/source/blender/io/wavefront_obj/intern/obj_import_mtl.hh b/source/blender/io/wavefront_obj/intern/obj_import_mtl.hh
index c058db1d21b..e701cc85d25 100644
--- a/source/blender/io/wavefront_obj/intern/obj_import_mtl.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_import_mtl.hh
@@ -34,64 +34,9 @@
#include "MEM_guardedalloc.h"
-namespace blender::io::obj {
-/**
- * Used for storing parameters for all kinds of texture maps from MTL file.
- */
-struct tex_map_XX {
- tex_map_XX(StringRef to_socket_id) : dest_socket_id(to_socket_id){};
-
- const std::string dest_socket_id{};
- float3 translation = {0.0f, 0.0f, 0.0f};
- float3 scale = {1.0f, 1.0f, 1.0f};
- /* Only Flat and Smooth projections are supported. */
- int projection_type = SHD_PROJ_FLAT;
- std::string image_path{};
- std::string mtl_dir_path;
-};
-
-/**
- * Store material data parsed from MTL file.
- */
-struct MTLMaterial {
- MTLMaterial()
- {
- texture_maps.add("map_Kd", tex_map_XX("Base Color"));
- texture_maps.add("map_Ks", tex_map_XX("Specular"));
- texture_maps.add("map_Ns", tex_map_XX("Roughness"));
- texture_maps.add("map_d", tex_map_XX("Alpha"));
- texture_maps.add("map_refl", tex_map_XX("Metallic"));
- texture_maps.add("map_Ke", tex_map_XX("Emission"));
- texture_maps.add("map_Bump", tex_map_XX("Normal"));
- }
-
- /**
- * 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 &tex_map_of_type(StringRef map_string)
- {
- {
- BLI_assert(texture_maps.contains_as(map_string));
- return texture_maps.lookup_as(map_string);
- }
- }
+#include "obj_export_mtl.hh"
- std::string name{};
- /* Always check for negative values while importing or exporting. Use defaults if
- * any value is negative. */
- float Ns{-1.0f};
- float3 Ka{-1.0f};
- float3 Kd{-1.0f};
- float3 Ks{-1.0f};
- float3 Ke{-1.0f};
- float Ni{-1.0f};
- float d{-1.0f};
- int illum{-1};
- Map<const std::string, tex_map_XX> texture_maps;
- /** Only used for Normal Map node: map_Bump. */
- float map_Bump_strength{-1.0f};
-};
+namespace blender::io::obj {
struct UniqueNodeDeleter {
void operator()(bNode *node)
diff --git a/source/blender/io/wavefront_obj/intern/string_utils.cc b/source/blender/io/wavefront_obj/intern/string_utils.cc
index 1aa4a522f18..f141e3ca1f6 100644
--- a/source/blender/io/wavefront_obj/intern/string_utils.cc
+++ b/source/blender/io/wavefront_obj/intern/string_utils.cc
@@ -213,15 +213,4 @@ std::string replace_all_occurences(StringRef original, StringRef to_remove, Stri
return clean;
}
-/**
- * Converts float3 to space-separated number string with no leading or trailing space.
- * Only to be used in NON performance-critical code.
- */
-std::string float3_to_string(const float3 &numbers)
-{
- std::ostringstream r_string;
- r_string << numbers[0] << " " << numbers[1] << " " << numbers[2];
- return r_string.str();
-};
-
} // namespace blender::io::obj
diff --git a/source/blender/io/wavefront_obj/intern/string_utils.hh b/source/blender/io/wavefront_obj/intern/string_utils.hh
index f8644a2bc50..e0b9feb8e82 100644
--- a/source/blender/io/wavefront_obj/intern/string_utils.hh
+++ b/source/blender/io/wavefront_obj/intern/string_utils.hh
@@ -29,6 +29,5 @@ void copy_string_to_float(Span<StringRef> src,
void copy_string_to_int(StringRef src, const int fallback_value, int &r_dst);
void copy_string_to_int(Span<StringRef> src, const int fallback_value, MutableSpan<int> r_dst);
std::string replace_all_occurences(StringRef original, StringRef to_remove, StringRef to_add);
-std::string float3_to_string(const float3 &numbers);
} // namespace blender::io::obj
More information about the Bf-blender-cvs
mailing list