2 #include "AL/usdmaya/Common.h"
3 #include "AL/usdmaya/AttributeType.h"
4 #include "AL/maya/DgNodeHelper.h"
6 #include "maya/MPlug.h"
7 #include "maya/MAngle.h"
8 #include "maya/MDistance.h"
9 #include "maya/MTime.h"
10 #include "maya/MFnAnimCurve.h"
12 #include "maya/MGlobal.h"
13 #include "maya/MStatus.h"
15 #include "pxr/base/gf/half.h"
16 #include "pxr/usd/usd/attribute.h"
17 #include "pxr/usd/usdGeom/xformOp.h"
25 namespace translators {
79 static MStatus
setVec3Anim(MObject node, MObject attr,
const UsdGeomXformOp op,
double conversionFactor = 1.0);
86 MStatus
setAngleAnim(MObject node, MObject attr,
const UsdGeomXformOp op);
94 MStatus
setFloatAttrAnim(MObject node, MObject attr, UsdAttribute usdAttr,
double conversionFactor = 1.0);
105 static MStatus getUsdBoolArray(
const MObject& node,
const MObject& attr, VtArray<bool>& values);
112 static MStatus getUsdInt8Array(
const MObject& node,
const MObject& attr, VtArray<int8_t>& values);
119 static MStatus getUsdInt16Array(
const MObject& node,
const MObject& attr, VtArray<int16_t>& values);
126 static MStatus getUsdInt32Array(
const MObject& node,
const MObject& attr, VtArray<int32_t>& values);
133 static MStatus getUsdInt64Array(
const MObject& node,
const MObject& attr, VtArray<int64_t>& values);
140 static MStatus getUsdHalfArray(
const MObject& node,
const MObject& attr, VtArray<half>& values);
147 static MStatus getUsdFloatArray(
const MObject& node,
const MObject& attr, VtArray<float>& values);
154 static MStatus getUsdDoubleArray(
const MObject& node,
const MObject& attr, VtArray<double>& values);
161 static MStatus setUsdBoolArray(
const MObject& node,
const MObject& attr,
const VtArray<bool>& values);
168 static MStatus setUsdInt8Array(
const MObject& node,
const MObject& attr,
const VtArray<int8_t>& values);
175 static MStatus setUsdInt16Array(
const MObject& node,
const MObject& attr,
const VtArray<int16_t>& values);
182 static MStatus setUsdInt32Array(
const MObject& node,
const MObject& attr,
const VtArray<int32_t>& values);
189 static MStatus setUsdInt64Array(
const MObject& node,
const MObject& attr,
const VtArray<int64_t>& values);
196 static MStatus setUsdHalfArray(
const MObject& node,
const MObject& attr,
const VtArray<half>& values);
203 static MStatus setUsdFloatArray(
const MObject& node,
const MObject& attr,
const VtArray<float>& values);
210 static MStatus setUsdDoubleArray(
const MObject& node,
const MObject& attr,
const VtArray<double>& values);
221 static MStatus
copyBool(MObject node, MObject attr,
const UsdAttribute& value);
228 static MStatus
copyFloat(MObject node, MObject attr,
const UsdAttribute& value);
235 static MStatus
copyDouble(MObject node, MObject attr,
const UsdAttribute& value);
242 static MStatus
copyInt(MObject node, MObject attr,
const UsdAttribute& value);
249 static MStatus
copyVec3(MObject node, MObject attr,
const UsdAttribute& value);
276 static MStatus
setMayaValue(MObject node, MObject attr,
const UsdAttribute& usdAttr);
294 static void copyAttributeValue(
const MPlug& attr, UsdAttribute& usdAttr,
const UsdTimeCode& timeCode);
300 static void copySimpleValue(
const MPlug& plug, UsdAttribute& usdAttr,
const UsdTimeCode& timeCode);
307 static void copyAttributeValue(
const MPlug& attr, UsdAttribute& usdAttr,
float scale,
const UsdTimeCode& timeCode);
314 static void copySimpleValue(
const MPlug& plug, UsdAttribute& usdAttr,
float scale,
const UsdTimeCode& timeCode);
321 MPlug plug(node, attr);
323 const char*
const xformErrorCreate =
"DgNodeTranslator:setVec3Anim error creating animation curve";
325 MFnAnimCurve acFnSetX;
326 acFnSetX.create(plug.child(0), NULL, &status);
329 MFnAnimCurve acFnSetY;
330 acFnSetY.create(plug.child(1), NULL, &status);
333 MFnAnimCurve acFnSetZ;
334 acFnSetZ.create(plug.child(2), NULL, &status);
337 std::vector<double> times;
338 op.GetTimeSamples(×);
340 const char*
const xformErrorKey =
"DgNodeTranslator:setVec3Anim error setting key on animation curve";
343 for(
auto const& timeValue: times)
345 const bool retValue = op.GetAs<T>(&value, timeValue);
346 if (!retValue)
continue;
348 MTime tm(timeValue, MTime::kFilm);
350 switch (acFnSetX.animCurveType())
352 case MFnAnimCurve::kAnimCurveTL:
353 case MFnAnimCurve::kAnimCurveTA:
354 case MFnAnimCurve::kAnimCurveTU:
356 acFnSetX.addKey(tm, value[0] * conversionFactor, MFnAnimCurve::kTangentGlobal, MFnAnimCurve::kTangentGlobal, NULL, &status);
358 acFnSetY.addKey(tm, value[1] * conversionFactor, MFnAnimCurve::kTangentGlobal, MFnAnimCurve::kTangentGlobal, NULL, &status);
360 acFnSetZ.addKey(tm, value[2] * conversionFactor, MFnAnimCurve::kTangentGlobal, MFnAnimCurve::kTangentGlobal, NULL, &status);
375 inline MStatus DgNodeTranslator::getUsdInt8Array(
const MObject& node,
const MObject& attr, VtArray<int8_t>& values)
377 MPlug plug(node, attr);
378 if(!plug || !plug.isArray())
380 const uint32_t num = plug.numElements();
386 inline MStatus DgNodeTranslator::getUsdInt16Array(
const MObject& node,
const MObject& attr, VtArray<int16_t>& values)
388 MPlug plug(node, attr);
389 if(!plug || !plug.isArray())
391 const uint32_t num = plug.numElements();
397 inline MStatus DgNodeTranslator::getUsdInt32Array(
const MObject& node,
const MObject& attr, VtArray<int32_t>& values)
399 MPlug plug(node, attr);
400 if(!plug || !plug.isArray())
402 const uint32_t num = plug.numElements();
408 inline MStatus DgNodeTranslator::getUsdInt64Array(
const MObject& node,
const MObject& attr, VtArray<int64_t>& values)
410 MPlug plug(node, attr);
411 if(!plug || !plug.isArray())
413 const uint32_t num = plug.numElements();
419 inline MStatus DgNodeTranslator::getUsdHalfArray(
const MObject& node,
const MObject& attr, VtArray<half>& values)
421 MPlug plug(node, attr);
422 if(!plug || !plug.isArray())
424 const uint32_t num = plug.numElements();
430 inline MStatus DgNodeTranslator::getUsdFloatArray(
const MObject& node,
const MObject& attr, VtArray<float>& values)
432 MPlug plug(node, attr);
433 if(!plug || !plug.isArray())
435 const uint32_t num = plug.numElements();
441 inline MStatus DgNodeTranslator::getUsdDoubleArray(
const MObject& node,
const MObject& attr, VtArray<double>& values)
443 MPlug plug(node, attr);
444 if(!plug || !plug.isArray())
446 const uint32_t num = plug.numElements();
452 inline MStatus DgNodeTranslator::setUsdInt8Array(
const MObject& node,
const MObject& attr,
const VtArray<int8_t>& values)
454 return setInt8Array(node, attr, values.cdata(), values.size());
458 inline MStatus DgNodeTranslator::setUsdInt16Array(
const MObject& node,
const MObject& attr,
const VtArray<int16_t>& values)
460 return setInt16Array(node, attr, values.cdata(), values.size());
464 inline MStatus DgNodeTranslator::setUsdInt32Array(
const MObject& node,
const MObject& attr,
const VtArray<int32_t>& values)
466 return setInt32Array(node, attr, values.cdata(), values.size());
470 inline MStatus DgNodeTranslator::setUsdInt64Array(
const MObject& node,
const MObject& attr,
const VtArray<int64_t>& values)
472 return setInt64Array(node, attr, values.cdata(), values.size());
476 inline MStatus DgNodeTranslator::setUsdHalfArray(
const MObject& node,
const MObject& attr,
const VtArray<half>& values)
478 return setHalfArray(node, attr, values.cdata(), values.size());
482 inline MStatus DgNodeTranslator::setUsdFloatArray(
const MObject& node,
const MObject& attr,
const VtArray<float>& values)
484 return setFloatArray(node, attr, values.cdata(), values.size());
488 inline MStatus DgNodeTranslator::setUsdDoubleArray(
const MObject& node,
const MObject& attr,
const VtArray<double>& values)
static void copySimpleValue(const MPlug &plug, UsdAttribute &usdAttr, const UsdTimeCode &timeCode)
copy the attribute value from the plug specified, at the given time, and store the data on the usdAtt...
static MStatus copyInt(MObject node, MObject attr, const UsdAttribute &value)
copy a boolean value from USD and apply to Maya attribute
static MStatus getDoubleArray(const MObject &node, const MObject &attr, std::vector< double > &values)
retrieve an array of double values from an attribute in Maya
Definition: DgNodeHelper.h:1154
static MStatus setFloatArray(const MObject &node, const MObject &attr, const std::vector< float > &values)
sets all values on a float array attribute on the specified node
Definition: DgNodeHelper.h:1195
MStatus setFloatAttrAnim(MObject node, MObject attr, UsdAttribute usdAttr, double conversionFactor=1.0)
creates animation curves in maya for the specified attribute
static MStatus setSingleMayaValue(MObject node, MObject attr, const UsdAttribute &usdAttr, const UsdDataType type)
copy a non array value from a usd attribute into the maya attribute specified
static MStatus setInt32Array(const MObject &node, const MObject &attr, const std::vector< int32_t > &values)
sets all values on a 32bit integer array attribute on the specified node
Definition: DgNodeHelper.h:1177
static MStatus addDynamicAttribute(MObject node, const UsdAttribute &usdAttr)
creates a new dynamic attribute on the Maya node specified which will be initialized from the usdAttr...
parameters for the exporter. These parameters are constructed by any command or file translator that ...
Definition: ExportParams.h:17
parameters for the importer
Definition: ImportParams.h:18
static MStatus getInt16Array(const MObject &node, const MObject &attr, std::vector< int16_t > &values)
retrieve an array of 16bit integer values from an attribute in Maya
Definition: DgNodeHelper.h:1099
MStatus setAngleAnim(MObject node, MObject attr, const UsdGeomXformOp op)
creates animation curves to animate the specified angle attribute
static MStatus copyDynamicAttributes(MObject node, UsdPrim &prim)
copy all custom attributes from the usd primitive onto the maya node.
static MStatus setDoubleArray(const MObject &node, const MObject &attr, const std::vector< double > &values)
sets all values on a double array attribute on the specified node
Definition: DgNodeHelper.h:1201
virtual MObject createNode(const UsdPrim &from, MObject parent, const char *nodeType, const ImporterParams ¶ms)
Creates a new maya node of the given type and set attributes based on input prim. ...
UsdDataType
A generalized set of USD attribute types that enable switch statements (instead of the if/else approa...
Definition: AttributeType.h:12
static MStatus getFloatArray(const MObject &node, const MObject &attr, std::vector< float > &values)
retrieve an array of float values from an attribute in Maya
Definition: DgNodeHelper.h:1143
static MStatus setInt64Array(const MObject &node, const MObject &attr, const std::vector< int64_t > &values)
sets all values on a 64bit integer array attribute on the specified node
Definition: DgNodeHelper.h:1183
static MStatus getInt64Array(const MObject &node, const MObject &attr, std::vector< int64_t > &values)
retrieve an array of 64bit integer values from an attribute in Maya
Definition: DgNodeHelper.h:1121
static MStatus setVec3Anim(MObject node, MObject attr, const UsdGeomXformOp op, double conversionFactor=1.0)
creates animation curves in maya for the specified attribute
Definition: DgNodeTranslator.h:319
Utility class that provides support for setting/getting attributes.
Definition: DgNodeHelper.h:21
static MStatus setInt8Array(const MObject &node, const MObject &attr, const std::vector< int8_t > &values)
sets all values on a 8bit integer array attribute on the specified node
Definition: DgNodeHelper.h:1165
static MStatus copyDouble(MObject node, MObject attr, const UsdAttribute &value)
copy a boolean value from USD and apply to Maya attribute
static MStatus copyVec3(MObject node, MObject attr, const UsdAttribute &value)
copy a boolean value from USD and apply to Maya attribute
static MStatus copyFloat(MObject node, MObject attr, const UsdAttribute &value)
copy a boolean value from USD and apply to Maya attribute
static MStatus getInt8Array(const MObject &node, const MObject &attr, std::vector< int8_t > &values)
retrieve an array of 8 bit char values from an attribute in Maya
Definition: DgNodeHelper.h:1088
static MStatus copyBool(MObject node, MObject attr, const UsdAttribute &value)
copy a boolean value from USD and apply to Maya attribute
static MStatus getHalfArray(const MObject &node, const MObject &attr, std::vector< half > &values)
retrieve an array of float values from an attribute in Maya (converted to halfs)
Definition: DgNodeHelper.h:1132
MStatus copyAttributes(const UsdPrim &from, MObject to, const ImporterParams ¶ms)
helper method to copy attributes from the UsdPrim to the Maya node
virtual bool attributeHandled(const UsdAttribute &usdAttr)
A temporary solution. Given a custom attribute, if a translator handles it somehow (i...
static MStatus registerType()
static type registration
static MStatus setInt16Array(const MObject &node, const MObject &attr, const std::vector< int16_t > &values)
sets all values on a 16bit integer array attribute on the specified node
Definition: DgNodeHelper.h:1171
static MStatus getInt32Array(const MObject &node, const MObject &attr, std::vector< int32_t > &values)
retrieve an array of 32bit integer values from an attribute in Maya
Definition: DgNodeHelper.h:1110
static MStatus setHalfArray(const MObject &node, const MObject &attr, const std::vector< half > &values)
sets all values on a float array attribute on the specified node (but convert from half float data) ...
Definition: DgNodeHelper.h:1189
static MStatus setMayaValue(MObject node, MObject attr, const UsdAttribute &usdAttr)
copy the value from the usdAttribute onto the maya attribute value
Utility class that transfers DgNodes between Maya and USD.
Definition: DgNodeTranslator.h:30
static void copyAttributeValue(const MPlug &attr, UsdAttribute &usdAttr, const UsdTimeCode &timeCode)
copy the attribute value from the plug specified, at the given time, and store the data on the usdAtt...
static MStatus setArrayMayaValue(MObject node, MObject attr, const UsdAttribute &usdAttr, const UsdDataType type)
copy an array value from a usd attribute into the maya attribute specified
#define AL_MAYA_CHECK_ERROR(status, ErrorString)
Given the status, validates that the status is ok. If not, an error is logged using the specified err...
Definition: Common.h:75