Skip to content

Commit

Permalink
HYDRA-955 : Standardize the methods GetPoints, GetNormals, getUVs, Ge…
Browse files Browse the repository at this point in the history
…tTangents
  • Loading branch information
lanierd-adsk committed Apr 8, 2024
1 parent 25a8ae7 commit b61b3ab
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions lib/mayaHydra/hydraExtensions/adapters/meshAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter
return VtValue(ret);
}

VtValue GetPoints(const MFnMesh& mesh)
VtValue GetPoints()
{
MStatus status;
MStatus status;
MFnMesh mesh(GetDagPath(), &status);
if (ARCH_UNLIKELY(!status)) {
return {};
}

const auto* rawPoints = reinterpret_cast<const GfVec3f*>(mesh.getRawPoints(&status));
if (ARCH_UNLIKELY(!status)) {
return {};
Expand All @@ -222,10 +227,15 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter
return VtValue(ret);
}

VtValue GetNormals(const MFnMesh& mesh)
VtValue GetNormals()
{
MStatus status;
MFnMesh mesh(GetDagPath(), &status);
if (ARCH_UNLIKELY(!status)) {
return {};
}

//Normals are per vertex
MStatus status;
MFloatVectorArray normals;
constexpr bool angleWeighted = false;
mesh.getVertexNormals(angleWeighted, normals);
Expand All @@ -244,21 +254,11 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter
GetDagPath().partialPathName().asChar());

if (key == HdTokens->points) {
MStatus status;
MFnMesh mesh(GetDagPath(), &status);
if (ARCH_UNLIKELY(!status)) {
return {};
}
return GetPoints(mesh);
return GetPoints();
}

if (key == HdTokens->normals) {
MStatus status;
MFnMesh mesh(GetDagPath(), &status);
if (ARCH_UNLIKELY(!status)) {
return {};
}
return GetNormals(mesh);
return GetNormals();
}

if (key == MayaHydraAdapterTokens->tangents) {
Expand All @@ -280,23 +280,13 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter
}

if (key == HdTokens->points) {
MStatus status;
MFnMesh mesh(GetDagPath(), &status);
if (ARCH_UNLIKELY(!status)) {
return 0;
}
return GetMayaHydraSceneIndex()->SampleValues(
maxSampleCount, times, samples, [&]() -> VtValue { return GetPoints(mesh); });
maxSampleCount, times, samples, [&]() -> VtValue { return GetPoints(); });
}

if (key == HdTokens->normals) {
MStatus status;
MFnMesh mesh(GetDagPath(), &status);
if (ARCH_UNLIKELY(!status)) {
return 0;
}
return GetMayaHydraSceneIndex()->SampleValues(
maxSampleCount, times, samples, [&]() -> VtValue { return GetNormals(mesh); });
maxSampleCount, times, samples, [&]() -> VtValue { return GetNormals(); });
}

if (key == MayaHydraAdapterTokens->tangents) {
Expand Down

0 comments on commit b61b3ab

Please sign in to comment.