Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
| Context not available. | |||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| #include "IO_path_util.hh" | |||||
| #include "obj_export_mesh.hh" | #include "obj_export_mesh.hh" | ||||
| #include "obj_export_mtl.hh" | #include "obj_export_mtl.hh" | ||||
| #include "obj_export_nurbs.hh" | #include "obj_export_nurbs.hh" | ||||
| Context not available. | |||||
| void MTLWriter::write_texture_map( | void MTLWriter::write_texture_map( | ||||
| const MTLMaterial &mtl_material, | const MTLMaterial &mtl_material, | ||||
| const Map<const eMTLSyntaxElement, tex_map_XX>::Item &texture_map) | const Map<const eMTLSyntaxElement, tex_map_XX>::Item &texture_map, | ||||
| const char *blen_filedir, | |||||
| const char *dest_dir, | |||||
| ePathReferenceMode path_mode, | |||||
| Set<std::pair<std::string, std::string>> ©_set) | |||||
| { | { | ||||
| std::string options; | std::string options; | ||||
| /* Option strings should have their own leading spaces. */ | /* Option strings should have their own leading spaces. */ | ||||
| Context not available. | |||||
| #define SYNTAX_DISPATCH(eMTLSyntaxElement) \ | #define SYNTAX_DISPATCH(eMTLSyntaxElement) \ | ||||
| if (texture_map.key == eMTLSyntaxElement) { \ | if (texture_map.key == eMTLSyntaxElement) { \ | ||||
| fmt_handler_.write<eMTLSyntaxElement>(options, texture_map.value.image_path); \ | std::string path = path_reference( \ | ||||
| texture_map.value.image_path.c_str(), blen_filedir, dest_dir, path_mode, ©_set); \ | |||||
| /* Always emit forward slashes for cross-platform compatibility. */ \ | |||||
howardt: Has this code been tested on Windows? | |||||
aras_pAuthorUnsubmitted Done Inline ActionsYes. I tested export with relative paths, using both forward & backward slashes on windows. Both the current and the existing python importers can import the forward-slashes files just fine (almost all Win32 APIs supports forward slashes for filenames). aras_p: Yes. I tested export with relative paths, using both forward & backward slashes on windows. | |||||
| std::replace(path.begin(), path.end(), '\\', '/'); \ | |||||
| fmt_handler_.write<eMTLSyntaxElement>(options, path.c_str()); \ | |||||
| return; \ | return; \ | ||||
| } | } | ||||
| Context not available. | |||||
| BLI_assert(!"This map type was not written to the file."); | BLI_assert(!"This map type was not written to the file."); | ||||
| } | } | ||||
| void MTLWriter::write_materials() | void MTLWriter::write_materials(const char *blen_filepath, | ||||
| ePathReferenceMode path_mode, | |||||
| const char *dest_dir) | |||||
| { | { | ||||
| if (mtlmaterials_.size() == 0) { | if (mtlmaterials_.size() == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| char blen_filedir[PATH_MAX]; | |||||
| BLI_split_dir_part(blen_filepath, blen_filedir, PATH_MAX); | |||||
| BLI_path_slash_native(blen_filedir); | |||||
| BLI_path_normalize(nullptr, blen_filedir); | |||||
| std::sort(mtlmaterials_.begin(), | std::sort(mtlmaterials_.begin(), | ||||
| mtlmaterials_.end(), | mtlmaterials_.end(), | ||||
| [](const MTLMaterial &a, const MTLMaterial &b) { return a.name < b.name; }); | [](const MTLMaterial &a, const MTLMaterial &b) { return a.name < b.name; }); | ||||
| Set<std::pair<std::string, std::string>> copy_set; | |||||
| for (const MTLMaterial &mtlmat : mtlmaterials_) { | for (const MTLMaterial &mtlmat : mtlmaterials_) { | ||||
| fmt_handler_.write<eMTLSyntaxElement::string>("\n"); | fmt_handler_.write<eMTLSyntaxElement::string>("\n"); | ||||
| fmt_handler_.write<eMTLSyntaxElement::newmtl>(mtlmat.name); | fmt_handler_.write<eMTLSyntaxElement::newmtl>(mtlmat.name); | ||||
| write_bsdf_properties(mtlmat); | write_bsdf_properties(mtlmat); | ||||
| for (const Map<const eMTLSyntaxElement, tex_map_XX>::Item &texture_map : | for (const auto &tex : mtlmat.texture_maps.items()) { | ||||
| mtlmat.texture_maps.items()) { | if (tex.value.image_path.empty()) { | ||||
| if (!texture_map.value.image_path.empty()) { | continue; | ||||
| write_texture_map(mtlmat, texture_map); | |||||
| } | } | ||||
| write_texture_map(mtlmat, tex, blen_filedir, dest_dir, path_mode, copy_set); | |||||
| } | } | ||||
| } | } | ||||
| path_reference_copy(copy_set); | |||||
| } | } | ||||
| Vector<int> MTLWriter::add_materials(const OBJMesh &mesh_to_export) | Vector<int> MTLWriter::add_materials(const OBJMesh &mesh_to_export) | ||||
| Context not available. | |||||
Has this code been tested on Windows?