Blender 脚本中永远循环?

问题描述 投票:0回答:1

如果你添加

while True:
    print("hi")

到 Blender 脚本窗口中的其他功能脚本并运行它,Blender 挂起。

这是不可取的,因为我正在尝试使用 Redis 作为发布-订阅代理,这样另一个脚本可以发送位置供 Blender 显示:

bpy.ops.mesh.primitive_uv_sphere_add(radius=0.005, location=(0, 0, 0))
ball = bpy.context.object
ball.name = 'sphere'


for message in pubsub.listen():
    if message['type'] == 'message':
        position_str = message['data'].decode('utf-8')
        position = ast.literal_eval(position_str)
        print(f"Received position: {position}")
        ball.location = position

这个永远循环也会挂起 Blender 并且不会按照我想要的方式移动球。

有什么办法让它发挥作用吗?

python redis blender
1个回答
0
投票

在搅拌机中, while true 循环会导致程序冻结。即使您不打算激活它,也要添加例外。

exception = False
while True:
    print("hi")
    if(exception):
        break
© www.soinside.com 2019 - 2024. All rights reserved.