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 write translator/utilities refactoring #420

Merged
merged 47 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0a2e072
Refactored _GetDagPath, _GetDagPathMap and moved them under UsdMayaUt…
Apr 10, 2020
f87dae6
Rename meshUtil to meshReadUtils.
Apr 10, 2020
4fe993e
- Initial commit to introduce TranslatorMeshWrite class ( this class …
Apr 10, 2020
b67e5e2
- Remove meshWriter_Subdiv and start using UsdMayaMeshUtil::assignSub…
Apr 10, 2020
8b94425
Created utility functions for writing Maya mesh data to USD:
Apr 10, 2020
a0ee49c
Create utility functions for writing out UVSets as Vec2f Primvars.
Apr 10, 2020
4160201
Removed meshWriter_Skin and created a new utility namespace (UsdMayaJ…
Apr 10, 2020
5c8f3a6
Removed meshWriter_Primvars and created a new utility for writing col…
Apr 10, 2020
331aee4
Start using UsdMayaWriteUtil::SetAttribute utilities in all writers:
Apr 10, 2020
9750303
Created utility functions for writing Maya mesh data to USD:
Apr 10, 2020
9c0ade6
Address feedback: use getDagPath() in UsdMayaWriteJobContext::CreateP…
May 25, 2020
1e492f2
Address feedbacks.
May 27, 2020
80f2240
Address feedback ( Matt ).
May 27, 2020
2b1e304
Address feedback ( Rob ).
May 27, 2020
9f2d55a
Address feedback: remove unnecessary try/catch.
May 27, 2020
45f0f51
Address feedback: rename wrapMeshUtil to wrapMeshWriteUtils
May 27, 2020
8e3a0ac
address feedback.
May 27, 2020
b7a202b
address feedback: make sure to handle both DAG nodes or DG nodes.
May 27, 2020
a02159c
Address feedback:
May 27, 2020
4ca16c0
Address feedback: use VtVec3fArray, VtIntArray, VtFloatArray instead …
May 27, 2020
ab0a321
Address feedback: return early if the status is false.
May 27, 2020
b5ec789
Merge pull request #421 from Autodesk/sabrih/MAYA-101460/pxr_mesh_wri…
HamedSabri-adsk May 28, 2020
25a5c20
Merge branch 'sabrih/MAYA-101460/pxr_mesh_write_part3' into sabrih/MA…
May 28, 2020
812adf6
Merge branch 'sabrih/MAYA-101460/pxr_mesh_write_part1' into sabrih/MA…
HamedSabri-adsk May 28, 2020
9b138b3
Merge pull request #423 from Autodesk/sabrih/MAYA-101460/pxr_mesh_wri…
HamedSabri-adsk May 28, 2020
9cb5880
Merge branch 'sabrih/MAYA-101460/pxr_mesh_write_part5' into sabrih/MA…
May 28, 2020
d5426d3
Address feedbacks:
May 28, 2020
047a097
Merge branch 'sabrih/MAYA-101460/pxr_mesh_write_part6' into sabrih/MA…
May 28, 2020
c1682b3
post merge fixes.
May 28, 2020
2d15079
address feedback:
May 29, 2020
2ea47fd
Merge pull request #426 from Autodesk/sabrih/MAYA-101460/pxr_mesh_wri…
HamedSabri-adsk May 29, 2020
35c0c0f
Address feedback: add parameter names in a function prototype
May 29, 2020
12ad434
address feedback: replace Default with Unauthored
May 29, 2020
5a64848
Address feedback: use VtVec3fArray, VtIntArray, VtFloatArray instead …
May 29, 2020
f7f193b
address feedback: fix the comments pointing at the old function names.
May 29, 2020
a7ccad1
address feedback: remove changes that were accidentally pulled into t…
May 29, 2020
6a4686e
Merge branch 'sabrih/MAYA-101460/pxr_mesh_write_part8' into sabrih/MA…
May 29, 2020
5ecb68c
Fix post merge!
May 29, 2020
062ac5a
Add feedback: refactor SetAttribute termplate functions.
Jun 1, 2020
21850e1
Merge branch 'sabrih/MAYA-101460/pxr_mesh_write_part9' into sabrih/MA…
Jun 1, 2020
39c824f
Merge branch 'dev' into sabrih/MAYA-101460/pxr_mesh_write_part1
Jun 1, 2020
d891b7e
Address feedback: swap the last 2 arguments passed to SetAttribute te…
Jun 1, 2020
a520d00
Fix python binding.
Jun 5, 2020
53dd501
Merge branch 'dev' into sabrih/MAYA-101460/pxr_mesh_write_part1
Jun 10, 2020
5803a46
comment out the logics in wrapMeshWriteUtils. This code is not used a…
Jun 11, 2020
be3c545
Revert "comment out the logics in wrapMeshWriteUtils. This code is no…
Jun 11, 2020
7a1f16a
Merge branch 'dev' into sabrih/MAYA-101460/pxr_mesh_write_part1
Jun 30, 2020
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
47 changes: 2 additions & 45 deletions lib/mayaUsd/fileio/primUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,13 @@

PXR_NAMESPACE_OPEN_SCOPE

static
MDagPath
_GetDagPath(const MFnDependencyNode& depNodeFn, const bool reportError = true)
{
try {
const MFnDagNode& dagNodeFn =
dynamic_cast<const MFnDagNode&>(depNodeFn);

MStatus status;
const MDagPath dagPath = dagNodeFn.dagPath(&status);
if (status == MS::kSuccess) {
const bool dagPathIsValid = dagPath.isValid(&status);
if (status == MS::kSuccess && dagPathIsValid) {
return dagPath;
}
}

if (reportError) {
TF_CODING_ERROR(
"Invalid MDagPath for MFnDagNode '%s'. Verify that it was "
"constructed using an MDagPath.",
dagNodeFn.fullPathName().asChar());
}
}
catch (const std::bad_cast& /* e */) {
// This is not a DAG node, so it can't have a DAG path.
}

return MDagPath();
}

static
UsdMayaUtil::MDagPathMap<SdfPath>
_GetDagPathMap(const MFnDependencyNode& depNodeFn, const SdfPath& usdPath)
{
const MDagPath dagPath = _GetDagPath(depNodeFn, /* reportError = */ false);
if (dagPath.isValid()) {
return UsdMayaUtil::MDagPathMap<SdfPath>({ {dagPath, usdPath} });
}

return UsdMayaUtil::MDagPathMap<SdfPath>({});
}

UsdMayaPrimUpdater::UsdMayaPrimUpdater(
const MFnDependencyNode& depNodeFn,
const SdfPath& usdPath) :
_dagPath(_GetDagPath(depNodeFn)),
_dagPath(UsdMayaUtil::getDagPath(depNodeFn)),
_mayaObject(depNodeFn.object()),
_usdPath(usdPath),
_baseDagToUsdPaths(_GetDagPathMap(depNodeFn, usdPath))
_baseDagToUsdPaths(UsdMayaUtil::getDagPathMap(depNodeFn, usdPath))
{
}

Expand Down
56 changes: 6 additions & 50 deletions lib/mayaUsd/fileio/primWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,6 @@ TF_DEFINE_PRIVATE_TOKENS(
(USD_inheritClassNames)
);


static
MDagPath
_GetDagPath(const MFnDependencyNode& depNodeFn, const bool reportError = true)
{
try {
const MFnDagNode& dagNodeFn =
dynamic_cast<const MFnDagNode&>(depNodeFn);

MStatus status;
const MDagPath dagPath = dagNodeFn.dagPath(&status);
if (status == MS::kSuccess) {
const bool dagPathIsValid = dagPath.isValid(&status);
if (status == MS::kSuccess && dagPathIsValid) {
return dagPath;
}
}

if (reportError) {
TF_CODING_ERROR(
"Invalid MDagPath for MFnDagNode '%s'. Verify that it was "
"constructed using an MDagPath.",
dagNodeFn.fullPathName().asChar());
}
}
catch (const std::bad_cast& /* e */) {
// This is not a DAG node, so it can't have a DAG path.
}

return MDagPath();
}

static
UsdMayaUtil::MDagPathMap<SdfPath>
_GetDagPathMap(const MFnDependencyNode& depNodeFn, const SdfPath& usdPath)
{
const MDagPath dagPath = _GetDagPath(depNodeFn, /* reportError = */ false);
if (dagPath.isValid()) {
return UsdMayaUtil::MDagPathMap<SdfPath>({{dagPath, usdPath}});
}

return UsdMayaUtil::MDagPathMap<SdfPath>({});
}

static
bool
_IsAnimated(const UsdMayaJobExportArgs& args, const MObject& obj)
Expand All @@ -118,10 +74,10 @@ UsdMayaPrimWriter::UsdMayaPrimWriter(
const SdfPath& usdPath,
UsdMayaWriteJobContext& jobCtx) :
_writeJobCtx(jobCtx),
_dagPath(_GetDagPath(depNodeFn)),
_dagPath(UsdMayaUtil::getDagPath(depNodeFn)),
_mayaObject(depNodeFn.object()),
_usdPath(usdPath),
_baseDagToUsdPaths(_GetDagPathMap(depNodeFn, usdPath)),
_baseDagToUsdPaths(UsdMayaUtil::getDagPathMap(depNodeFn, usdPath)),
_exportVisibility(jobCtx.GetArgs().exportVisibility),
_hasAnimCurves(_IsAnimated(jobCtx.GetArgs(), depNodeFn.object()))
{
Expand Down Expand Up @@ -219,10 +175,10 @@ UsdMayaPrimWriter::Write(const UsdTimeCode& usdTime)
UsdGeomTokens->inherited :
UsdGeomTokens->invisible);

_SetAttribute(
imageable.CreateVisibilityAttr(VtValue(), true),
visibilityTok,
usdTime);
UsdMayaWriteUtil::SetAttribute(imageable.CreateVisibilityAttr(VtValue(), true),
visibilityTok,
usdTime,
_GetSparseValueWriter());
}
}

Expand Down
26 changes: 0 additions & 26 deletions lib/mayaUsd/fileio/primWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,6 @@ class UsdMayaPrimWriter
MAYAUSD_CORE_PUBLIC
const UsdMayaJobExportArgs& _GetExportArgs() const;

/// Sets the value of \p attr to \p value at \p time with value
/// compression. When this method is used to write attribute values,
/// any redundant authoring of the default value or of time-samples
/// are avoided (by using the utility class UsdUtilsSparseValueWriter).
template <typename T>
bool _SetAttribute(
const UsdAttribute& attr,
const T& value,
const UsdTimeCode time = UsdTimeCode::Default()) {
VtValue val(value);
return _valueWriter.SetAttribute(attr, &val, time);
}

/// \overload
/// This overload takes the value by pointer and hence avoids a copy
/// of the value.
/// However, it swaps out the value held in \p value for efficiency,
/// leaving it in default-constructed state (value-initialized).
template <typename T>
bool _SetAttribute(
const UsdAttribute& attr,
T* value,
const UsdTimeCode time = UsdTimeCode::Default()) {
return _valueWriter.SetAttribute(attr, VtValue::Take(*value), time);
}

/// Get the attribute value-writer object to be used when writing
/// attributes. Access to this is provided so that attribute authoring
/// happening inside non-member functions can make use of it.
Expand Down
34 changes: 31 additions & 3 deletions lib/mayaUsd/fileio/translators/translatorMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#include <maya/MPointArray.h>
#include <maya/MString.h>

#include <mayaUsd/fileio/utils/meshUtil.h>
#include <mayaUsd/fileio/utils/meshReadUtils.h>
#include <mayaUsd/fileio/utils/meshWriteUtils.h>
#include <mayaUsd/fileio/utils/readUtil.h>
#include <mayaUsd/nodes/pointBasedDeformerNode.h>
#include <mayaUsd/nodes/stageNode.h>
Expand Down Expand Up @@ -211,11 +212,11 @@ TranslatorMeshRead::TranslatorMeshRead(const UsdGeomMesh& mesh,
if (mesh.GetSubdivisionSchemeAttr().Get(&subdScheme) && subdScheme == UsdGeomTokens->none) {
if (normals.size() == static_cast<size_t>(meshFn.numFaceVertices()) &&
mesh.GetNormalsInterpolation() == UsdGeomTokens->faceVarying) {
UsdMayaMeshUtil::SetEmitNormalsTag(meshFn, true);
UsdMayaMeshReadUtils::setEmitNormalsTag(meshFn, true);
}
}
else {
stat = UsdMayaMeshUtil::assignSubDivTagsToMesh(mesh, m_meshObj, meshFn);
stat = UsdMayaMeshReadUtils::assignSubDivTagsToMesh(mesh, m_meshObj, meshFn);
}

// Copy UsdGeomMesh schema attrs into Maya if they're authored.
Expand Down Expand Up @@ -485,6 +486,33 @@ TranslatorMeshRead::shapePath() const
return m_shapePath;
}

TranslatorMeshWrite::TranslatorMeshWrite(const MFnDependencyNode& depNodeFn,
const UsdStageRefPtr& stage,
const SdfPath& usdPath,
const MDagPath& dagPath)
{
if (!TF_VERIFY(dagPath.isValid())) {
return;
}

if (!UsdMayaMeshWriteUtils::isMeshValid(dagPath)) {
return;
}

m_usdMesh = UsdGeomMesh::Define(stage, usdPath);
if (!TF_VERIFY(
m_usdMesh,
"Could not define UsdGeomMesh at path '%s'\n",
usdPath.GetText())) {
return;
}
}

UsdGeomMesh
TranslatorMeshWrite::usdMesh() const
{
return m_usdMesh;
}

} // namespace MayaUsd

Expand Down
21 changes: 21 additions & 0 deletions lib/mayaUsd/fileio/translators/translatorMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,25 @@ class MAYAUSD_CORE_PUBLIC TranslatorMeshRead
SdfPath m_shapePath;
};

class MAYAUSD_CORE_PUBLIC TranslatorMeshWrite
{
public:
TranslatorMeshWrite(const MFnDependencyNode&,
const UsdStageRefPtr&,
const SdfPath&,
const MDagPath&);

~TranslatorMeshWrite() = default;

TranslatorMeshWrite(const TranslatorMeshWrite&) = delete;
TranslatorMeshWrite& operator=(const TranslatorMeshWrite&) = delete;
TranslatorMeshWrite(TranslatorMeshWrite&&) = delete;
TranslatorMeshWrite& operator=(TranslatorMeshWrite&&) = delete;

UsdGeomMesh usdMesh() const;

private:
UsdGeomMesh m_usdMesh;
};

} // namespace MayaUsd
8 changes: 6 additions & 2 deletions lib/mayaUsd/fileio/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
target_sources(${PROJECT_NAME}
PRIVATE
adaptor.cpp
meshUtil.cpp
jointWriteUtils.cpp
meshReadUtils.cpp
meshWriteUtils.cpp
readUtil.cpp
roundTripUtil.cpp
shadingUtil.cpp
Expand All @@ -15,7 +17,9 @@ target_sources(${PROJECT_NAME}

set(headers
adaptor.h
meshUtil.h
jointWriteUtils.h
meshReadUtils.h
meshWriteUtils.h
readUtil.h
roundTripUtil.h
shadingUtil.h
Expand Down
Loading