-
Notifications
You must be signed in to change notification settings - Fork 0
/
leanAgainstWall.py
89 lines (72 loc) · 3.22 KB
/
leanAgainstWall.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
82
83
84
85
86
87
88
89
import maya.cmds as cmds
import math
class LeanObject:
wall = None
object = None
def loadInWall(self):
LeanObject.wall = cmds.ls(sl=True)
def loadInObject(self):
LeanObject.object = cmds.ls(sl=True)
def leanIt(self):
directionList = FindPolyInformation().direction()
angleForRot = FindPolyInformation().findAxis()
if angleForRot[0] == True:
if directionList[0] == -1:
rot, piv = FindPolyInformation().findRotXNeg()
else:
rot, piv = FindPolyInformation().findRotXPos()
cmds.rotate(rot, 0, 0, LeanObject.object, pivot=piv)
elif angleForRot[2] == True:
if directionList[2] == 1:
rot, piv = FindPolyInformation().findRotZNeg()
else:
rot, piv = FindPolyInformation().findRotZPos()
cmds.rotate(0, 0, rot, LeanObject.object, pivot=piv)
class FindPolyInformation:
def __init__(self):
cmds.select(LeanObject.wall)
self.xmin_Wall, self.ymin_Wall, self.zmin_Wall, self.xmax_Wall, self.ymax_Wall, self.zmax_Wall = \
cmds.xform(bb=True, query=True)
cmds.select(LeanObject.object)
self.xmin_Obj, self.ymin_Obj, self.zmin_Obj, self.xmax_Obj, self.ymax_Obj, self.zmax_Obj = \
cmds.xform(bb=True, query=True)
def findRotXPos(self):
adjacentLine = abs(self.zmax_Obj - self.zmin_Wall)
hypLine = self.ymax_Obj
return (90 - radiansToDegree(math.acos(adjacentLine / hypLine))), \
[(self.xmax_Obj + self.xmin_Obj) / 2.0, 0, self.zmax_Obj]
def findRotXNeg(self):
adjacentLine = abs(self.zmin_Obj - self.zmax_Wall)
hypLine = self.ymax_Obj
return (-90 + radiansToDegree(math.acos(adjacentLine / hypLine))), \
[(self.xmax_Obj + self.xmin_Obj) / 2.0, 0, self.zmin_Obj]
def findRotZPos(self):
adjacentLine = abs(self.xmin_Obj - self.xmax_Wall)
hypLine = self.ymax_Obj
return 90 - radiansToDegree(math.acos(adjacentLine/hypLine)), \
[self.xmin_Obj, 0, (self.zmax_Obj + self.zmin_Obj)/2.0]
def findRotZNeg(self):
adjacentLine = abs(self.xmax_Obj - self.xmin_Wall)
hypLine = self.ymax_Obj
return -90 + radiansToDegree(math.acos(adjacentLine / hypLine)), \
[self.xmax_Obj, 0, (self.zmax_Obj + self.zmin_Obj) / 2.0]
def direction(self):
direction = [0, 0, 0]
if (self.xmax_Obj + self.xmin_Obj)/2.0 > (self.xmax_Wall + self.xmin_Wall)/2.0:
direction[2] = -1
elif (self.xmax_Obj + self.xmin_Obj)/2.0 < (self.xmax_Wall + self.xmin_Wall)/2.0:
direction[2] = 1
if (self.zmax_Obj + self.zmin_Obj)/2.0 > (self.zmax_Wall + self.zmin_Wall)/2.0:
direction[0] = -1
elif (self.zmax_Obj + self.zmin_Obj)/2.0 < (self.zmax_Wall + self.zmin_Wall)/2.0:
direction[0] = 1
return direction
def findAxis(self):
angles = [False, False, False]
if abs((self.xmax_Wall - self.xmin_Wall)) > abs((self.zmax_Wall - self.zmin_Wall)):
angles[0] = True
else:
angles[2] = True
return angles
def radiansToDegree(radian):
return radian * 180 / 3.14