From 2db1851c261eae4b368f476b372aa25ded2951a6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 3 Nov 2009 18:56:42 +0000 Subject: [PATCH] uv smart project now in unwrap menu with 2 most important options --- release/scripts/io/add_mesh_torus.py | 6 +- release/scripts/io/uvcalc_smart_project.py | 67 ++++++++++++++-------- release/scripts/ui/space_view3d.py | 2 +- release/scripts/ui/space_view3d_toolbar.py | 3 +- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/release/scripts/io/add_mesh_torus.py b/release/scripts/io/add_mesh_torus.py index 27ef587ce5a..ddc4f0b9770 100644 --- a/release/scripts/io/add_mesh_torus.py +++ b/release/scripts/io/add_mesh_torus.py @@ -74,7 +74,7 @@ def add_torus(major_rad, minor_rad, major_seg, minor_seg): from bpy.props import * -class AddTorusPrimitive(bpy.types.Operator): +class AddTorus(bpy.types.Operator): '''Add a torus mesh.''' bl_idname = "mesh.primitive_torus_add" bl_label = "Add Torus" @@ -125,12 +125,12 @@ class AddTorusPrimitive(bpy.types.Operator): return ('FINISHED',) # Register the operator -bpy.ops.add(AddTorusPrimitive) +bpy.ops.add(AddTorus) # Add to a menu import dynamic_menu -menu_func = (lambda self, context: self.layout.itemO("mesh.primitive_torus_add", +menu_func = (lambda self, context: self.layout.itemO(AddTorus.bl_idname, text="Torus", icon='ICON_MESH_DONUT')) menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, menu_func) diff --git a/release/scripts/io/uvcalc_smart_project.py b/release/scripts/io/uvcalc_smart_project.py index 1aeaab44d73..328470a5ec5 100644 --- a/release/scripts/io/uvcalc_smart_project.py +++ b/release/scripts/io/uvcalc_smart_project.py @@ -821,7 +821,7 @@ class thickface(object): global ob ob = None -def main(context): +def main(context, island_margin, projection_limit): global USER_FILL_HOLES global USER_FILL_HOLES_QUALITY global USER_STRETCH_ASPECT @@ -847,35 +847,16 @@ def main(context): raise('error, no selected mesh objects') # Create the variables. - USER_PROJECTION_LIMIT = (66) + USER_PROJECTION_LIMIT = projection_limit USER_ONLY_SELECTED_FACES = (1) USER_SHARE_SPACE = (1) # Only for hole filling. USER_STRETCH_ASPECT = (1) # Only for hole filling. - USER_ISLAND_MARGIN = (0.0) # Only for hole filling. + USER_ISLAND_MARGIN = island_margin # Only for hole filling. 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. - - pup_block = [\ - 'Projection',\ - ('Angle Limit:', USER_PROJECTION_LIMIT, 1, 89, 'lower for more projection groups, higher for less distortion.'),\ - ('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.'),\ - ('Island Margin:', USER_ISLAND_MARGIN, 0.0, 0.5, 'Margin to reduce bleed from adjacent islands.'),\ - 'Fill in empty areas',\ - ('Fill Holes', USER_FILL_HOLES, 'Fill in empty areas reduced texture waistage (slow).'),\ - ('Fill Quality:', USER_FILL_HOLES_QUALITY, 1, 100, 'Depends on fill holes, how tightly to fill UV holes, (higher is slower)'),\ - ] - # Reuse variable if len(obList) == 1: ob = "Unwrap %i Selected Mesh" @@ -1123,20 +1104,60 @@ def main(context): #XXX Window.WaitCursor(0) #XXX Window.RedrawAll() +""" + 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.'),\ +* ('Island Margin:', USER_ISLAND_MARGIN, 0.0, 0.5, ''),\ + 'Fill in empty areas',\ + ('Fill Holes', USER_FILL_HOLES, 'Fill in empty areas reduced texture waistage (slow).'),\ + ('Fill Quality:', USER_FILL_HOLES_QUALITY, 1, 100, 'Depends on fill holes, how tightly to fill UV holes, (higher is slower)'),\ + ] +""" + +from bpy.props import * class SmartProject(bpy.types.Operator): '''This script projection unwraps the selected faces of a mesh. it operates on all selected mesh objects, and can be used unwrap selected faces, or all faces.''' bl_idname = "uv.smart_project" bl_label = "Smart UV Project" + bl_register = True + bl_undo = True + + angle_limit = FloatProperty(name="Angle Limit", + 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.", + default=0.0, min=0.0, max=1.0) + def poll(self, context): return context.active_object != None def execute(self, context): - main(context) + main(context, self.island_margin, self.angle_limit) return ('FINISHED',) bpy.ops.add(SmartProject) +# Add to a menu +import dynamic_menu + +menu_func = (lambda self, context: self.layout.itemO(SmartProject.bl_idname, + text="Smart Project")) + +menu_item = dynamic_menu.add(bpy.types.VIEW3D_MT_uv_map, menu_func) + if __name__ == '__main__': bpy.ops.uv.smart_project() diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index e4de79942f2..33e2df11f8e 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -90,7 +90,7 @@ class VIEW3D_MT_snap(bpy.types.Menu): layout.itemO("view3d.snap_cursor_to_grid", text="Cursor to Grid") layout.itemO("view3d.snap_cursor_to_active", text="Cursor to Active") -class VIEW3D_MT_uv_map(bpy.types.Menu): +class VIEW3D_MT_uv_map(dynamic_menu.DynMenu): bl_label = "UV Mapping" def draw(self, context): diff --git a/release/scripts/ui/space_view3d_toolbar.py b/release/scripts/ui/space_view3d_toolbar.py index 2311482ac22..809201b55b4 100644 --- a/release/scripts/ui/space_view3d_toolbar.py +++ b/release/scripts/ui/space_view3d_toolbar.py @@ -109,7 +109,8 @@ class VIEW3D_PT_tools_meshedit(View3DPanel): col = layout.column(align=True) col.itemL(text="UV Mapping:") - col.itemO("uv.mapping_menu", text="Unwrap") + col.item_stringO("wm.call_menu", "name", "VIEW3D_MT_uv_map", text="Unwrap") + col.itemO("mesh.uvs_rotate") col.itemO("mesh.uvs_mirror")