Substance Painter 2020.1 (6.1.0) より、従来の JavaScript API に加え、 Python API が追加されました。
Substance Painter Version 2020.1 (6.1.0)リリースノート – Born Digital サポート
しかし、公式ドキュメントでは Python API の存在はいまだ触れられていません。どこから手を付けていいのかわかりにくかったので、入り口の部分だけメモしておきます。
なお、SP 2020.2 時点で Python API のバージョンは 0.0.2 となっています。この記事の内容はすぐ陳腐化する可能性が高いことに注意してください。
Python API リファレンスの場所
- アプリ内メニューバーの Help > Documentation > Python API をクリックすると、ローカルにあるHTMLファイルが開かれる
- Windows の場合、実際のパスは C:\Program Files\Allegorithmic\Substance Painter\resources\python-doc\index.html
- なぜかオンラインでは公開されていない
- JavaScript API も同様
- ググれなくて困る…
スクリプトの配置場所
-
"Python > Plugin Folder" で、プラグイン保存先フォルダーが開く
- Windows の場合、C:\Users<USER NAME>\Documents\Allegorithmic\Substance Painter\python\plugins
- .py ファイルは plugins/ 直下に配置する
- サブフォルダー内に置いても読み込まれない
Python コンソール
- "Windows > Views > Python Console" でコンソールウィンドウを表示
- 例えば以下のコマンドでリファレンスを見られる
- 字がやたら小さいので、HTML リファレンスを見たほうがいい
# モジュールをロード
import substance_painter
# モジュールの説明を表示
help(substance_painter)
# project モジュールの説明を表示
help(substance_painter.project)
簡単なプラグインを作るチュートリアル
plugins/hello_plugin.py
を以下の内容で作成する。
"""The hello world of python scripting in Substance Painter
"""
from PySide2 import QtWidgets
import substance_painter.ui
plugin_widgets = []
"""Keep track of added ui elements for cleanup"""
def start_plugin():
"""This method is called when the plugin is started."""
# Create a simple text widget
hello_widget = QtWidgets.QTextEdit()
hello_widget.setText("Hello from python scripting!")
hello_widget.setReadOnly(True)
hello_widget.setWindowTitle("Hello Plugin")
# Add this widget as a dock to the interface
substance_painter.ui.add_dock_widget(hello_widget)
# Store added widget for proper cleanup when stopping the plugin
plugin_widgets.append(hello_widget)
def close_plugin():
"""This method is called when the plugin is stopped."""
# We need to remove all added widgets from the UI.
for widget in plugin_widgets:
substance_painter.ui.delete_ui_element(widget)
plugin_widgets.clear()
if __name__ == "__main__":
start_plugin()
"Python > Reload Plugin Folders" で、フォルダーを再スキャン。
"Python > hello_plugin" という項目ができているので、クリック。
画面内に "HELLO PLUGIN" というウィジェット (ペイン) が作成されれば成功です。
その他補足
- 公式のプラグイン共有サイトでは、2020年7月30日現在、Python プラグインはシェアされていません。
- Substance Share « The Free Exchange Platform »
- そもそも JavaScript のも少ないし、大抵が古い
- Painter のプラグインは全然流行ってない?
- プラグインを書こうと思った動機は、メッシュを変更するたびに "Edit > Project Configuration..." からリロードするのが非常に面倒だったからなのですが、再読み込みする API はどうやら存在しないようです。なぜ作らない!
- 要望も集まってる → Reload mesh button. – Feedback