[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37889] trunk/blender/release/scripts/ startup/bl_operators/uvcalc_smart_project.py: fix [#27787] Smart UV Unwrap Results in Overlaps

Campbell Barton ideasman42 at gmail.com
Tue Jun 28 08:51:56 CEST 2011


Revision: 37889
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37889
Author:   campbellbarton
Date:     2011-06-28 06:51:55 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
fix [#27787] Smart UV Unwrap Results in Overlaps
added optional face area weighting (from 2.4x) since this can result in overlapping faces.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py

Modified: trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py	2011-06-28 05:17:17 UTC (rev 37888)
+++ trunk/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py	2011-06-28 06:51:55 UTC (rev 37889)
@@ -746,15 +746,17 @@
                 uv.y= (uv.y+yoffset) * yfactor
 
 
-
 def VectoQuat(vec):
-    vec = vec.normalized()
-    if abs(vec.x) > 0.5:
-        return vec.to_track_quat('Z', 'X')
-    else:
-        return vec.to_track_quat('Z', 'Y')
+    a3 = vec.normalized()
+    up = Vector((0.0, 0.0, 1.0))
+    if abs(a3.dot(up)) == 1.0:
+        up = Vector((0.0, 1.0, 0.0))
 
+    a1 = a3.cross(up).normalized()
+    a2 = a3.cross(a1)
+    return Matrix((a1, a2, a3)).to_quaternion()
 
+
 class thickface(object):
     __slost__= 'v', 'uv', 'no', 'area', 'edge_keys'
     def __init__(self, face, uvface, mesh_verts):
@@ -791,7 +793,11 @@
 
 global ob
 ob = None
-def main(context, island_margin, projection_limit):
+def main(context,
+         island_margin,
+         projection_limit,
+         user_area_weight,
+         ):
     global USER_FILL_HOLES
     global USER_FILL_HOLES_QUALITY
     global USER_STRETCH_ASPECT
@@ -844,7 +850,6 @@
     USER_FILL_HOLES = (0)
     USER_FILL_HOLES_QUALITY = (50) # Only for hole filling.
     USER_VIEW_INIT = (0) # Only for hole filling.
-    USER_AREA_WEIGHT = (1) # Only for hole filling.
 
     # Reuse variable
     if len(obList) == 1:
@@ -970,12 +975,15 @@
 
             # Add the average of all these faces normals as a projectionVec
             averageVec = Vector((0.0, 0.0, 0.0))
-            if USER_AREA_WEIGHT:
+            if user_area_weight == 0.0:
                 for fprop in newProjectMeshFaces:
-                    averageVec += (fprop.no * fprop.area)
+                    averageVec += fprop.no
+            elif user_area_weight == 1.0:
+                for fprop in newProjectMeshFaces:
+                    averageVec += fprop.no * fprop.area
             else:
                 for fprop in newProjectMeshFaces:
-                    averageVec += fprop.no
+                    averageVec += fprop.no * ((fprop.area * user_area_weight) + (1.0 - user_area_weight))
 
             if averageVec.x != 0 or averageVec.y != 0 or averageVec.z != 0: # Avoid NAN
                 projectVecs.append(averageVec.normalized())
@@ -1062,7 +1070,7 @@
                 f_uv = f.uv
                 for j, v in enumerate(f.v):
                     # XXX - note, between mathutils in 2.4 and 2.5 the order changed.
-                    f_uv[j][:] = (v.co * MatQuat)[:2]
+                    f_uv[j][:] = (v.co * MatQuat).xy
 
 
         if USER_SHARE_SPACE:
@@ -1098,13 +1106,9 @@
 """
     pup_block = [\
     'Projection',\
-*	('Angle Limit:', USER_PROJECTION_LIMIT, 1, 89, ''),\
     ('Selected Faces Only', USER_ONLY_SELECTED_FACES, 'Use only selected faces from all selected meshes.'),\
     ('Init from view', USER_VIEW_INIT, 'The first projection will be from the view vector.'),\
-    ('Area Weight', USER_AREA_WEIGHT, 'Weight projections vector by face area.'),\
     '',\
-    '',\
-    '',\
     'UV Layout',\
     ('Share Tex Space', USER_SHARE_SPACE, 'Objects Share texture space, map all objects into 1 uvmap.'),\
     ('Stretch to bounds', USER_STRETCH_ASPECT, 'Stretch the final output to texture bounds.'),\
@@ -1125,19 +1129,27 @@
     bl_options = {'REGISTER', 'UNDO'}
 
     angle_limit = FloatProperty(name="Angle Limit",
-            description="lower for more projection groups, higher for less distortion.",
+            description="lower for more projection groups, higher for less distortion",
             default=66.0, min=1.0, max=89.0)
 
     island_margin = FloatProperty(name="Island Margin",
-            description="Margin to reduce bleed from adjacent islands.",
+            description="Margin to reduce bleed from adjacent islands",
             default=0.0, min=0.0, max=1.0)
 
+    user_area_weight = FloatProperty(name="Area Weight",
+            description="Weight projections vector by faces with larger areas",
+            default=0.0, min=0.0, max=1.0)
+
     @classmethod
     def poll(cls, context):
         return context.active_object != None
 
     def execute(self, context):
-        main(context, self.island_margin, self.angle_limit)
+        main(context,
+             self.island_margin,
+             self.angle_limit,
+             self.user_area_weight,
+             )
         return {'FINISHED'}
 
     def invoke(self, context, event):




More information about the Bf-blender-cvs mailing list