文章目录
基础环境配置
最新的方法感觉很简单
就直接在这里下载2.93 , 使用的时候好像不需要Xvfb?
为内置python下载一些东西
blender_path=blender-2.93.15-linux-x64 # 自己写
blender_python_path=$blender_path/2.93/python/bin/python3.9
export PATH="$blender_path:$PATH"
#blender --background --version
#blender --background --python-expr "import sys; print('\nThe version of python is '+sys.version.split(' ')[0])"
#blender --background --python-expr "import sys; import os; print('\nThe path to the installation of python of blender can be:'); print('\n'.join(['- '+x.replace('/lib/python', '/bin/python') for x in sys.path if 'python' in (file:=os.path.split(x)[-1]) and not file.endswith('.zip')]))"
# 注意检查 python 版本
$blender_python_path -m ensurepip --upgrade
for e in pytest-shutil matplotlib tqdm hydra-core six shortuuid moviepy natsort
do
$blender_python_path -m pip install $e #--user --upgrade
done
安装及资料
apt-get install blender
虚拟桌面 Xvfb
在服务器上想要运行blender需要建立虚拟桌面,挺简单的就
apt-get install xvfb
使用的时候,首先开启虚拟桌面到后台,然后就可以运行 blender 了
export DISPLAY=:6
Xvfb -ac :6 -screen 0 640x480x24 & # 1920x1080x24
blender -b --render-output tmp/res -f 0
blender 内置 python 修改 packages
找了半天至今不知道 blender 到底是调用的哪里的 python ,不过我猜测它可能把 python 给直接编译进去了,所以后期我们应该是换不了这个python的。所以就直接 sys 中替换加载变量的路径就行。
具体就是先运行
blender -b -P ck_bpy.py
ck_bpy.py 就写一个 print(sys.path)
获得路径,然后自己的 python 也打印一下,把路径拿出来,插入到指定位置就行。
内置blender 安装库
看到这里也可以考虑把 anaconda 的环境装到这里
cd D:/program/BlenderFoundation/Blender2.93/2.93/python/bin
./python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
cd D:/program/BlenderFoundation/Blender2.93/2.93/python/Scripts
./pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
./pip install Pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
./pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple
编译 blender (别看了)
svn 太慢,wget 下载的方法如下
wget -P download -r -p -np https://svn.blender.org/svnroot/bf-blender/trunk/lib/linux_centos7_x86_64 -o res.log
初步尝试杂记
渲染
用默认的blend,调用脚本渲染
blender -b -P tmp/test.py -o tmp/res -f 0
import bpy
for e in bpy.data.objects:
print(e.name)
bpy.ops.render.render()
bpy.data.images['Render Result'].save_render(filepath='tmp/res/example.png')
直接命令行指定渲染
https://blenderartists.org/t/animating-rotation-using-keyframes-in-python/590243
blender -b --render-output tmp/res -f 0
计算
ob.matrix_world = Matrix.Translation(ob.location) * Matrix.Rotation(radians(45), 4, 'Z')
自己的一些代码
(未整理)
打印(print)到控制台
直接print 调用脚本时看不到
from bpy import context
import builtins as __builtin__
def console_print(*args, **kwargs):
for a in context.screen.areas:
if a.type == 'CONSOLE':
c = {
}
c['area'] = a
c['space_data'] = a.spaces.active
c['region'] = a.regions[-1]
c['window'] = context.window
c['screen'] = context.screen
s = " ".join([str(arg) for arg in args])
for line in s.split("\n"):
bpy.ops.console.scrollback_append(c, text=line)
def print(*args, **kwargs):

本文档详细介绍了如何在服务器上配置Blender 2.93的环境,包括安装、设置虚拟桌面Xvfb、修改内置Python包路径以及安装额外库。此外,还探讨了如何使用Blender内置Python进行渲染、骨骼驱动和关键帧动画,并提供了相关代码示例。最后,作者分享了在Blender中进行渲染和动画计算的一些实用技巧和注意事项。
最低0.47元/天 解锁文章
2841

被折叠的 条评论
为什么被折叠?



