Skip to content

Commit

Permalink
Address feedback: swap the last 2 arguments passed to SetAttribute te…
Browse files Browse the repository at this point in the history
…mplate function.
  • Loading branch information
Hamed Sabri committed Jun 1, 2020
1 parent 39c824f commit d891b7e
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 108 deletions.
4 changes: 2 additions & 2 deletions lib/mayaUsd/fileio/primWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ UsdMayaPrimWriter::Write(const UsdTimeCode& usdTime)

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

Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/utils/jointWriteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ UsdMayaJointUtil::writeSkinningData(UsdGeomMesh& primSchema,

GfMatrix4d geomBindTransform;
if (UsdMayaJointUtil::getGeomBindTransform(skinCluster,&geomBindTransform)) {
UsdMayaWriteUtil::SetAttribute(bindingAPI.CreateGeomBindTransformAttr(), &geomBindTransform, valueWriter);
UsdMayaWriteUtil::SetAttribute(bindingAPI.CreateGeomBindTransformAttr(),
&geomBindTransform, UsdTimeCode::Default(), valueWriter);
}

UsdMayaJointUtil::warnForPostDeformationTransform(usdPath, dagPath, skinCluster);
Expand Down
43 changes: 23 additions & 20 deletions lib/mayaUsd/fileio/utils/meshWriteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace
{
// Simple case of non-indexed primvars.
if (indices.empty()) {
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), values, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), values, usdTime, valueWriter);
return;
}

Expand All @@ -202,17 +202,17 @@ namespace

const VtValue paddedValues = UsdMayaUtil::pushFirstValue(values, defaultValue);
if (!paddedValues.IsEmpty()) {
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), paddedValues, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.CreateIndicesAttr(), UsdMayaUtil::shiftIndices(indices, 1), valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), paddedValues, usdTime, valueWriter);
UsdMayaWriteUtil::SetAttribute(primvar.CreateIndicesAttr(), UsdMayaUtil::shiftIndices(indices, 1), usdTime, valueWriter);
}
else {
TF_CODING_ERROR("Unable to pad values array for <%s>",
primvar.GetAttr().GetPath().GetText());
}
}
else {
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), values, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.CreateIndicesAttr(), indices, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), values, usdTime, valueWriter);
UsdMayaWriteUtil::SetAttribute(primvar.CreateIndicesAttr(), indices, usdTime, valueWriter);
}
}
else {
Expand All @@ -227,8 +227,8 @@ namespace

const VtValue paddedValues = UsdMayaUtil::pushFirstValue(values, defaultValue);
if (!paddedValues.IsEmpty()) {
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), paddedValues, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.CreateIndicesAttr(), UsdMayaUtil::shiftIndices(indices, 1), valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primvar.GetAttr(), paddedValues, usdTime, valueWriter);
UsdMayaWriteUtil::SetAttribute(primvar.CreateIndicesAttr(), UsdMayaUtil::shiftIndices(indices, 1), usdTime, valueWriter);
}
else {
TF_CODING_ERROR("Unable to pad values array for <%s>",
Expand Down Expand Up @@ -613,10 +613,12 @@ UsdMayaMeshWriteUtils::assignSubDivTagsToUSDPrim(MFnMesh& meshFn,
}

// not animatable
UsdMayaWriteUtil::SetAttribute(primSchema.GetCornerIndicesAttr(), &subdCornerIndices, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetCornerIndicesAttr(),
&subdCornerIndices, UsdTimeCode::Default(), valueWriter);

// not animatable
UsdMayaWriteUtil::SetAttribute(primSchema.GetCornerSharpnessesAttr(), &subdCornerSharpnesses, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetCornerSharpnessesAttr(),
&subdCornerSharpnesses, UsdTimeCode::Default(), valueWriter);
}

// Edge Creasing
Expand Down Expand Up @@ -648,20 +650,20 @@ UsdMayaMeshWriteUtils::assignSubDivTagsToUSDPrim(MFnMesh& meshFn,
if (!creases.empty()) {
VtIntArray creaseIndicesVt(creases.size());
std::copy(creases.begin(), creases.end(), creaseIndicesVt.begin());
UsdMayaWriteUtil::SetAttribute(primSchema.GetCreaseIndicesAttr(), &creaseIndicesVt, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetCreaseIndicesAttr(), &creaseIndicesVt, UsdTimeCode::Default(), valueWriter);
}
if (!numCreases.empty()) {
VtIntArray creaseLengthsVt(numCreases.size());
std::copy(numCreases.begin(), numCreases.end(), creaseLengthsVt.begin());
UsdMayaWriteUtil::SetAttribute(primSchema.GetCreaseLengthsAttr(), &creaseLengthsVt, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetCreaseLengthsAttr(), &creaseLengthsVt, UsdTimeCode::Default(), valueWriter);
}
if (!creaseSharpnesses.empty()) {
VtFloatArray creaseSharpnessesVt(creaseSharpnesses.size());
std::copy(
creaseSharpnesses.begin(),
creaseSharpnesses.end(),
creaseSharpnessesVt.begin());
UsdMayaWriteUtil::SetAttribute(primSchema.GetCreaseSharpnessesAttr(), &creaseSharpnessesVt, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetCreaseSharpnessesAttr(), &creaseSharpnessesVt, UsdTimeCode::Default(), valueWriter);
}
}
}
Expand Down Expand Up @@ -690,8 +692,8 @@ UsdMayaMeshWriteUtils::writePointsData(const MFnMesh& meshFn,
// Compute the extent using the raw points
UsdGeomPointBased::ComputeExtent(points, &extent);

UsdMayaWriteUtil::SetAttribute(primSchema.GetPointsAttr(), &points, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primSchema.CreateExtentAttr(), &extent, valueWriter,usdTime);
UsdMayaWriteUtil::SetAttribute(primSchema.GetPointsAttr(), &points, usdTime, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.CreateExtentAttr(), &extent, usdTime, valueWriter);
}

void
Expand All @@ -715,8 +717,8 @@ UsdMayaMeshWriteUtils::writeFaceVertexIndicesData(const MFnMesh& meshFn,
curFaceVertexIndex++;
}
}
UsdMayaWriteUtil::SetAttribute(primSchema.GetFaceVertexCountsAttr(), &faceVertexCounts, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primSchema.GetFaceVertexIndicesAttr(), &faceVertexIndices, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primSchema.GetFaceVertexCountsAttr(), &faceVertexCounts, usdTime, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetFaceVertexIndicesAttr(), &faceVertexIndices, usdTime, valueWriter);
}

void
Expand All @@ -733,7 +735,7 @@ UsdMayaMeshWriteUtils::writeInvisibleFacesData(const MFnMesh& meshFn,
// use memcpy() to copy the data. HS April 20, 2019
memcpy((int32_t*)subdHoles.data(), ptr, count * sizeof(uint32_t));
// not animatable in Maya, so we'll set default only
UsdMayaWriteUtil::SetAttribute(primSchema.GetHoleIndicesAttr(), &subdHoles, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.GetHoleIndicesAttr(), &subdHoles, UsdTimeCode::Default(), valueWriter);
}
}

Expand Down Expand Up @@ -857,7 +859,8 @@ UsdMayaMeshWriteUtils::writeSubdivInterpBound(MFnMesh& meshFn,
{
TfToken sdInterpBound = UsdMayaMeshWriteUtils::getSubdivInterpBoundary(meshFn);
if (!sdInterpBound.IsEmpty()) {
UsdMayaWriteUtil::SetAttribute(primSchema.CreateInterpolateBoundaryAttr(), sdInterpBound, valueWriter);
UsdMayaWriteUtil::SetAttribute(primSchema.CreateInterpolateBoundaryAttr(),
sdInterpBound, UsdTimeCode::Default(), valueWriter);
}
}

Expand All @@ -869,7 +872,7 @@ UsdMayaMeshWriteUtils::writeSubdivFVLinearInterpolation(MFnMesh& meshFn,
TfToken sdFVLinearInterpolation = UsdMayaMeshWriteUtils::getSubdivFVLinearInterpolation(meshFn);
if (!sdFVLinearInterpolation.IsEmpty()) {
UsdMayaWriteUtil::SetAttribute(primSchema.CreateFaceVaryingLinearInterpolationAttr(),
sdFVLinearInterpolation, valueWriter);
sdFVLinearInterpolation, UsdTimeCode::Default(), valueWriter);
}
}

Expand All @@ -884,7 +887,7 @@ UsdMayaMeshWriteUtils::writeNormalsData(const MFnMesh& meshFn,

if (UsdMayaMeshWriteUtils::getMeshNormals(meshFn, &meshNormals,&normalInterp)) {

UsdMayaWriteUtil::SetAttribute(primSchema.GetNormalsAttr(), &meshNormals, valueWriter, usdTime);
UsdMayaWriteUtil::SetAttribute(primSchema.GetNormalsAttr(), &meshNormals, usdTime, valueWriter);

primSchema.SetNormalsInterpolation(normalInterp);
}
Expand Down
35 changes: 13 additions & 22 deletions lib/mayaUsd/fileio/utils/writeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ UsdMayaWriteUtil::SetUsdAttr(
return false;
}

return SetAttribute(usdAttr, val, valueWriter, usdTime);
return SetAttribute(usdAttr, val, usdTime, valueWriter);
}

// This method inspects the JSON blob stored in the
Expand Down Expand Up @@ -1026,7 +1026,7 @@ UsdMayaWriteUtil::WriteAPISchemaAttributesToPrim(
/*custom*/ false,
attrDef->GetVariability());
const UsdTimeCode usdTime = UsdTimeCode::Default();
SetAttribute(attr, value, valueWriter, usdTime);
SetAttribute(attr, value, usdTime, valueWriter);
}
}
}
Expand Down Expand Up @@ -1069,7 +1069,7 @@ UsdMayaWriteUtil::WriteSchemaAttributesToPrim(
attrDef->GetTypeName(),
/*custom*/ false,
attrDef->GetVariability());
if (SetAttribute(attr, value, valueWriter, usdTime)) {
if (SetAttribute(attr, value, usdTime, valueWriter)) {
count++;
}
}
Expand Down Expand Up @@ -1180,8 +1180,7 @@ UsdMayaWriteUtil::WriteArrayAttrsToInstancer(
[](double x) {
return (int64_t) x;
});
SetAttribute(instancer.CreateIdsAttr(), indicesOrIds,
valueWriter, usdTime);
SetAttribute(instancer.CreateIdsAttr(), indicesOrIds, usdTime, valueWriter);
}
else {
// Skip writing the id's, but still generate the indicesOrIds array.
Expand Down Expand Up @@ -1210,14 +1209,13 @@ UsdMayaWriteUtil::WriteArrayAttrsToInstancer(
return (int) numPrototypes - 1;
}
});
SetAttribute(instancer.CreateProtoIndicesAttr(), vtArray,
valueWriter, usdTime);
SetAttribute(instancer.CreateProtoIndicesAttr(), vtArray, usdTime, valueWriter);
}
else {
VtIntArray vtArray;
vtArray.assign(numInstances, 0);
SetAttribute(instancer.CreateProtoIndicesAttr(),
vtArray, valueWriter, usdTime);
vtArray, usdTime, valueWriter);
}

if (inputPointsData.checkArrayExist("position", type) &&
Expand All @@ -1232,14 +1230,12 @@ UsdMayaWriteUtil::WriteArrayAttrsToInstancer(
[](const MVector& v) {
return GfVec3f(v.x, v.y, v.z);
});
SetAttribute(instancer.CreatePositionsAttr(), vtArray,
valueWriter,usdTime);
SetAttribute(instancer.CreatePositionsAttr(), vtArray, usdTime, valueWriter);
}
else {
VtVec3fArray vtArray;
vtArray.assign(numInstances, GfVec3f(0.0f));
SetAttribute(instancer.CreatePositionsAttr(),
vtArray, valueWriter, usdTime);
SetAttribute(instancer.CreatePositionsAttr(), vtArray, usdTime, valueWriter);
}

if (inputPointsData.checkArrayExist("rotation", type) &&
Expand All @@ -1257,14 +1253,12 @@ UsdMayaWriteUtil::WriteArrayAttrsToInstancer(
* GfRotation(GfVec3d::ZAxis(), v.z);
return GfQuath(rot.GetQuat());
});
SetAttribute(instancer.CreateOrientationsAttr(),
vtArray, valueWriter, usdTime);
SetAttribute(instancer.CreateOrientationsAttr(), vtArray, usdTime, valueWriter);
}
else {
VtQuathArray vtArray;
vtArray.assign(numInstances, GfQuath(0.0f));
SetAttribute(instancer.CreateOrientationsAttr(),
vtArray, valueWriter, usdTime);
SetAttribute(instancer.CreateOrientationsAttr(), vtArray, usdTime, valueWriter);
}

if (inputPointsData.checkArrayExist("scale", type) &&
Expand All @@ -1279,14 +1273,12 @@ UsdMayaWriteUtil::WriteArrayAttrsToInstancer(
[](const MVector& v) {
return GfVec3f(v.x, v.y, v.z);
});
SetAttribute(instancer.CreateScalesAttr(), vtArray,
valueWriter, usdTime);
SetAttribute(instancer.CreateScalesAttr(), vtArray, usdTime, valueWriter);
}
else {
VtVec3fArray vtArray;
vtArray.assign(numInstances, GfVec3f(1.0));
SetAttribute(instancer.CreateScalesAttr(), vtArray,
valueWriter, usdTime);
SetAttribute(instancer.CreateScalesAttr(), vtArray, usdTime, valueWriter);
}

// Note: Maya stores visibility as an array of doubles, one corresponding
Expand All @@ -1307,8 +1299,7 @@ UsdMayaWriteUtil::WriteArrayAttrsToInstancer(
}
}
}
SetAttribute(instancer.CreateInvisibleIdsAttr(), invisibleIds,
valueWriter, usdTime);
SetAttribute(instancer.CreateInvisibleIdsAttr(), invisibleIds, usdTime, valueWriter);
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions lib/mayaUsd/fileio/utils/writeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ struct UsdMayaWriteUtil
static bool SetAttribute(
const UsdAttribute& attr,
const T& value,
UsdUtilsSparseValueWriter* valueWriter = nullptr,
const UsdTimeCode time = UsdTimeCode::Default())
const UsdTimeCode time = UsdTimeCode::Default(),
UsdUtilsSparseValueWriter* valueWriter = nullptr)
{
return valueWriter ?
valueWriter->SetAttribute(attr, VtValue(value), time) :
Expand All @@ -330,8 +330,8 @@ struct UsdMayaWriteUtil
static bool SetAttribute(
const UsdAttribute& attr,
T* value,
UsdUtilsSparseValueWriter* valueWriter = nullptr,
const UsdTimeCode time = UsdTimeCode::Default())
const UsdTimeCode time = UsdTimeCode::Default(),
UsdUtilsSparseValueWriter* valueWriter = nullptr)
{
return valueWriter ?
valueWriter->SetAttribute(attr, VtValue::Take(*value), time) :
Expand Down
24 changes: 12 additions & 12 deletions lib/usd/translators/cameraWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ PxrUsdTranslators_CameraWriter::writeCameraAttrs(
if (camFn.isOrtho()) {
UsdMayaWriteUtil::SetAttribute(primSchema.GetProjectionAttr(),
UsdGeomTokens->orthographic,
_GetSparseValueWriter(), usdTime);
usdTime, _GetSparseValueWriter());

// Contrary to the documentation, Maya actually stores the orthographic
// width in centimeters (Maya's internal unit system), not inches.
Expand All @@ -112,14 +112,14 @@ PxrUsdTranslators_CameraWriter::writeCameraAttrs(
// camera in Maya, and aspect ratio, lens squeeze ratio, and film
// offset have no effect.
UsdMayaWriteUtil::SetAttribute(primSchema.GetHorizontalApertureAttr(),
static_cast<float>(orthoWidth), _GetSparseValueWriter(), usdTime);
static_cast<float>(orthoWidth), usdTime, _GetSparseValueWriter());

UsdMayaWriteUtil::SetAttribute(primSchema.GetVerticalApertureAttr(),
static_cast<float>(orthoWidth),
_GetSparseValueWriter(), usdTime);
usdTime, _GetSparseValueWriter());
} else {
UsdMayaWriteUtil::SetAttribute(primSchema.GetProjectionAttr(),
UsdGeomTokens->perspective, _GetSparseValueWriter(), usdTime);
UsdGeomTokens->perspective, usdTime, _GetSparseValueWriter());

// Lens squeeze ratio applies horizontally only.
const double horizontalAperture = UsdMayaUtil::ConvertInchesToMM(
Expand All @@ -135,35 +135,35 @@ PxrUsdTranslators_CameraWriter::writeCameraAttrs(
(camFn.shakeEnabled() ? camFn.verticalFilmOffset() + camFn.verticalShake() : camFn.verticalFilmOffset()));

UsdMayaWriteUtil::SetAttribute(primSchema.GetHorizontalApertureAttr(),
static_cast<float>(horizontalAperture), _GetSparseValueWriter(), usdTime);
static_cast<float>(horizontalAperture), usdTime, _GetSparseValueWriter());

UsdMayaWriteUtil::SetAttribute(primSchema.GetVerticalApertureAttr(),
static_cast<float>(verticalAperture), _GetSparseValueWriter(), usdTime);
static_cast<float>(verticalAperture), usdTime, _GetSparseValueWriter());

UsdMayaWriteUtil::SetAttribute(primSchema.GetHorizontalApertureOffsetAttr(),
static_cast<float>(horizontalApertureOffset), _GetSparseValueWriter(), usdTime);
static_cast<float>(horizontalApertureOffset), usdTime, _GetSparseValueWriter());

UsdMayaWriteUtil::SetAttribute(primSchema.GetVerticalApertureOffsetAttr(),
static_cast<float>(verticalApertureOffset), _GetSparseValueWriter(),usdTime);
static_cast<float>(verticalApertureOffset), usdTime, _GetSparseValueWriter());
}

// Set the lens parameters.
UsdMayaWriteUtil::SetAttribute(primSchema.GetFocalLengthAttr(),
static_cast<float>(camFn.focalLength()), _GetSparseValueWriter(), usdTime);
static_cast<float>(camFn.focalLength()), usdTime, _GetSparseValueWriter());

// Always export focus distance and fStop regardless of what
// camFn.isDepthOfField() says. Downstream tools can choose to ignore or
// override them.
UsdMayaWriteUtil::SetAttribute(primSchema.GetFocusDistanceAttr(),
static_cast<float>(camFn.focusDistance()), _GetSparseValueWriter(), usdTime);
static_cast<float>(camFn.focusDistance()), usdTime, _GetSparseValueWriter());

UsdMayaWriteUtil::SetAttribute(primSchema.GetFStopAttr(),
static_cast<float>(camFn.fStop()), _GetSparseValueWriter(), usdTime);
static_cast<float>(camFn.fStop()), usdTime, _GetSparseValueWriter());

// Set the clipping planes.
GfVec2f clippingRange(camFn.nearClippingPlane(), camFn.farClippingPlane());
UsdMayaWriteUtil::SetAttribute(primSchema.GetClippingRangeAttr(), clippingRange,
_GetSparseValueWriter(), usdTime);
usdTime, _GetSparseValueWriter());

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/translators/instancerWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ PxrUsdTranslators_InstancerWriter::writeInstancerAttrs(
GfVec3d origin;
if (_GetTransformedOriginInLocalSpace(opData.mayaPath, &origin)) {
UsdGeomXformOp translateOp = opData.op;
UsdMayaWriteUtil::SetAttribute(translateOp.GetAttr(), -origin, _GetSparseValueWriter(), usdTime);
UsdMayaWriteUtil::SetAttribute(translateOp.GetAttr(), -origin, usdTime, _GetSparseValueWriter());
}
}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ PxrUsdTranslators_InstancerWriter::writeInstancerAttrs(
instancer.GetPrim().GetStage()->Load(instancer.GetPath());
VtArray<GfVec3f> extent(2);
if (instancer.ComputeExtentAtTime(&extent, usdTime, usdTime)) {
UsdMayaWriteUtil::SetAttribute(instancer.CreateExtentAttr(), &extent, _GetSparseValueWriter(), usdTime);
UsdMayaWriteUtil::SetAttribute(instancer.CreateExtentAttr(), &extent, usdTime, _GetSparseValueWriter());
}

return true;
Expand Down
Loading

0 comments on commit d891b7e

Please sign in to comment.