import bpy
from sys import argv

directory = argv[-3].removesuffix("/")
list_file = argv[-2]
resolution = int(argv[-1])

for name in open(list_file):
    name = name.strip()
    print(f"-- {name}")
    input_glb = f"{directory}/{name}.glb"
    output_png = f"{directory}/{name}.png"
    print(input_glb, output_png)

    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete(use_global=False, confirm=False)

    bpy.ops.import_scene.gltf(filepath=input_glb)

    bpy.context.scene.camera = bpy.data.objects["Camera3D"]
    bpy.context.scene.render.film_transparent = True
    bpy.context.scene.render.resolution_x = resolution
    bpy.context.scene.render.resolution_y = resolution
    bpy.context.scene.render.image_settings.file_format = "PNG"
    bpy.context.scene.render.engine = 'CYCLES'
    bpy.context.scene.cycles.samples = 512
    bpy.context.scene.view_settings.view_transform = 'Khronos PBR Neutral'

    bpy.ops.render.render()
    bpy.data.images["Render Result"].save_render(output_png)
