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 #####
21 "name": "Texture Atlas",
22 "author": "Andreas Esau, Paul Geraskin, Campbell Barton",
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",
33 from bpy
.types
import (
38 from bpy
.props
import (
49 def check_all_objects_visible(self
, context
):
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
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):
69 group
= scene
.ms_lightmap_groups
[scene
.ms_lightmap_groups_index
]
71 if group
.name
in bpy
.data
.groups
:
75 self
.report({'INFO'}, "No Such Group %r!" % group
.name
)
79 class TexAtl_Main(Panel
):
80 bl_label
= "Texture Atlas"
81 bl_space_type
= 'PROPERTIES'
82 bl_region_type
= 'WINDOW'
84 bl_options
= {'DEFAULT_CLOSED'}
86 def draw(self
, context
):
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()
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()
135 "object.ms_run", text
="StartManualUnwrap", icon
="LAMP_SPOT")
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
151 old_context
= context
.area
.type
153 # Check if group exists
154 if check_group_exist(self
, context
) is False:
157 group
= scene
.ms_lightmap_groups
[scene
.ms_lightmap_groups_index
]
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
)
178 self
.report({'INFO'}, "Not All Objects Are Visible!!!")
180 # set old context back
182 context
.area
.type = old_context
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
198 old_context
= context
.area
.type
200 # Check if group exists
201 if check_group_exist(self
, context
) is False:
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!!!")
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
230 context
.area
.type = old_context
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
246 old_context
= context
.area
.type
248 # Check if group exists
249 if check_group_exist(self
, context
) is False:
252 group
= scene
.ms_lightmap_groups
[scene
.ms_lightmap_groups_index
]
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
)
267 self
.report({'INFO'}, "Not All Objects Are Visible!!!")
269 # set old context back
271 context
.area
.type = old_context
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(
295 items
=(('0', 'Smart_Unwrap', 'Smart_Unwrap'),
296 ('1', 'Lightmap', 'Lightmap'),
297 ('2', 'No_Unwrap', 'No_Unwrap'),
300 resolutionX
= EnumProperty(
302 items
=(('256', '256', ''),
304 ('1024', '1024', ''),
305 ('2048', '2048', ''),
306 ('4096', '4096', ''),
307 ('8192', '8192', ''),
308 ('16384', '16384', ''),
312 resolutionY
= EnumProperty(
314 items
=(('256', '256', ''),
316 ('1024', '1024', ''),
317 ('2048', '2048', ''),
318 ('4096', '4096', ''),
319 ('8192', '8192', ''),
320 ('16384', '16384', ''),
324 autoUnwrapPrecision
= FloatProperty(
325 name
="autoUnwrapPrecision",
330 template_list_controls
= StringProperty(
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)
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:
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
:
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:
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
:
424 tex
= object.data
.uv_textures
.get(group_name
)
426 object.data
.uv_textures
.remove(tex
)
429 obj_group
.objects
.unlink(object)
430 object.hide_render
= False
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:
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
:
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
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)
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
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
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
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
)
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
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)
569 if object.data
.uv_textures
.active
is None:
570 tex
= object.data
.uv_textures
.new()
571 tex
.name
= self
.group_name
573 if self
.group_name
not in object.data
.uv_textures
:
574 tex
= object.data
.uv_textures
.new()
575 tex
.name
= self
.group_name
577 tex
.active_render
= True
579 tex
= object.data
.uv_textures
[self
.group_name
]
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
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
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
619 ob_merge
.select
= False
621 bpy
.ops
.object.select_all(action
='DESELECT')
623 # We do the MergeList beacuse we will duplicate grouped objects
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
632 object.hide_select
= False
634 bpy
.ops
.object.select_all(action
='DESELECT')
637 # activate lightmap uv if existant
638 for uv
in object.data
.uv_textures
:
639 if uv
.name
== self
.group_name
:
641 scene
.objects
.active
= object
643 # Duplicate Temp Object
644 bpy
.ops
.object.select_all(action
='DESELECT')
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
654 object.select
= False
655 object.hide_select
= isObjHideSelect
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
)
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
)
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
700 bpy
.ops
.object.select_all(action
='DESELECT')
701 ob_merge
.select
= True
702 scene
.objects
.active
= ob_merge
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)
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
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
[
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
776 for obj
in groupSeparate
.objects
:
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)
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()
821 bpy
.utils
.unregister_module(__name__
)
824 if __name__
== "__main__":