34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def main() -> None:
|
|
if "--" not in sys.argv or len(sys.argv[sys.argv.index("--") + 1 :]) != 2:
|
|
raise SystemExit("usage: blender --background --factory-startup --python generate-asset-preview-identity.py -- INPUT OUTPUT")
|
|
source_arg, output_arg = sys.argv[sys.argv.index("--") + 1 :]
|
|
source = pathlib.Path(source_arg).resolve()
|
|
output = pathlib.Path(output_arg).resolve()
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
image = bpy.data.images.load(str(source), check_existing=False)
|
|
width, height = image.size[:]
|
|
scene = bpy.context.scene
|
|
scene.render.image_settings.file_format = "PNG"
|
|
scene.render.image_settings.color_mode = "RGBA"
|
|
scene.render.image_settings.color_depth = "8"
|
|
scene.render.image_settings.compression = 0
|
|
scene.display_settings.display_device = "sRGB"
|
|
scene.view_settings.view_transform = "Standard"
|
|
scene.view_settings.look = "None"
|
|
scene.view_settings.exposure = 0
|
|
scene.view_settings.gamma = 1
|
|
image.save_render(str(output), scene=scene)
|
|
if not output.is_file() or output.stat().st_size == 0:
|
|
raise RuntimeError("asset preview output was not written")
|
|
print(f"asset-preview-generated width={width} height={height} output={output}")
|
|
|
|
|
|
main()
|