-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfix_negative_scale.py
64 lines (48 loc) · 1.91 KB
/
fix_negative_scale.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
bl_info = {
"name": "Fix Objects with Negative Scale",
"author": "ambi",
"version": (1, 0),
"blender": (3, 1, 0),
"location": "View3D > Object > Select > Fix Negative Scale",
"description": "Selects all objects in the scene with negative scale and applies the transform",
"category": "Object",
}
import bpy
class OBJECT_OT_fix_negative_scale(bpy.types.Operator):
bl_idname = "object.fix_negative_scale"
bl_label = "Fix Negative Scale"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
mirrored_mesh = {}
objs = bpy.context.scene.objects
for obj in objs:
count = int(obj.scale.x < 0) + int(obj.scale.y < 0) + int(obj.scale.z < 0)
if count % 2 == 1:
if obj.data not in mirrored_mesh:
new_mesh = obj.data.copy()
for v in new_mesh.vertices:
v.co.x *= -1.0
mirrored_mesh[obj.data] = new_mesh
for obj in objs:
count = int(obj.scale.x < 0) + int(obj.scale.y < 0) + int(obj.scale.z < 0)
if count % 2 == 1:
obj.data = mirrored_mesh[obj.data]
obj.scale.x = -obj.scale.x
obj.select_set(True)
else:
obj.select_set(False)
if len(mirrored_mesh) > 0:
self.report({"INFO"}, "Created new meshes: %d" % len(mirrored_mesh))
else:
self.report({"INFO"}, "No negative scale objects found")
return {"FINISHED"}
def menu_func(self, context):
self.layout.operator(OBJECT_OT_fix_negative_scale.bl_idname)
def register():
bpy.utils.register_class(OBJECT_OT_fix_negative_scale)
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_fix_negative_scale)
bpy.types.VIEW3D_MT_object.remove(menu_func)
if __name__ == "__main__":
register()