我正在尝试用搅拌机中的粒子系统模拟多个下落物体。
为了训练某些 CNN,我需要场景中可见的单个元素的分割掩码。到目前为止,我只能执行部分导出掩码任务。比如通过组合节点导出掩码或者使用python提取一些属性。
到目前为止我尝试的是:
import bpy
from bpy_extras.object_utils import world_to_camera_view
context = bpy.context
dg = context.evaluated_depsgraph_get()
ob = context.object.evaluated_get(dg)
ps = ob.particle_systems.active
scene = bpy.context.scene
cam = bpy.data.objects['Camera']
render = scene.render
res_x = render.resolution_x
res_y = render.resolution_y
for frame in range(30,35):
scene.frame_set(frame)
bpy.ops.render.render(write_still = True)
print("res_x:{},res_y:{}".format(res_x, res_y))
for particle in ps.particles:
if particle.is_visible:
print(particle.location)
coords_2d = world_to_camera_view(scene, cam, particle.location)
x = coords_2d[0]
y = coords_2d[1]
dist_to_cam = coords_2d[2]
rnd = lambda i: round(i)
print("x:{},y:{}".format(rnd(res_x*x),res_y- rnd(res_y*y)))
如果有人能告诉我一种更可靠的清洁方法来导出所有可见单粒子对象的蒙版,同时考虑重叠,在搅拌机中我将非常感激。
谢谢