diff options
Diffstat (limited to 'source/blender/io/usd/intern/usd_reader_mesh.cc')
-rw-r--r-- | source/blender/io/usd/intern/usd_reader_mesh.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 77c79852141..8138f38fcad 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -33,6 +33,7 @@ #include <pxr/base/vt/value.h> #include <pxr/usd/sdf/types.h> #include <pxr/usd/usdGeom/mesh.h> +#include <pxr/usd/usdGeom/primvarsAPI.h> #include <pxr/usd/usdGeom/subset.h> #include <pxr/usd/usdShade/materialBindingAPI.h> @@ -287,11 +288,13 @@ bool USDMeshReader::topology_changed(const Mesh *existing_mesh, const double mot mesh_prim_.GetFaceVertexCountsAttr().Get(&face_counts_, motionSampleTime); mesh_prim_.GetPointsAttr().Get(&positions_, motionSampleTime); + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + /* TODO(makowalski): Reading normals probably doesn't belong in this function, * as this is not required to determine if the topology has changed. */ /* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */ - pxr::UsdGeomPrimvar primvar = mesh_prim_.GetPrimvar(usdtokens::normalsPrimvar); + pxr::UsdGeomPrimvar primvar = primvarsAPI.GetPrimvar(usdtokens::normalsPrimvar); if (primvar.HasValue()) { primvar.ComputeFlattened(&normals_, motionSampleTime); normal_interpolation_ = primvar.GetInterpolation(); @@ -355,6 +358,8 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo std::vector<UVSample> uv_primvars(ldata->totlayer); + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + if (has_uvs_) { for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; @@ -385,11 +390,11 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo } /* Early out if mesh doesn't have primvar. */ - if (!mesh_prim_.HasPrimvar(uv_token)) { + if (!primvarsAPI.HasPrimvar(uv_token)) { continue; } - if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim_.GetPrimvar(uv_token)) { + if (pxr::UsdGeomPrimvar uv_primvar = primvarsAPI.GetPrimvar(uv_token)) { uv_primvar.ComputeFlattened(&uv_primvars[layer_idx].uvs, motionSampleTime); uv_primvars[layer_idx].interpolation = uv_primvar.GetInterpolation(); } @@ -804,8 +809,8 @@ void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double mot std::map<pxr::SdfPath, int> mat_map; bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); - bke::SpanAttributeWriter<int> material_indices = - attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE); + bke::SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>( + "material_index", ATTR_DOMAIN_FACE); this->assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map); material_indices.finish(); /* Build material name map if it's not built yet. */ @@ -835,12 +840,14 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, is_left_handed_ = true; } + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + std::vector<pxr::TfToken> uv_tokens; /* Currently we only handle UV primvars. */ if (read_flag & MOD_MESHSEQ_READ_UV) { - std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars(); + std::vector<pxr::UsdGeomPrimvar> primvars = primvarsAPI.GetPrimvars(); for (pxr::UsdGeomPrimvar p : primvars) { @@ -914,7 +921,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, std::map<pxr::SdfPath, int> mat_map; bke::MutableAttributeAccessor attributes = active_mesh->attributes_for_write(); bke::SpanAttributeWriter<int> material_indices = - attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE); + attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_FACE); assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map); material_indices.finish(); } |