TexTools is a UV and Texture tool set for 3dsMax created several years ago. This open repository will port in time several of the UV tools to Blender in python. http://renderhjs.net/textools/blender
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

97 lines
2.9 KiB

import bpy
import os
import bmesh
from mathutils import Vector
from collections import defaultdict
from math import pi
from . import utilities_uv
from . import utilities_ui
class op(bpy.types.Operator):
bl_idname = "uv.textools_unwrap_edge_peel"
bl_label = "Peel Edge"
bl_description = "Unwrap pipe along selected edges"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.active_object:
return False
if bpy.context.active_object.type != 'MESH':
return False
# Only in Edit mode
if bpy.context.active_object.mode != 'EDIT':
return False
# Need view Face mode
if tuple(bpy.context.scene.tool_settings.mesh_select_mode)[1] == False:
return False
return True
def execute(self, context):
unwrap_edges_pipe(self, context)
return {'FINISHED'}
def unwrap_edges_pipe(self, context):
bm = bmesh.from_edit_mesh(bpy.context.active_object.data)
uv_layers = bm.loops.layers.uv.verify()
contextViewUV = utilities_ui.GetContextViewUV()
if not contextViewUV:
self.report({'ERROR_INVALID_INPUT'},
"This tool requires an available UV/Image view.")
return
# selected_initial = [edge for edge in bm.edges if edge.select]
selected_edges = []
selected_faces = []
# Extend loop selection
bpy.ops.mesh.loop_multi_select(ring=False)
selected_edges = [edge for edge in bm.edges if edge.select]
if len(selected_edges) == 0:
self.report({'ERROR_INVALID_INPUT'}, "No edges selected in the view")
return
# Convert linked selection to single UV island
bpy.ops.mesh.select_linked(delimit=set())
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bpy.ops.uv.textools_unwrap_faces_iron()
selected_faces = [face for face in bm.faces if face.select]
if len(selected_faces) == 0:
self.report({'ERROR_INVALID_INPUT'}, "No faces available")
return
# Mark previous selected edges as Seam
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
for edge in selected_edges:
edge.select = True
bpy.ops.mesh.mark_seam(clear=False)
# Follow active quad unwrap for faces
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
for face in selected_faces:
face.select = True
bm.faces.active = selected_faces[0]
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.0226216)
bpy.ops.uv.select_all(action='SELECT')
bpy.ops.uv.textools_rectify(contextViewUV)
# TODO: Restore initial selection
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.utils.register_class(op)