0

私は現在ブレンダー 3.0 で作業していますが、いくつかのレンダリングを実行する際に問題が発生しました (これはブレンダー 2.93 でも発生します)。
私のチームには、Python を介していくつかのオブジェクト (40 ~ 50) をスポーンするシーンがあり (それらは特定のコレクション内のオブジェクトの複製です)、レンダリングしてファイルに保存します。各レンダリングの後、メモリの問題を回避するためにいくつかのクリーンアップ コードを実行します (約 10,000 のレンダリングが必要です)。クリーンアップ コードを実行して次のレンダリングに備えるには、最初は約 0.05 秒かかりますが、1.5/2k のレンダリング後は 5 分以上かかります (実行されるレンダリングの数が増えるにつれて、現在のレンダリングと次のレンダリングの間のフリーズ時間が長くなります) )。ブレンダーを再起動して「フリーズ期間をリセット」して 0 秒にします。
全体的なコードは次のようになります。

for idx in range(number_of_renders):
    camera.location = Vector(random, random, random)
    camera_target.location = Vector(random, random, random)
    ... # randomly set hide_viewport and hide_render to true/false to change overall brightness of all lights
    spawned_objects = populate_scene(settings)
    bpy.ops.render.render(write_still=True)
    metrics = generate_metrics(settings) # generate some metrics about facing objects
    save_metrics(metrics) # save the metrics in a .txt file
    cleanup(spawned_objects)

複製を作成するために使用するコード:

templates = [template.name for template in bpy.data.collections.get("Templates").objects]
... # set random image to all templates textures
source_object = bpy.data.objects[random.choice(templates)] # get a random object from templates
product = source_object.copy()
product.data = source_object.data.copy()
product.location.x/y/z = ...
spawned_objects.append(product)
if facing_object: # if it is a facing object we add it into the facing collection (we measure some metrics later on)
    facing_collection.objects.link(product)
else:
    background_collection.objects.link(product)

生成されたオブジェクトを消去するために使用しているコード:

def cleanup(spawned_objects):
    # Deselect all eventually selected objects
    bpy.ops.object.select_all(action='DESELECT')

    # Select only the spawned objects
    for obj in spawned_objects:
        obj.select_set(True)

    # Delete spawned objects
    bpy.ops.object.delete()

    # Cleanup
    for block in bpy.data.meshes:
        if block.users == 0:
            bpy.data.meshes.remove(block)

    for block in bpy.data.materials:
        if block.users == 0:
            bpy.data.materials.remove(block)

    for block in bpy.data.textures:
        if block.users == 0:
            bpy.data.textures.remove(block)

    for block in bpy.data.images:
        if block.users == 0:
            bpy.data.images.remove(block)

私たちは現在、プログラムを 10 回実行することでこの問題を「解決」しており、毎回 1k のレンダリングを上限として、それらを 1 つのディレクトリにまとめています。フリーズが発生する理由や、レンダリングを重ねるほどフリーズが長くなる理由について何か考えはありますか?

4

0 に答える 0