@@ -75,9 +75,7 @@ class Anton_OT_Initializer(bpy.types.Operator):
75
75
bl_description = 'Initializes design space'
76
76
77
77
def execute (self , context ):
78
- """Design space can be defined either via ``SHAPE`` or ``HULL`` mode. In case of ``SHAPE``, existing geometry
79
- is used for design space definition whereas ``HULL`` mode defines a design space with the existing objects as obstacles and
80
- a scaled convexhull as design space boundary.
78
+ """Design space is defined with existing geometry.
81
79
82
80
:ivar objects: List of all the obstacle objects
83
81
:vartype objects: ``list``
@@ -93,109 +91,18 @@ def execute(self, context):
93
91
bpy .context .space_data .shading .type = 'MATERIAL'
94
92
95
93
if not scene .anton .defined :
96
- if scene .anton .mode == 'HULL' :
94
+ scene .anton .filename = active_object . name
97
95
98
- from scipy . spatial import ConvexHull
99
- objects = list ( )
100
- points = list ()
96
+ bpy . ops . export_mesh . stl ( filepath = os . path . join ( scene . anton . workspace_path , scene . anton . filename + '.stl' ), ascii = True )
97
+ active_object . select_set ( True )
98
+ bpy . ops . object . delete ()
101
99
102
- bound_scale = 1.25
103
-
104
- for _obj in bpy .data .objects :
105
- dim = np .array ([_obj .dimensions [0 ], _obj .dimensions [1 ], _obj .dimensions [2 ]])
106
- if np .linalg .norm (dim ) > 0 :
107
- if _obj .name_full != active_object .name_full :
108
- objects .append (_obj )
109
-
110
- theta = _obj .rotation_euler [0 ]
111
- alpha = _obj .rotation_euler [1 ]
112
- beta = _obj .rotation_euler [2 ]
113
-
114
- rot_x = np .array ([[1 , 0 , 0 ], [0 , np .cos (theta ), - 1 * np .sin (theta )], [0 , np .sin (theta ), np .cos (theta )]])
115
- rot_y = np .array ([[np .cos (alpha ), 0 , np .sin (alpha )], [0 , 1 , 0 ], [- 1 * np .sin (alpha ), 0 , np .cos (alpha )]])
116
- rot_z = np .array ([[np .cos (beta ), - 1 * np .sin (beta ), 0 ], [np .sin (beta ), np .cos (beta ), 0 ], [0 , 0 , 1 ]])
117
-
118
- _rotational_matrix = np .matmul (np .matmul (rot_x , rot_y ), rot_z )
119
-
120
- for _vert in _obj .bound_box :
121
- _scaled_bound = bound_scale * np .array ([_obj .scale [0 ] * _vert [0 ], _obj .scale [1 ] * _vert [1 ], _obj .scale [2 ] * _vert [2 ]])
122
- temp = _scaled_bound + np .array ([_obj .location [0 ], _obj .location [1 ], _obj .location [2 ]])
123
- _rotated_bound = np .matmul (_rotational_matrix , temp .T ).T
124
- points .append (_rotated_bound )
125
-
126
- hull = ConvexHull (points )
127
- points = np .array (points )
128
-
129
- with open (os .path .join (scene .anton .workspace_path , 'hull.stl' ), 'w' ) as f :
130
- f .write ('GENERATED BY ANTON\n ' )
131
- for _face in hull .simplices :
132
- _a = points [_face ][1 ] - points [_face ][0 ]
133
- _b = points [_face ][2 ] - points [_face ][0 ]
134
- _cross_product = np .cross (_a , _b )
135
- _normal = 1.0 / np .linalg .norm (_cross_product ) * _cross_product
136
-
137
- f .write ('facet normal {} {} {}\n ' .format (
138
- _normal [0 ],
139
- _normal [1 ],
140
- _normal [2 ]))
141
- f .write ('outer loop\n ' )
142
- for i in range (3 ):
143
- f .write ('vertex {} {} {}\n ' .format (
144
- points [_face ][i ][0 ],
145
- points [_face ][i ][1 ],
146
- points [_face ][i ][2 ]))
147
-
148
- f .write ('endloop\n ' )
149
- f .write ('endfacet\n ' )
150
-
151
- f .write ('endsolid\n ' )
152
-
153
- active_object .select_set (True )
154
-
155
- for _obj in objects :
156
- bpy .ops .object .modifier_add (type = 'BOOLEAN' )
157
- bpy .context .object .modifiers ["Boolean" ].operation = 'UNION'
158
- bpy .context .object .modifiers ["Boolean" ].object = _obj
159
- bpy .ops .object .modifier_apply (apply_as = 'DATA' , modifier = "Boolean" )
160
-
161
- bpy .ops .object .select_all (action = 'DESELECT' )
162
- _obj .select_set (True )
163
- bpy .ops .object .delete ()
164
-
165
- active_object .select_set (True )
166
-
167
- scene .anton .filename = active_object .name
168
-
169
- bpy .ops .import_mesh .stl (filepath = os .path .join (scene .anton .workspace_path , 'hull.stl' ))
170
- bpy .ops .object .modifier_add (type = 'BOOLEAN' )
171
- bpy .context .object .modifiers ["Boolean" ].operation = 'DIFFERENCE'
172
- bpy .context .object .modifiers ["Boolean" ].object = active_object
173
- bpy .ops .object .modifier_apply (apply_as = 'DATA' , modifier = "Boolean" )
174
-
175
- bpy .ops .object .select_all (action = 'DESELECT' )
176
- active_object .select_set (True )
177
- bpy .ops .object .delete ()
178
-
179
- bpy .ops .export_mesh .stl (filepath = os .path .join (scene .anton .workspace_path , scene .anton .filename + '.stl' ), ascii = True )
180
- active_object = bpy .context .active_object
181
- active_object .select_set (True )
182
- bpy .ops .object .delete ()
183
-
184
- bpy .ops .import_mesh .stl (filepath = os .path .join (scene .anton .workspace_path , scene .anton .filename + '.stl' ))
185
-
186
- else :
187
- scene .anton .filename = active_object .name
188
-
189
- bpy .ops .export_mesh .stl (filepath = os .path .join (scene .anton .workspace_path , scene .anton .filename + '.stl' ), ascii = True )
190
- active_object .select_set (True )
191
- bpy .ops .object .delete ()
192
-
193
- bpy .ops .import_mesh .stl (filepath = os .path .join (scene .anton .workspace_path , scene .anton .filename + '.stl' ))
100
+ bpy .ops .import_mesh .stl (filepath = os .path .join (scene .anton .workspace_path , scene .anton .filename + '.stl' ))
194
101
195
102
active_object = bpy .context .active_object
196
103
197
104
scene .anton .initialized = True
198
- self .report ({'INFO' }, 'Mode: {}' . format ( scene . anton . mode ) )
105
+ self .report ({'INFO' }, 'Initialized design space.' )
199
106
return {'FINISHED' }
200
107
else :
201
108
self .report ({'ERROR' }, 'Design space has already been initialized. In order to re-initialize, kindly restart the process.' )
0 commit comments