KAZIK/tools/generators/audit_studio_source.py

38 lines
2 KiB
Python

"""Open the saved Blender source, check portability, and render a mouse close-up."""
from pathlib import Path
import sys,json
import bpy
sys.path.insert(0,str(Path(__file__).resolve().parent))
from build_cinematic_v4 import camera
ROOT=Path(__file__).resolve().parents[2]
source=ROOT/'assets/cinematics/blender/eblan-workshop-v4.blend'
bpy.ops.wm.open_mainfile(filepath=str(source))
scene=bpy.context.scene
prefs=bpy.context.preferences.addons['cycles'].preferences
prefs.compute_device_type='OPTIX';prefs.get_devices()
for device in prefs.devices:device.use=device.type=='OPTIX'
scene.cycles.device='GPU';scene.cycles.denoising_use_gpu=True
missing=[]
for image in bpy.data.images:
if image.source in {'FILE','SEQUENCE'} and not image.packed_file:
if not Path(bpy.path.abspath(image.filepath)).is_file():missing.append(image.filepath)
assert not missing,missing
assert scene.render.resolution_x==1920 and scene.render.resolution_y==1080
assert scene.frame_end==192 and scene.render.fps==24
assert sum(o.name.startswith('Energy / complete') for o in scene.objects)==7
for name in ['Mouse / left click','Mouse / right click','Mouse / rubber scroll wheel',
'Tower / populated motherboard','Studio / printed all-night build notice']:
assert name in scene.objects,name
scene.frame_set(24)
bpy.ops.wm.save_as_mainfile(filepath=str(source))
report=dict(objects=len(scene.objects),meshes=sum(o.type=='MESH' for o in scene.objects),
energy_cans=7,missing_images=missing,resolution=[1920,1080],frames=192,fps=24)
(ROOT/'build/cinematic-v4/source-audit.json').write_text(json.dumps(report,indent=2))
# This camera is a review view only; it is added after saving the actual film set.
cam,focus=camera('Review only / mouse detail',(.48,-.65,1.02),(.335,-.365,.825),65)
cam.data.dof.aperture_fstop=8
scene.render.resolution_x=1280;scene.render.resolution_y=720;scene.cycles.samples=96
scene.render.filepath=str(ROOT/'build/cinematic-v4/mouse-detail.png')
bpy.ops.render.render(write_still=True)
print('SOURCE_AUDIT_PASS',report)