Last active
August 29, 2024 14:21
-
-
Save mio3io/844fb93577467fbac05188c1bcf4e8cc to your computer and use it in GitHub Desktop.
ミラー適用してあるようにUV展開するBlenderスクリプト(ミラーUの位置指定などは事前にしておく)【使い方】新規スクリプトを作ってコピペして▶の実行ボタン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
obj = bpy.context.active_object | |
if obj.type == 'MESH': | |
bpy.ops.object.mode_set(mode='OBJECT') | |
bpy.ops.object.mode_set(mode='EDIT') | |
vg = obj.vertex_groups.new(name="TempDataTransfer") | |
selected_verts = [v.index for v in obj.data.vertices if v.select] | |
bpy.ops.object.mode_set(mode='OBJECT') | |
vg.add(selected_verts, 1.0, 'ADD') | |
obj_copy = obj.copy() | |
obj_copy.data = obj.data.copy() | |
bpy.context.collection.objects.link(obj_copy) | |
bpy.context.view_layer.objects.active = obj_copy | |
try: | |
if obj_copy.data.shape_keys: | |
obj_copy.shape_key_clear() | |
for mod in obj_copy.modifiers: | |
if mod.type == 'MIRROR': | |
mod.use_mirror_u = True # MirrorUをオンにしたくない場合は削除 | |
bpy.ops.object.modifier_apply(modifier=mod.name) | |
break | |
bpy.ops.object.mode_set(mode='EDIT') | |
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001) | |
bpy.ops.object.mode_set(mode='OBJECT') | |
bpy.context.view_layer.objects.active = obj | |
data_transfer_mod = obj.modifiers.new(name="DataTransfer", type='DATA_TRANSFER') | |
data_transfer_mod.object = obj_copy | |
data_transfer_mod.use_loop_data = True | |
data_transfer_mod.data_types_loops = {'UV'} | |
data_transfer_mod.vertex_group = vg.name | |
bpy.ops.object.modifier_apply(modifier=data_transfer_mod.name) | |
except: | |
print("Error") | |
finally: | |
obj.vertex_groups.remove(obj.vertex_groups[vg.name]) | |
bpy.data.objects.remove(obj_copy, do_unlink=True) | |
bpy.ops.object.mode_set(mode='EDIT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
作業用に選択部分の頂点グループとオブジェクトのコピーを作成
コピーのシェイプキーを削除してミラー適用してUV展開
コピーのUVを元のオブジェクトに転送
作業用の頂点グループとコピーを削除
を自動化しているため、この手順を踏めばスクリプトを使わなくても可能