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

Add support for float and double types to the converter (and proxy accessor) #1892

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions lib/mayaUsd/utils/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
|:-----------------|:----------------------|:---------------------------------------------------------------|:------------------------|:-------------------|
| Bool | bool | MFnNumericData::kBoolean | bool | MakeMayaSimpleData |
| Int | int | MFnNumericData::kInt | int | MakeMayaSimpleData |
| Float | float | MFnNumericData::kFloat | float | MakeMayaSimpleData |
| Double | double | MFnNumericData::kDouble | double | MakeMayaSimpleData |
||
| String | std::string | MFnData::kString, MFn::kStringData | MString, MFnStringData | MakeMayaFnData |
||
Expand Down Expand Up @@ -190,6 +192,46 @@ template <> struct MakeMayaSimpleData<int> : public std::true_type
}
};

//! \brief Type trait for Maya's float type providing get and set methods for data handle and
//! plugs.
template <> struct MakeMayaSimpleData<float> : public std::true_type
{
using Type = float;
enum
{
kNumericType = MFnNumericData::kFloat
};

static void get(const MDataHandle& handle, Type& value) { value = handle.asFloat(); }

static void set(MDataHandle& handle, const Type& value) { handle.setFloat(value); }

static void set(const MPlug& plug, MDGModifier& dst, const Type& value)
{
dst.newPlugValueFloat(plug, value);
}
};

//! \brief Type trait for Maya's double type providing get and set methods for data handle and
//! plugs.
template <> struct MakeMayaSimpleData<double> : public std::true_type
{
using Type = double;
enum
{
kNumericType = MFnNumericData::kDouble
};

static void get(const MDataHandle& handle, Type& value) { value = handle.asDouble(); }

static void set(MDataHandle& handle, const Type& value) { handle.setDouble(value); }

static void set(const MPlug& plug, MDGModifier& dst, const Type& value)
{
dst.newPlugValueDouble(plug, value);
}
};

//---------------------------------------------------------------------------------
//! \brief Type trait declaration for complex data types. Each specialized type will inherit
//! from std::true_type
Expand Down Expand Up @@ -1008,6 +1050,8 @@ struct Converter::GenerateConverters

createConverter<bool, bool>(converters, SdfValueTypeNames->Bool);
createConverter<int, int32_t>(converters, SdfValueTypeNames->Int);
createConverter<float, float>(converters, SdfValueTypeNames->Float);
createConverter<double, double>(converters, SdfValueTypeNames->Double);

createConverter<MString, std::string>(converters, SdfValueTypeNames->String);
createConverter<float3, GfVec3f>(converters, SdfValueTypeNames->Float3);
Expand Down
28 changes: 27 additions & 1 deletion test/lib/testMayaUsdConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def createMPlugAndUsdAttribute(self, sdfValueType, nodeName, stage, primPath):

def runTypeChecks(self, sdfValueType, value1, value2):
"""
Test for Sdf.ValueTypeNames.Bool type, veryfing:
Test for Sdf.ValueTypeNames.XXX type, veryfing:
- we can find the converter of given sdf type name
- we can find the converter with a pair of maya plug and usd attribute
- we can convert vtvalue --> maya plug (value1)
Expand Down Expand Up @@ -154,6 +154,32 @@ def testBoolConverter(self):
self.runTypeChecks(sdfValueType,value1,value2)
self.runErrorHandlingChecks(sdfValueType,value1,errSdfValueType)

def testFloatConverter(self):
"""
Test for Sdf.ValueTypeNames.Float
"""
#
value1 = Vt.Float(3.14)
value2 = Vt.Float(9.98)
sdfValueType = Sdf.ValueTypeNames.Float
errSdfValueType = Sdf.ValueTypeNames.String
#
self.runTypeChecks(sdfValueType,value1,value2)
self.runErrorHandlingChecks(sdfValueType,value1,errSdfValueType)

def testDoubleConverter(self):
"""
Test for Sdf.ValueTypeNames.Double
"""
#
value1 = Vt.Double(3.14)
value2 = Vt.Double(9.98)
sdfValueType = Sdf.ValueTypeNames.Double
errSdfValueType = Sdf.ValueTypeNames.String
#
self.runTypeChecks(sdfValueType,value1,value2)
self.runErrorHandlingChecks(sdfValueType,value1,errSdfValueType)

def testStringConverter(self):
"""
Test for Sdf.ValueTypeNames.String
Expand Down