renderStill: ask Blender for the engine by assignment; add headless live smoke
Found by running the actions on Blender 5.2.3 headless: the render engine enum is dynamic, bl_rna lists only BLENDER_EEVEE, so CYCLES and WORKBENCH were refused. The fake in the tests now behaves like the real enum. surfaces/blender/tests/live/ headless_smoke.py runs every scene action against real bpy. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e9a780569f
commit
4b2fefa368
4 changed files with 116 additions and 7 deletions
|
|
@ -681,8 +681,13 @@ class BrokkrBlenderTarget:
|
|||
render = scene.render
|
||||
path = sa.resolve_inside(self.output_dir, str(command.get("outputPath") or ""), "output")
|
||||
file_format = sa.still_format(path)
|
||||
engines = tuple(item.identifier for item in render.bl_rna.properties["engine"].enum_items)
|
||||
engine = sa.choice(command, "engine", engines)
|
||||
# The engine enum is dynamic (Cycles and add-on engines register at runtime), and RNA's
|
||||
# enum_items on a dynamic enum lists only its static defaults, so the running Blender is
|
||||
# asked by assignment below and a TypeError there is the refusal.
|
||||
engine = command.get("engine")
|
||||
if engine is not None and (not isinstance(engine, str) or not engine.strip()):
|
||||
raise sa.ActionRefused("engine must be a render engine identifier.")
|
||||
engine = engine.strip().upper() if engine else None
|
||||
width = sa.integer(command, "resolutionX", 1, sa.MAX_RESOLUTION)
|
||||
height = sa.integer(command, "resolutionY", 1, sa.MAX_RESOLUTION)
|
||||
camera_name = str(command.get("cameraName") or "")
|
||||
|
|
@ -697,7 +702,10 @@ class BrokkrBlenderTarget:
|
|||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
if engine is not None:
|
||||
render.engine = engine
|
||||
try:
|
||||
render.engine = engine
|
||||
except TypeError:
|
||||
raise sa.ActionRefused(f"engine {engine} is not available in this Blender.") from None
|
||||
if width is not None:
|
||||
render.resolution_x = width
|
||||
if height is not None:
|
||||
|
|
|
|||
|
|
@ -128,3 +128,8 @@ gets a `failed` receipt whose message names the rule):
|
|||
`resolutionY` (whole numbers, 1 to 16384), `cameraName`. Engine, resolution,
|
||||
camera, file path and format are restored after the render. The render blocks
|
||||
Blender's UI until it finishes.
|
||||
|
||||
The scene actions were run against Blender 5.2.3 LTS headless with
|
||||
`surfaces/blender/tests/live/headless_smoke.py` (usage in its docstring). One real
|
||||
failure it found: Blender's `engine` enum is dynamic, so `bl_rna` lists only
|
||||
`BLENDER_EEVEE`; `renderStill` now asks Blender by assignment instead.
|
||||
|
|
|
|||
75
surfaces/blender/tests/live/headless_smoke.py
Normal file
75
surfaces/blender/tests/live/headless_smoke.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
"""Live Blender smoke for the scene actions. Not part of the unittest run: it needs Blender.
|
||||
|
||||
BROKKR_RUN=<scratch dir> BROKKR_ADDON=<path to surfaces/blender/brokkr_bridge> \
|
||||
blender --background --factory-startup --python surfaces/blender/tests/live/headless_smoke.py
|
||||
|
||||
Writes a tiny .glb into <scratch>/in, runs every scene action against real bpy, and prints
|
||||
RESULT lines (accepted/failed) plus the state each action should have produced.
|
||||
Last run: Blender 5.2.3 LTS on Windows, all actions accepted, both escapes refused.
|
||||
"""
|
||||
import json, struct, sys, types, os, traceback
|
||||
from pathlib import Path
|
||||
import bpy
|
||||
|
||||
ROOT = Path(os.environ["BROKKR_RUN"]).resolve()
|
||||
ADDON = Path(os.environ["BROKKR_ADDON"]).resolve()
|
||||
(ROOT / "in").mkdir(parents=True, exist_ok=True)
|
||||
(ROOT / "out").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# tiny triangle glb
|
||||
pos = struct.pack("<9f", 0,0,0, 1,0,0, 0,1,0)
|
||||
gltf = {"asset": {"version": "2.0"}, "scene": 0, "scenes": [{"nodes": [0]}], "nodes": [{"mesh": 0, "name": "Tri"}],
|
||||
"meshes": [{"primitives": [{"attributes": {"POSITION": 0}}]}],
|
||||
"buffers": [{"byteLength": len(pos)}],
|
||||
"bufferViews": [{"buffer": 0, "byteLength": len(pos), "target": 34962}],
|
||||
"accessors": [{"bufferView": 0, "componentType": 5126, "count": 3, "type": "VEC3", "min": [0,0,0], "max": [1,1,0]}]}
|
||||
j = json.dumps(gltf).encode(); j += b" " * (-len(j) % 4)
|
||||
b = pos + b"\0" * (-len(pos) % 4)
|
||||
glb = struct.pack("<4sII", b"glTF", 2, 12 + 8 + len(j) + 8 + len(b)) + struct.pack("<I4s", len(j), b"JSON") + j + struct.pack("<I4s", len(b), b"BIN\0") + b
|
||||
(ROOT / "in" / "tiny.glb").write_bytes(glb)
|
||||
|
||||
pkg = types.ModuleType("brokkr_bridge"); pkg.__path__ = [str(ADDON)]
|
||||
sys.modules["brokkr_bridge"] = pkg
|
||||
from brokkr_bridge import blender_target as bt
|
||||
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
target = bt.BrokkrBlenderTarget(bpy)
|
||||
target.configure_action_dirs(str(ROOT / "in"), str(ROOT / "out"))
|
||||
ctx = bpy.context
|
||||
results = []
|
||||
|
||||
def run(label, **cmd):
|
||||
cmd.setdefault("commandId", label)
|
||||
try:
|
||||
r = target.execute_command(bpy.context, cmd)
|
||||
except Exception:
|
||||
r = {"status": "EXCEPTION", "message": traceback.format_exc()}
|
||||
print("RESULT", label, r["status"], r.get("message", "").replace("\n", " | ")[:400], flush=True)
|
||||
results.append((label, r["status"]))
|
||||
return r
|
||||
|
||||
print("BLENDER", bpy.app.version_string)
|
||||
run("createCam", action="createObject", objectType="CAMERA", name="Cam", location=[0, -3, 1])
|
||||
run("createLight", action="createObject", objectType="LIGHT", name="Lamp", location=[2, -2, 3])
|
||||
run("importGltf", action="importGltf", filepath="tiny.glb")
|
||||
print("OBJECTS", sorted(bpy.data.objects.keys()))
|
||||
run("importGltf_escape", action="importGltf", filepath="../x.glb")
|
||||
run("setCamera", action="setCamera", targetObjectName="Cam", lens=24, cameraType="PANO", panoramaType="EQUIRECTANGULAR", active=True, clipEnd=200)
|
||||
cam = bpy.data.objects["Cam"].data
|
||||
print("CAM", cam.lens, cam.type, getattr(cam, "panorama_type", None), bpy.context.scene.camera and bpy.context.scene.camera.name)
|
||||
run("setLight", action="setLight", targetObjectName="Lamp", energy=500, color=[1, 0.5, 0.2], lightType="AREA")
|
||||
l = bpy.data.objects["Lamp"].data
|
||||
print("LIGHT", l.energy, tuple(l.color), l.type)
|
||||
run("setWorld", action="setWorld", color=[0.1, 0.2, 0.4], strength=1.5)
|
||||
w = bpy.context.scene.world
|
||||
print("WORLD", w and w.name, w and tuple(w.node_tree.nodes["Background"].inputs["Color"].default_value), w and w.node_tree.nodes["Background"].inputs["Strength"].default_value)
|
||||
sc = bpy.context.scene
|
||||
print("ENGINES", [i.identifier for i in sc.render.bl_rna.properties["engine"].enum_items])
|
||||
sc.cycles.samples = 1
|
||||
run("renderStill_cycles_pano", action="renderStill", outputPath="pano.png", engine="CYCLES", resolutionX=64, resolutionY=32, cameraName="Cam")
|
||||
print("FILE pano", (ROOT / "out" / "pano.png").exists(), (ROOT / "out" / "pano.png").stat().st_size if (ROOT / "out" / "pano.png").exists() else 0)
|
||||
run("renderStill_workbench", action="renderStill", outputPath="wb/shot.jpg", engine="BLENDER_WORKBENCH", resolutionX=64, resolutionY=64)
|
||||
print("FILE wb", (ROOT / "out" / "wb" / "shot.jpg").exists())
|
||||
run("renderStill_escape", action="renderStill", outputPath="../evil.png")
|
||||
print("RESTORED", sc.render.engine, sc.render.resolution_x, sc.render.resolution_y, sc.camera and sc.camera.name)
|
||||
print("SUMMARY", results)
|
||||
|
|
@ -27,11 +27,32 @@ class Enum:
|
|||
self.enum_items = [NS(identifier=n) for n in names]
|
||||
|
||||
|
||||
class FakeRender:
|
||||
"""Assigning an engine Blender does not have raises TypeError, as RNA enums do. The enum's
|
||||
bl_rna lists only the static default, as a real dynamic enum does (Blender 5.2.3 reports
|
||||
only BLENDER_EEVEE there while Cycles is installed)."""
|
||||
|
||||
ENGINES = ("BLENDER_EEVEE", "CYCLES", "BLENDER_WORKBENCH")
|
||||
|
||||
def __init__(self):
|
||||
self._engine = "BLENDER_EEVEE"
|
||||
self.resolution_x, self.resolution_y, self.filepath = 1920, 1080, "//old"
|
||||
self.image_settings = NS(file_format="PNG")
|
||||
self.bl_rna = NS(properties={"engine": Enum("BLENDER_EEVEE")})
|
||||
|
||||
@property
|
||||
def engine(self):
|
||||
return self._engine
|
||||
|
||||
@engine.setter
|
||||
def engine(self, value):
|
||||
if value not in self.ENGINES:
|
||||
raise TypeError(f"enum {value!r} not found")
|
||||
self._engine = value
|
||||
|
||||
|
||||
def fake_render():
|
||||
render = NS(engine="BLENDER_EEVEE", resolution_x=1920, resolution_y=1080, filepath="//old",
|
||||
image_settings=NS(file_format="PNG"))
|
||||
render.bl_rna = NS(properties={"engine": Enum("BLENDER_EEVEE", "CYCLES", "BLENDER_WORKBENCH")})
|
||||
return render
|
||||
return FakeRender()
|
||||
|
||||
|
||||
class Objects(dict):
|
||||
|
|
|
|||
Loading…
Reference in a new issue