オブジェクトのポリゴンやマテリアル、テクスチャ、画像までがファイル内で名前をつけて管理されています。
映像等、レンダリング画像が最終出力になる場合には問題がないのですが、
ゲームのデータ等では名称を統一する必要があったりします
命名規則は様々ですが 今使ってる命名パターンでアドオンを作成してみました
bl_info = {
"name": "リソースの名前を統一",
"author": "Yukimi",
"version": (3, 0),
"blender": (2, 60, 0),
"location": "プロパティ > オブジェクト",
"description": "アクティブオブジェクトのデータ、マテリアルの名称を統一",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Object"
}
import bpy
from bpy.props import StringProperty
class CalibratePanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "uniform name Panel"
bl_idname = "OBJECT_uniform_name"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
scene = context.scene
obj = context.object
row = layout.row()
row.label(text="Active object is: " + obj.name)
row = layout.row()
row.operator("ab.get_f_name")
row = layout.row()
row.prop(scene, "uni_basename")
row = layout.row()
row.operator("ab.uniform_name")
#名称の変更
class RenameButton(bpy.types.Operator):
bl_idname = "ab.uniform_name"
bl_label = "名前の統一化"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
scene = context.scene
if not "uni_basename" in scene: pass
ID = scene.uni_basename
obj = context.object
#オブジェクトの名前を揃える
obj.name = ID + "_Obj"
obj.data.name = ID + "_Mesh"
if obj.data.uv_textures:
obj.data.uv_textures.active.name = ID + "_UV" #アクティブなもののみ変更
if obj.material_slots:
for i,mat_slot in enumerate(obj.material_slots):
mat = mat_slot.material
if not mat: continue
mat.name= ID + "_Mtl_%02d" % i
if mat.active_texture:
tex = mat.active_texture
tex.name = ID + "_Tex_%02d" % i
if tex.type == 'IMAGE' and tex.image:
tex.image.name = ID + "_Img_%02d" % i
return{'FINISHED'}
#ファイル名を取得してテキスト入力の値を設定
class fpathButtonButton(bpy.types.Operator):
bl_idname = "ab.get_f_name"
bl_label = "ファイル名の取得"
def execute(self, context):
import os
base_name = os.path.basename(bpy.context.blend_data.filepath)
f_name = os.path.splitext(base_name)[0]
context.scene.uni_basename = f_name
return{'FINISHED'}
def init_props():
scene = bpy.types.Scene
scene.uni_basename = StringProperty(name = "揃える名前", default= "" )
#プロパティの削除
def crear_props():
scene = bpy.types.Scene
del uni_basename
def register():
bpy.utils.register_module(__name__)
init_props()
def unregister():
bpy.utils.unregister_module(__name__)
crear_props()
if __name__ == "__main__":
register()
プロパティのオブジェクトタブに追加する形になっています現状はUVはアクティブなもののみ末尾に_UVをつけ、マテリアルに通し番号をつけ、 テクスチャ、イメージ名はマテリアルの通し番号で命名するようにしています
名称の変更部分はシンプルなので 個々の案件によって調整できるかと思います
いかがでしょうか

0 件のコメント:
コメントを投稿