Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| else if (parse_keyword(line, "mtllib")) { | else if (parse_keyword(line, "mtllib")) { | ||||
| mtl_libraries_.append(line.trim()); | add_mtl_library(line.trim()); | ||||
| } | } | ||||
| /* Comments. */ | /* Comments. */ | ||||
| else if (line.startswith("#")) { | else if (line.startswith("#")) { | ||||
| Context not available. | |||||
| memmove(buffer.data(), buffer.data() + last_nl, left_size); | memmove(buffer.data(), buffer.data() + last_nl, left_size); | ||||
| buffer_offset = left_size; | buffer_offset = left_size; | ||||
| } | } | ||||
| add_default_mtl_library(); | |||||
| } | } | ||||
| static eMTLSyntaxElement mtl_line_start_to_enum(StringRef &line) | static eMTLSyntaxElement mtl_line_start_to_enum(StringRef &line) | ||||
| Context not available. | |||||
| return mtl_libraries_; | return mtl_libraries_; | ||||
| } | } | ||||
| void OBJParser::add_mtl_library(const std::string &path) | |||||
| { | |||||
| if (!mtl_libraries_.contains(path)) { | |||||
| mtl_libraries_.append(path); | |||||
| } | |||||
| } | |||||
| void OBJParser::add_default_mtl_library() | |||||
| { | |||||
| /* Add any existing .mtl file that's with the same base name as the .obj file | |||||
| * into candidate .mtl files to search through. This is not technically following the | |||||
| * spec, but the old python importer was doing it, and there are user files out there | |||||
| * that contain "mtllib bar.mtl" for a foo.obj, and depend on finding materials | |||||
| * from foo.mtl (see T97757). */ | |||||
| char mtl_file_path[FILE_MAX]; | |||||
| BLI_strncpy(mtl_file_path, import_params_.filepath, sizeof(mtl_file_path)); | |||||
| BLI_path_extension_replace(mtl_file_path, sizeof(mtl_file_path), ".mtl"); | |||||
| if (BLI_exists(mtl_file_path)) { | |||||
| char mtl_file_base[FILE_MAX]; | |||||
| BLI_split_file_part(mtl_file_path, mtl_file_base, sizeof(mtl_file_base)); | |||||
| add_mtl_library(mtl_file_base); | |||||
| } | |||||
| } | |||||
| MTLParser::MTLParser(StringRef mtl_library, StringRefNull obj_filepath) | MTLParser::MTLParser(StringRef mtl_library, StringRefNull obj_filepath) | ||||
| { | { | ||||
| char obj_file_dir[FILE_MAXDIR]; | char obj_file_dir[FILE_MAXDIR]; | ||||
| Context not available. | |||||
| if (parse_keyword(line, "newmtl")) { | if (parse_keyword(line, "newmtl")) { | ||||
| line = line.trim(); | line = line.trim(); | ||||
| if (r_materials.remove_as(line)) { | if (r_materials.contains(line)) { | ||||
| std::cerr << "Duplicate material found:'" << line | material = nullptr; | ||||
| << "', using the last encountered Material definition." << std::endl; | } | ||||
| else { | |||||
| material = r_materials.lookup_or_add(string(line), std::make_unique<MTLMaterial>()).get(); | |||||
| } | } | ||||
| material = r_materials.lookup_or_add(string(line), std::make_unique<MTLMaterial>()).get(); | |||||
| } | } | ||||
| else if (material != nullptr) { | else if (material != nullptr) { | ||||
| if (parse_keyword(line, "Ns")) { | if (parse_keyword(line, "Ns")) { | ||||
| Context not available. | |||||
| parse_float(line, 1.0f, material->d); | parse_float(line, 1.0f, material->d); | ||||
| } | } | ||||
| else if (parse_keyword(line, "illum")) { | else if (parse_keyword(line, "illum")) { | ||||
| parse_int(line, 2, material->illum); | /* Some files incorrectly use a float (T60135). */ | ||||
| float val; | |||||
| parse_float(line, 1.0f, val); | |||||
| material->illum = val; | |||||
| } | } | ||||
| else { | else { | ||||
| parse_texture_map(line, material, mtl_dir_path_); | parse_texture_map(line, material, mtl_dir_path_); | ||||
| Context not available. | |||||