Revert "Update lanuages"
[blender-addons.git] / uv_texture_atlas.py
blob14db2e8772f8be85c24fefa71bf578d1c3702051
1 # BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # END GPL LICENSE BLOCK #####
20 bl_info = {
21 "name": "Texture Atlas",
22 "author": "Andreas Esau, Paul Geraskin, Campbell Barton",
23 "version": (0, 2, 1),
24 "blender": (2, 67, 0),
25 "location": "Properties > Render",
26 "description": "A simple Texture Atlas for unwrapping many objects. It creates additional UV",
27 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
28 "Scripts/UV/TextureAtlas",
29 "category": "UV",
32 import bpy
33 from bpy.types import (
34 Operator,
35 Panel,
36 PropertyGroup,
38 from bpy.props import (
39 BoolProperty,
40 CollectionProperty,
41 EnumProperty,
42 FloatProperty,
43 IntProperty,
44 StringProperty,
46 import mathutils
49 def check_all_objects_visible(self, context):
50 scene = context.scene
51 group = scene.ms_lightmap_groups[scene.ms_lightmap_groups_index]
52 isAllObjectsVisible = True
53 bpy.ops.object.select_all(action='DESELECT')
54 for thisObject in bpy.data.groups[group.name].objects:
55 isThisObjectVisible = False
56 # scene.objects.active = thisObject
57 for thisLayerNumb in range(20):
58 if thisObject.layers[thisLayerNumb] is True and scene.layers[thisLayerNumb] is True:
59 isThisObjectVisible = True
60 break
61 # If Object is on an invisible Layer
62 if isThisObjectVisible is False:
63 isAllObjectsVisible = False
64 return isAllObjectsVisible
67 def check_group_exist(self, context, use_report=True):
68 scene = context.scene
69 group = scene.ms_lightmap_groups[scene.ms_lightmap_groups_index]
71 if group.name in bpy.data.groups:
72 return True
73 else:
74 if use_report:
75 self.report({'INFO'}, "No Such Group %r!" % group.name)
76 return False
79 class TexAtl_Main(Panel):
80 bl_label = "Texture Atlas"
81 bl_space_type = 'PROPERTIES'
82 bl_region_type = 'WINDOW'
83 bl_context = "render"
84 bl_options = {'DEFAULT_CLOSED'}
86 def draw(self, context):
87 scene = context.scene
88 ob = context.object
90 col = self.layout.column()
91 row = self.layout.row()
92 split = self.layout.split()
94 row.template_list("UI_UL_list", "template_list_controls", scene,
95 "ms_lightmap_groups", scene, "ms_lightmap_groups_index", rows=2, maxrows=5)
96 col = row.column(align=True)
97 col.operator("scene.ms_add_lightmap_group", icon='ZOOMIN', text="")
98 col.operator("scene.ms_del_lightmap_group", icon='ZOOMOUT', text="")
100 row = self.layout.row(align=True)
102 # Resolution and Unwrap types (only if Lightmap group is added)
103 if context.scene.ms_lightmap_groups:
104 group = scene.ms_lightmap_groups[scene.ms_lightmap_groups_index]
105 row.label(text="Resolution:")
106 row.prop(group, 'resolutionX', text='')
107 row.prop(group, 'resolutionY', text='')
108 row = self.layout.row()
109 #self.layout.separator()
111 row = self.layout.row()
112 row.operator("scene.ms_remove_other_uv",
113 text="RemoveOtherUVs", icon="GROUP")
114 row.operator("scene.ms_remove_selected",
115 text="RemoveSelected", icon="GROUP")
116 #self.layout.separator()
118 row = self.layout.row()
119 row.operator("scene.ms_add_selected_to_group",
120 text="AddSelected", icon="GROUP")
121 row.operator("scene.ms_select_group",
122 text="SelectGroup", icon="GROUP")
124 #self.layout.separator()
125 self.layout.label(text="Auto Unwrap:")
126 self.layout.prop(group, 'unwrap_type', text='Lightmap', expand=True)
127 row = self.layout.row()
128 row.operator(
129 "object.ms_auto", text="Auto Unwrap", icon="LAMP_SPOT")
130 row.prop(group, 'autoUnwrapPrecision', text='')
132 self.layout.label(text="Manual Unwrap:")
133 row = self.layout.row()
134 row.operator(
135 "object.ms_run", text="StartManualUnwrap", icon="LAMP_SPOT")
136 row.operator(
137 "object.ms_run_remove", text="FinishManualUnwrap", icon="LAMP_SPOT")
140 class TexAtl_RunAuto(Operator):
141 bl_idname = "object.ms_auto"
142 bl_label = "Auto Unwrapping"
143 bl_description = "Auto Unwrapping"
145 def execute(self, context):
146 scene = context.scene
148 # get old context
149 old_context = None
150 if context.area:
151 old_context = context.area.type
153 # Check if group exists
154 if check_group_exist(self, context) is False:
155 return {'CANCELLED'}
157 group = scene.ms_lightmap_groups[scene.ms_lightmap_groups_index]
158 if context.area:
159 context.area.type = 'VIEW_3D'
161 if bpy.ops.object.mode_set.poll():
162 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
164 if group.bake is True and bpy.data.groups[group.name].objects:
166 # Check if objects are all on the visible Layers.
167 isAllObjVisible = check_all_objects_visible(self, context)
169 if isAllObjVisible is True:
170 resX = int(group.resolutionX)
171 resY = int(group.resolutionY)
172 bpy.ops.object.ms_create_lightmap(
173 group_name=group.name, resolutionX=resX, resolutionY=resY)
174 bpy.ops.object.ms_merge_objects(
175 group_name=group.name, unwrap=True)
176 bpy.ops.object.ms_separate_objects(group_name=group.name)
177 else:
178 self.report({'INFO'}, "Not All Objects Are Visible!!!")
180 # set old context back
181 if context.area:
182 context.area.type = old_context
184 return{'FINISHED'}
187 class TexAtl_RunStart(Operator):
188 bl_idname = "object.ms_run"
189 bl_label = "Make Manual Unwrapping Object"
190 bl_description = "Makes Manual Unwrapping Object"
192 def execute(self, context):
193 scene = context.scene
195 # get old context
196 old_context = None
197 if context.area:
198 old_context = context.area.type
200 # Check if group exists
201 if check_group_exist(self, context) is False:
202 return {'CANCELLED'}
204 if context.area:
205 context.area.type = 'VIEW_3D'
206 group = scene.ms_lightmap_groups[scene.ms_lightmap_groups_index]
208 if bpy.ops.object.mode_set.poll():
209 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
211 if group.bake is True and bpy.data.groups[group.name].objects:
213 # Check if objects are all on the visible Layers.
214 isAllObjVisible = check_all_objects_visible(self, context)
216 if bpy.data.objects.get(group.name + "_mergedObject") is not None:
217 self.report({'INFO'}, "Old Merged Object Exists!!!")
218 elif isAllObjVisible is False:
219 self.report({'INFO'}, "Not All Objects Are Visible!!!")
220 else:
221 resX = int(group.resolutionX)
222 resY = int(group.resolutionY)
223 bpy.ops.object.ms_create_lightmap(
224 group_name=group.name, resolutionX=resX, resolutionY=resY)
225 bpy.ops.object.ms_merge_objects(
226 group_name=group.name, unwrap=False)
228 # set old context back
229 if context.area:
230 context.area.type = old_context
232 return{'FINISHED'}
235 class TexAtl_RunFinish(Operator):
236 bl_idname = "object.ms_run_remove"
237 bl_label = "Remove Manual Unwrapping Object"
238 bl_description = "Removes Manual Unwrapping Object"
240 def execute(self, context):
241 scene = context.scene
243 # get old context
244 old_context = None
245 if context.area:
246 old_context = context.area.type
248 # Check if group exists
249 if check_group_exist(self, context) is False:
250 return {'CANCELLED'}
252 group = scene.ms_lightmap_groups[scene.ms_lightmap_groups_index]
253 if context.area:
254 context.area.type = 'VIEW_3D'
256 if bpy.ops.object.mode_set.poll():
257 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
259 if group.bake is True and bpy.data.groups[group.name].objects:
261 # Check if objects are all on the visible Layers.
262 isAllObjVisible = check_all_objects_visible(self, context)
264 if isAllObjVisible is True:
265 bpy.ops.object.ms_separate_objects(group_name=group.name)
266 else:
267 self.report({'INFO'}, "Not All Objects Are Visible!!!")
269 # set old context back
270 if context.area:
271 context.area.type = old_context
273 return{'FINISHED'}
276 class TexAtl_UVLayers(PropertyGroup):
277 name = StringProperty(default="")
280 class TexAtl_VertexGroups(PropertyGroup):
281 name = StringProperty(default="")
284 class TexAtl_Groups(PropertyGroup):
285 name = StringProperty(default="")
288 class TexAtl_MSLightmapGroups(PropertyGroup):
290 name = StringProperty(default="")
291 bake = BoolProperty(default=True)
293 unwrap_type = EnumProperty(
294 name="unwrap_type",
295 items=(('0', 'Smart_Unwrap', 'Smart_Unwrap'),
296 ('1', 'Lightmap', 'Lightmap'),
297 ('2', 'No_Unwrap', 'No_Unwrap'),
300 resolutionX = EnumProperty(
301 name="resolutionX",
302 items=(('256', '256', ''),
303 ('512', '512', ''),
304 ('1024', '1024', ''),
305 ('2048', '2048', ''),
306 ('4096', '4096', ''),
307 ('8192', '8192', ''),
308 ('16384', '16384', ''),
310 default='1024'
312 resolutionY = EnumProperty(
313 name="resolutionY",
314 items=(('256', '256', ''),
315 ('512', '512', ''),
316 ('1024', '1024', ''),
317 ('2048', '2048', ''),
318 ('4096', '4096', ''),
319 ('8192', '8192', ''),
320 ('16384', '16384', ''),
322 default='1024'
324 autoUnwrapPrecision = FloatProperty(
325 name="autoUnwrapPrecision",
326 default=0.01,
327 min=0.001,
328 max=10
330 template_list_controls = StringProperty(
331 default="bake",
332 options={"HIDDEN"},
336 class TexAtl_MergedObjects(PropertyGroup):
337 name = StringProperty()
338 vertex_groups = CollectionProperty(
339 type=TexAtl_VertexGroups,
341 groups = CollectionProperty(type=TexAtl_Groups)
342 uv_layers = CollectionProperty(type=TexAtl_UVLayers)
345 class TexAtl_AddSelectedToGroup(Operator):
346 bl_idname = "scene.ms_add_selected_to_group"
347 bl_label = "Add to Group"
348 bl_description = "Adds selected Objects to current Group"
350 def execute(self, context):
351 scene = context.scene
352 group_name = scene.ms_lightmap_groups[
353 scene.ms_lightmap_groups_index].name
355 # Create a New Group if it was deleted.
356 obj_group = bpy.data.groups.get(group_name)
357 if obj_group is None:
358 obj_group = bpy.data.groups.new(group_name)
360 # Add objects to a group
361 if bpy.ops.object.mode_set.poll():
362 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
364 for object in context.selected_objects:
365 if object.type == 'MESH' and object.name not in obj_group.objects:
366 obj_group.objects.link(object)
368 return {'FINISHED'}
371 class TexAtl_SelectGroup(Operator):
372 bl_idname = "scene.ms_select_group"
373 bl_label = "sel Group"
374 bl_description = "Selected Objects of current Group"
376 def execute(self, context):
377 scene = context.scene
378 group_name = scene.ms_lightmap_groups[
379 scene.ms_lightmap_groups_index].name
381 # Check if group exists
382 if check_group_exist(self, context) is False:
383 return {'CANCELLED'}
385 if bpy.ops.object.mode_set.poll():
386 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
388 bpy.ops.object.select_all(action='DESELECT')
389 obj_group = bpy.data.groups[group_name]
390 for object in obj_group.objects:
391 object.select = True
392 return {'FINISHED'}
395 class TexAtl_RemoveFromGroup(Operator):
396 bl_idname = "scene.ms_remove_selected"
397 bl_label = "del Selected"
398 bl_description = "Remove Selected Group and UVs"
400 # remove all modifiers
401 # for m in mesh.modifiers:
402 # bpy.ops.object.modifier_remove(modifier=m.name)
404 def execute(self, context):
405 scene = context.scene
407 # Check if group exists
408 if check_group_exist(self, context) is False:
409 return {'CANCELLED'}
411 if bpy.ops.object.mode_set.poll():
412 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
414 for group in scene.ms_lightmap_groups:
415 group_name = group.name
417 obj_group = bpy.data.groups[group_name]
418 for object in context.selected_objects:
419 scene.objects.active = object
421 if object.type == 'MESH' and object.name in obj_group.objects:
423 # remove UV
424 tex = object.data.uv_textures.get(group_name)
425 if tex is not None:
426 object.data.uv_textures.remove(tex)
428 # remove from group
429 obj_group.objects.unlink(object)
430 object.hide_render = False
432 return {'FINISHED'}
435 class TexAtl_RemoveOtherUVs(Operator):
436 bl_idname = "scene.ms_remove_other_uv"
437 bl_label = "remOther"
438 bl_description = "Remove Other UVs from Selected"
440 def execute(self, context):
441 scene = context.scene
442 group_name = scene.ms_lightmap_groups[
443 scene.ms_lightmap_groups_index].name
445 # Check if group exists
446 if check_group_exist(self, context) is False:
447 return {'CANCELLED'}
449 if bpy.ops.object.mode_set.poll():
450 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
451 # bpy.ops.object.select_all(action='DESELECT')
453 obj_group = bpy.data.groups[group_name]
455 # Remove other UVs of selected objects
456 for object in context.selected_objects:
457 scene.objects.active = object
458 if object.type == 'MESH' and object.name in obj_group.objects:
460 # remove UVs
461 UVLIST = []
462 for uv in object.data.uv_textures:
463 if uv.name != group_name:
464 UVLIST.append(uv.name)
466 for uvName in UVLIST:
467 tex = object.data.uv_textures[uvName]
468 object.data.uv_textures.remove(tex)
470 UVLIST.clear() # clear array
472 return {'FINISHED'}
475 class TexAtl_AddLightmapGroup(Operator):
476 bl_idname = "scene.ms_add_lightmap_group"
477 bl_label = "add Lightmap"
478 bl_description = "Adds a new Lightmap Group"
480 name = StringProperty(name="Group Name", default='TextureAtlas')
482 def execute(self, context):
483 scene = context.scene
484 obj_group = bpy.data.groups.new(self.name)
486 item = scene.ms_lightmap_groups.add()
487 item.name = obj_group.name
488 #item.resolution = '1024'
489 scene.ms_lightmap_groups_index = len(scene.ms_lightmap_groups) - 1
491 # Add selested objects to group
492 for object in context.selected_objects:
493 if object.type == 'MESH':
494 obj_group.objects.link(object)
496 return {'FINISHED'}
498 def invoke(self, context, event):
499 wm = context.window_manager
500 return wm.invoke_props_dialog(self)
503 class TexAtl_DelLightmapGroup(Operator):
504 bl_idname = "scene.ms_del_lightmap_group"
505 bl_label = "delete Lightmap"
506 bl_description = "Deletes active Lightmap Group"
508 def execute(self, context):
509 scene = context.scene
510 if len(scene.ms_lightmap_groups) > 0:
511 idx = scene.ms_lightmap_groups_index
512 group_name = scene.ms_lightmap_groups[idx].name
514 # Remove Group
515 group = bpy.data.groups.get(group_name)
516 if group is not None:
518 # Unhide Objects if they are hidden
519 for obj in group.objects:
520 obj.hide_render = False
521 obj.hide = False
523 bpy.data.groups.remove(group, do_unlink=True)
525 # Remove Lightmap Group
526 scene.ms_lightmap_groups.remove(scene.ms_lightmap_groups_index)
527 scene.ms_lightmap_groups_index -= 1
528 if scene.ms_lightmap_groups_index < 0:
529 scene.ms_lightmap_groups_index = 0
531 return {'FINISHED'}
534 class TexAtl_CreateLightmap(Operator):
535 bl_idname = "object.ms_create_lightmap"
536 bl_label = "TextureAtlas - Generate Lightmap"
537 bl_description = "Generates a Lightmap"
539 group_name = StringProperty(default='')
540 resolutionX = IntProperty(default=1024)
541 resolutionY = IntProperty(default=1024)
543 def execute(self, context):
544 scene = context.scene
546 # Create/Update Image
547 image = bpy.data.images.get(self.group_name)
548 if image is None:
549 image = bpy.data.images.new(
550 name=self.group_name, width=self.resolutionX, height=self.resolutionY)
552 image.generated_type = 'COLOR_GRID'
553 image.generated_width = self.resolutionX
554 image.generated_height = self.resolutionY
555 obj_group = bpy.data.groups[self.group_name]
557 # non MESH objects for removal list
558 NON_MESH_LIST = []
560 for object in obj_group.objects:
561 # Remove non MESH objects
563 if object.type != 'MESH':
564 NON_MESH_LIST.append(object)
565 elif object.type == 'MESH' and len(object.data.vertices) == 0:
566 NON_MESH_LIST.append(object)
567 else:
568 # Add Image to faces
569 if object.data.uv_textures.active is None:
570 tex = object.data.uv_textures.new()
571 tex.name = self.group_name
572 else:
573 if self.group_name not in object.data.uv_textures:
574 tex = object.data.uv_textures.new()
575 tex.name = self.group_name
576 tex.active = True
577 tex.active_render = True
578 else:
579 tex = object.data.uv_textures[self.group_name]
580 tex.active = True
581 tex.active_render = True
583 for face_tex in tex.data:
584 face_tex.image = image
586 # remove non NESH objects
587 for object in NON_MESH_LIST:
588 obj_group.objects.unlink(object)
590 NON_MESH_LIST.clear() # clear array
592 return{'FINISHED'}
595 class TexAtl_MergeObjects(Operator):
596 bl_idname = "object.ms_merge_objects"
597 bl_label = "TextureAtlas - TexAtl_MergeObjects"
598 bl_description = "Merges Objects and stores Origins"
600 group_name = StringProperty(default='')
601 unwrap = BoolProperty(default=False)
603 def execute(self, context):
604 scene = context.scene
606 # objToDelete = None
607 bpy.ops.object.select_all(action='DESELECT')
608 ob_merged_old = bpy.data.objects.get(self.group_name + "_mergedObject")
609 if ob_merged_old is not None:
610 ob_merged_old.select = True
611 scene.objects.active = ob_merged_old
612 bpy.ops.object.delete(use_global=True)
614 me = bpy.data.meshes.new(self.group_name + '_mergedObject')
615 ob_merge = bpy.data.objects.new(self.group_name + '_mergedObject', me)
616 ob_merge.location = scene.cursor_location # position object at 3d-cursor
617 scene.objects.link(ob_merge) # Link object to scene
618 me.update()
619 ob_merge.select = False
621 bpy.ops.object.select_all(action='DESELECT')
623 # We do the MergeList beacuse we will duplicate grouped objects
624 mergeList = []
625 for object in bpy.data.groups[self.group_name].objects:
626 mergeList.append(object)
628 for object in mergeList:
629 # make object temporary unhidden
630 isObjHideSelect = object.hide_select
631 object.hide = False
632 object.hide_select = False
634 bpy.ops.object.select_all(action='DESELECT')
635 object.select = True
637 # activate lightmap uv if existant
638 for uv in object.data.uv_textures:
639 if uv.name == self.group_name:
640 uv.active = True
641 scene.objects.active = object
643 # Duplicate Temp Object
644 bpy.ops.object.select_all(action='DESELECT')
645 object.select = True
646 scene.objects.active = object
647 bpy.ops.object.duplicate(linked=False, mode='TRANSLATION')
648 activeNowObject = scene.objects.active
649 activeNowObject.select = True
651 # hide render of original mesh
652 object.hide_render = True
653 object.hide = True
654 object.select = False
655 object.hide_select = isObjHideSelect
657 # remove unused UV
658 # remove UVs
659 UVLIST = []
660 for uv in activeNowObject.data.uv_textures:
661 if uv.name != self.group_name:
662 UVLIST.append(uv.name)
664 for uvName in UVLIST:
665 tex = activeNowObject.data.uv_textures[uvName]
666 activeNowObject.data.uv_textures.remove(tex)
668 UVLIST.clear() # clear array
670 # create vertex groups for each selected object
671 scene.objects.active = activeNowObject
672 vgroup = activeNowObject.vertex_groups.new(name=object.name)
673 vgroup.add(
674 list(range(len(activeNowObject.data.vertices))), weight=1.0, type='ADD')
676 # save object name in merged object
677 item = ob_merge.ms_merged_objects.add()
678 item.name = object.name
680 # Add material to a tempObject if there are no materialSlots on the object
681 if not activeNowObject.data.materials:
682 matName = "zz_TextureAtlas_NO_Material"
683 mat = bpy.data.materials.get(matName)
685 if mat is None:
686 mat = bpy.data.materials.new(matName)
688 activeNowObject.data.materials.append(mat)
690 # merge objects together
691 bpy.ops.object.select_all(action='DESELECT')
692 activeNowObject.select = True
693 ob_merge.select = True
694 scene.objects.active = ob_merge
695 bpy.ops.object.join()
697 mergeList.clear() # Clear Merge List
699 # make Unwrap
700 bpy.ops.object.select_all(action='DESELECT')
701 ob_merge.select = True
702 scene.objects.active = ob_merge
704 # Unfide all faces
705 bpy.ops.object.mode_set(mode='EDIT')
706 bpy.ops.mesh.reveal()
707 bpy.ops.mesh.select_all(action='SELECT')
708 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
710 if self.unwrap is True:
711 groupProps = scene.ms_lightmap_groups[self.group_name]
712 unwrapType = groupProps.unwrap_type
714 if unwrapType == '0' or unwrapType == '1':
715 bpy.ops.object.mode_set(mode='EDIT')
717 if unwrapType == '0':
719 bpy.ops.uv.smart_project(
720 angle_limit=72.0, island_margin=groupProps.autoUnwrapPrecision, user_area_weight=0.0)
721 elif unwrapType == '1':
722 bpy.ops.uv.lightmap_pack(
723 PREF_CONTEXT='ALL_FACES', PREF_PACK_IN_ONE=True, PREF_NEW_UVLAYER=False,
724 PREF_APPLY_IMAGE=False, PREF_IMG_PX_SIZE=1024, PREF_BOX_DIV=48, PREF_MARGIN_DIV=groupProps.autoUnwrapPrecision)
725 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
727 return{'FINISHED'}
730 class TexAtl_SeparateObjects(Operator):
731 bl_idname = "object.ms_separate_objects"
732 bl_label = "TextureAtlas - Separate Objects"
733 bl_description = "Separates Objects and restores Origin"
735 group_name = StringProperty(default='')
737 def execute(self, context):
738 scene = context.scene
740 ob_merged = bpy.data.objects.get(self.group_name + "_mergedObject")
741 if ob_merged is not None:
743 # if scene.objects.active is not None:
744 # bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
745 bpy.ops.object.select_all(action='DESELECT')
746 ob_merged.hide = False
747 ob_merged.select = True
748 groupSeparate = bpy.data.groups.new(ob_merged.name)
749 groupSeparate.objects.link(ob_merged)
750 ob_merged.select = False
752 doUnhidePolygons = False
753 for ms_obj in ob_merged.ms_merged_objects:
754 # select vertex groups and separate group from merged
755 # object
756 bpy.ops.object.select_all(action='DESELECT')
757 ob_merged.select = True
758 scene.objects.active = ob_merged
760 bpy.ops.object.mode_set(mode='EDIT')
761 if doUnhidePolygons is False:
762 # Unhide Polygons only once
763 bpy.ops.mesh.reveal()
764 doUnhidePolygons = True
766 bpy.ops.mesh.select_all(action='DESELECT')
767 ob_merged.vertex_groups.active_index = ob_merged.vertex_groups[
768 ms_obj.name].index
769 bpy.ops.object.vertex_group_select()
770 bpy.ops.mesh.separate(type='SELECTED')
771 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
772 # scene.objects.active.select = False
774 # find separeted object
775 ob_separeted = None
776 for obj in groupSeparate.objects:
777 if obj != ob_merged:
778 ob_separeted = obj
779 break
781 # Copy UV Coordinates to the original mesh
782 if ms_obj.name in scene.objects:
783 ob_merged.select = False
784 ob_original = scene.objects[ms_obj.name]
785 isOriginalToSelect = ob_original.hide_select
786 ob_original.hide_select = False
787 ob_original.hide = False
788 ob_original.select = True
789 scene.objects.active = ob_separeted
790 bpy.ops.object.join_uvs()
791 ob_original.hide_render = False
792 ob_original.select = False
793 ob_original.hide_select = isOriginalToSelect
794 ob_original.data.update()
796 # delete separeted object
797 bpy.ops.object.select_all(action='DESELECT')
798 ob_separeted.select = True
799 bpy.ops.object.delete(use_global=False)
801 # delete duplicated object
802 bpy.ops.object.select_all(action='DESELECT')
803 ob_merged.select = True
804 bpy.ops.object.delete(use_global=False)
806 return{'FINISHED'}
809 def register():
810 bpy.utils.register_module(__name__)
812 bpy.types.Object.ms_merged_objects = CollectionProperty(
813 type=TexAtl_MergedObjects)
815 bpy.types.Scene.ms_lightmap_groups = CollectionProperty(
816 type=TexAtl_MSLightmapGroups)
818 bpy.types.Scene.ms_lightmap_groups_index = IntProperty()
820 def unregister():
821 bpy.utils.unregister_module(__name__)
824 if __name__ == "__main__":
825 register()