[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4559] contrib/py/scripts/addons/ uv_texture_atlas.py: Added new Contribution Script TextureAtlas v0.17.

paul geraskin paul_geraskin at mail.ru
Mon Jun 10 12:21:42 CEST 2013


Revision: 4559
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4559
Author:   mifth
Date:     2013-06-10 10:21:42 +0000 (Mon, 10 Jun 2013)
Log Message:
-----------
Added new Contribution Script TextureAtlas v0.17.
>From here:  https://code.google.com/p/blender-addons-by-mifth/
Ideasman_42 will review it.

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

Added: contrib/py/scripts/addons/uv_texture_atlas.py
===================================================================
--- contrib/py/scripts/addons/uv_texture_atlas.py	                        (rev 0)
+++ contrib/py/scripts/addons/uv_texture_atlas.py	2013-06-10 10:21:42 UTC (rev 4559)
@@ -0,0 +1,696 @@
+bl_info = {
+    "name": "Texture Atlas",
+    "author": "Andreas Esau, Paul Geraskin",
+    "version": (0, 17),
+    "blender": (2, 6, 6),
+    "location": "Properties > Render",
+    "description": "A simple Texture Atlas for baking of many objects. It creates additional UV",
+    "wiki_url": "http://code.google.com/p/blender-addons-by-mifth/",
+    "tracker_url": "http://code.google.com/p/blender-addons-by-mifth/issues/list",
+    "category": "UV"}
+
+import bpy
+from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty, FloatProperty
+import mathutils
+
+class TextureAtlas(bpy.types.Panel):
+    bl_label = "Texture Atlas"
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "render"
+    COMPAT_ENGINES = {'BLENDER_RENDER'}
+    
+    def draw(self, context):
+        col = self.layout.column()
+        row = self.layout.row()
+        split = self.layout.split()
+        ob = context.object
+        scene = context.scene
+        row.template_list("UI_UL_list", "template_list_controls", scene, "ms_lightmap_groups", scene, "ms_lightmap_groups_index", rows=2,  maxrows=5)
+        col = row.column(align=True)
+        col.operator("scene.ms_add_lightmap_group", icon='ZOOMIN', text="")
+        col.operator("scene.ms_del_lightmap_group", icon='ZOOMOUT', text="")
+        
+        row = self.layout.row(align=True)
+        
+        try:
+
+            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")
+
+        
+        
+class runAuto(bpy.types.Operator):
+    bl_idname = "object.ms_auto"
+    bl_label = "Auto Unwrapping"
+    bl_description = "Auto Unwrapping"
+    
+    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')
+    
+            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) 
+                 
+            bpy.context.area.type = old_context
+
+        except:
+            self.report({'INFO'}, "Something went wrong!") 
+            bpy.context.area.type = old_context  
+        return{'FINISHED'}   
+        
+        
+class runStart(bpy.types.Operator):
+    bl_idname = "object.ms_run"
+    bl_label = "Make Manual Unwrapping Object"
+    bl_description = "Makes Manual Unwrapping Object"
+    
+    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')
+    
+            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=False)
+
+            bpy.context.area.type = old_context
+
+        except:
+             self.report({'INFO'}, "Something went wrong!") 
+             bpy.context.area.type = old_context  
+        return{'FINISHED'}
+    
+
+class runFinish(bpy.types.Operator):
+    bl_idname = "object.ms_run_remove"
+    bl_label = "Remove Manual Unwrapping Object"
+    bl_description = "Removes Manual Unwrapping Object"
+    
+    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')
+    
+            if group.bake == True and len(bpy.data.groups[group.name].objects) > 0:
+
+                 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  
+        return{'FINISHED'}
+        
+    
+class uv_layers(bpy.types.PropertyGroup):
+    name = bpy.props.StringProperty(default="")
+
+   
+class vertex_groups(bpy.types.PropertyGroup):
+    name = bpy.props.StringProperty(default="") 
+    
+class groups(bpy.types.PropertyGroup):
+    name = bpy.props.StringProperty(default="") 
+
+class ms_lightmap_groups(bpy.types.PropertyGroup):
+    
+    #def update(self,context):
+        #for object in bpy.data.groups[self.name].objects:
+            #for material in object.data.materials:
+                #material.texture_slots[self.name].use = self.bake
+    
+    name = bpy.props.StringProperty(default="")
+    bake = bpy.props.BoolProperty(default=True)
+    #bake = bpy.props.BoolProperty(default=True, update=update)
+
+    unwrap_type = EnumProperty(name="unwrap_type",items=(('0','Smart_Unwrap', 'Smart_Unwrap'),('1','Lightmap', 'Lightmap'), ('2','No_Unwrap', 'No_Unwrap')))
+    resolution = EnumProperty(name="resolution",items=(('256','256','256'),('512','512','512'),('1024','1024','1024'),('2048','2048','2048'),('4096','4096','4096')))
+    template_list_controls = StringProperty(default="bake", options={"HIDDEN"})
+    
+    
+
+class mergedObjects(bpy.types.PropertyGroup):
+    name = bpy.props.StringProperty(default="")
+    vertex_groups = bpy.props.CollectionProperty(type=vertex_groups)
+    groups = bpy.props.CollectionProperty(type=groups)
+    uv_layers = bpy.props.CollectionProperty(type=uv_layers)
+    
+
+class addSelectedToGroup(bpy.types.Operator):
+    bl_idname = "scene.ms_add_selected_to_group" 
+    bl_label = ""
+    bl_description = "Adds selected Objects to current Group"
+    
+    
+    def execute(self, context):
+        try:
+            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)
+            
+            
+        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
+                    
+        return {'FINISHED'}
+
+class selectGroup(bpy.types.Operator):
+    bl_idname = "scene.ms_select_group" 
+    bl_label = ""
+    bl_description = "Selected Objects of current Group"
+    
+    
+    def execute(self, context):
+        try:
+            group_name = bpy.context.scene.ms_lightmap_groups[bpy.context.scene.ms_lightmap_groups_index].name
+        except:
+            self.report({'INFO'}, "No Groups Exists!")
+
+        try:
+            bpy.ops.object.mode_set(mode = 'OBJECT')
+            bpy.ops.object.select_all(action='DESELECT')
+            for object in bpy.data.groups[group_name].objects:
+                  object.select = True 
+        except:
+            pass
+                    
+        return {'FINISHED'}    
+        
+        
+class removeFromGroup(bpy.types.Operator):
+    bl_idname = "scene.ms_remove_selected" 
+    bl_label = ""
+    bl_description = "Remove Selected Group and UVs"
+    
+    ### removeUV method
+    def removeUV(self, mesh, name):
+             for uv in mesh.data.uv_textures:
+                   if uv.name == name:
+                        uv.active = True
+                        bpy.ops.mesh.uv_texture_remove()
+                        
+        
+        #remove all modifiers
+        #for m in mesh.modifiers:
+            #bpy.ops.object.modifier_remove(modifier=m.name)
+            
+    
+    def execute(self, context):
+        ### set 3dView context
+        old_context = bpy.context.area.type        
+        bpy.context.area.type = 'VIEW_3D'
+        bpy.ops.object.mode_set(mode = 'OBJECT')
+        
+        for group in bpy.context.scene.ms_lightmap_groups:        
+            group_name = group.name
+

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list