|
|
@@ -1,219 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-# ---------------------------- Operators ------------------------
|
|
3
|
|
-import bpy
|
|
4
|
|
-import math
|
|
5
|
|
-
|
|
6
|
|
-from mathutils import Vector
|
|
7
|
|
-
|
|
8
|
|
-from . import cfg
|
|
9
|
|
-from . import at_interface
|
|
10
|
|
-from . at_calc_func import at_random_fill, fill_rotation
|
|
11
|
|
-
|
|
12
|
|
-
|
|
13
|
|
-class OBJECT_OT_at_start(bpy.types.Operator):
|
|
14
|
|
- """Start and init the addon"""
|
|
15
|
|
- bl_idname = 'scene.at_op'
|
|
16
|
|
- bl_label = "Start array"
|
|
17
|
|
-
|
|
18
|
|
- @classmethod
|
|
19
|
|
- def poll(cls, context):
|
|
20
|
|
- return not context.scene.arraytools_prop.already_start
|
|
21
|
|
-
|
|
22
|
|
- def execute(self, context):
|
|
23
|
|
- cfg.init_array_tool(context)
|
|
24
|
|
- return {'FINISHED'}
|
|
25
|
|
-
|
|
26
|
|
-
|
|
27
|
|
-class OBJECT_OT_at_done(bpy.types.Operator):
|
|
28
|
|
- """Apply the settings"""
|
|
29
|
|
- bl_idname = 'scene.at_done'
|
|
30
|
|
- bl_label = "Done !"
|
|
31
|
|
-
|
|
32
|
|
- def execute(self, context):
|
|
33
|
|
- cfg.atools_objs.clear()
|
|
34
|
|
- #cfg.at_mtx_list.clear()
|
|
35
|
|
- array_col = bpy.data.collections.get(cfg.col_name)
|
|
36
|
|
- cfg.col_name = "Array_collection"
|
|
37
|
|
- context.scene.arraytools_prop.up_ui_reset()
|
|
38
|
|
- context.scene.arraytools_prop.already_start = False
|
|
39
|
|
- return {'FINISHED'}
|
|
40
|
|
-
|
|
41
|
|
-
|
|
42
|
|
-class OBJECT_OT_at_cancel(bpy.types.Operator):
|
|
43
|
|
- """Cancel the settings"""
|
|
44
|
|
- bl_idname = 'scene.at_cancel'
|
|
45
|
|
- bl_label = "Cancel"
|
|
46
|
|
-
|
|
47
|
|
- def execute(self, context):
|
|
48
|
|
- scn = context.scene
|
|
49
|
|
- scn.arraytools_prop.at_del_all(True)
|
|
50
|
|
- scn.arraytools_prop.up_ui_reset()
|
|
51
|
|
- scn.arraytools_prop.already_start = False
|
|
52
|
|
- cfg.col_name = "Array_collection"
|
|
53
|
|
- return {'FINISHED'}
|
|
54
|
|
-
|
|
55
|
|
-
|
|
56
|
|
-class OBJECT_OT_fill_tr(bpy.types.Operator):
|
|
57
|
|
- """Fill the random translation fields"""
|
|
58
|
|
- bl_idname = 'scene.fill_tr'
|
|
59
|
|
- bl_label = "Fill"
|
|
60
|
|
-
|
|
61
|
|
- def execute(self, context):
|
|
62
|
|
- prop = context.scene.arraytools_prop
|
|
63
|
|
- offset = prop.tr_offset
|
|
64
|
|
-
|
|
65
|
|
- for i in range(3):
|
|
66
|
|
- if offset[i] == 0.0:
|
|
67
|
|
- prop.tr_min[i], prop.tr_max[i] = at_random_fill(-3.0, 3.0)
|
|
68
|
|
- else:
|
|
69
|
|
- prop.tr_min[i], prop.tr_max[i] = at_random_fill(-offset[i]/2, offset[i]/2)
|
|
70
|
|
- return{'FINISHED'}
|
|
71
|
|
-
|
|
72
|
|
-
|
|
73
|
|
-class OBJECT_OT_fill_sc(bpy.types.Operator):
|
|
74
|
|
- """Fill the random scale fields"""
|
|
75
|
|
- bl_idname = 'scene.fill_sc'
|
|
76
|
|
- bl_label = "Fill"
|
|
77
|
|
-
|
|
78
|
|
- def execute(self, context):
|
|
79
|
|
- prop = context.scene.arraytools_prop
|
|
80
|
|
- offset = prop.sc_offset
|
|
81
|
|
-
|
|
82
|
|
- if 100 in [offset[0], offset[1], offset[2]]:
|
|
83
|
|
- prop.sc_min_x, prop.sc_max_x = at_random_fill(40.0, 120.0)
|
|
84
|
|
- prop.sc_min_y, prop.sc_max_y = at_random_fill(40.0, 120.0)
|
|
85
|
|
- prop.sc_min_z, prop.sc_max_z = at_random_fill(40.0, 120.0)
|
|
86
|
|
- else:
|
|
87
|
|
- rand = [(100 - offset[i]) / 2 for i in range(3)]
|
|
88
|
|
- print(rand)
|
|
89
|
|
- prop.sc_min_x, prop.sc_max_x = at_random_fill(offset[0]-rand[0], offset[0]+rand[0])
|
|
90
|
|
- prop.sc_min_y, prop.sc_max_y = at_random_fill(offset[1]-rand[1], offset[1]+rand[1])
|
|
91
|
|
- prop.sc_min_z, prop.sc_max_z = at_random_fill(offset[2]-rand[2], offset[2]+rand[2])
|
|
92
|
|
- if prop.sc_all:
|
|
93
|
|
- prop.sc_min_x = prop.sc_min_y = prop.sc_min_z
|
|
94
|
|
- prop.sc_max_x = prop.sc_max_y = prop.sc_max_z
|
|
95
|
|
- return {'FINISHED'}
|
|
96
|
|
-
|
|
97
|
|
-
|
|
98
|
|
-class OBJECT_OT_fill_rot(bpy.types.Operator):
|
|
99
|
|
- """Fill the random rotation fields"""
|
|
100
|
|
- bl_idname = 'scene.fill_rot'
|
|
101
|
|
- bl_label = "Fill"
|
|
102
|
|
-
|
|
103
|
|
- def execute(self, context):
|
|
104
|
|
- fill_rotation(context)
|
|
105
|
|
- return {'FINISHED'}
|
|
106
|
|
-
|
|
107
|
|
-
|
|
108
|
|
-class OBJECT_OT_x360(bpy.types.Operator):
|
|
109
|
|
- """Quick 360 degrees on X axis"""
|
|
110
|
|
- bl_idname = 'scene.x360'
|
|
111
|
|
- bl_label = "360"
|
|
112
|
|
-
|
|
113
|
|
- def execute(self, context):
|
|
114
|
|
- prop = context.scene.arraytools_prop
|
|
115
|
|
- prop.tr_offset = Vector((0.0, 0.0, 0.0))
|
|
116
|
|
- prop.rot_global = Vector((math.pi/180*360, 0.0, 0.0))
|
|
117
|
|
- return{'FINISHED'}
|
|
118
|
|
-
|
|
119
|
|
-
|
|
120
|
|
-class OBJECT_OT_y360(bpy.types.Operator):
|
|
121
|
|
- """Quick 360 degrees on Y axis"""
|
|
122
|
|
- bl_idname = 'scene.y360'
|
|
123
|
|
- bl_label = "360"
|
|
124
|
|
-
|
|
125
|
|
- def execute(self, context):
|
|
126
|
|
- prop = context.scene.arraytools_prop
|
|
127
|
|
- prop.tr_offset = Vector((0.0, 0.0, 0.0))
|
|
128
|
|
- prop.rot_global = Vector((0.0, math.pi/180*360, 0.0))
|
|
129
|
|
- return{'FINISHED'}
|
|
130
|
|
-
|
|
131
|
|
-
|
|
132
|
|
-class OBJECT_OT_z360(bpy.types.Operator):
|
|
133
|
|
- """Quick 360 degrees on Z axis"""
|
|
134
|
|
- bl_idname = 'scene.z360'
|
|
135
|
|
- bl_label = "360"
|
|
136
|
|
-
|
|
137
|
|
- def execute(self, context):
|
|
138
|
|
- prop = context.scene.arraytools_prop
|
|
139
|
|
- prop.tr_offset = Vector((0.0, 0.0, 0.0))
|
|
140
|
|
- prop.rot_global = Vector((0.0, 0.0, math.pi/180*360))
|
|
141
|
|
- return{'FINISHED'}
|
|
142
|
|
-
|
|
143
|
|
-
|
|
144
|
|
-class OBJECT_OT_reset_tr(bpy.types.Operator):
|
|
145
|
|
- """Reset the settings of random translation"""
|
|
146
|
|
- bl_idname = 'scene.at_reset_tr'
|
|
147
|
|
- bl_label = 'Reset'
|
|
148
|
|
-
|
|
149
|
|
- def execute(self, context):
|
|
150
|
|
- prop = context.scene.arraytools_prop
|
|
151
|
|
- prop.tr_min[0], prop.tr_min[1], prop.tr_min[2] = 0.0, 0.0, 0.0
|
|
152
|
|
- prop.tr_max[0], prop.tr_max[1], prop.tr_max[2] = 0.0, 0.0, 0.0
|
|
153
|
|
-
|
|
154
|
|
- # if operator is used many times
|
|
155
|
|
- # get weird result != 0 with vector
|
|
156
|
|
- # prop.tr_max = Vector((0.0, 0.0, 0.0))
|
|
157
|
|
- return {'FINISHED'}
|
|
158
|
|
-
|
|
159
|
|
-
|
|
160
|
|
-class OBJECT_OT_reset_sc(bpy.types.Operator):
|
|
161
|
|
- """Reset the settings of random scale"""
|
|
162
|
|
- bl_idname = 'scene.at_reset_sc'
|
|
163
|
|
- bl_label = 'Reset'
|
|
164
|
|
-
|
|
165
|
|
- def execute(self, context):
|
|
166
|
|
- prop = context.scene.arraytools_prop
|
|
167
|
|
- prop.sc_min_x, prop.sc_min_y, prop.sc_min_z = 100, 100, 100
|
|
168
|
|
- prop.sc_max_x, prop.sc_max_y, prop.sc_max_z = 100, 100, 100
|
|
169
|
|
- return{'FINISHED'}
|
|
170
|
|
-
|
|
171
|
|
-
|
|
172
|
|
-class OBJECT_OT_reset_rot(bpy.types.Operator):
|
|
173
|
|
- """Reset the settings of random rotation"""
|
|
174
|
|
- bl_idname = 'scene.at_reset_rot'
|
|
175
|
|
- bl_label = 'Reset'
|
|
176
|
|
-
|
|
177
|
|
- def execute(self, context):
|
|
178
|
|
- prop = context.scene.arraytools_prop
|
|
179
|
|
- prop.rot_min[0], prop.rot_min[1], prop.rot_min[2] = 0.0, 0.0, 0.0
|
|
180
|
|
- prop.rot_max[0], prop.rot_max[1], prop.rot_max[2] = 0.0, 0.0, 0.0
|
|
181
|
|
- return{'FINISHED'}
|
|
182
|
|
-
|
|
183
|
|
-
|
|
184
|
|
-class OBJECT_OT_reset_second(bpy.types.Operator):
|
|
185
|
|
- """Reset the settings of row options"""
|
|
186
|
|
- bl_idname = 'scene.at_reset_second'
|
|
187
|
|
- bl_label = 'Reset'
|
|
188
|
|
-
|
|
189
|
|
- def execute(self, context):
|
|
190
|
|
- prop = context.scene.arraytools_prop
|
|
191
|
|
- prop.tr_second = (0,0,0)
|
|
192
|
|
- prop.sc_second = (100,100,100)
|
|
193
|
|
- prop.rot_second = (0,0,0)
|
|
194
|
|
- return {'FINISHED'}
|
|
195
|
|
-
|
|
196
|
|
-
|
|
197
|
|
-class OBJECT_OT_error(bpy.types.Operator):
|
|
198
|
|
- """Draw a message box to display error"""
|
|
199
|
|
- bl_idname = "info.at_error"
|
|
200
|
|
- bl_label = "Message info"
|
|
201
|
|
-
|
|
202
|
|
- info: bpy.props.StringProperty(
|
|
203
|
|
- name = "Message",
|
|
204
|
|
- description = "Display a message",
|
|
205
|
|
- default = ''
|
|
206
|
|
- )
|
|
207
|
|
-
|
|
208
|
|
- def execute(self, context):
|
|
209
|
|
- self.report({'INFO'}, self.info)
|
|
210
|
|
- print(self.info)
|
|
211
|
|
- return {'FINISHED'}
|
|
212
|
|
-
|
|
213
|
|
- def invoke(self, context, event):
|
|
214
|
|
- return context.window_manager.invoke_props_dialog(self)
|
|
215
|
|
-
|
|
216
|
|
- def draw(self, context):
|
|
217
|
|
- layout = self.layout
|
|
218
|
|
- layout.label(text=self.info)
|
|
219
|
|
- layout.label(text="")
|