-
Notifications
You must be signed in to change notification settings - Fork 140
/
op_meshtex_trim_collapse.py
60 lines (43 loc) · 1.58 KB
/
op_meshtex_trim_collapse.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
import bpy
import bmesh
from . import utilities_meshtex
def is_available():
# If the selection contains a boolean modifier
obj_textures = utilities_meshtex.find_texture_meshes(bpy.context.selected_objects)
for obj in obj_textures:
for modifier in obj.modifiers:
if modifier.type == 'BOOLEAN':
return True
return False
class op(bpy.types.Operator):
bl_idname = "uv.textools_meshtex_trimcollapse"
bl_label = "Collapse"
bl_description = "Trim Mesh Texture"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if (not bpy.context.active_object) or bpy.context.active_object.mode != 'OBJECT':
return False
return is_available()
def execute(self, context):
collapse(self)
return {'FINISHED'}
def collapse(self):
# Collect texture meshes
obj_textures = utilities_meshtex.find_texture_meshes( bpy.context.selected_objects )
previous_selection = bpy.context.selected_objects.copy()
previous_active = bpy.context.view_layer.objects.active
if len(obj_textures) == 0:
self.report({'ERROR_INVALID_INPUT'}, "No meshes found for mesh textures" )
return
# Apply bool modifier to trim
for obj in obj_textures:
bpy.ops.object.select_all(action='DESELECT')
obj.select_set( state = True, view_layer = None)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.convert(target='MESH')
# restore selection
bpy.ops.object.select_all(action='DESELECT')
for obj in previous_selection:
obj.select_set( state = True, view_layer = None)
bpy.context.view_layer.objects.active = previous_active