Skip to content

Commit

Permalink
* rename to unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminSauder committed Oct 12, 2021
1 parent f126b93 commit 2be8cb0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
14 changes: 7 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
imp.reload(op_uv_crop)
imp.reload(op_uv_fill)
imp.reload(op_uv_resize)
imp.reload(op_uv_unfold)
imp.reload(op_uv_unwrap)
imp.reload(op_uv_size_get)


Expand Down Expand Up @@ -139,7 +139,7 @@
from . import op_uv_fill
from . import op_uv_resize
from . import op_uv_size_get
from . import op_uv_unfold
from . import op_uv_unwrap


# Import general modules. Important: must be placed here and not on top
Expand Down Expand Up @@ -990,10 +990,10 @@ def draw(self, context):
row.operator(op_rectify.op.bl_idname, text="Rectify", icon_value = icon_get("op_rectify"))

split = col.split(factor=0.75, align=True)
split.operator(op_uv_unfold.op.bl_idname, text="Unfold", icon_value = icon_get("op_uv_unfold")).axis="xy"
split.operator(op_uv_unwrap.op.bl_idname, text="Unwrap", icon_value = icon_get("op_uv_unwrap")).axis="xy"
row = split.row(align=True)
row.operator(op_uv_unfold.op.bl_idname, text="U").axis="x"
row.operator(op_uv_unfold.op.bl_idname, text="V").axis="y"
row.operator(op_uv_unwrap.op.bl_idname, text="U").axis="x"
row.operator(op_uv_unwrap.op.bl_idname, text="V").axis="y"

row = col.row(align=True)
row.scale_y = 1.25
Expand Down Expand Up @@ -1526,7 +1526,7 @@ def menu_IMAGE_uvs(self, context):
layout.operator(op_rectify.op.bl_idname, text="Rectify", icon_value = icon_get("op_rectify"))
layout.operator(op_uv_crop.op.bl_idname, text="Crop", icon_value = icon_get("op_uv_crop"))
layout.operator(op_uv_fill.op.bl_idname, text="Fill", icon_value = icon_get("op_uv_fill"))
layout.operator(op_uv_unfold.op.bl_idname, text="Unfold", icon_value = icon_get("op_uv_unfold"))
layout.operator(op_uv_unwrap.op.bl_idname, text="Unwrap", icon_value = icon_get("op_uv_unwrap"))
layout.operator(op_relax.op.bl_idname, text="Relax", icon_value = icon_get("op_relax"))

layout.separator()
Expand Down Expand Up @@ -1695,7 +1695,7 @@ def register():
"op_unwrap_edge_peel.bip",
"op_uv_crop.bip",
"op_uv_fill.bip",
"op_uv_unfold.bip",
"op_uv_unwrap.bip",
"texel_density.bip"
]
for icon in icons:
Expand Down
File renamed without changes
File renamed without changes.
33 changes: 18 additions & 15 deletions op_uv_unfold.py → op_uv_unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


class op(bpy.types.Operator):
bl_idname = "uv.textools_uv_unfold"
bl_label = "Unfold"
bl_description = "Unfold selected uv's"
bl_idname = "uv.textools_uv_unwrap"
bl_label = "Unwrap"
bl_description = "Unwrap selected uv's"
bl_options = {'UNDO'}

axis: bpy.props.StringProperty(name="axis", default="xy")
Expand Down Expand Up @@ -38,26 +38,23 @@ def execute(self, context):


def main(context, axis):
print("operator_uv_unfold()")
# print("operator_uv_unwrap()")

bm = bmesh.from_edit_mesh(bpy.context.active_object.data)
uv_layer = bm.loops.layers.uv.verify()

utilities_uv.selection_store()
selected_faces = utilities_uv.selection_store(return_selected_UV_faces=True)

# analyze if a full uv-island has been selected
full_islands = utilities_uv.getSelectionIslands(bm, uv_layer)
islands = utilities_uv.splittedSelectionByIsland(bm, uv_layer)
full_islands = utilities_uv.getSelectionIslands(bm, uv_layer, selected_faces)
islands = utilities_uv.splittedSelectionByIsland(bm, uv_layer, selected_faces)

selected_uv_islands = []
for island in islands:
for full_island in full_islands:
if island == full_island:
selected_uv_islands.append(list(island))

# if len(selected_uv_islands) > 0:
# print(f"found {len(selected_uv_islands)} fully selected islands")

utilities_uv.selection_restore()

# store pins and edge seams
Expand All @@ -78,7 +75,7 @@ def main(context, axis):
uv_coords.append(uv.uv.copy())

# pin one vert to keep the island somewhat in place, otherwise it can get moved away quite randomly by the uv unwrap method
# also store some uvs to reconstruction orientation
# also store some uvs data to reconstruction orientation
orient_uvs = []
if len(selected_uv_islands) > 0:
for island in selected_uv_islands:
Expand Down Expand Up @@ -113,7 +110,7 @@ def main(context, axis):
island_bbox = utilities_uv.get_BBOX(island, bm, uv_layer)

x_min, x_max, y_min, y_max, x_min_coord, x_max_coord, y_min_coord, y_max_coord = orient_uvs[index]

intial_x_axis = x_min_coord - x_max_coord
intial_x_angle = up.angle_signed(intial_x_axis)

Expand All @@ -128,12 +125,18 @@ def main(context, axis):

angle_x = current_x_angle - intial_x_angle
angle_y = current_y_angle - intial_y_angle

angle = min(angle_x, angle_y)

c = island_bbox['center']
utilities_uv.rotate_island(island, uv_layer, angle, c.x, c.y)
center = island_bbox['center']
utilities_uv.rotate_island(island, uv_layer, angle, center.x, center.y)

#keep it the same size
scale_x = intial_x_axis.length / axis_x_current.length
scale_y = intial_y_axis.length / axis_y_current.length
scale = min([scale_x, scale_y], key=lambda x:abs(x-1.0)) #pick scale closer to 1.0
utilities_uv.scale_island(island, uv_layer, scale, scale, center)

#move back into place
delta = x_min_coord - x_min.uv
utilities_uv.move_island(island, delta.x, delta.y)

Expand Down
18 changes: 18 additions & 0 deletions utilities_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ def rotate_island(island, uv_layer = None, angle = 0, center_x=0, center_y=0):
loop[uv_layer].uv.y = yr + center_y


def scale_island(island, uv_layer, scale_x, scale_y, pivot=None):
"""Scale a list of faces by 'scale_x, scale_y'. """

if not pivot:
bbox = get_BBOX(island, None, uv_layer)
pivot = bbox['center']

for face in island:
for loop in face.loops:
x, y = loop[uv_layer].uv
xt = x - pivot.x
yt = y - pivot.y
xs = xt * scale_x
ys = yt * scale_y
loop[uv_layer].uv.x = xs + pivot.x
loop[uv_layer].uv.y = ys + pivot.y


def set_selected_faces(faces, bm, uv_layers):
for face in faces:
for loop in face.loops:
Expand Down

0 comments on commit 2be8cb0

Please sign in to comment.