From f366d197db24cf611866a8d847b4022a6a46504e Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Thu, 1 Sep 2022 20:38:56 +0300 Subject: Fix T100737: OBJ/USD import: imported object has no active material, material has 2 users Fixes issues in importers written in C++ (T100737): - Materials had one reference count too much. Affected Collada, Alembic, USD, OBJ importers, looks like "since forever". - Active material index was not properly set on imported meshes. Regression since 3.3 (D15145). Affected Alembic, USD, OBJ. Note: now it sets the first material as the active one, whereas previously the last one was set as active. First one sounds more "intuitive" to me. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15831 --- source/blender/io/usd/intern/usd_reader_material.cc | 2 ++ source/blender/io/usd/intern/usd_reader_mesh.cc | 3 +++ 2 files changed, 5 insertions(+) (limited to 'source/blender/io/usd/intern') diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 8feceee55ed..52addfeb418 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -4,6 +4,7 @@ #include "usd_reader_material.h" #include "BKE_image.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_node.h" @@ -266,6 +267,7 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater /* Create the material. */ Material *mtl = BKE_material_add(bmain_, mtl_name.c_str()); + id_us_min(&mtl->id); /* Get the UsdPreviewSurface shader source for the material, * if there is one. */ diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 45657525527..de638b0a837 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -168,6 +168,9 @@ static void assign_materials(Main *bmain, std::cout << "WARNING: Couldn't assign material " << it->first << std::endl; } } + if (ob->totcol > 0) { + ob->actcol = 1; + } } } // namespace utils -- cgit v1.2.3