"""Real sandbox scene builds keep searching until enough usable props are placed. python -I tests/test_sandbox_scene_build.py """ import json import os from pathlib import Path import struct import subprocess import sys import tempfile import tracemalloc from types import SimpleNamespace import unittest sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "tools")) import sandbox_scene # noqa: E402 import world_names # noqa: E402 TRIANGLE = "v 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n" def entity(name, x, y=0, **extra): return dict(archetype=world_names.joaat(name), position=[x, y, 0], rotation=[0, 0, 0, 1], lod_level=0, scale_xy=1, scale_z=1, **extra) class SceneBuildTests(unittest.TestCase): def setUp(self): temporary = tempfile.TemporaryDirectory() self.addCleanup(temporary.cleanup) self.root = Path(temporary.name) self.models = self.root / "models" self.models.mkdir() self.items = [] self.add_model("synthetic_prop") def add_model(self, name, obj=TRIANGLE): filename = name + ".obj" (self.models / filename).write_text(obj, encoding="utf-8", newline="\n") self.items.append({"Name": name, "File": filename, "MeshShaders": [0]}) def build_scene(self, rows, max_props, radius=20, center=(0, 0)): (self.models / "manifest.json").write_text(json.dumps({"Items": self.items}), encoding="utf-8", newline="\n") placements = self.root / "entities.jsonl" placements.write_text("\n".join(json.dumps(row) for row in rows) + "\n", encoding="utf-8", newline="\n") scene = self.root / "scene.bin" result = subprocess.run( [sys.executable, "-I", sandbox_scene.__file__, "--entities", str(placements), "--models", str(self.models), *(["--center", *map(str, center)] if center is not None else []), "--radius", str(radius), "--max-props", str(max_props), "--out", str(scene)], capture_output=True, text=True, timeout=30, ) self.assertEqual(result.returncode, 0, result.stdout + result.stderr) self.assertEqual(result.stderr, "") data = scene.read_bytes() self.assertEqual(data[:4], b"LSB1") version, textures, meshes, draws = struct.unpack_from("<4I", data, 4) self.assertEqual((version, textures), (1, 0)) offset = 32 # LSB1 header, including the scene center. for _ in range(meshes): vertices, indices = struct.unpack_from("