Python:2.7版本
Blender: 2.9版本
通过外部Python调用cmd命令行,不启动Blender界面,执行BlenderPython代码,并传递参数,然后进行模型操作、渲染等等。
cmd调用的命令:blender.exe -b -P python_blender.py - - arg1 arg2
其中arg1和arg2是cmd传递的参数
读取参数用
arg1 = sys.argv[-2]
arg2 = sys.argv[-1]
外部Python:
python_cmd.py
import os, subprocess
blender_path = "D:\\Blender2.90\\blender.exe"
python_path = "E:\\\Python\\blender_export_glb.py"
cmd = '{} -b -P {} -- {} {}'.format(blender_path, python_path, gltf_path, object_name)
subprocess.call(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
blender_export_glb.py
import bpy
data_path = str(sys.argv[-1])
asset_name = str(sys.argv[-2])
# 后面写相关blender的逻辑