USD: Make consistent Primvar checks during attribute import

- Remove redundant .HasValue() calls
  We are calling `GetPrimvarsWithValues` which will do the HasValue
  checks for us already.
- Consistently skip non-array primvars
  We only want to import in the array attributes. Consistently check for
  this in each of our loops.

Pull Request: https://projects.blender.org/blender/blender/pulls/132816
This commit is contained in:
Jesse Yurkovich
2025-01-09 00:16:18 +01:00
committed by Jesse Yurkovich
parent 69cc4c708d
commit 08e63c4f3e
4 changed files with 15 additions and 39 deletions

View File

@@ -289,13 +289,12 @@ void USDCurvesReader::read_custom_data(bke::CurvesGeometry &curves,
std::vector<pxr::UsdGeomPrimvar> primvars = pv_api.GetPrimvarsWithValues();
for (const pxr::UsdGeomPrimvar &pv : primvars) {
if (!pv.HasValue()) {
continue;
const pxr::SdfValueTypeName pv_type = pv.GetTypeName();
if (!pv_type.IsArray()) {
continue; /* Skip non-array primvar attributes. */
}
const pxr::SdfValueTypeName pv_type = pv.GetTypeName();
const pxr::TfToken pv_interp = pv.GetInterpolation();
const std::optional<bke::AttrDomain> domain = convert_usd_interp_to_blender(pv_interp);
const std::optional<eCustomDataType> type = convert_usd_type_to_blender(pv_type);

View File

@@ -662,22 +662,12 @@ void USDMeshReader::read_custom_data(const ImportSettings *settings,
pxr::TfToken active_uv_set_name;
/* Convert primvars to custom layer data. */
for (pxr::UsdGeomPrimvar &pv : primvars) {
if (!pv.HasValue()) {
BKE_reportf(reports(),
RPT_WARNING,
"Skipping primvar %s, mesh %s -- no value",
pv.GetName().GetText(),
&mesh->id.name[2]);
continue;
}
if (!pv.GetAttr().GetTypeName().IsArray()) {
/* Non-array attributes are technically improper USD. */
continue;
}
for (const pxr::UsdGeomPrimvar &pv : primvars) {
const pxr::SdfValueTypeName type = pv.GetTypeName();
if (!type.IsArray()) {
continue; /* Skip non-array primvar attributes. */
}
const pxr::TfToken varying_type = pv.GetInterpolation();
const pxr::TfToken name = pxr::UsdGeomPrimvar::StripPrimvarsName(pv.GetPrimvarName());

View File

@@ -129,15 +129,13 @@ void USDPointsReader::read_custom_data(PointCloud *point_cloud,
std::vector<pxr::UsdGeomPrimvar> primvars = pv_api.GetPrimvarsWithValues();
for (const pxr::UsdGeomPrimvar &pv : primvars) {
if (!pv.HasValue()) {
continue;
}
const pxr::SdfValueTypeName pv_type = pv.GetTypeName();
if (!pv_type.IsArray()) {
continue; /* Skip non-array primvar attributes. */
}
const bke::AttrDomain domain = bke::AttrDomain::Point;
const std::optional<eCustomDataType> type = convert_usd_type_to_blender(pv_type);
if (!type.has_value()) {
return;
}

View File

@@ -187,18 +187,9 @@ void USDShapeReader::apply_primvars_to_mesh(Mesh *mesh, const double motionSampl
pxr::TfToken active_color_name;
for (const pxr::UsdGeomPrimvar &pv : primvars) {
if (!pv.HasValue()) {
BKE_reportf(reports(),
RPT_WARNING,
"Skipping primvar %s, mesh %s -- no value",
pv.GetName().GetText(),
&mesh->id.name[2]);
continue;
}
if (!pv.GetAttr().GetTypeName().IsArray()) {
/* Non-array attributes are technically improper USD. */
continue;
const pxr::SdfValueTypeName pv_type = pv.GetTypeName();
if (!pv_type.IsArray()) {
continue; /* Skip non-array primvar attributes. */
}
const pxr::TfToken name = pxr::UsdGeomPrimvar::StripPrimvarsName(pv.GetPrimvarName());
@@ -208,9 +199,7 @@ void USDShapeReader::apply_primvars_to_mesh(Mesh *mesh, const double motionSampl
continue;
}
const pxr::SdfValueTypeName sdf_type = pv.GetTypeName();
const std::optional<eCustomDataType> type = convert_usd_type_to_blender(sdf_type);
const std::optional<eCustomDataType> type = convert_usd_type_to_blender(pv_type);
if (type == CD_PROP_COLOR) {
/* Set the active color name to 'displayColor', if a color primvar
* with this name exists. Otherwise, use the name of the first