Blenderのクロスシミュレーションのベイクをptcache.bakeコマンドから実行しようとしても、下記のようなエラーが出てベイクできない。
bpy.ops.ptcache.bake(bake=True)
> RuntimeError: Operator bpy.ops.ptcache.bake.poll() failed, context is incorrect
解決法
オペレーターにシーン・アクティブオブジェクト・シミュレーションのモディファイアのポイントキャッシュ情報を渡す必要がある模様。
ベイクをクリアする際(ptcache.free_bake)も同様の情報を渡す。
obj = bpy.context.object
for mod in obj.modifiers:
if mod.type == 'CLOTH':
override = {'scene': bpy.context.scene, 'active_object': obj, 'point_cache': mod.point_cache}
bpy.ops.ptcache.free_bake(override)
bpy.ops.ptcache.bake(bake=True)
break