From bcc2656299ad72b224c5f2644518759561c31045 Mon Sep 17 00:00:00 2001 From: Michael Kowalski Date: Tue, 1 Nov 2022 11:55:58 -0400 Subject: USD IO: replace deprecated primvars API. Updated the code to use the UsdGeomPrimvarsAPI class to read and write mesh primvars instead of the now deprecated primvars accessors in UsdGeomImageable. This will be required to build with USD 22.11 in the future, where the deprecated functions have been removed. --- source/blender/io/usd/intern/usd_reader_mesh.cc | 15 +++++++++++---- source/blender/io/usd/intern/usd_writer_mesh.cc | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'source/blender/io') diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 01db6baeb5c..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 #include #include +#include #include #include @@ -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 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(); } @@ -835,12 +840,14 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, is_left_handed_ = true; } + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + std::vector uv_tokens; /* Currently we only handle UV primvars. */ if (read_flag & MOD_MESHSEQ_READ_UV) { - std::vector primvars = mesh_prim_.GetPrimvars(); + std::vector primvars = primvarsAPI.GetPrimvars(); for (pxr::UsdGeomPrimvar p : primvars) { diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index e949bafe517..e7d79e888e4 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -4,6 +4,7 @@ #include "usd_hierarchy_iterator.h" #include +#include #include #include @@ -107,6 +108,8 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ { pxr::UsdTimeCode timecode = get_export_time_code(); + pxr::UsdGeomPrimvarsAPI primvarsAPI(usd_mesh.GetPrim()); + const CustomData *ldata = &mesh->ldata; for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; @@ -119,7 +122,7 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ * for texture coordinates by naming the UV Map as such, without having to guess which UV Map * is the "standard" one. */ pxr::TfToken primvar_name(pxr::TfMakeValidIdentifier(layer->name)); - pxr::UsdGeomPrimvar uv_coords_primvar = usd_mesh.CreatePrimvar( + pxr::UsdGeomPrimvar uv_coords_primvar = primvarsAPI.CreatePrimvar( primvar_name, pxr::SdfValueTypeNames->TexCoord2fArray, pxr::UsdGeomTokens->faceVarying); MLoopUV *mloopuv = static_cast(layer->data); -- cgit v1.2.3