forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirrormirror.py
235 lines (174 loc) · 7.97 KB
/
mirrormirror.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#Mirror Mirror Integration V1
import bpy
from bgl import *
from bpy.props import *
from math import radians, degrees
from ... utils.context import ExecutionContext
from ... preferences import tool_overlays_enabled, get_hops_preferences_colors_with_transparency, Hops_display_time, Hops_fadeout_time
from ... utils.blender_ui import get_location_in_current_3d_view
from .. utils import clear_ssharps, mark_ssharps, set_smoothing
from ... overlay_drawer import show_custom_overlay, disable_active_overlays, show_text_overlay
from ... graphics.drawing2d import set_drawing_dpi, draw_horizontal_line, draw_boolean, draw_text, draw_box, draw_logo_csharp
import bpy
from bpy.app.handlers import persistent
#------------------- FUNCTIONS------------------------------
# Do the Basic Union, Difference and Intersection Operations
def Operation(context,_operation):
''' select the object, then select what you want it's mirror object to be '''
#select 2 context object
try:
# select objects
if(len(bpy.context.selected_objects)) == 1 : # one is selected , add mirror mod immediately to that object#
modifier_ob = bpy.context.active_object
mirror_mod = modifier_ob.modifiers.new("mirror_mirror","MIRROR")
else:
mirror_ob = bpy.context.active_object # last ob selected
mirror_ob.select_set(False) # pop modifier_ob from sel_stack
modifier_ob = bpy.context.selected_objects[0]
mirror_mod = modifier_ob.modifiers.new("mirror_mirror","MIRROR")
mirror_mod.mirror_object = mirror_ob
if _operation == "MIRROR_X":
mirror_mod.use_x = True
mirror_mod.use_y = False
mirror_mod.use_z = False
elif _operation == "MIRROR_Y":
mirror_mod.use_x = False
mirror_mod.use_y = True
mirror_mod.use_z = False
elif _operation == "MIRROR_Z":
mirror_mod.use_x = False
mirror_mod.use_y = False
mirror_mod.use_z = True
mirror_ob.select= 1
modifier_ob.select=1
bpy.bpy.context.view_layer.objects.active = modifier_ob
except:
pass
#------------------- OPERATOR CLASSES ------------------------------
# Mirror Tool
class MirrorX(bpy.types.Operator):
"""This adds an X mirror to the selected object"""
bl_idname = "hops.mirror_mirror_x"
bl_label = "Mirror X"
bl_options = {"REGISTER", "UNDO"}
axis = "X"
@classmethod
def poll(cls, context):
object = context.active_object
return context.active_object is not None
def invoke(self, context, event):
self.execute(context)
if tool_overlays_enabled():
disable_active_overlays()
self.wake_up_overlay = show_custom_overlay(draw,
parameter_getter = self.parameter_getter,
location = get_location_in_current_3d_view("CENTER", "BOTTOM", offset = (0, 130)),
location_type = "CUSTOM",
stay_time = Hops_display_time(),
fadeout_time = Hops_fadeout_time())
return {"FINISHED"}
def parameter_getter(self):
return self.axis
def execute(self, context):
Operation(context,"MIRROR_X")
try: self.wake_up_overlay()
except: pass
return {'FINISHED'}
class MirrorY(bpy.types.Operator):
"""This adds a Y mirror modifier"""
bl_idname = "hops.mirror_mirror_y"
bl_label = "Mirror Y"
bl_options = {"REGISTER", "UNDO"}
axis = "Y"
@classmethod
def poll(cls, context):
object = context.active_object
return context.active_object is not None
def invoke(self, context, event):
self.execute(context)
object = bpy.context.active_object
if object.hops.status != "CSTEP":
if tool_overlays_enabled():
disable_active_overlays()
self.wake_up_overlay = show_custom_overlay(draw,
parameter_getter = self.parameter_getter,
location = get_location_in_current_3d_view("CENTER", "BOTTOM", offset = (0, 130)),
location_type = "CUSTOM",
stay_time = Hops_display_time(),
fadeout_time = Hops_fadeout_time())
return {"FINISHED"}
def parameter_getter(self):
return self.axis
def execute(self, context):
Operation(context,"MIRROR_Y")
try: self.wake_up_overlay()
except: pass
return {'FINISHED'}
class MirrorZ(bpy.types.Operator):
"""This add a Z mirror modifier"""
bl_idname = "hops.mirror_mirror_z"
bl_label = "Mirror Z"
bl_options = {"REGISTER", "UNDO"}
axis = "Z"
@classmethod
def poll(cls, context):
object = context.active_object
return context.active_object is not None
def invoke(self, context, event):
self.execute(context)
object = bpy.context.active_object
if object.hops.status != "CSTEP":
if tool_overlays_enabled():
disable_active_overlays()
self.wake_up_overlay = show_custom_overlay(draw,
parameter_getter = self.parameter_getter,
location = get_location_in_current_3d_view("CENTER", "BOTTOM", offset = (0, 130)),
location_type = "CUSTOM",
stay_time = Hops_display_time(),
fadeout_time = Hops_fadeout_time())
return {"FINISHED"}
def parameter_getter(self):
return self.axis
def execute(self, context):
Operation(context,"MIRROR_Z")
try: self.wake_up_overlay()
except: pass
return {'FINISHED'}
# Overlay
###################################################################
def draw(display, parameter_getter):
axis = parameter_getter()
scale_factor = 0.9
glEnable(GL_BLEND)
glEnable(GL_LINE_SMOOTH)
set_drawing_dpi(display.get_dpi() * scale_factor)
dpi_factor = display.get_dpi_factor() * scale_factor
line_height = 18 * dpi_factor
transparency = display.transparency
color_text1, color_text2, color_border, color_border2 = get_hops_preferences_colors_with_transparency(transparency)
region_width = bpy.context.region.width
# Box
########################################################
location = display.location
x, y = location.x - 60* dpi_factor, location.y - 118* dpi_factor
draw_box(0, 43 *dpi_factor, region_width, -4 * dpi_factor, color = color_border2)
draw_box(0, 0, region_width, -82 * dpi_factor, color = color_border)
draw_logo_csharp(color_border2) #Logo so illa. I love this bitch.
# Name
########################################################
draw_text("MIRROR_mirror", x - 380 *dpi_factor , y -12*dpi_factor,
align = "LEFT", size = 20 , color = color_text2)
# First Coloumn
########################################################
x = x - 160 * dpi_factor
r = 34 * dpi_factor
draw_text("AXIS", x , y,
align = "LEFT",size = 11, color = color_text2)
draw_text(axis, x + r, y,
align = "LEFT",size = 11, color = color_text2)
#draw_text("Mirrored Across: ", x, y - line_height,
# align = "LEFT", size = 12, color = color_text2)
#draw_text(axis, x + r, y - line_height,
# align = "LEFT", size = 12, color = color_text2)
glDisable(GL_BLEND)
glDisable(GL_LINE_SMOOTH)