1
1

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 commit is contained in:
2023-03-15 23:33:06 -04:00
parent c1cd7c6b4c
commit 5ea31db2ce

View File

@@ -449,11 +449,17 @@ void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime)
pxr::UsdGeomPrimvarsAPI primvarsAPI = pxr::UsdGeomPrimvarsAPI(mesh_prim_);
std::vector<pxr::UsdGeomPrimvar> primvars = primvarsAPI.GetPrimvars();
std::vector<pxr::UsdGeomPrimvar> primvars = primvarsAPI.GetPrimvarsWithValues();
pxr::TfToken active_color_name;
/* Convert all color primvars to custom layer data. */
for (pxr::UsdGeomPrimvar pv : primvars) {
if (!pv.HasValue()) {
continue;
}
pxr::SdfValueTypeName type = pv.GetTypeName();
if (!ELEM(type,
@@ -465,6 +471,13 @@ void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime)
pxr::TfToken name = pv.GetPrimvarName();
/* Set the active color name to 'displayColor', if a color primvar
* with this name exists. Otherwise, use the name of the first
* color primvar we find for the active color. */
if (active_color_name.IsEmpty() || name == usdtokens::displayColor) {
active_color_name = name;
}
/* Skip if we read this primvar before and it isn't animated. */
if (primvar_varying_map_.find(name) != primvar_varying_map_.end() &&
!primvar_varying_map_.at(name)) {
@@ -473,6 +486,10 @@ void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime)
read_colors(mesh, pv, motionSampleTime);
}
if (!active_color_name.IsEmpty()) {
BKE_id_attributes_active_color_set(&mesh->id, active_color_name.GetText());
}
}
void USDMeshReader::read_colors(Mesh *mesh,