本日はBlenderPython枠です。
Blenderでは様々なフォーマットのファイルに出力をサポートしています。
今回はUSDZへのエクスポートに関するテーマです。
〇USDZについて
USDZ(.usdz)はUniversal Scene Description形式のファイルフォーマットの中でZ形式での非圧縮形態をUSDZと呼びます。
近年AppleのクイックルックビューなどでUSDZが用いられていることでApple製品を中心に使用されるようになってきました。
BlenderにおいてはUSDZ形式のファイルフォーマットのエクスポートはサポートされています。
しかしながらUSDZ形式としてエクスポートするためにはUniversal Scene Descriptionの形式でエクスポートを選択し、拡張子でusdzと明示する必要があります。
〇USDZのエクスポートを行うアドオンを作る
今回もいつものごとくできるかわからない状態で始めています。
まずはBlenderのエクスポートメニューに新しいコマンドを追加していきます。
メニューにコマンドを追加する処理は次のようになります。
def menu_func_export(self, context):
self.layout.operator(ExportUSDZ.bl_idname, text="USDZ (.usdz)")
self.layout.operatorを使って、ExportUSDZクラスのオペレーターをメニューに追加しています。
実際のエクスポートクラスは以下です。
class ExportUSDZ(bpy.types.Operator):
bl_idname = "export_scene.usdz"
bl_label = "Export USDZ"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
print("Exporting to USDZ:", self.filepath)
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
ここではcontext.window_manager.fileselect_add(self)で最終的にファイル選択ダイアログが表示されます。

〇コード
import bpy
def menu_func_export(self, context):
self.layout.operator(ExportUSDZ.bl_idname, text="USDZ (.usdz)")
class ExportUSDZ(bpy.types.Operator):
bl_idname = "export_scene.usdz"
bl_label = "Export USDZ"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
print("Exporting to USDZ:", self.filepath)
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(ExportUSDZ)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ExportUSDZ)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()
このコードを実行することでエクスポートにUSDZ(.usdz)が追加されます。

本日は以上です。
ここでは側だけなので次回は中身を作っていきます。