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

Pixar Mesh read translator/utilities refactoring #343

Merged
merged 9 commits into from
Mar 21, 2020
20 changes: 20 additions & 0 deletions lib/fileio/translators/translatorMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ TranslatorMeshRead::TranslatorMeshRead(const UsdGeomMesh& mesh,
return;
}

// set mesh name
const auto& primName = prim.GetName().GetString();
const auto shapeName = TfStringPrintf("%sShape", primName.c_str());
meshFn.setName(MString(shapeName.c_str()), false, &stat);

if (!stat) {
*status = stat;
return;
}

// store the path
m_shapePath = prim.GetPath().AppendChild(TfToken(shapeName));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the mesh function set is created, we set it's name and then store the SdfPath that is created off of it.


// Set normals if supplied
MIntArray normalsFaceIds;
if (normals.size() == static_cast<size_t>(meshFn.numFaceVertices())) {
Expand Down Expand Up @@ -469,5 +482,12 @@ TranslatorMeshRead::pointsNumTimeSamples() const
return m_pointsNumTimeSamples;
}

SdfPath
TranslatorMeshRead::shapePath() const
{
return m_shapePath;
}


} // namespace MayaUsd

4 changes: 4 additions & 0 deletions lib/fileio/translators/translatorMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class MAYAUSD_CORE_PUBLIC TranslatorMeshRead
MString pointBasedDeformerName() const;
size_t pointsNumTimeSamples() const;

SdfPath shapePath() const;

private:
MStatus setPointBasedDeformerForMayaNode(const MObject&,
const MObject&,
Expand All @@ -72,6 +74,8 @@ class MAYAUSD_CORE_PUBLIC TranslatorMeshRead
MString m_newPointBasedDeformerName;
bool m_wantCacheAnimation;
size_t m_pointsNumTimeSamples;

SdfPath m_shapePath;
};

} // namespace MayaUsd
9 changes: 1 addition & 8 deletions lib/usd/translators/meshReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,11 @@ MayaUsdPrimReaderMesh::Read(UsdMayaPrimReaderContext* context)
&status);
CHECK_MSTATUS_AND_RETURN(status, false);

// shape name
const auto& primName = prim.GetName().GetString();
status = UsdMayaUtil::setName(meshRead.meshObject(), primName);
CHECK_MSTATUS_AND_RETURN(status, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just wrong! UsdMayaUtil::setName was creating a new object of type MFnMesh and set it's name.


// mesh is a shape, so read Gprim properties
UsdMayaTranslatorGprim::Read(mesh, meshRead.meshObject(), context);

// undo/redo mesh object
const auto shapeName = TfStringPrintf("%sShape", primName.c_str());
const auto shapePath = prim.GetPath().AppendChild(TfToken(shapeName));
context->RegisterNewMayaNode(shapePath.GetString(), meshRead.meshObject());
context->RegisterNewMayaNode(meshRead.shapePath().GetString(), meshRead.meshObject());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now get the path from the meshRead and pass it in to be registered with the Maya mesh object.


// undo/redo deformable mesh (blenshape, PointBasedDeformer)
if (meshRead.pointsNumTimeSamples() > 0) {
Expand Down
15 changes: 0 additions & 15 deletions lib/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,18 +2031,3 @@ UsdMayaUtil::convert(const std::string& str)
{
return MString(str.data(), static_cast<int>(str.size()));
}

MStatus
UsdMayaUtil::setName(const MObject& meshObj, const std::string& shapeName)
{
if(meshObj.apiType() != MFn::kMesh){
return MS::kFailure;
}

MStatus status{MS::kSuccess};

MFnMesh meshFn(meshObj);
meshFn.setName(MString(shapeName.c_str()), false, &status);

return status;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was indeed a weird and almost useless function that I introduced. Sigh....

}
3 changes: 0 additions & 3 deletions lib/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,6 @@ MString convert(const TfToken& token);
MAYAUSD_CORE_PUBLIC
std::string convert(const MString&);

MAYAUSD_CORE_PUBLIC
MStatus setName(const MObject& meshObj, const std::string& name);

} // namespace UsdMayaUtil


Expand Down