From 04160c4d4db0e43c7bed2829542ddfc701b90671 Mon Sep 17 00:00:00 2001 From: Michael Kowalski Date: Sun, 19 Mar 2023 19:44:17 -0400 Subject: [PATCH] USD import fix: set active mesh color. Fixed a bug where the active color wasn't being set on imported meshes, resulting in no colors displaying in the viewport. This bug has been in the code for a long time. However, the colors have been displaying correctly until recently, so this issue wasn't previously apparent. Also, changed custom color data name from "displayColors" to "displayColor", to match the actual USD primvar name. (This was a typo in the original code.) Note that pull request https://projects.blender.org/blender/blender/pulls/104542 addresses other issues in the color import code (e.g., converting all color primvars and not just "displayColor", avoiding hard-coding of attribute names, handling all iterpolation types, etc.). However, the current commit is meant as a short term fix to a regression, where the "displayColor" attribute does not render in the viewport at all, until the above pull can be merged. --- source/blender/io/usd/intern/usd_reader_mesh.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 79446728acb..84f1872081e 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -458,10 +458,10 @@ void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime) return; } - void *cd_ptr = add_customdata_cb(mesh, "displayColors", CD_PROP_BYTE_COLOR); + void *cd_ptr = add_customdata_cb(mesh, "displayColor", CD_PROP_BYTE_COLOR); if (!cd_ptr) { - std::cerr << "WARNING: Couldn't add displayColors custom data.\n"; + std::cerr << "WARNING: Couldn't add displayColor custom data.\n"; return; } @@ -504,6 +504,8 @@ void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime) colors[loop_index].a = unit_float_to_uchar_clamp(1.0); } } + + BKE_id_attributes_active_color_set(&mesh->id, "displayColor"); } void USDMeshReader::read_vertex_creases(Mesh *mesh, const double motionSampleTime) -- 2.30.2