この記事について(備忘録)
https://github.com/hbertiche/NeuralClothSim
上記の論文を実装する際に
$ blender --python get_body_model.py
$ blender --python get_sequence.py
というblenderのコードを入力するところがあります。
Windowsの初期設定ではblenderのパスが通っていないため、大体の環境ではおそらくエラーが発生します。仮想環境に入らない状態でblenderにパスを通すのと、仮想環境下でblenderにパスを通すのではやり方が違うため両方紹介します。
目次
環境
Windows11
Python 3.13.0
PowerShell
仮想環境に入らない状態でblenderのパスを通す時
1. Blenderのインストールディレクトリを確認
通常、Blenderは以下の場所にインストールされています:
C:\Program Files\Blender Foundation\Blender [バージョン]
例:C:\Program Files\Blender Foundation\Blender 3.0
このパスをコピーしておきます。
2. 環境変数の設定
(著者のWindows11は英語なのでスクショに記載されているのは英語になります)
-
Windowsアイコンを右クリックし、「System」を選択
-
「Advanced system settings」を選択System Propertiesが開く
-
System Propertiesの「Advanced」タブに移動
-
「Environment Variables」をクリック
-
下のスクショのようにPATHを選んで「OK」をクリック
-
「Edit environment variable」の画面で、「New」をクリックし、先程コピーしたblenderのパスを入力。この時点で下図のようになっているはず
-
「OK」をクリックして、すべてのダイアログを閉じます。
3. 動作確認
コマンドプロンプトを再起動し(おそらく再起動しないと反映されない可能性がある。)、以下のコマンドを実行してBlenderのバージョン情報が表示されるか確認します:
blender --version
下記のメッセージが表示されれば成功。
TBBmalloc: skip allocation functions replacement in ucrtbase.dll: unknown prologue for function _msize
Blender 4.2.2 LTS
build date: 2024-09-24
build time: 01:17:42
build commit date: 2024-09-23
build commit time: 12:18
build hash: c03d7d98a413
build branch: blender-v4.2-release
build platform: Windows
build type: Release
build c flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3 /nologo /J /Gd /MP /bigobj /Zc:inline -openmp
build c++ flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3 /EHsc /nologo /J /Gd /MP /EHsc /bigobj /permissive- /Zc:__cplusplus /Zc:inline -openmp
build link flags: /MACHINE:X64 /SUBSYSTEM:CONSOLE /STACK:2097152 /ignore:4049 /ignore:4217 /ignore:4221
build system: CMake
venvの仮想環境下でblenderのパスを通す時
何もパスを通していない状態でblender --version
のコマンドを使うとおそらく以下のエラーが出現します。
blender : The term 'blender' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ blender --version
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (blender:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
1. Activate.ps1の編集
テキストエディタ(メモ帳、Visual Studio Codeなど)でActivate.ps1を開きます。
Activate.ps1のどこかに以下のようにPATHが通っているはずです。
# Add the venv to the PATH
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
以下のようにパスを追加します。
# Add the venv to the PATH
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
# Add Blender to the PATH
$env:Path += ";C:\Program Files\Blender Foundation\Blender 4.2\bin\"
2. PowerShellの再起動
仮想環境からdeactivateして、PowerShellを再起動してください(重要)
3. 動作確認
コマンドプロンプトを再起動し(おそらく再起動しないと反映されない可能性がある。)、以下のコマンドを実行してBlenderのバージョン情報が表示されるか確認します:
blender --version
下記のメッセージが表示されれば成功。
TBBmalloc: skip allocation functions replacement in ucrtbase.dll: unknown prologue for function _msize
Blender 4.2.2 LTS
build date: 2024-09-24
build time: 01:17:42
build commit date: 2024-09-23
build commit time: 12:18
build hash: c03d7d98a413
build branch: blender-v4.2-release
build platform: Windows
build type: Release
build c flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3 /nologo /J /Gd /MP /bigobj /Zc:inline -openmp
build c++ flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3 /EHsc /nologo /J /Gd /MP /EHsc /bigobj /permissive- /Zc:__cplusplus /Zc:inline -openmp
build link flags: /MACHINE:X64 /SUBSYSTEM:CONSOLE /STACK:2097152 /ignore:4049 /ignore:4217 /ignore:4221
build system: CMake