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):
4 years ago
bl_idname = "uv.textools_meshtex_trim"
bl_label = "Trim"
bl_description = "Trim Mesh Texture"
bl_options = {'REGISTER', 'UNDO'}
4 years ago
@classmethod
def poll(cls, context):
if not bpy.context.active_object or bpy.context.active_object.mode != 'OBJECT':
return False
4 years ago
4 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
4 years ago
if len(utilities_meshtex.find_texture_meshes(bpy.context.selected_objects)) > 0:
4 years ago
return True
4 years ago
return False
4 years ago
def execute(self, context):
trim(self)
return {'FINISHED'}
def trim(self):
4 years ago
# Wrap the mesh texture around the
4 years ago
print("Trim Mesh Texture :)")
4 years ago
# Collect UV mesh
obj_uv = utilities_meshtex.find_uv_mesh(bpy.context.selected_objects)
if not obj_uv:
4 years ago
self.report({'ERROR_INVALID_INPUT'}, "No UV mesh found")
4 years ago
return
4 years ago
# Collect texture meshes
4 years ago
obj_textures = utilities_meshtex.find_texture_meshes(
bpy.context.selected_objects)
4 years ago
if len(obj_textures) == 0:
4 years ago
self.report({'ERROR_INVALID_INPUT'},
"No meshes found for mesh textures")
4 years ago
return
4 years ago
# Setup Thickness
utilities_meshtex.uv_mesh_fit(obj_uv, obj_textures)
4 years ago
# Apply bool modifier to trim
for obj in obj_textures:
name = "Trim UV"
4 years ago
if name in obj.modifiers:
4 years ago
obj.modifiers.remove(obj.modifiers[name])
4 years ago
modifier_bool = obj.modifiers.new(name=name, type='BOOLEAN')
modifier_bool.object = obj_uv
4 years ago
bpy.ops.ui.textools_popup(
'INVOKE_DEFAULT', message="Collapse modifiers before wrapping")
bpy.utils.register_class(op)