[Bf-blender-cvs] [641f859f882] soc-2020-io-performance: Material: Disambiguate mat_nr + 1.
Ankit Meel
noreply at git.blender.org
Wed Sep 16 13:05:54 CEST 2020
Commit: 641f859f882ccd51e2d580a3e4390af103a885e8
Author: Ankit Meel
Date: Wed Sep 16 14:27:09 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB641f859f882ccd51e2d580a3e4390af103a885e8
Material: Disambiguate mat_nr + 1.
===================================================================
M source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
M source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
===================================================================
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
index 3dfbaa76688..1109a017a04 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
@@ -234,7 +234,8 @@ void OBJMesh::calc_smooth_groups(const bool use_bitflags)
*/
const Material *OBJMesh::get_object_material(const short mat_nr) const
{
- return BKE_object_material_get(export_object_eval_, mat_nr);
+ /* "+ 1" as material getter needs one-based indices. */
+ return BKE_object_material_get(export_object_eval_, mat_nr + 1);
}
bool OBJMesh::is_ith_poly_smooth(const uint poly_index) const
@@ -271,17 +272,18 @@ const char *OBJMesh::get_object_mesh_name() const
}
/**
- * Get object's material (at the given index) name.
+ * Get object's material (at the given index) name. The given index should be zero-based.
*/
-const char *OBJMesh::get_object_material_name(short mat_nr) const
+const char *OBJMesh::get_object_material_name(const short mat_nr) const
{
- const Material *mat = BKE_object_material_get(export_object_eval_, mat_nr);
-#ifdef DEBUG
+ const Material *mat = get_object_material(mat_nr);
if (!mat) {
+#ifdef DEBUG
std::cerr << "Material not found for mat_nr = " << mat_nr << std::endl;
- }
#endif
- return mat ? mat->id.name + 2 : nullptr;
+ return nullptr;
+ }
+ return mat->id.name + 2;
}
/**
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc b/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
index 8d7d0111a71..02b68767a80 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
@@ -314,12 +314,12 @@ void MaterialWrap::store_image_textures(MTLMaterial &r_mtl_mat) const
*/
void MaterialWrap::fill_materials()
{
- export_mtl_ = obj_mesh_data_.get_object_material(i + 1);
for (short i = 0; i < obj_mesh_data_.tot_materials(); i++) {
+ export_mtl_ = obj_mesh_data_.get_object_material(i);
if (!export_mtl_) {
continue;
}
- r_mtl_materials_[i].name = obj_mesh_data_.get_object_material_name(i + 1);
+ r_mtl_materials_[i].name = obj_mesh_data_.get_object_material_name(i);
init_bsdf_node(obj_mesh_data_.get_object_name());
store_bsdf_properties(r_mtl_materials_[i]);
store_image_textures(r_mtl_materials_[i]);
More information about the Bf-blender-cvs
mailing list