我是搅拌机和蟒蛇的新手。我有一个搅拌机模型(.blend),我想将其批量渲染为多个图像,为每个图像提供一些属性。
我用这些参数编写了一个 python 脚本,如下所示:
import bpy
pi = 3.14159265
fov = 50
scene = bpy.data.scenes["Scene"]
# Set render resolution
scene.render.resolution_x = 480
scene.render.resolution_y = 359
# Set camera fov in degrees
scene.camera.data.angle = fov*(pi/180.0)
# Set camera rotation in euler angles
scene.camera.rotation_mode = 'XYZ'
scene.camera.rotation_euler[0] = 0.0*(pi/180.0)
scene.camera.rotation_euler[1] = 0.0*(pi/180.0)
scene.camera.rotation_euler[2] = -30.0*(pi/180.0)
# Set camera translation
scene.camera.location.x = 0.0
scene.camera.location.y = 0.0
scene.camera.location.z = 80.0
然后我就这样运行
blender -b marker_a4.blend --python "marker_a4.py" -o //out -F JPEG -x 1 -f 1
例如,如果我尝试使用 python 脚本的参数
...
import sys
...
fov = float(sys.argv[5])
...
并运行它:
blender -b marker_a4.blend --python "marker_a4.py" 80.0 -o //out -F JPEG -x 1 -f 1
渲染已完成,但我在开始时收到此消息。
read blend: /home/roho/workspace/encuadro/renders/marker/model/marker_a4.blend
read blend: /home/roho/workspace/encuadro/renders/marker/model/80.0
Unable to open "/home/roho/workspace/encuadro/renders/marker/model/80.0": No such file or directory.
...
谁能告诉我这是什么原因造成的?我认为搅拌机也将其解析为模型,但不明白为什么。后来我尝试了一些更复杂的方法来解析 python 中的参数(argparse),但它根本不起作用。所以我想在这个层面上可能会发生一些奇怪的事情。
Thanks!
我找到了我最初寻找的解决方案。
正如 Junuxx 所说:“你不能将命令行参数直接传递给 python这个情况...”但实际上你可以将参数传递给 python,但在另一种情况下。
所以做我想做的事情的方法是直接在 python 脚本中渲染和保存
import sys
fov = float(sys.argv[-1])
...
# Set Scenes camera and output filename
bpy.data.scenes["Scene"].render.file_format = 'PNG'
bpy.data.scenes["Scene"].render.filepath = '//out'
# Render Scene and store the scene
bpy.ops.render.render( write_still=True )
--python 选项(或 -P)必须位于末尾,您可以使用 -- 指定参数,然后加载模型并运行脚本。
> blender -b "demo.blend" -P script.py -- 50
感谢我发现的这个链接:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)