-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_math.py
60 lines (52 loc) · 2.67 KB
/
test_math.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
import math
import pymel.core as pm
from maya.api import OpenMaya
maya_useNewAPI = True
def check_for_intermediate_joint(joint_1_dag, joint_2_dag):
dagModifer_1 = OpenMaya.MFnDagNode(joint_1_dag)
dagModifer_2 = OpenMaya.MFnDagNode(joint_2_dag)
joint_1_child = dagModifer_1.child(0)
joint_2_parent = dagModifer_2.parent(0)
if joint_1_child and joint_2_dag :
if joint_1_child == joint_2_parent :
joint_3_dag = OpenMaya.MDagPath.getAPathTo(joint_1_child)
return joint_1_child, joint_3_dag
else :
OpenMaya.MGlobal.displayError('There is no intermediate child beetween {} and {}'.format(joint_1_dag.partialPathName(),
joint_2_dag.partialPathName()))
def build_translate_joints(start, end) :
print(start)
print(end)
start_joint = pm.PyNode(start)
end_joint = pm.PyNode(end)
start_pos = (pm.getAttr(start_joint.translateX),
pm.getAttr(start_joint.translateY),
pm.getAttr(start_joint.translateZ))
end_pos = pm.xform(end_joint,q=True,t=True,ws=True)
'''end_pos = (pm.getAttr(end_joint.translateX)+pm.getAttr(mid_joint.translateX),
pm.getAttr(end_joint.translateY)+pm.getAttr(mid_joint.translateY),
pm.getAttr(end_joint.translateZ) + pm.getAttr(mid_joint.translateZ))'''
print(start_pos)
pm.select(cl = True)
effector_start = pm.joint(name = 'TranslationStartJoint', p = start_pos)
effectort_end = pm.joint(name= 'TranslateEndJoint', p= end_pos)
pm.joint(effector_start, edit=True, oj = 'xyz', sao='yup')
pm.joint(effectort_end,edit = True, o= (0, 0, 0))
def select_joints():
#selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.setTrackSelectionOrderEnabled(True)
selection = OpenMaya.MGlobal.getActiveSelectionList()
print(OpenMaya.MGlobal.trackSelectionOrderEnabled())
if selection.length() == 2 :
crank_rotation_joint_dag = selection.getDagPath(0)
crank_rotation_joint_node = crank_rotation_joint_dag.node()
shaft_end_dag = selection.getDagPath(1)
shaft_end_node = shaft_end_dag.node()
shaft_start_node, shaft_start_dag = check_for_intermediate_joint(crank_rotation_joint_dag,shaft_end_dag)
return crank_rotation_joint_dag, shaft_start_dag, shaft_end_dag
else :
OpenMaya.MGlobal.displayError('You need to select 2 joints : {} selected'.format(selection.length()))
def build_setup() :
rotate_center,crank_end, shaft_end = select_joints()
build_translate_joints(rotate_center, shaft_end)
build_setup()