Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace UsdGeomImageable primvar methods #2327

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/translators/translatorMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/gprim.h>
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdGeom/subset.h>
#include <pxr/usd/usdShade/material.h>
#include <pxr/usd/usdShade/materialBindingAPI.h>
Expand Down Expand Up @@ -226,7 +227,7 @@ static void _BindUVs(
// We need the UV set names as they were in the USD scene, not the roundtripped original names:
UsdGeomMesh mesh(primSchema.GetPrim());
if (mesh) {
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(mesh).GetPrimvars();
for (const UsdGeomPrimvar& primvar : primvars) {
const SdfValueTypeName typeName = primvar.GetTypeName();
if (typeName == SdfValueTypeNames->TexCoord2fArray
Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/fileio/translators/translatorMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <mayaUsd/undo/OpUndoItems.h>
#include <mayaUsd/utils/util.h>

#include <pxr/usd/usdGeom/primvarsAPI.h>

#include <maya/MColor.h>
#include <maya/MColorArray.h>
#include <maya/MDGModifier.h>
Expand Down Expand Up @@ -143,7 +145,7 @@ TranslatorMeshRead::TranslatorMeshRead(
mesh.GetPointsAttr().Get(&points, pointsTimeSample);

/* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */
UsdGeomPrimvar primvar = mesh.GetPrimvar(UsdGeomTokens->normals);
UsdGeomPrimvar primvar = UsdGeomPrimvarsAPI(mesh).GetPrimvar(UsdGeomTokens->normals);

if (primvar.HasValue()) {
primvar.ComputeFlattened(&normals, normalsTimeSample);
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/utils/meshReadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <pxr/base/tf/token.h>
#include <pxr/base/vt/array.h>
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdGeom/subset.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usd/usdUtils/pipeline.h>
Expand Down Expand Up @@ -598,7 +599,7 @@ void UsdMayaMeshReadUtils::assignPrimvarsToMesh(
MFnMesh meshFn(meshObj);

// GETTING PRIMVARS
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(mesh).GetPrimvars();
bool firstUVPrimvar = true;

for (const UsdGeomPrimvar& primvar : primvars) {
Expand Down
21 changes: 13 additions & 8 deletions lib/mayaUsd/fileio/utils/meshWriteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/pointBased.h>
#include <pxr/usd/usdGeom/primvar.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdGeom/subset.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usd/usdUtils/pipeline.h>
Expand Down Expand Up @@ -269,7 +270,8 @@ UsdGeomPrimvar createUVPrimVar(
? (SdfValueTypeNames->Float2Array)
: (SdfValueTypeNames->TexCoord2fArray);

UsdGeomPrimvar primVar = primSchema.CreatePrimvar(name, uvValueType, interp);
UsdGeomPrimvar primVar
= UsdGeomPrimvarsAPI(primSchema).CreatePrimvar(name, uvValueType, interp);

setPrimvar(
primVar, assignmentIndices, VtValue(data), VtValue(UnauthoredUV), usdTime, valueWriter);
Expand Down Expand Up @@ -684,8 +686,10 @@ void UsdMayaMeshWriteUtils::exportReferenceMesh(
const int numVertices = referenceMesh.numVertices();
VtVec3fArray points(mayaRawVec3, mayaRawVec3 + numVertices);

UsdGeomPrimvar primVar = primSchema.CreatePrimvar(
UsdUtilsGetPrefName(), SdfValueTypeNames->Point3fArray, UsdGeomTokens->vertex);
UsdGeomPrimvar primVar
= UsdGeomPrimvarsAPI(primSchema)
.CreatePrimvar(
UsdUtilsGetPrefName(), SdfValueTypeNames->Point3fArray, UsdGeomTokens->vertex);

if (!primVar) {
return;
Expand Down Expand Up @@ -1147,8 +1151,8 @@ bool UsdMayaMeshWriteUtils::createRGBPrimVar(
interp = TfToken();
}

UsdGeomPrimvar primVar
= primSchema.CreatePrimvar(name, SdfValueTypeNames->Color3fArray, interp);
UsdGeomPrimvar primVar = UsdGeomPrimvarsAPI(primSchema)
.CreatePrimvar(name, SdfValueTypeNames->Color3fArray, interp);

setPrimvar(
primVar,
Expand Down Expand Up @@ -1186,8 +1190,8 @@ bool UsdMayaMeshWriteUtils::createRGBAPrimVar(
interp = TfToken();
}

UsdGeomPrimvar primVar
= primSchema.CreatePrimvar(name, SdfValueTypeNames->Color4fArray, interp);
UsdGeomPrimvar primVar = UsdGeomPrimvarsAPI(primSchema)
.CreatePrimvar(name, SdfValueTypeNames->Color4fArray, interp);

VtArray<GfVec4f> rgbaData(numValues);
for (size_t i = 0; i < rgbaData.size(); ++i) {
Expand Down Expand Up @@ -1229,7 +1233,8 @@ bool UsdMayaMeshWriteUtils::createAlphaPrimVar(
interp = TfToken();
}

UsdGeomPrimvar primVar = primSchema.CreatePrimvar(name, SdfValueTypeNames->FloatArray, interp);
UsdGeomPrimvar primVar
= UsdGeomPrimvarsAPI(primSchema).CreatePrimvar(name, SdfValueTypeNames->FloatArray, interp);
setPrimvar(
primVar,
assignmentIndices,
Expand Down
6 changes: 4 additions & 2 deletions lib/mayaUsd/fileio/utils/writeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <pxr/usd/usd/timeCode.h>
#include <pxr/usd/usdGeom/imageable.h>
#include <pxr/usd/usdGeom/primvar.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usd/usdRi/statementsAPI.h>
#include <pxr/usd/usdUtils/sparseValueWriter.h>
Expand Down Expand Up @@ -192,15 +193,16 @@ UsdGeomPrimvar UsdMayaWriteUtil::GetOrCreatePrimvar(
}

// See if the primvar already exists. If so, return it.
primvar = imageable.GetPrimvar(primvarNameToken);
UsdGeomPrimvarsAPI pvAPI(imageable);
primvar = pvAPI.GetPrimvar(primvarNameToken);
if (primvar) {
return primvar;
}

const SdfValueTypeName& typeName
= Converter::getUsdTypeName(attrPlug, translateMayaDoubleToUsdSinglePrecision);
if (typeName) {
primvar = imageable.CreatePrimvar(primvarNameToken, typeName, interpolation, elementSize);
primvar = pvAPI.CreatePrimvar(primvarNameToken, typeName, interpolation, elementSize);
}

return primvar;
Expand Down
5 changes: 3 additions & 2 deletions lib/usd/translators/meshWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/pointBased.h>
#include <pxr/usd/usdGeom/primvar.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdSkel/root.h>
#include <pxr/usd/usdUtils/pipeline.h>

Expand Down Expand Up @@ -840,8 +841,8 @@ void PxrUsdTranslators_MeshWriter::cleanupPrimvars()
// If the indexed primvar doesn't need the unassigned value (because all
// of the indices are assigned), then we can remove the unassigned value
// and shift all the indices down.
const UsdGeomMesh primSchema(GetUsdPrim());
for (const UsdGeomPrimvar& primvar : primSchema.GetPrimvars()) {
const UsdGeomPrimvarsAPI pvAPI(GetUsdPrim());
for (const UsdGeomPrimvar& primvar : pvAPI.GetPrimvars()) {
if (!primvar) {
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/usd/translators/nurbsSurfaceWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <pxr/usd/usdGeom/nurbsCurves.h>
#include <pxr/usd/usdGeom/nurbsPatch.h>
#include <pxr/usd/usdGeom/pointBased.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdUtils/pipeline.h>

#include <maya/MDoubleArray.h>
Expand Down Expand Up @@ -333,8 +334,9 @@ bool PxrUsdTranslators_NurbsSurfaceWriter::writeNurbsSurfaceAttrs(
SdfValueTypeName uvValueType = (UsdMayaWriteUtil::WriteUVAsFloat2())
? (SdfValueTypeNames->Float2Array)
: (SdfValueTypeNames->TexCoord2fArray);
UsdGeomPrimvar uvSet = primSchema.CreatePrimvar(
UsdUtilsGetPrimaryUVSetName(), uvValueType, UsdGeomTokens->vertex);
UsdGeomPrimvar uvSet
= UsdGeomPrimvarsAPI(primSchema)
.CreatePrimvar(UsdUtilsGetPrimaryUVSetName(), uvValueType, UsdGeomTokens->vertex);
UsdMayaWriteUtil::SetAttribute(
uvSet.GetAttr(), &stValues, UsdTimeCode::Default(), _GetSparseValueWriter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "AL/usdmaya/utils/MeshUtils.h"
#include "test_usdmaya.h"

#include <pxr/usd/usdGeom/primvarsAPI.h>

#include <maya/MFileIO.h>

using namespace AL::usdmaya::fileio::translators;
Expand Down Expand Up @@ -228,7 +230,7 @@ TEST(translators_MeshTranslator, generateIncrementingIndices)

UsdGeomPrimvar getDefaultUvSet(UsdGeomMesh mesh)
{
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(mesh).GetPrimvars();
for (auto pvar : primvars) {
if (pvar.GetPrimvarName() == TfToken("st")) {
return pvar;
Expand Down Expand Up @@ -625,7 +627,7 @@ TEST(translators_MeshTranslator, uniformUvExport)

UsdGeomPrimvar getDefaultColourSet(UsdGeomMesh mesh)
{
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(mesh).GetPrimvars();
for (auto pvar : primvars) {
if (pvar.GetPrimvarName() == TfToken("test")) {
return pvar;
Expand Down
6 changes: 4 additions & 2 deletions plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <mayaUsdUtils/DiffCore.h>
#include <mayaUsdUtils/SIMD.h>

#include <pxr/usd/usdGeom/primvarsAPI.h>

#include <maya/MDoubleArray.h>
#include <maya/MFloatArray.h>
#include <maya/MIntArray.h>
Expand Down Expand Up @@ -526,7 +528,7 @@ void ColourSetBuilder::performDiffTest(PrimVarDiffReport& report)
//----------------------------------------------------------------------------------------------------------------------
MStringArray hasNewColourSet(UsdGeomMesh& geom, MFnMesh& mesh, PrimVarDiffReport& report)
{
const std::vector<UsdGeomPrimvar> primvars = geom.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(geom).GetPrimvars();
MStringArray setNames;
mesh.getColorSetNames(setNames);

Expand Down Expand Up @@ -738,7 +740,7 @@ void UvSetBuilder::performDiffTest(PrimVarDiffReport& report)
//----------------------------------------------------------------------------------------------------------------------
MStringArray hasNewUvSet(UsdGeomMesh& geom, const MFnMesh& mesh, PrimVarDiffReport& report)
{
const std::vector<UsdGeomPrimvar> primvars = geom.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(geom).GetPrimvars();
MStringArray setNames;
mesh.getUVSetNames(setNames);

Expand Down
46 changes: 25 additions & 21 deletions plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mayaUsdUtils/DebugCodes.h>
#include <mayaUsdUtils/DiffCore.h>

#include <pxr/usd/usdGeom/primvarsAPI.h>
#include <pxr/usd/usdUtils/pipeline.h>

#include <maya/MGlobal.h>
Expand Down Expand Up @@ -202,11 +203,12 @@ void MeshImportContext::gatherFaceConnectsAndVertices()

// According to the docs for UsdGeomMesh: If 'normals' and 'primvars:normals' are both
// specified, the latter has precedence.
const TfToken primvarNormalsToken("primvars:normals");
TfToken interpolation = mesh.GetNormalsInterpolation();
bool hasNormalsOpinion = false;
if (mesh.HasPrimvar(primvarNormalsToken)) {
UsdGeomPrimvar primvar = mesh.GetPrimvar(primvarNormalsToken);
const TfToken primvarNormalsToken("primvars:normals");
TfToken interpolation = mesh.GetNormalsInterpolation();
bool hasNormalsOpinion = false;
UsdGeomPrimvarsAPI pvAPI(mesh);
if (pvAPI.HasPrimvar(primvarNormalsToken)) {
UsdGeomPrimvar primvar = pvAPI.GetPrimvar(primvarNormalsToken);
interpolation = primvar.GetInterpolation();
hasNormalsOpinion = true;
primvar.Get(&normalsData, m_timeCode);
Expand Down Expand Up @@ -508,9 +510,10 @@ bool MeshImportContext::applyVertexNormals()
if (normals.length()) {
// According to the docs for UsdGeomMesh: If 'normals' and 'primvars:normals' are both
// specified, the latter has precedence.
TfToken primvarNormalsToken("primvars:normals");
if (mesh.HasPrimvar(primvarNormalsToken)) {
UsdGeomPrimvar primvar = mesh.GetPrimvar(primvarNormalsToken);
TfToken primvarNormalsToken("primvars:normals");
UsdGeomPrimvarsAPI pvAPI(mesh);
if (pvAPI.HasPrimvar(primvarNormalsToken)) {
UsdGeomPrimvar primvar = pvAPI.GetPrimvar(primvarNormalsToken);
const TfToken interpolation = primvar.GetInterpolation();
const bool isIndexed = primvar.IsIndexed();
if (interpolation == UsdGeomTokens->vertex) {
Expand Down Expand Up @@ -679,7 +682,7 @@ bool MeshImportContext::applyEdgeCreases()

void MeshImportContext::applyColourSetData()
{
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(mesh).GetPrimvars();
for (auto it = primvars.begin(), end = primvars.end(); it != end; ++it) {

const UsdGeomPrimvar& primvar = *it;
Expand Down Expand Up @@ -849,7 +852,7 @@ void MeshImportContext::applyColourSetData()
void MeshImportContext::applyUVs()
{
const TfToken prefToken("pref");
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
const std::vector<UsdGeomPrimvar> primvars = UsdGeomPrimvarsAPI(mesh).GetPrimvars();
for (auto it = primvars.begin(), end = primvars.end(); it != end; ++it) {
const UsdGeomPrimvar& primvar = *it;
TfToken name, interpolation;
Expand Down Expand Up @@ -1213,7 +1216,7 @@ void MeshExportContext::copyUvSetData()
if (uvSetNames[i] == "map1") {
uvSetNames[i] = "st";
}
UsdGeomPrimvar uvSet = mesh.CreatePrimvar(
UsdGeomPrimvar uvSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(uvSetNames[i].asChar()),
SdfValueTypeNames->Float2Array,
UsdGeomTokens->constant);
Expand All @@ -1238,7 +1241,7 @@ void MeshExportContext::copyUvSetData()
if (uvSetNames[i] == "map1") {
uvSetNames[i] = "st";
}
UsdGeomPrimvar uvSet = mesh.CreatePrimvar(
UsdGeomPrimvar uvSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(uvSetNames[i].asChar()),
SdfValueTypeNames->Float2Array,
UsdGeomTokens->vertex);
Expand All @@ -1254,7 +1257,7 @@ void MeshExportContext::copyUvSetData()
if (uvSetNames[i] == "map1") {
uvSetNames[i] = "st";
}
UsdGeomPrimvar uvSet = mesh.CreatePrimvar(
UsdGeomPrimvar uvSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(uvSetNames[i].asChar()),
SdfValueTypeNames->Float2Array,
UsdGeomTokens->uniform);
Expand All @@ -1272,7 +1275,7 @@ void MeshExportContext::copyUvSetData()

/// \todo Ideally I'd want some form of interpolation scheme such as
/// UsdGeomTokens->faceVaryingIndexed
UsdGeomPrimvar uvSet = mesh.CreatePrimvar(
UsdGeomPrimvar uvSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(uvSetNames[i].asChar()),
SdfValueTypeNames->Float2Array,
UsdGeomTokens->faceVarying);
Expand Down Expand Up @@ -1561,7 +1564,7 @@ void MeshExportContext::copyColourSetData()
}
}
}
UsdGeomPrimvar colourSet = mesh.CreatePrimvar(
UsdGeomPrimvar colourSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(colourSetNames[i].asChar()),
SdfValueTypeNames->Color3fArray,
interpolation);
Expand Down Expand Up @@ -1589,7 +1592,7 @@ void MeshExportContext::copyColourSetData()
}
}
}
UsdGeomPrimvar opacitySet = mesh.CreatePrimvar(
UsdGeomPrimvar opacitySet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
displayOpacityToken, SdfValueTypeNames->FloatArray, interpolation);
opacitySet.Set(alphaValues, m_timeCode);
}
Expand All @@ -1616,7 +1619,7 @@ void MeshExportContext::copyColourSetData()
}
}
}
UsdGeomPrimvar colourSet = mesh.CreatePrimvar(
UsdGeomPrimvar colourSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(colourSetNames[i].asChar()),
SdfValueTypeNames->Color4fArray,
interpolation);
Expand Down Expand Up @@ -1663,7 +1666,7 @@ void MeshExportContext::copyColourSetData()
}
}
}
UsdGeomPrimvar colourSet = mesh.CreatePrimvar(
UsdGeomPrimvar colourSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(diff_report[i].setName().asChar()),
SdfValueTypeNames->Color3fArray,
interp);
Expand All @@ -1688,7 +1691,7 @@ void MeshExportContext::copyColourSetData()
}
}
}
UsdGeomPrimvar colourSet = mesh.CreatePrimvar(
UsdGeomPrimvar colourSet = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
TfToken(diff_report[i].setName().asChar()),
SdfValueTypeNames->Color4fArray,
interp);
Expand Down Expand Up @@ -1861,7 +1864,7 @@ void MeshExportContext::copyBindPoseData(UsdTimeCode time)
{
if (diffGeom & kPoints) {

UsdGeomPrimvar pRefPrimVarAttr = mesh.CreatePrimvar(
UsdGeomPrimvar pRefPrimVarAttr = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
UsdUtilsGetPrefName(), SdfValueTypeNames->Point3fArray, UsdGeomTokens->vertex);

if (pRefPrimVarAttr) {
Expand Down Expand Up @@ -1889,7 +1892,8 @@ void MeshExportContext::copyNormalData(UsdTimeCode time, bool copyAsPrimvar)
UsdAttribute normalsAttr = mesh.GetNormalsAttr();
UsdGeomPrimvar primvar;
if (copyAsPrimvar) {
primvar = mesh.CreatePrimvar(normalPrimvarName, SdfValueTypeNames->Float3Array);
primvar = UsdGeomPrimvarsAPI(mesh).CreatePrimvar(
normalPrimvarName, SdfValueTypeNames->Float3Array);
normalsAttr = primvar.GetAttr();
}

Expand Down
Loading