-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutil.py
81 lines (60 loc) · 2.02 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import maya.cmds as cmds
from .utility.nurbs import util
G_LOC_GRP = '_Locators'
G_CTRL_GRP = '_Controllers'
G_JNT_GRP = '_Joints'
G_MESH_GRP = '_Meshes'
def create_locators_on_curve(curve, sample):
"""
Create locators uniformly spread on curve
:param curve: str. single nurbsCurve node
:param sample: int. number of sample points
:return: list. list of locators created
"""
locs = list()
points, tangents = util.get_point_on_curve(curve, sample)
for index in range(len(points)):
point = points[index]
tangent = tangents[index]
loc = cmds.spaceLocator()
locs.append(loc)
temp_node = cmds.createNode('transform')
cmds.xform(
temp_node,
t=[point.x+tangent.x, point.y+tangent.y, point.z+tangent.z]
)
cmds.xform(loc, t=[point.x, point.y, point.z])
constraint = cmds.aimConstraint(temp_node, loc)[0]
cmds.delete([temp_node, constraint])
return locs
def create_outliner_grp():
"""
Create different groups in the outliner
"""
for grp in [G_LOC_GRP, G_JNT_GRP, G_CTRL_GRP, G_MESH_GRP]:
if not cmds.ls(grp):
cmds.group(em=1, name=grp)
def move(obj, pos):
"""
Move object relative to its current position
:param obj: str. maya object
:param pos: list. position x, y and z
"""
return cmds.move(pos[0], pos[1], pos[2], obj, r=1)
def move_to(obj, pos):
"""
Move object to an absolute position (i.e. set transform to position)
:param obj: str. maya object
:param pos: list. position x, y and z
"""
return cmds.move(pos[0], pos[1], pos[2], obj, absolute=1)
def uniform_scale(obj, scale):
"""
Scale object relative to its current scale
:param obj: str. maya object
:param scale: int. uniform scale value
"""
if cmds.nodeType(obj) == 'joint':
default = cmds.getAttr('{}.radius'.format(obj))
return cmds.setAttr('{}.radius'.format(obj), scale * default)
return cmds.scale(scale, scale, scale, obj)