2
"""General utility methods"""
3
__docformat__ = "restructuredtext"
5
import maya.OpenMaya as api
6
import mrv.maya.undo as undo
8
MScriptUtil = api.MScriptUtil
15
def in_double3_out_vector(function):
17
:return: MVector containing result of function with signature
18
function(double [3])"""
20
su.createFromDouble(0.0, 0.0, 0.0)
21
ptr = su.asDoublePtr()
24
return api.MVector(su.getDoubleArrayItem(ptr,0), su.getDoubleArrayItem(ptr,1), su.getDoubleArrayItem(ptr,2))
26
def in_two_floats_out_tuple(function):
28
:return: tuple containing result of function with signature
29
function(float& f1, float& f2)"""
30
suf1 = MScriptUtil() # keep it, otherwise it might deinitialize its memory
32
pf1 = suf1.asFloatPtr()
33
pf2 = suf2.asFloatPtr()
37
return (MScriptUtil.getFloat(pf1), MScriptUtil.getFloat(pf2))
39
def in_double3_as_vector(function, vec_value):
40
"""Set the value in vec_value to passed in function as double [3] and
43
su.createFromList([vec_value.x, vec_value.y, vec_value.z], 3)
44
ptr = su.asDoublePtr()
48
def undoable_in_double3_as_vector(function, vec_old_value, vec_new_value):
49
"""function supports the signature function(double [3] const) and will
50
change the underlying instance to the respective values as retrieved
51
from the passed in vector.
52
The calling method must be enclosed in an undoable decorator.
54
:param vec_old_value: vector with the old value of the corresponding getX method
55
:param vec_new_value: vector with new value that is to be set"""
56
op = undo.GenericOperation()
57
op.setDoitCmd( in_double3_as_vector, function, vec_new_value)
58
op.setUndoitCmd( in_double3_as_vector, function, vec_old_value )
62
#}END conversion methods