Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
| Context not available. | |||||
| Object *MeshFromGeometry::create_mesh( | Object *MeshFromGeometry::create_mesh( | ||||
| Main *bmain, | Main *bmain, | ||||
| const Map<std::string, std::unique_ptr<MTLMaterial>> &materials, | Map<std::string, std::unique_ptr<MTLMaterial>> &materials, | ||||
| Map<std::string, Material *> &created_materials, | Map<std::string, Material *> &created_materials, | ||||
| const OBJImportParams &import_params) | const OBJImportParams &import_params) | ||||
| { | { | ||||
| Context not available. | |||||
| static Material *get_or_create_material( | static Material *get_or_create_material( | ||||
| Main *bmain, | Main *bmain, | ||||
| const std::string &name, | const std::string &name, | ||||
| const Map<std::string, std::unique_ptr<MTLMaterial>> &materials, | Map<std::string, std::unique_ptr<MTLMaterial>> &materials, | ||||
| Map<std::string, Material *> &created_materials) | Map<std::string, Material *> &created_materials) | ||||
| { | { | ||||
| /* Have we created this material already? */ | /* Have we created this material already? */ | ||||
| Context not available. | |||||
| return *found_mat; | return *found_mat; | ||||
| } | } | ||||
| /* We have not, will have to create it. */ | /* We have not, will have to create it. Create a new default | ||||
| if (!materials.contains(name)) { | * MTLMaterial too, in case the OBJ file tries to use a material | ||||
| std::cerr << "Material named '" << name << "' not found in material library." << std::endl; | * that was not in the MTL file. */ | ||||
| return nullptr; | const MTLMaterial &mtl = *materials.lookup_or_add(name, std::make_unique<MTLMaterial>()).get(); | ||||
| } | |||||
| Material *mat = BKE_material_add(bmain, name.c_str()); | Material *mat = BKE_material_add(bmain, name.c_str()); | ||||
| const MTLMaterial &mtl = *materials.lookup(name); | |||||
| ShaderNodetreeWrap mat_wrap{bmain, mtl, mat}; | ShaderNodetreeWrap mat_wrap{bmain, mtl, mat}; | ||||
| /* Viewport shading uses legacy r,g,b material values. */ | |||||
| if (mtl.Kd[0] >= 0 && mtl.Kd[1] >= 0 && mtl.Kd[2] >= 0) { | |||||
| mat->r = mtl.Kd[0]; | |||||
| mat->g = mtl.Kd[1]; | |||||
| mat->b = mtl.Kd[2]; | |||||
| } | |||||
| mat->use_nodes = true; | mat->use_nodes = true; | ||||
| mat->nodetree = mat_wrap.get_nodetree(); | mat->nodetree = mat_wrap.get_nodetree(); | ||||
| BKE_ntree_update_main_tree(bmain, mat->nodetree, nullptr); | BKE_ntree_update_main_tree(bmain, mat->nodetree, nullptr); | ||||
| Context not available. | |||||
| void MeshFromGeometry::create_materials( | void MeshFromGeometry::create_materials( | ||||
| Main *bmain, | Main *bmain, | ||||
| const Map<std::string, std::unique_ptr<MTLMaterial>> &materials, | Map<std::string, std::unique_ptr<MTLMaterial>> &materials, | ||||
| Map<std::string, Material *> &created_materials, | Map<std::string, Material *> &created_materials, | ||||
| Object *obj) | Object *obj) | ||||
| { | { | ||||
| Context not available. | |||||