Skip to content

Commit a9a1436

Browse files
committed
Refactored blanket imports of global util modules
Blanket importing the global util modules may cause unintended name collisions when a matching module is present in the subpackage in question. To mitigate this, blanket imports were replaced by imports of specific members only.
1 parent 03fce2e commit a9a1436

File tree

27 files changed

+178
-178
lines changed

27 files changed

+178
-178
lines changed

Arma3ObjectBuilder/io_armature/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import bpy_extras
33

44
from . import importer
5-
from .. import utils
5+
from ..utils import op_report, is_valid_idx
66

77

88
class A3OB_OT_import_armature(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
@@ -37,13 +37,13 @@ def draw(self, context):
3737

3838
def execute(self, context):
3939
scene_props = context.scene.a3ob_rigging
40-
if not utils.is_valid_idx(self.skeleton_index, scene_props.skeletons):
41-
utils.op_report(self, {'ERROR'}, "No skeleton was selected")
40+
if not is_valid_idx(self.skeleton_index, scene_props.skeletons):
41+
op_report(self, {'ERROR'}, "No skeleton was selected")
4242
return {'FINISHED'}
4343

4444
skeleton = scene_props.skeletons[self.skeleton_index]
4545
if not importer.is_valid_skeleton(skeleton):
46-
utils.op_report(self, {'ERROR'}, "Invalid skeleton definiton, run skeleton validation for RTM for more info")
46+
op_report(self, {'ERROR'}, "Invalid skeleton definiton, run skeleton validation for RTM for more info")
4747
return {'FINISHED'}
4848

4949
importer.import_armature(self, skeleton)

Arma3ObjectBuilder/io_asc/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import bpy_extras
33

44
from . import props, importer, exporter
5-
from .. import utils
6-
from .. import utils_io
5+
from ..utils import op_report, PanelHeaderLinkMixin
6+
from ..utils_io import ExportFileHandler
77

88

9-
class A3OB_PT_object_dtm(bpy.types.Panel, utils.PanelHeaderLinkMixin):
9+
class A3OB_PT_object_dtm(bpy.types.Panel, PanelHeaderLinkMixin):
1010
bl_region_type = 'WINDOW'
1111
bl_space_type = 'PROPERTIES'
1212
bl_label = "Object Builder: DTM Properties"
@@ -75,7 +75,7 @@ def draw(self, context):
7575
def execute(self, context):
7676
with open(self.filepath) as file:
7777
importer.read_file(self, context, file)
78-
utils.op_report(self, {'INFO'}, "Successfully imported DTM")
78+
op_report(self, {'INFO'}, "Successfully imported DTM")
7979

8080
return {'FINISHED'}
8181

@@ -153,9 +153,9 @@ def draw(self, context):
153153
def execute(self, context):
154154
obj = context.active_object
155155

156-
with utils_io.ExportFileHandler(self.filepath, "wt") as file:
156+
with ExportFileHandler(self.filepath, "wt") as file:
157157
exporter.write_file(self, context, file, obj)
158-
utils.op_report(self, {'INFO'}, "Successfuly exported DTM")
158+
op_report(self, {'INFO'}, "Successfuly exported DTM")
159159

160160
return {'FINISHED'}
161161

Arma3ObjectBuilder/io_mcfg/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from . import importer, exporter
55
from .validator import SkeletonValidator
6-
from .. import utils
7-
from .. import utils_io
6+
from ..utils import op_report
7+
from ..utils_io import ExportFileHandler
88
from ..logger import ProcessLoggerNull
99

1010

@@ -42,10 +42,10 @@ def execute(self, context):
4242
count_skeletons = importer.read_file(self, context)
4343

4444
if count_skeletons > 0:
45-
utils.op_report(self, {'INFO'}, "Successfully imported %d skeleton(s)" % count_skeletons)
45+
op_report(self, {'INFO'}, "Successfully imported %d skeleton(s)" % count_skeletons)
4646
return {'FINISHED'}
4747

48-
utils.op_report(self, {'ERROR'}, "Could not import any skeletons (check the system console)")
48+
op_report(self, {'ERROR'}, "Could not import any skeletons (check the system console)")
4949

5050
return {'FINISHED'}
5151

@@ -109,12 +109,12 @@ def execute(self, context):
109109

110110
validator = SkeletonValidator(ProcessLoggerNull())
111111
if not validator.validate(skeleton, False, True):
112-
utils.op_report(self, {'ERROR'}, "Invalid skeleton definiton, run skeleton validation for more info")
112+
op_report(self, {'ERROR'}, "Invalid skeleton definiton, run skeleton validation for more info")
113113
return {'FINISHED'}
114114

115-
with utils_io.ExportFileHandler(self.filepath, "w") as file:
115+
with ExportFileHandler(self.filepath, "w") as file:
116116
exporter.write_file(self, skeleton, file)
117-
utils.op_report(self, {'INFO'}, "Successfuly exported %s" % skeleton.name)
117+
op_report(self, {'INFO'}, "Successfuly exported %s" % skeleton.name)
118118

119119
return {'FINISHED'}
120120

Arma3ObjectBuilder/io_p3d/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from . import ui_object, ui_mat
77
from . import importer, exporter
88
from .. import get_prefs
9-
from .. import utils
10-
from .. import utils_io
9+
from ..utils import op_report
10+
from ..utils_io import ExportFileHandler
1111

1212

1313
class A3OB_OT_import_p3d(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
@@ -103,7 +103,7 @@ def draw(self, context):
103103
def execute(self, context):
104104
with open(self.filepath, "rb") as file:
105105
lod_objects = importer.read_file(self, context, file)
106-
utils.op_report(self, {'INFO'}, "Successfully imported %d LODs (check the logs in the system console)" % len(lod_objects))
106+
op_report(self, {'INFO'}, "Successfully imported %d LODs (check the logs in the system console)" % len(lod_objects))
107107

108108
return {'FINISHED'}
109109

@@ -323,20 +323,20 @@ def draw(self, context):
323323

324324
def execute(self, context):
325325
if not exporter.can_export(self, context):
326-
utils.op_report(self, {'ERROR'}, "There are no LODs to export")
326+
op_report(self, {'ERROR'}, "There are no LODs to export")
327327
return {'FINISHED'}
328328

329329
temp_collection = exporter.create_temp_collection(context)
330330

331-
with utils_io.ExportFileHandler(self.filepath, "wb") as file:
331+
with ExportFileHandler(self.filepath, "wb") as file:
332332
# The export needs to be put inside a try-catch block in order to do the temporary object cleanup.
333333
try:
334334
lod_count, exported_count = exporter.write_file(self, context, file, temp_collection)
335335

336336
if lod_count == exported_count:
337-
utils.op_report(self, {'INFO'}, "Successfully exported all %d LODs (check the logs in the system console)" % exported_count)
337+
op_report(self, {'INFO'}, "Successfully exported all %d LODs (check the logs in the system console)" % exported_count)
338338
else:
339-
utils.op_report(self, {'WARNING'}, "Only exported %d/%d LODs (check the logs in the system console)" % (exported_count, lod_count))
339+
op_report(self, {'WARNING'}, "Only exported %d/%d LODs (check the logs in the system console)" % (exported_count, lod_count))
340340

341341
finally:
342342
if not get_prefs().preserve_preprocessed_lods:

Arma3ObjectBuilder/io_p3d/exporter.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from . import flags as p3d_flags
1616
from .validator import LODValidator
1717
from .. import get_prefs
18-
from .. import utils
19-
from .. import utils_compat as computils
18+
from ..utils import edit_bmesh
19+
from ..utils_compat import call_operator_ctx, mesh_auto_smooth, mesh_static_normals_iterator
2020
from ..logger import ProcessLogger, ProcessLoggerNull
2121

2222

@@ -83,7 +83,7 @@ def apply_modifiers(obj):
8383
m = modifiers.pop(0)
8484
try:
8585
ctx["modifier"] = m
86-
computils.call_operator_ctx(bpy.ops.object.modifier_apply, ctx, modifier= m.name)
86+
call_operator_ctx(bpy.ops.object.modifier_apply, ctx, modifier= m.name)
8787
except:
8888
obj.modifiers.remove(m)
8989

@@ -95,13 +95,13 @@ def apply_transforms(obj):
9595
"selected_editable_objects": [obj],
9696
"edit_object": None
9797
}
98-
computils.call_operator_ctx(bpy.ops.object.transform_apply, ctx)
98+
call_operator_ctx(bpy.ops.object.transform_apply, ctx)
9999

100100

101101
# In order to simplify merging the LOD parts, and the data access later on, the dereferenced
102102
# flags need to be written directly into their respective integer bmesh layers.
103103
def bake_flags_vertex(obj):
104-
with utils.edit_bmesh(obj) as bm:
104+
with edit_bmesh(obj) as bm:
105105
bm.verts.ensure_lookup_table()
106106

107107
layer = p3d_flags.get_layer_flags_vertex(bm)
@@ -117,7 +117,7 @@ def bake_flags_vertex(obj):
117117

118118

119119
def bake_flags_face(obj):
120-
with utils.edit_bmesh(obj) as bm:
120+
with edit_bmesh(obj) as bm:
121121
bm.faces.ensure_lookup_table()
122122

123123
layer = p3d_flags.get_layer_flags_face(bm)
@@ -133,7 +133,7 @@ def bake_flags_face(obj):
133133

134134

135135
def blank_flags_vertex(obj):
136-
with utils.edit_bmesh(obj) as bm:
136+
with edit_bmesh(obj) as bm:
137137
bm.verts.ensure_lookup_table()
138138
layer = p3d_flags.get_layer_flags_vertex(bm)
139139

@@ -142,7 +142,7 @@ def blank_flags_vertex(obj):
142142

143143

144144
def blank_flags_face(obj):
145-
with utils.edit_bmesh(obj) as bm:
145+
with edit_bmesh(obj) as bm:
146146
bm.faces.ensure_lookup_table()
147147
layer = p3d_flags.get_layer_flags_face(bm)
148148

@@ -172,7 +172,7 @@ def merge_sub_objects(operator, main_obj, sub_objects):
172172
"selected_objects": all_objects,
173173
"selected_editable_objects": all_objects
174174
}
175-
computils.call_operator_ctx(bpy.ops.object.join, ctx)
175+
call_operator_ctx(bpy.ops.object.join, ctx)
176176

177177

178178
def merge_proxy_objects(main_obj, proxy_objects, relative):
@@ -201,7 +201,7 @@ def merge_proxy_objects(main_obj, proxy_objects, relative):
201201
"selected_objects": all_objects,
202202
"selected_editable_objects": all_objects
203203
}
204-
computils.call_operator_ctx(bpy.ops.object.join, ctx)
204+
call_operator_ctx(bpy.ops.object.join, ctx)
205205

206206
return proxy_lookup
207207

@@ -239,7 +239,7 @@ def get_sub_objects(obj, temp_collection):
239239
continue
240240

241241
if not child.mode == 'OBJECT':
242-
computils.call_operator_ctx(bpy.ops.object.mode_set, {"active_object": child}, mode='OBJECT')
242+
call_operator_ctx(bpy.ops.object.mode_set, {"active_object": child}, mode='OBJECT')
243243

244244
child_copy = duplicate_object(child, temp_collection)
245245

@@ -256,7 +256,7 @@ def sort_sections(obj):
256256
for i in range(len(obj.material_slots)):
257257
sections[i] = []
258258

259-
with utils.edit_bmesh(obj) as bm:
259+
with edit_bmesh(obj) as bm:
260260
bm.faces.ensure_lookup_table()
261261

262262
for face in bm.faces:
@@ -282,8 +282,8 @@ def cleanup_normals(operator, obj):
282282
"active_object": obj,
283283
"object": obj
284284
}
285-
computils.call_operator_ctx(bpy.ops.mesh.customdata_custom_splitnormals_clear, ctx)
286-
computils.mesh_auto_smooth(obj.data)
285+
call_operator_ctx(bpy.ops.mesh.customdata_custom_splitnormals_clear, ctx)
286+
mesh_auto_smooth(obj.data)
287287
mod = obj.modifiers.new("Temp", 'WEIGHTED_NORMAL')
288288
mod.weight = 50
289289
mod.keep_sharp = True
@@ -337,7 +337,7 @@ def get_lod_data(operator, context, validator, temp_collection):
337337

338338
# Some operator polls fail later if an object is in edit mode.
339339
if not obj.mode == 'OBJECT':
340-
computils.call_operator_ctx(bpy.ops.object.mode_set, {"active_object": obj}, mode='OBJECT')
340+
call_operator_ctx(bpy.ops.object.mode_set, {"active_object": obj}, mode='OBJECT')
341341

342342
main_obj = duplicate_object(obj, temp_collection)
343343
is_valid = True
@@ -410,7 +410,7 @@ def process_normals(mesh):
410410
normals_index = {}
411411
normals_lookup_dict = {}
412412

413-
for i, normal in computils.mesh_static_normals_iterator(mesh):
413+
for i, normal in mesh_static_normals_iterator(mesh):
414414
if normal not in normals_index:
415415
normals_index[normal] = len(normals_index)
416416
output.append(normal)

Arma3ObjectBuilder/io_p3d/flags.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Helper functions to handle vertex and face flag values.
22

33

4-
from .. import utils
4+
from ..utils import edit_bmesh
55

66

77
flags_vertex_surface = {
@@ -180,7 +180,7 @@ def set_flag_face(props, value):
180180

181181

182182
def remove_group_vertex(obj, group_id):
183-
with utils.edit_bmesh(obj) as bm:
183+
with edit_bmesh(obj) as bm:
184184
bm.verts.ensure_lookup_table()
185185
layer = get_layer_flags_vertex(bm)
186186
for vertex in bm.verts:
@@ -189,7 +189,7 @@ def remove_group_vertex(obj, group_id):
189189

190190

191191
def assign_group_vertex(obj, group_id):
192-
with utils.edit_bmesh(obj) as bm:
192+
with edit_bmesh(obj) as bm:
193193
bm.verts.ensure_lookup_table()
194194

195195
layer = get_layer_flags_vertex(bm)
@@ -201,7 +201,7 @@ def assign_group_vertex(obj, group_id):
201201

202202
def select_group_vertex(obj, group_id, select = True):
203203
group_count = len(obj.a3ob_properties_object_flags.vertex)
204-
with utils.edit_bmesh(obj) as bm:
204+
with edit_bmesh(obj) as bm:
205205
bm.verts.ensure_lookup_table()
206206

207207
layer = get_layer_flags_vertex(bm)
@@ -212,7 +212,7 @@ def select_group_vertex(obj, group_id, select = True):
212212

213213

214214
def clear_groups_vertex(obj):
215-
with utils.edit_bmesh(obj) as bm:
215+
with edit_bmesh(obj) as bm:
216216
flag_props = obj.a3ob_properties_object_flags
217217
flag_props.vertex.clear()
218218
flag_props.vertex_index = -1
@@ -221,7 +221,7 @@ def clear_groups_vertex(obj):
221221

222222

223223
def remove_group_face(obj, group_id):
224-
with utils.edit_bmesh(obj) as bm:
224+
with edit_bmesh(obj) as bm:
225225
bm.verts.ensure_lookup_table()
226226
layer = get_layer_flags_vertex(bm)
227227
for vertex in bm.verts:
@@ -230,7 +230,7 @@ def remove_group_face(obj, group_id):
230230

231231

232232
def assign_group_face(obj, group_id):
233-
with utils.edit_bmesh(obj) as bm:
233+
with edit_bmesh(obj) as bm:
234234
bm.faces.ensure_lookup_table()
235235

236236
layer = get_layer_flags_face(bm)
@@ -242,7 +242,7 @@ def assign_group_face(obj, group_id):
242242

243243
def select_group_face(obj, group_id, select = True):
244244
group_count = len(obj.a3ob_properties_object_flags.face)
245-
with utils.edit_bmesh(obj) as bm:
245+
with edit_bmesh(obj) as bm:
246246
bm.faces.ensure_lookup_table()
247247

248248
layer = get_layer_flags_face(bm)
@@ -253,7 +253,7 @@ def select_group_face(obj, group_id, select = True):
253253

254254

255255
def clear_groups_face(obj):
256-
with utils.edit_bmesh(obj) as bm:
256+
with edit_bmesh(obj) as bm:
257257
flag_props = obj.a3ob_properties_object_flags
258258
flag_props.face.clear()
259259
flag_props.face_index = -1

Arma3ObjectBuilder/io_p3d/importer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from . import data as p3d
1414
from . import flags as p3d_flags
1515
from . import utils as p3d_utils
16-
from .. import utils_io
17-
from .. import utils_compat as computils
16+
from ..utils_io import restore_absolute
17+
from ..utils_compat import call_operator_ctx, mesh_auto_smooth
1818
from ..logger import ProcessLogger
1919

2020

@@ -222,7 +222,7 @@ def process_proxies(operator, obj, proxy_lookup, empty_material):
222222
continue
223223

224224
obj.vertex_groups.active = vgroup
225-
computils.call_operator_ctx(bpy.ops.object.vertex_group_select)
225+
call_operator_ctx(bpy.ops.object.vertex_group_select)
226226

227227
try:
228228
bpy.ops.mesh.separate(type='SELECTED')
@@ -253,7 +253,7 @@ def process_proxies(operator, obj, proxy_lookup, empty_material):
253253

254254
path, index = proxy_lookup[vgroup.name]
255255
proxy_obj.vertex_groups.remove(vgroup)
256-
proxy_obj.a3ob_properties_object_proxy.proxy_path = utils_io.restore_absolute(path, ".p3d") if operator.absolute_paths else path
256+
proxy_obj.a3ob_properties_object_proxy.proxy_path = restore_absolute(path, ".p3d") if operator.absolute_paths else path
257257
proxy_obj.a3ob_properties_object_proxy.proxy_index = index
258258

259259
proxy_obj.a3ob_properties_object_flags.vertex.clear()
@@ -323,7 +323,7 @@ def process_lod(operator, logger, lod, materials, materials_lookup, categories,
323323
for face in mesh.polygons:
324324
face.use_smooth = True
325325

326-
computils.mesh_auto_smooth(mesh)
326+
mesh_auto_smooth(mesh)
327327

328328
if 'NORMALS' in operator.additional_data and lod_index in p3d.P3D_LOD_Resolution.LODS_VISUAL:
329329
if process_normals(mesh, lod):

0 commit comments

Comments
 (0)