Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'uv_magic_uv/muv_wsuv_ops.py')
-rw-r--r--uv_magic_uv/muv_wsuv_ops.py165
1 files changed, 144 insertions, 21 deletions
diff --git a/uv_magic_uv/muv_wsuv_ops.py b/uv_magic_uv/muv_wsuv_ops.py
index 3e47d960..4ee8b4f9 100644
--- a/uv_magic_uv/muv_wsuv_ops.py
+++ b/uv_magic_uv/muv_wsuv_ops.py
@@ -20,12 +20,18 @@
__author__ = "McBuff, Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "4.4"
-__date__ = "2 Aug 2017"
+__version__ = "4.5"
+__date__ = "19 Nov 2017"
import bpy
import bmesh
+from mathutils import Vector
+from bpy.props import (
+ FloatProperty,
+ BoolProperty,
+ EnumProperty
+)
from . import muv_common
@@ -86,6 +92,9 @@ class MUV_WSUVMeasure(bpy.types.Operator):
props.ref_scale = scale / len(sel_faces)
+ self.report(
+ {'INFO'}, "Average face size: {0}".format(props.ref_scale))
+
return {'FINISHED'}
@@ -99,6 +108,44 @@ class MUV_WSUVApply(bpy.types.Operator):
bl_description = "Apply scaled UV based on scale calculation"
bl_options = {'REGISTER', 'UNDO'}
+ proportional_scaling = BoolProperty(
+ name="Proportional Scaling",
+ default=True
+ )
+ scaling_factor = FloatProperty(
+ name="Scaling Factor",
+ default=1.0,
+ max=1000.0,
+ min=0.00001
+ )
+ origin = EnumProperty(
+ name="Origin",
+ description="Aspect Origin",
+ items=[
+ ('CENTER', 'Center', 'Center'),
+ ('LEFT_TOP', 'Left Top', 'Left Bottom'),
+ ('LEFT_CENTER', 'Left Center', 'Left Center'),
+ ('LEFT_BOTTOM', 'Left Bottom', 'Left Bottom'),
+ ('CENTER_TOP', 'Center Top', 'Center Top'),
+ ('CENTER_BOTTOM', 'Center Bottom', 'Center Bottom'),
+ ('RIGHT_TOP', 'Right Top', 'Right Top'),
+ ('RIGHT_CENTER', 'Right Center', 'Right Center'),
+ ('RIGHT_BOTTOM', 'Right Bottom', 'Right Bottom')
+
+ ],
+ default="CENTER"
+ )
+
+ def draw(self, _):
+ layout = self.layout
+
+ row = layout.row()
+ row.prop(self, "proportional_scaling")
+ row = layout.row()
+ row.prop(self, "scaling_factor")
+ if self.proportional_scaling:
+ row.enabled = False
+
def execute(self, context):
props = context.scene.muv_props.wsuv
obj = bpy.context.active_object
@@ -122,26 +169,102 @@ class MUV_WSUVApply(bpy.types.Operator):
scale = scale + calc_face_scale(uv_layer, f)
scale = scale / len(sel_faces)
- ratio = props.ref_scale / scale
-
- orig_area = bpy.context.area.type
- bpy.context.area.type = 'IMAGE_EDITOR'
-
- # select all UV related to the selected faces
- bpy.ops.uv.select_all(action='SELECT')
-
- # apply scaled UV
- bpy.ops.transform.resize(
- value=(ratio, ratio, ratio),
- constraint_axis=(False, False, False),
- constraint_orientation='GLOBAL',
- mirror=False,
- proportional='DISABLED',
- proportional_edit_falloff='SMOOTH',
- proportional_size=1)
-
- bpy.context.area.type = orig_area
+ self.report(
+ {'INFO'}, "Average face size: {0}".format(scale))
+
+ if self.proportional_scaling:
+ factor = props.ref_scale / scale
+ else:
+ factor = self.scaling_factor
+
+ # calculate origin
+ if self.origin == 'CENTER':
+ origin = Vector((0.0, 0.0))
+ num = 0
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin = origin + uv
+ num = num + 1
+ origin = origin / num
+ elif self.origin == 'LEFT_TOP':
+ origin = Vector((100000.0, -100000.0))
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = min(origin.x, uv.x)
+ origin.y = max(origin.y, uv.y)
+ elif self.origin == 'LEFT_CENTER':
+ origin = Vector((100000.0, 0.0))
+ num = 0
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = min(origin.x, uv.x)
+ origin.y = origin.y + uv.y
+ num = num + 1
+ origin.y = origin.y / num
+ elif self.origin == 'LEFT_BOTTOM':
+ origin = Vector((100000.0, 100000.0))
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = min(origin.x, uv.x)
+ origin.y = min(origin.y, uv.y)
+ elif self.origin == 'CENTER_TOP':
+ origin = Vector((0.0, -100000.0))
+ num = 0
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = origin.x + uv.x
+ origin.y = max(origin.y, uv.y)
+ num = num + 1
+ origin.x = origin.x / num
+ elif self.origin == 'CENTER_BOTTOM':
+ origin = Vector((0.0, 100000.0))
+ num = 0
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = origin.x + uv.x
+ origin.y = min(origin.y, uv.y)
+ num = num + 1
+ origin.x = origin.x / num
+ elif self.origin == 'RIGHT_TOP':
+ origin = Vector((-100000.0, -100000.0))
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = max(origin.x, uv.x)
+ origin.y = max(origin.y, uv.y)
+ elif self.origin == 'RIGHT_CENTER':
+ origin = Vector((-100000.0, 0.0))
+ num = 0
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = max(origin.x, uv.x)
+ origin.y = origin.y + uv.y
+ num = num + 1
+ origin.y = origin.y / num
+ elif self.origin == 'RIGHT_BOTTOM':
+ origin = Vector((-100000.0, 100000.0))
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ origin.x = max(origin.x, uv.x)
+ origin.y = min(origin.y, uv.y)
+
+ # update UV coordinate
+ for f in sel_faces:
+ for l in f.loops:
+ uv = l[uv_layer].uv
+ diff = uv - origin
+ l[uv_layer].uv = origin + diff * factor
bmesh.update_edit_mesh(obj.data)
+ self.report({'INFO'}, "Scaling factor: {0}".format(factor))
+
return {'FINISHED'}