You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Blender-TexTools/op_meshtex_trim.py

74 lines
2.0 KiB
Python

import bpy
import bmesh
import operator
from mathutils import Vector
from collections import defaultdict
from math import pi
import math
from . import utilities_meshtex
class op(bpy.types.Operator):
5 years ago
bl_idname = "uv.textools_meshtex_trim"
bl_label = "Trim"
bl_description = "Trim Mesh Texture"
bl_options = {'REGISTER', 'UNDO'}
5 years ago
@classmethod
def poll(cls, context):
if not bpy.context.active_object or bpy.context.active_object.mode != 'OBJECT':
return False
5 years ago
5 years ago
if len(bpy.context.selected_objects) >= 1:
# Find a UV mesh
if utilities_meshtex.find_uv_mesh(bpy.context.selected_objects):
# Find 1 or more meshes to wrap
5 years ago
if len(utilities_meshtex.find_texture_meshes(bpy.context.selected_objects)) > 0:
5 years ago
return True
5 years ago
return False
5 years ago
def execute(self, context):
trim(self)
return {'FINISHED'}
def trim(self):
5 years ago
# Wrap the mesh texture around the
5 years ago
print("Trim Mesh Texture :)")
5 years ago
# Collect UV mesh
obj_uv = utilities_meshtex.find_uv_mesh(bpy.context.selected_objects)
if not obj_uv:
5 years ago
self.report({'ERROR_INVALID_INPUT'}, "No UV mesh found")
5 years ago
return
5 years ago
# Collect texture meshes
5 years ago
obj_textures = utilities_meshtex.find_texture_meshes(
bpy.context.selected_objects)
5 years ago
if len(obj_textures) == 0:
5 years ago
self.report({'ERROR_INVALID_INPUT'},
"No meshes found for mesh textures")
5 years ago
return
5 years ago
# Setup Thickness
utilities_meshtex.uv_mesh_fit(obj_uv, obj_textures)
5 years ago
# Apply bool modifier to trim
for obj in obj_textures:
name = "Trim UV"
5 years ago
if name in obj.modifiers:
5 years ago
obj.modifiers.remove(obj.modifiers[name])
5 years ago
modifier_bool = obj.modifiers.new(name=name, type='BOOLEAN')
modifier_bool.object = obj_uv
5 years ago
bpy.ops.ui.textools_popup(
'INVOKE_DEFAULT', message="Collapse modifiers before wrapping")
bpy.utils.register_class(op)