Multi-Objects: MESH_OT_faces_mirror_uv
Changes from reviewer (Dalai Felinto): * pep8. * Skip meshes that come from libraries. * `Copy Mirrored UV coords > Copy Mirrored UV Coords`. * Remove mesh(es) from warnings, report mesh or meshes based on number. https://developer.blender.org/D3529
This commit is contained in:
@@ -30,7 +30,7 @@ from bpy.props import (
|
||||
class MeshMirrorUV(Operator):
|
||||
"""Copy mirror UV coordinates on the X axis based on a mirrored mesh"""
|
||||
bl_idname = "mesh.faces_mirror_uv"
|
||||
bl_label = "Copy Mirrored UV coords"
|
||||
bl_label = "Copy Mirrored UV Coords"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
direction: EnumProperty(
|
||||
@@ -49,22 +49,14 @@ class MeshMirrorUV(Operator):
|
||||
default=3,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
obj = context.active_object
|
||||
return (obj and obj.type == 'MESH' and obj.data.uv_layers.active)
|
||||
|
||||
def execute(self, context):
|
||||
DIR = (self.direction == 'NEGATIVE')
|
||||
# Returns has_active_UV_layer, double_warn.
|
||||
def do_mesh_mirror_UV(self, mesh, DIR):
|
||||
precision = self.precision
|
||||
double_warn = 0
|
||||
|
||||
ob = context.active_object
|
||||
is_editmode = (ob.mode == 'EDIT')
|
||||
if is_editmode:
|
||||
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
||||
|
||||
mesh = ob.data
|
||||
if not mesh.uv_layers.active:
|
||||
# has_active_UV_layer, double_warn
|
||||
return False, 0
|
||||
|
||||
# mirror lookups
|
||||
mirror_gt = {}
|
||||
@@ -144,13 +136,68 @@ class MeshMirrorUV(Operator):
|
||||
k_map = v1.index(v2[k])
|
||||
uv1[k].xy = - (uv2[k_map].x - 0.5) + 0.5, uv2[k_map].y
|
||||
|
||||
# has_active_UV_layer, double_warn
|
||||
return True, double_warn
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
obj = context.view_layer.objects.active
|
||||
return (obj and obj.type == 'MESH')
|
||||
|
||||
def execute(self, context):
|
||||
DIR = (self.direction == 'NEGATIVE')
|
||||
|
||||
total_no_active_UV = 0
|
||||
total_duplicates = 0
|
||||
meshes_with_duplicates = 0
|
||||
|
||||
ob = context.view_layer.objects.active
|
||||
is_editmode = (ob.mode == 'EDIT')
|
||||
if is_editmode:
|
||||
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
||||
|
||||
meshes = [ob.data for ob in context.view_layer.objects.selected
|
||||
if ob.type == 'MESH' and ob.data.library is None]
|
||||
|
||||
for mesh in meshes:
|
||||
mesh.tag = False
|
||||
|
||||
for mesh in meshes:
|
||||
if mesh.tag:
|
||||
continue
|
||||
|
||||
mesh.tag = True
|
||||
|
||||
has_active_UV_layer, double_warn = self.do_mesh_mirror_UV(mesh, DIR)
|
||||
|
||||
if not has_active_UV_layer:
|
||||
total_no_active_UV = total_no_active_UV + 1
|
||||
|
||||
elif double_warn:
|
||||
total_duplicates += double_warn
|
||||
meshes_with_duplicates = meshes_with_duplicates + 1
|
||||
|
||||
if is_editmode:
|
||||
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
||||
|
||||
if double_warn:
|
||||
self.report({'WARNING'},
|
||||
"%d duplicates found, mirror may be incomplete" %
|
||||
double_warn)
|
||||
if total_duplicates and total_no_active_UV:
|
||||
self.report({'WARNING'}, "%d %s with no active UV layer. "
|
||||
"%d duplicates found in %d mesh%s, mirror may be incomplete."
|
||||
% (total_no_active_UV,
|
||||
"mesh" if total_no_active_UV == 1 else "meshes",
|
||||
total_duplicates,
|
||||
meshes_with_duplicates,
|
||||
"mesh" if meshes_with_duplicates == 1 else "meshes"))
|
||||
elif total_no_active_UV:
|
||||
self.report({'WARNING'}, "%d %s with no active UV layer."
|
||||
% (total_no_active_UV,
|
||||
"mesh" if total_no_active_UV == 1 else "meshes"))
|
||||
elif total_duplicates:
|
||||
self.report({'WARNING'}, "%d duplicates found in %d %s,"
|
||||
" mirror may be incomplete."
|
||||
% (total_duplicates,
|
||||
meshes_with_duplicates,
|
||||
"mesh" if meshes_with_duplicates == 1 else "meshes"))
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user