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:
authorAras Pranckevicius <aras@nesnausk.org>2022-08-11 15:51:36 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-08-11 15:51:36 +0300
commit0a096f2be233b6faca468a1add615fb72e57909e (patch)
treeca5591dba8f268173620910694dfd2278a4d3621 /source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
parented55054e57a35278e90d7ecd512521289d450fd8 (diff)
Fix T98781: OBJ exporter wrongly writing default material socket values when textures are present
Report T98781 and part of T97642: the MTLMaterial info only captures image nodes and the default socket values. When the image information is present, do not emit the socket defaults - the .MTL spec states they are multiplied together, but the default value is not used in blender when the socket is connected. Also contains svn tests repository update to extend the test coverage, and update test expectation outputs.
Diffstat (limited to 'source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc')
-rw-r--r--source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc47
1 files changed, 29 insertions, 18 deletions
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
index 36a9cf1b9ae..53aa80700cc 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
@@ -547,20 +547,29 @@ StringRefNull MTLWriter::mtl_file_path() const
return mtl_filepath_;
}
-void MTLWriter::write_bsdf_properties(const MTLMaterial &mtl_material)
+void MTLWriter::write_bsdf_properties(const MTLMaterial &mtl)
{
- fmt_handler_.write<eMTLSyntaxElement::Ns>(mtl_material.Ns);
- fmt_handler_.write<eMTLSyntaxElement::Ka>(
- mtl_material.Ka.x, mtl_material.Ka.y, mtl_material.Ka.z);
- fmt_handler_.write<eMTLSyntaxElement::Kd>(
- mtl_material.Kd.x, mtl_material.Kd.y, mtl_material.Kd.z);
- fmt_handler_.write<eMTLSyntaxElement::Ks>(
- mtl_material.Ks.x, mtl_material.Ks.y, mtl_material.Ks.z);
- fmt_handler_.write<eMTLSyntaxElement::Ke>(
- mtl_material.Ke.x, mtl_material.Ke.y, mtl_material.Ke.z);
- fmt_handler_.write<eMTLSyntaxElement::Ni>(mtl_material.Ni);
- fmt_handler_.write<eMTLSyntaxElement::d>(mtl_material.d);
- fmt_handler_.write<eMTLSyntaxElement::illum>(mtl_material.illum);
+ /* For various material properties, we only capture information
+ * coming from the texture, or the default value of the socket.
+ * When the texture is present, do not emit the default value. */
+ if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Ns).is_valid()) {
+ fmt_handler_.write<eMTLSyntaxElement::Ns>(mtl.Ns);
+ }
+ fmt_handler_.write<eMTLSyntaxElement::Ka>(mtl.Ka.x, mtl.Ka.y, mtl.Ka.z);
+ if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Kd).is_valid()) {
+ fmt_handler_.write<eMTLSyntaxElement::Kd>(mtl.Kd.x, mtl.Kd.y, mtl.Kd.z);
+ }
+ if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Ks).is_valid()) {
+ fmt_handler_.write<eMTLSyntaxElement::Ks>(mtl.Ks.x, mtl.Ks.y, mtl.Ks.z);
+ }
+ if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Ke).is_valid()) {
+ fmt_handler_.write<eMTLSyntaxElement::Ke>(mtl.Ke.x, mtl.Ke.y, mtl.Ke.z);
+ }
+ fmt_handler_.write<eMTLSyntaxElement::Ni>(mtl.Ni);
+ if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_d).is_valid()) {
+ fmt_handler_.write<eMTLSyntaxElement::d>(mtl.d);
+ }
+ fmt_handler_.write<eMTLSyntaxElement::illum>(mtl.illum);
}
void MTLWriter::write_texture_map(
@@ -583,12 +592,13 @@ void MTLWriter::write_texture_map(
options.append(" -bm ").append(std::to_string(mtl_material.map_Bump_strength));
}
+ std::string path = path_reference(
+ texture_map.value.image_path.c_str(), blen_filedir, dest_dir, path_mode, &copy_set);
+ /* Always emit forward slashes for cross-platform compatibility. */
+ std::replace(path.begin(), path.end(), '\\', '/');
+
#define SYNTAX_DISPATCH(eMTLSyntaxElement) \
if (texture_map.key == eMTLSyntaxElement) { \
- std::string path = path_reference( \
- texture_map.value.image_path.c_str(), blen_filedir, dest_dir, path_mode, &copy_set); \
- /* Always emit forward slashes for cross-platform compatibility. */ \
- std::replace(path.begin(), path.end(), '\\', '/'); \
fmt_handler_.write<eMTLSyntaxElement>(options, path.c_str()); \
return; \
}
@@ -600,6 +610,7 @@ void MTLWriter::write_texture_map(
SYNTAX_DISPATCH(eMTLSyntaxElement::map_refl);
SYNTAX_DISPATCH(eMTLSyntaxElement::map_Ke);
SYNTAX_DISPATCH(eMTLSyntaxElement::map_Bump);
+#undef SYNTAX_DISPATCH
BLI_assert(!"This map type was not written to the file.");
}
@@ -626,7 +637,7 @@ void MTLWriter::write_materials(const char *blen_filepath,
fmt_handler_.write<eMTLSyntaxElement::newmtl>(mtlmat.name);
write_bsdf_properties(mtlmat);
for (const auto &tex : mtlmat.texture_maps.items()) {
- if (tex.value.image_path.empty()) {
+ if (!tex.value.is_valid()) {
continue;
}
write_texture_map(mtlmat, tex, blen_filedir, dest_dir, path_mode, copy_set);