-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIncremental_Bone_Rotation.py
185 lines (138 loc) · 5.79 KB
/
Incremental_Bone_Rotation.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
bl_info = {
"name": "Incremental bone rotation",
"author": "Hannah Ümit <twitter.com/HannahUmit>",
"version": (1,0),
"blender": (2, 80, 0),
"category": "Edit",
"location": "3D Viewport",
"description": " USE F3 AND TYPE IN INCREMENTAL BONE!!! Incremental bone rotation EAT SHIT PUSSIES, formula by Sas van Gulik, implemented by yours truly. ALSO TO REMOVE THE INCREMENTAL BONE ROTATION, RMEOVE THE DRIVER AND CUSTOM PROPERTY LOL IDFK HOW TO FIX THAT SHIT RN",
"warning": "",
"doc_url": "",
"tracker_url": "",
}
import bpy
from rna_prop_ui import rna_idprop_ui_create
class IncrementalBoneRotation(bpy.types.Operator):
"""Tooltip"""
bl_idname = "select.incrementalbonerotation_operator"
bl_label = "Incremental Bone Rotation"
bl_options = {'REGISTER', 'UNDO'}
x_rotincui: bpy.props.BoolProperty(
name="X",
description='Amount of degrees that you want to incrementally rotate in the X axis',
default=False,
)
y_rotincui: bpy.props.BoolProperty(
name="Y",
description='Amount of degrees that you want to incrementally rotate in the Y axis',
default=False,
)
z_rotincui: bpy.props.BoolProperty(
name="Z",
description='Amount of degrees that you want to incrementally rotate in the Z axis',
default=False,
)
def execute(self, context):
obj = context.active_pose_bone
if self.x_rotincui:
obj.rotation_mode = 'XYZ'
rna_idprop_ui_create(
obj,
"increments_X",
default = 10,
min=0, max=360,
soft_min=None, soft_max=None,
description="Amount of degrees that you want to incrementally rotate in the X axis",
overridable=False,
subtype=None,
)
Xpath = obj.path_from_id() + "[\"increments_X\"]"
#create driver
Xdriver = obj.driver_add("rotation_euler", 0)
Xdriver.driver.type = 'SCRIPTED'
Xdriver.driver.use_self = True
Xdriver.driver.expression = "round( self.rotation_euler.x / float (radians(increment_rot)) ) * (radians(increment_rot))"
#change driver variable properties
Xvar = Xdriver.driver.variables.new()
Xvar.name = 'increment_rot'
Xvar.type = 'SINGLE_PROP'
Xvar.targets[0].id = bpy.context.active_object
Xvar.targets[0].data_path = Xpath
if self.y_rotincui:
obj.rotation_mode = 'XYZ'
rna_idprop_ui_create(
obj,
"increments_Y",
default = 10,
min=0, max=360,
soft_min=None, soft_max=None,
description="Amount of degrees that you want to incrementally rotate in the Y axis",
overridable=False,
subtype=None,
)
Ypath = obj.path_from_id() + "[\"increments_Y\"]"
#create driver
Ydriver = obj.driver_add("rotation_euler", 1)
Ydriver.driver.type = 'SCRIPTED'
Ydriver.driver.use_self = True
Ydriver.driver.expression = "round( self.rotation_euler.y / float (radians(increment_rot)) ) * (radians(increment_rot))"
#change driver variable properties
Yvar = Ydriver.driver.variables.new()
Yvar.name = 'increment_rot'
Yvar.type = 'SINGLE_PROP'
Yvar.targets[0].id = bpy.context.active_object
Yvar.targets[0].data_path = Ypath
if self.z_rotincui:
obj.rotation_mode = 'XYZ'
rna_idprop_ui_create(
obj,
"increments_Z",
default = 10,
min=0, max=360,
soft_min=None, soft_max=None,
description="Amount of degrees that you want to incrementally rotate in the Z axis",
overridable=False,
subtype=None,
)
Zpath = obj.path_from_id() + "[\"increments_Z\"]"
#create driver
Zdriver = obj.driver_add("rotation_euler", 2)
Zdriver.driver.type = 'SCRIPTED'
Zdriver.driver.use_self = True
Zdriver.driver.expression = "round( self.rotation_euler.z / float (radians(increment_rot)) ) * (radians(increment_rot))"
#change driver variable properties
Zvar = Zdriver.driver.variables.new()
Zvar.name = 'increment_rot'
Zvar.type = 'SINGLE_PROP'
Zvar.targets[0].id = bpy.context.active_object
Zvar.targets[0].data_path = Zpath
return {'FINISHED'}
# class RemoveBoneRotation(bpy.types.Operator):
#
# def execute(self, context):
#
# removeinc_x = bpy.ops.wm.properties_remove(data_path="active_pose_bone", property_name="increments_X")
# removeinc_y = bpy.ops.wm.properties_remove(data_path="active_pose_bone", property_name="increments_Y")
# removeinc_z = bpy.ops.wm.properties_remove(data_path="active_pose_bone", property_name="increments_Z")
#
# if "FINISHED" in removeinc_x:
# bpy.context.active_pose_bone.driver_remove("rotation_euler", 0)
#
# if "FINISHED" in removeinc_y:
# bpy.context.active_pose_bone.driver_remove("rotation_euler", 1)
#
# if "FINISHED" in removeinc_z:
# bpy.context.active_pose_bone.driver_remove("rotation_euler", 2)
#
# return {'FINISHED'}
blender_classes = [
IncrementalBoneRotation
]
def register():
for blender_class in blender_classes:
bpy.utils.register_class(blender_class)
def unregister():
for blender_class in blender_classes:
bpy.utils.unregister_class(blender_class)
if __name__ == "__main__":
register()