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
="Resolutiom:")
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
147 old_context
= context
.area
.type
149 # Check if group exists
150 if check_group_exist(self
, context
) is False:
153 group
= scene
.ms_lightmap_groups
[scene
.ms_lightmap_groups_index
]
154 context
.area
.type = 'VIEW_3D'
156 if bpy
.ops
.object.mode_set
.poll():
157 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
159 if group
.bake
is True and bpy
.data
.groups
[group
.name
].objects
:
161 # Check if objects are all on the visible Layers.
162 isAllObjVisible
= check_all_objects_visible(self
, context
)
164 if isAllObjVisible
is True:
165 resX
= int(group
.resolutionX
)
166 resY
= int(group
.resolutionY
)
167 bpy
.ops
.object.ms_create_lightmap(
168 group_name
=group
.name
, resolutionX
=resX
, resolutionY
=resY
)
169 bpy
.ops
.object.ms_merge_objects(
170 group_name
=group
.name
, unwrap
=True)
171 bpy
.ops
.object.ms_separate_objects(group_name
=group
.name
)
173 self
.report({'INFO'}, "Not All Objects Are Visible!!!")
175 context
.area
.type = old_context
180 class TexAtl_RunStart(Operator
):
181 bl_idname
= "object.ms_run"
182 bl_label
= "Make Manual Unwrapping Object"
183 bl_description
= "Makes Manual Unwrapping Object"
185 def execute(self
, context
):
186 scene
= context
.scene
187 old_context
= context
.area
.type
189 # Check if group exists
190 if check_group_exist(self
, context
) is False:
193 context
.area
.type = 'VIEW_3D'
194 group
= scene
.ms_lightmap_groups
[scene
.ms_lightmap_groups_index
]
196 if bpy
.ops
.object.mode_set
.poll():
197 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
199 if group
.bake
is True and bpy
.data
.groups
[group
.name
].objects
:
201 # Check if objects are all on the visible Layers.
202 isAllObjVisible
= check_all_objects_visible(self
, context
)
204 if bpy
.data
.objects
.get(group
.name
+ "_mergedObject") is not None:
205 self
.report({'INFO'}, "Old Merged Object Exists!!!")
206 elif isAllObjVisible
is False:
207 self
.report({'INFO'}, "Not All Objects Are Visible!!!")
209 resX
= int(group
.resolutionX
)
210 resY
= int(group
.resolutionY
)
211 bpy
.ops
.object.ms_create_lightmap(
212 group_name
=group
.name
, resolutionX
=resX
, resolutionY
=resY
)
213 bpy
.ops
.object.ms_merge_objects(
214 group_name
=group
.name
, unwrap
=False)
216 context
.area
.type = old_context
221 class TexAtl_RunFinish(Operator
):
222 bl_idname
= "object.ms_run_remove"
223 bl_label
= "Remove Manual Unwrapping Object"
224 bl_description
= "Removes Manual Unwrapping Object"
226 def execute(self
, context
):
227 scene
= context
.scene
228 old_context
= context
.area
.type
230 # Check if group exists
231 if check_group_exist(self
, context
) is False:
234 group
= scene
.ms_lightmap_groups
[scene
.ms_lightmap_groups_index
]
235 context
.area
.type = 'VIEW_3D'
237 if bpy
.ops
.object.mode_set
.poll():
238 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
240 if group
.bake
is True and bpy
.data
.groups
[group
.name
].objects
:
242 # Check if objects are all on the visible Layers.
243 isAllObjVisible
= check_all_objects_visible(self
, context
)
245 if isAllObjVisible
is True:
246 bpy
.ops
.object.ms_separate_objects(group_name
=group
.name
)
248 self
.report({'INFO'}, "Not All Objects Are Visible!!!")
250 context
.area
.type = old_context
254 class TexAtl_UVLayers(PropertyGroup
):
255 name
= StringProperty(default
="")
258 class TexAtl_VertexGroups(PropertyGroup
):
259 name
= StringProperty(default
="")
262 class TexAtl_Groups(PropertyGroup
):
263 name
= StringProperty(default
="")
266 class TexAtl_MSLightmapGroups(PropertyGroup
):
268 name
= StringProperty(default
="")
269 bake
= BoolProperty(default
=True)
271 unwrap_type
= EnumProperty(
273 items
=(('0', 'Smart_Unwrap', 'Smart_Unwrap'),
274 ('1', 'Lightmap', 'Lightmap'),
275 ('2', 'No_Unwrap', 'No_Unwrap'),
278 resolutionX
= EnumProperty(
280 items
=(('256', '256', ''),
282 ('1024', '1024', ''),
283 ('2048', '2048', ''),
284 ('4096', '4096', ''),
285 ('8192', '8192', ''),
286 ('16384', '16384', ''),
290 resolutionY
= EnumProperty(
292 items
=(('256', '256', ''),
294 ('1024', '1024', ''),
295 ('2048', '2048', ''),
296 ('4096', '4096', ''),
297 ('8192', '8192', ''),
298 ('16384', '16384', ''),
302 autoUnwrapPrecision
= FloatProperty(
303 name
="autoUnwrapPrecision",
308 template_list_controls
= StringProperty(
314 class TexAtl_MergedObjects(PropertyGroup
):
315 name
= StringProperty()
316 vertex_groups
= CollectionProperty(
317 type=TexAtl_VertexGroups
,
319 groups
= CollectionProperty(type=TexAtl_Groups
)
320 uv_layers
= CollectionProperty(type=TexAtl_UVLayers
)
323 class TexAtl_AddSelectedToGroup(Operator
):
324 bl_idname
= "scene.ms_add_selected_to_group"
325 bl_label
= "Add to Group"
326 bl_description
= "Adds selected Objects to current Group"
328 def execute(self
, context
):
329 scene
= context
.scene
330 group_name
= scene
.ms_lightmap_groups
[
331 scene
.ms_lightmap_groups_index
].name
333 # Create a New Group if it was deleted.
334 obj_group
= bpy
.data
.groups
.get(group_name
)
335 if obj_group
is None:
336 obj_group
= bpy
.data
.groups
.new(group_name
)
338 # Add objects to a group
339 if bpy
.ops
.object.mode_set
.poll():
340 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
342 for object in context
.selected_objects
:
343 if object.type == 'MESH' and object.name
not in obj_group
.objects
:
344 obj_group
.objects
.link(object)
349 class TexAtl_SelectGroup(Operator
):
350 bl_idname
= "scene.ms_select_group"
351 bl_label
= "sel Group"
352 bl_description
= "Selected Objects of current Group"
354 def execute(self
, context
):
355 scene
= context
.scene
356 group_name
= scene
.ms_lightmap_groups
[
357 scene
.ms_lightmap_groups_index
].name
359 # Check if group exists
360 if check_group_exist(self
, context
) is False:
363 if bpy
.ops
.object.mode_set
.poll():
364 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
366 bpy
.ops
.object.select_all(action
='DESELECT')
367 obj_group
= bpy
.data
.groups
[group_name
]
368 for object in obj_group
.objects
:
373 class TexAtl_RemoveFromGroup(Operator
):
374 bl_idname
= "scene.ms_remove_selected"
375 bl_label
= "del Selected"
376 bl_description
= "Remove Selected Group and UVs"
378 # remove all modifiers
379 # for m in mesh.modifiers:
380 # bpy.ops.object.modifier_remove(modifier=m.name)
382 def execute(self
, context
):
383 scene
= context
.scene
385 # Check if group exists
386 if check_group_exist(self
, context
) is False:
389 if bpy
.ops
.object.mode_set
.poll():
390 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
392 for group
in scene
.ms_lightmap_groups
:
393 group_name
= group
.name
395 obj_group
= bpy
.data
.groups
[group_name
]
396 for object in context
.selected_objects
:
397 scene
.objects
.active
= object
399 if object.type == 'MESH' and object.name
in obj_group
.objects
:
402 tex
= object.data
.uv_textures
.get(group_name
)
404 object.data
.uv_textures
.remove(tex
)
407 obj_group
.objects
.unlink(object)
408 object.hide_render
= False
413 class TexAtl_RemoveOtherUVs(Operator
):
414 bl_idname
= "scene.ms_remove_other_uv"
415 bl_label
= "remOther"
416 bl_description
= "Remove Other UVs from Selected"
418 def execute(self
, context
):
419 scene
= context
.scene
420 group_name
= scene
.ms_lightmap_groups
[
421 scene
.ms_lightmap_groups_index
].name
423 # Check if group exists
424 if check_group_exist(self
, context
) is False:
427 if bpy
.ops
.object.mode_set
.poll():
428 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
429 # bpy.ops.object.select_all(action='DESELECT')
431 obj_group
= bpy
.data
.groups
[group_name
]
433 # Remove other UVs of selected objects
434 for object in context
.selected_objects
:
435 scene
.objects
.active
= object
436 if object.type == 'MESH' and object.name
in obj_group
.objects
:
440 for uv
in object.data
.uv_textures
:
441 if uv
.name
!= group_name
:
442 UVLIST
.append(uv
.name
)
444 for uvName
in UVLIST
:
445 tex
= object.data
.uv_textures
[uvName
]
446 object.data
.uv_textures
.remove(tex
)
448 UVLIST
.clear() # clear array
453 class TexAtl_AddLightmapGroup(Operator
):
454 bl_idname
= "scene.ms_add_lightmap_group"
455 bl_label
= "add Lightmap"
456 bl_description
= "Adds a new Lightmap Group"
458 name
= StringProperty(name
="Group Name", default
='TextureAtlas')
460 def execute(self
, context
):
461 scene
= context
.scene
462 obj_group
= bpy
.data
.groups
.new(self
.name
)
464 item
= scene
.ms_lightmap_groups
.add()
465 item
.name
= obj_group
.name
466 #item.resolution = '1024'
467 scene
.ms_lightmap_groups_index
= len(scene
.ms_lightmap_groups
) - 1
469 # Add selested objects to group
470 for object in context
.selected_objects
:
471 if object.type == 'MESH':
472 obj_group
.objects
.link(object)
476 def invoke(self
, context
, event
):
477 wm
= context
.window_manager
478 return wm
.invoke_props_dialog(self
)
481 class TexAtl_DelLightmapGroup(Operator
):
482 bl_idname
= "scene.ms_del_lightmap_group"
483 bl_label
= "delete Lightmap"
484 bl_description
= "Deletes active Lightmap Group"
486 def execute(self
, context
):
487 scene
= context
.scene
488 if len(scene
.ms_lightmap_groups
) > 0:
489 idx
= scene
.ms_lightmap_groups_index
490 group_name
= scene
.ms_lightmap_groups
[idx
].name
493 group
= bpy
.data
.groups
.get(group_name
)
494 if group
is not None:
496 # Unhide Objects if they are hidden
497 for obj
in group
.objects
:
498 obj
.hide_render
= False
501 bpy
.data
.groups
.remove(group
)
503 # Remove Lightmap Group
504 scene
.ms_lightmap_groups
.remove(scene
.ms_lightmap_groups_index
)
505 scene
.ms_lightmap_groups_index
-= 1
506 if scene
.ms_lightmap_groups_index
< 0:
507 scene
.ms_lightmap_groups_index
= 0
512 class TexAtl_CreateLightmap(Operator
):
513 bl_idname
= "object.ms_create_lightmap"
514 bl_label
= "TextureAtlas - Generate Lightmap"
515 bl_description
= "Generates a Lightmap"
517 group_name
= StringProperty(default
='')
518 resolutionX
= IntProperty(default
=1024)
519 resolutionY
= IntProperty(default
=1024)
521 def execute(self
, context
):
522 scene
= context
.scene
524 # Create/Update Image
525 image
= bpy
.data
.images
.get(self
.group_name
)
527 image
= bpy
.data
.images
.new(
528 name
=self
.group_name
, width
=self
.resolutionX
, height
=self
.resolutionY
)
530 image
.generated_type
= 'COLOR_GRID'
531 image
.generated_width
= self
.resolutionX
532 image
.generated_height
= self
.resolutionY
533 obj_group
= bpy
.data
.groups
[self
.group_name
]
535 # non MESH objects for removal list
538 for object in obj_group
.objects
:
539 # Remove non MESH objects
541 if object.type != 'MESH':
542 NON_MESH_LIST
.append(object)
543 elif object.type == 'MESH' and len(object.data
.vertices
) == 0:
544 NON_MESH_LIST
.append(object)
547 if object.data
.uv_textures
.active
is None:
548 tex
= object.data
.uv_textures
.new()
549 tex
.name
= self
.group_name
551 if self
.group_name
not in object.data
.uv_textures
:
552 tex
= object.data
.uv_textures
.new()
553 tex
.name
= self
.group_name
555 tex
.active_render
= True
557 tex
= object.data
.uv_textures
[self
.group_name
]
559 tex
.active_render
= True
561 for face_tex
in tex
.data
:
562 face_tex
.image
= image
564 # remove non NESH objects
565 for object in NON_MESH_LIST
:
566 obj_group
.objects
.unlink(object)
568 NON_MESH_LIST
.clear() # clear array
573 class TexAtl_MergeObjects(Operator
):
574 bl_idname
= "object.ms_merge_objects"
575 bl_label
= "TextureAtlas - TexAtl_MergeObjects"
576 bl_description
= "Merges Objects and stores Origins"
578 group_name
= StringProperty(default
='')
579 unwrap
= BoolProperty(default
=False)
581 def execute(self
, context
):
582 scene
= context
.scene
585 bpy
.ops
.object.select_all(action
='DESELECT')
586 ob_merged_old
= bpy
.data
.objects
.get(self
.group_name
+ "_mergedObject")
587 if ob_merged_old
is not None:
588 ob_merged_old
.select
= True
589 scene
.objects
.active
= ob_merged_old
590 bpy
.ops
.object.delete(use_global
=True)
592 me
= bpy
.data
.meshes
.new(self
.group_name
+ '_mergedObject')
593 ob_merge
= bpy
.data
.objects
.new(self
.group_name
+ '_mergedObject', me
)
594 ob_merge
.location
= scene
.cursor_location
# position object at 3d-cursor
595 scene
.objects
.link(ob_merge
) # Link object to scene
597 ob_merge
.select
= False
599 bpy
.ops
.object.select_all(action
='DESELECT')
601 # We do the MergeList beacuse we will duplicate grouped objects
603 for object in bpy
.data
.groups
[self
.group_name
].objects
:
604 mergeList
.append(object)
606 for object in mergeList
:
607 # make object temporary unhidden
608 isObjHideSelect
= object.hide_select
610 object.hide_select
= False
612 bpy
.ops
.object.select_all(action
='DESELECT')
615 # activate lightmap uv if existant
616 for uv
in object.data
.uv_textures
:
617 if uv
.name
== self
.group_name
:
619 scene
.objects
.active
= object
621 # Duplicate Temp Object
622 bpy
.ops
.object.select_all(action
='DESELECT')
624 scene
.objects
.active
= object
625 bpy
.ops
.object.duplicate(linked
=False, mode
='TRANSLATION')
626 activeNowObject
= scene
.objects
.active
627 activeNowObject
.select
= True
629 # hide render of original mesh
630 object.hide_render
= True
632 object.select
= False
633 object.hide_select
= isObjHideSelect
638 for uv
in activeNowObject
.data
.uv_textures
:
639 if uv
.name
!= self
.group_name
:
640 UVLIST
.append(uv
.name
)
642 for uvName
in UVLIST
:
643 tex
= activeNowObject
.data
.uv_textures
[uvName
]
644 activeNowObject
.data
.uv_textures
.remove(tex
)
646 UVLIST
.clear() # clear array
648 # create vertex groups for each selected object
649 scene
.objects
.active
= activeNowObject
650 vgroup
= activeNowObject
.vertex_groups
.new(name
=object.name
)
652 list(range(len(activeNowObject
.data
.vertices
))), weight
=1.0, type='ADD')
654 # save object name in merged object
655 item
= ob_merge
.ms_merged_objects
.add()
656 item
.name
= object.name
658 # Add material to a tempObject if there are no materialSlots on the object
659 if not activeNowObject
.data
.materials
:
660 matName
= "zz_TextureAtlas_NO_Material"
661 mat
= bpy
.data
.materials
.get(matName
)
664 mat
= bpy
.data
.materials
.new(matName
)
666 activeNowObject
.data
.materials
.append(mat
)
668 # merge objects together
669 bpy
.ops
.object.select_all(action
='DESELECT')
670 activeNowObject
.select
= True
671 ob_merge
.select
= True
672 scene
.objects
.active
= ob_merge
673 bpy
.ops
.object.join()
675 mergeList
.clear() # Clear Merge List
678 bpy
.ops
.object.select_all(action
='DESELECT')
679 ob_merge
.select
= True
680 scene
.objects
.active
= ob_merge
683 bpy
.ops
.object.mode_set(mode
='EDIT')
684 bpy
.ops
.mesh
.reveal()
685 bpy
.ops
.mesh
.select_all(action
='SELECT')
686 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
688 if self
.unwrap
is True:
689 groupProps
= scene
.ms_lightmap_groups
[self
.group_name
]
690 unwrapType
= groupProps
.unwrap_type
692 if unwrapType
== '0' or unwrapType
== '1':
693 bpy
.ops
.object.mode_set(mode
='EDIT')
695 if unwrapType
== '0':
697 bpy
.ops
.uv
.smart_project(
698 angle_limit
=72.0, island_margin
=groupProps
.autoUnwrapPrecision
, user_area_weight
=0.0)
699 elif unwrapType
== '1':
700 bpy
.ops
.uv
.lightmap_pack(
701 PREF_CONTEXT
='ALL_FACES', PREF_PACK_IN_ONE
=True, PREF_NEW_UVLAYER
=False,
702 PREF_APPLY_IMAGE
=False, PREF_IMG_PX_SIZE
=1024, PREF_BOX_DIV
=48, PREF_MARGIN_DIV
=groupProps
.autoUnwrapPrecision
)
703 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
708 class TexAtl_SeparateObjects(Operator
):
709 bl_idname
= "object.ms_separate_objects"
710 bl_label
= "TextureAtlas - Separate Objects"
711 bl_description
= "Separates Objects and restores Origin"
713 group_name
= StringProperty(default
='')
715 def execute(self
, context
):
716 scene
= context
.scene
718 ob_merged
= bpy
.data
.objects
.get(self
.group_name
+ "_mergedObject")
719 if ob_merged
is not None:
721 # if scene.objects.active is not None:
722 # bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
723 bpy
.ops
.object.select_all(action
='DESELECT')
724 ob_merged
.hide
= False
725 ob_merged
.select
= True
726 groupSeparate
= bpy
.data
.groups
.new(ob_merged
.name
)
727 groupSeparate
.objects
.link(ob_merged
)
728 ob_merged
.select
= False
730 doUnhidePolygons
= False
731 for ms_obj
in ob_merged
.ms_merged_objects
:
732 # select vertex groups and separate group from merged
734 bpy
.ops
.object.select_all(action
='DESELECT')
735 ob_merged
.select
= True
736 scene
.objects
.active
= ob_merged
738 bpy
.ops
.object.mode_set(mode
='EDIT')
739 if doUnhidePolygons
is False:
740 # Unhide Polygons only once
741 bpy
.ops
.mesh
.reveal()
742 doUnhidePolygons
= True
744 bpy
.ops
.mesh
.select_all(action
='DESELECT')
745 ob_merged
.vertex_groups
.active_index
= ob_merged
.vertex_groups
[
747 bpy
.ops
.object.vertex_group_select()
748 bpy
.ops
.mesh
.separate(type='SELECTED')
749 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
750 # scene.objects.active.select = False
752 # find separeted object
754 for obj
in groupSeparate
.objects
:
759 # Copy UV Coordinates to the original mesh
760 if ms_obj
.name
in scene
.objects
:
761 ob_merged
.select
= False
762 ob_original
= scene
.objects
[ms_obj
.name
]
763 isOriginalToSelect
= ob_original
.hide_select
764 ob_original
.hide_select
= False
765 ob_original
.hide
= False
766 ob_original
.select
= True
767 scene
.objects
.active
= ob_separeted
768 bpy
.ops
.object.join_uvs()
769 ob_original
.hide_render
= False
770 ob_original
.select
= False
771 ob_original
.hide_select
= isOriginalToSelect
772 ob_original
.data
.update()
774 # delete separeted object
775 bpy
.ops
.object.select_all(action
='DESELECT')
776 ob_separeted
.select
= True
777 bpy
.ops
.object.delete(use_global
=False)
779 # delete duplicated object
780 bpy
.ops
.object.select_all(action
='DESELECT')
781 ob_merged
.select
= True
782 bpy
.ops
.object.delete(use_global
=False)
788 bpy
.utils
.register_module(__name__
)
790 bpy
.types
.Object
.ms_merged_objects
= CollectionProperty(
791 type=TexAtl_MergedObjects
)
793 bpy
.types
.Scene
.ms_lightmap_groups
= CollectionProperty(
794 type=TexAtl_MSLightmapGroups
)
796 bpy
.types
.Scene
.ms_lightmap_groups_index
= IntProperty()
799 bpy
.utils
.unregister_module(__name__
)
802 if __name__
== "__main__":