[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4560] contrib/py/scripts/addons/ uv_texture_atlas.py: Script TextureAtlas v0.18.

paul geraskin paul_geraskin at mail.ru
Mon Jun 10 14:21:35 CEST 2013


Revision: 4560
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4560
Author:   mifth
Date:     2013-06-10 12:21:35 +0000 (Mon, 10 Jun 2013)
Log Message:
-----------
Script TextureAtlas v0.18. for Ideasman_42 review.

Modified Paths:
--------------
    contrib/py/scripts/addons/uv_texture_atlas.py

Modified: contrib/py/scripts/addons/uv_texture_atlas.py
===================================================================
--- contrib/py/scripts/addons/uv_texture_atlas.py	2013-06-10 10:21:42 UTC (rev 4559)
+++ contrib/py/scripts/addons/uv_texture_atlas.py	2013-06-10 12:21:35 UTC (rev 4560)
@@ -1,7 +1,25 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
 bl_info = {
     "name": "Texture Atlas",
     "author": "Andreas Esau, Paul Geraskin",
-    "version": (0, 17),
+    "version": (0, 18),
     "blender": (2, 6, 6),
     "location": "Properties > Render",
     "description": "A simple Texture Atlas for baking of many objects. It creates additional UV",
@@ -32,32 +50,29 @@
         col.operator("scene.ms_del_lightmap_group", icon='ZOOMOUT', text="")
         
         row = self.layout.row(align=True)
-        
-        try:
 
+        # Resolution and Unwrap types (only if Lightmap group is added)
+        if len(bpy.context.scene.ms_lightmap_groups) > 0:
             row.prop(context.scene.ms_lightmap_groups[context.scene.ms_lightmap_groups_index], 'resolution', text='Resolution',expand=True)
             row = self.layout.row()
             row.prop(context.scene.ms_lightmap_groups[context.scene.ms_lightmap_groups_index], 'unwrap_type', text='Lightmap',expand=True)
             row = self.layout.row()            
-      
-        except:
-            pass    
-        
-        row = self.layout.row()
-        row.operator("scene.ms_remove_other_uv", text="Remove Other UVs",icon="GROUP")
-        row.operator("scene.ms_remove_selected", text="Remove Selected Group and UVs",icon="GROUP")          
-        row = self.layout.row()
-        row = self.layout.row()
-        row = self.layout.row()
-        row.operator("scene.ms_add_selected_to_group", text="Add Selection To Current Group",icon="GROUP")
-        row.operator("scene.ms_select_group", text="Select Current Group",icon="GROUP")
 
-        row = self.layout.row()
-        row.operator("object.ms_auto",text="Auto Unwrap",icon="LAMP_SPOT")        
-        row = self.layout.row()        
-        row.operator("object.ms_run",text="Start Manual Unwrap/Bake",icon="LAMP_SPOT")
-        row.operator("object.ms_run_remove",text="Finsh Manual Unwrap/Bake",icon="LAMP_SPOT")
+            row = self.layout.row()
+            row.operator("scene.ms_remove_other_uv", text="Remove Other UVs",icon="GROUP")
+            row.operator("scene.ms_remove_selected", text="Remove Selected Group and UVs",icon="GROUP")          
+            row = self.layout.row()
+            row = self.layout.row()
+            row = self.layout.row()
+            row.operator("scene.ms_add_selected_to_group", text="Add Selection To Current Group",icon="GROUP")
+            row.operator("scene.ms_select_group", text="Select Current Group",icon="GROUP")
 
+            row = self.layout.row()
+            row.operator("object.ms_auto",text="Auto Unwrap",icon="LAMP_SPOT")        
+            row = self.layout.row()        
+            row.operator("object.ms_run",text="Start Manual Unwrap/Bake",icon="LAMP_SPOT")
+            row.operator("object.ms_run_remove",text="Finsh Manual Unwrap/Bake",icon="LAMP_SPOT")   
+
         
         
 class runAuto(bpy.types.Operator):
@@ -68,23 +83,21 @@
     def execute(self, context):
         old_context = bpy.context.area.type
 
-        try:
-            group = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index]
-            bpy.context.area.type = 'VIEW_3D'
-            bpy.ops.object.mode_set(mode = 'OBJECT')
+        
+        group = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index]
+        bpy.context.area.type = 'VIEW_3D'
+        if bpy.context.scene.objects.active != None:
+            bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
     
-            if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
+        if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
 
-                 res = int(bpy.context.scene.ms_lightmap_groups[group.name].resolution)
-                 bpy.ops.object.ms_create_lightmap(group_name=group.name, resolution=res)  
-                 bpy.ops.object.ms_merge_objects(group_name=group.name, unwrap=True)
-                 bpy.ops.object.ms_separate_objects(group_name=group.name) 
+             res = int(bpy.context.scene.ms_lightmap_groups[group.name].resolution)
+             bpy.ops.object.ms_create_lightmap(group_name=group.name, resolution=res)  
+             bpy.ops.object.ms_merge_objects(group_name=group.name, unwrap=True)
+             bpy.ops.object.ms_separate_objects(group_name=group.name) 
                  
-            bpy.context.area.type = old_context
+        bpy.context.area.type = old_context
 
-        except:
-            self.report({'INFO'}, "Something went wrong!") 
-            bpy.context.area.type = old_context  
         return{'FINISHED'}   
         
         
@@ -96,23 +109,20 @@
     def execute(self, context):
         old_context = bpy.context.area.type
 
-        try:
-            group = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index]
-            bpy.context.area.type = 'VIEW_3D'
-            bpy.ops.object.mode_set(mode = 'OBJECT')
+        
+        group = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index]
+        bpy.context.area.type = 'VIEW_3D'
+        if bpy.context.scene.objects.active != None:
+            bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
     
-            if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
+        if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
 
-                 res = int(bpy.context.scene.ms_lightmap_groups[group.name].resolution)
-                 bpy.ops.object.ms_create_lightmap(group_name=group.name, resolution=res)  
+             res = int(bpy.context.scene.ms_lightmap_groups[group.name].resolution)
+             bpy.ops.object.ms_create_lightmap(group_name=group.name, resolution=res)  
                     
-                 bpy.ops.object.ms_merge_objects(group_name=group.name, unwrap=False)
+             bpy.ops.object.ms_merge_objects(group_name=group.name, unwrap=False)
 
-            bpy.context.area.type = old_context
-
-        except:
-             self.report({'INFO'}, "Something went wrong!") 
-             bpy.context.area.type = old_context  
+        bpy.context.area.type = old_context
         return{'FINISHED'}
     
 
@@ -124,21 +134,18 @@
     def execute(self, context):
         old_context = bpy.context.area.type
 
-        try:
-            group = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index]
-            bpy.context.area.type = 'VIEW_3D'
-            bpy.ops.object.mode_set(mode = 'OBJECT')
+        
+        group = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index]
+        bpy.context.area.type = 'VIEW_3D'
+        if bpy.context.scene.objects.active != None:
+            bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
     
-            if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
+        if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
 
-                 bpy.ops.object.ms_separate_objects(group_name=group.name) 
+             bpy.ops.object.ms_separate_objects(group_name=group.name) 
                       
-            bpy.context.area.type = old_context
-            #bpy.ops.object.select_all(action='DESELECT')
-
-        except:
-             self.report({'INFO'}, "Something went wrong!") 
-             bpy.context.area.type = old_context  
+        bpy.context.area.type = old_context
+        #bpy.ops.object.select_all(action='DESELECT')
         return{'FINISHED'}
         
     
@@ -183,30 +190,25 @@
     
     
     def execute(self, context):
-        try:
-            group_name = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index].name
+        
+        group_name = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index].name
             
-            #Create a New Group if it was deleted.
-            isExist = False
-            for groupObj in bpy.data.groups:
-                 if groupObj == group_name:
-                     isExist = True
-                     
-            if isExist == False:
-                bpy.data.groups.new(group_name)
+        #Create a New Group if it was deleted.
+        isExist = False
+        for groupObj in bpy.data.groups:
+             if groupObj == group_name:
+                 isExist = True
+        if isExist == False:
+            bpy.data.groups.new(group_name)
+
+        # Add objects to  ag roup    
+        if bpy.context.scene.objects.active != None:    
+            bpy.ops.object.mode_set(mode='OBJECT', toggle=False)    
             
-            
-        except:
-            self.report({'INFO'}, "No Groups Exists!")
-            
         for object in bpy.context.selected_objects:
-            if object.type == 'MESH':
-                try:
-                    bpy.ops.object.mode_set(mode = 'OBJECT')
-                    bpy.data.groups[group_name].objects.link(object)
-                except:
-                    pass
-                    
+            if object.type == 'MESH' and bpy.data.groups[group_name] not in object.users_group:
+                bpy.data.groups[group_name].objects.link(object)
+                                    
         return {'FINISHED'}
 
 class selectGroup(bpy.types.Operator):
@@ -216,19 +218,15 @@
     
     

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list