File size: 21,505 Bytes
71e9dba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | ---
id: GAM_task_12_godot_scene_node_debug
name: Godot 3 损坏 .tscn 场景节点修复 + 编辑器+运行双视图通关
category: GAM
timeout_seconds: 5400
---
## Prompt
Task background: `/tmp_workspace/exec/` is a small Godot 3 toy-level project whose main scene is
`scenes/main.tscn`. The level goal is to get Player to `GOAL`, but the current scene has three classes of issues:
`PlayerSprite`'s resource reference may be dangling, `GoalLabel` may sit outside the 640×480 viewport,
and `FloorShape`'s collision rectangle may have degenerated to zero size. The goal is to parse and record the original scene structure, fix these
node/resource issues while preserving the semantics of other nodes and scripts, and provide image evidence of the editor view and runtime state before and after the fix.
Please produce the following files, preserving field names and file names:
- `/tmp_workspace/results/before/main.tscn`: an unmodified copy of the original main scene, used for diff records.
- `/tmp_workspace/results/parse_before.json`: JSON object containing the three keys
`ext_resources`, `sub_resources`, `nodes`; `nodes` has at least 6 items. Suggested structure:
`ext_resources` entries contain `id,path,type`, `sub_resources` entries contain `id,type,props`,
`nodes` entries contain `name,type,parent,props`.
- `/tmp_workspace/results/bugs.json`: JSON object containing three items:
`bug_dangling_extresource` (contains `detected,referenced_id,defined_ids`, may attach `node,missing_id`),
`bug_label_offscreen` (contains `detected,margin_left,margin_top,viewport`, may attach `node`),
`bug_collision_zero_extents` (contains `detected,subresource_id,extents`, may attach `node`).
Each item's fields should describe the corresponding triggering evidence.
- `/tmp_workspace/proj/scenes/main_fixed.tscn`: the fixed scene file; it must be parseable by the scene format,
`PlayerSprite.texture` must reference a defined `ExtResource` id, `GoalLabel`'s
`margin_left,margin_top,margin_right,margin_bottom` must all fall within a reasonable range of the 640×480 viewport,
and the `RectangleShape2D` extents referenced by `FloorShape` must both be greater than 0 on each axis.
- `/tmp_workspace/results/view_editor_before.png`: image evidence showing the editor view of the original project;
the scene tree / node panel and 2D viewport should be visible, with text such as `Scene`, `Node`, `Inspector`,
`FileSystem`, or `Godot` recognizable.
- `/tmp_workspace/results/view_play_bug.png`: image evidence showing at least one of the issues during pre-fix runtime,
for example a missing texture, the character falling out of the playable area, or `GOAL` not being visible; the frame should be a real game state, with one of the HUD/hint texts
`ScenePlay`, `GOAL`, `arrows`, `reach`, or `left/right` visible.
- `/tmp_workspace/results/view_editor_after.png`: image evidence showing the post-fix editor view; it should be apparent that
the Player texture is normal, `GoalLabel` is inside the viewport, and the Floor collision shape is no longer a degenerate point.
- `/tmp_workspace/results/view_play_finish.png`: image evidence showing that the level can be completed after the fix, with
the Player, the floor, and the `GOAL` text all visible in the frame.
- `/tmp_workspace/results/runtime.log`: non-empty runtime log containing scene/character initialization markers such as `scene ready`, `player`, or `main`.
- `/tmp_workspace/results/parse_after.json`: JSON object with the same schema as `parse_before.json`,
reflecting the post-fix scene structure.
- `/tmp_workspace/results/diff.txt`: text diff between the original main scene and `main_fixed.tscn`, with line count between 6 and 200.
- `/tmp_workspace/results/report.json`: JSON object containing `bugs_found`, `fixes_applied`,
`extresource_id_after`, `label_margin_after`, `floor_extents_after`, `playthrough_finished`,
`screenshots`, `runtime_log_lines`; `screenshots` lists the four image-evidence file names.
## Expected Behavior
成功时,`parse_before.json` 和 `parse_after.json` 都能以
`ext_resources/sub_resources/nodes` 描述场景结构,`bugs.json` 对悬空资源引用、
离屏标签和零尺寸碰撞形状三类问题均给出 `detected=true` 与可核查证据。
`/tmp_workspace/proj/scenes/main_fixed.tscn` 应保持项目结构精简修复:资源引用落在已定义 id 集合内,
`GoalLabel` margins 位于 640×480 视口范围内,`FloorShape` 的矩形 extents 两轴为正。
图像证据应分别显示原始编辑视图、修复前问题状态、修复后编辑视图和完成状态;最后一张应可见
Player、地板与 `GOAL`。`runtime.log` 应含初始化标记,`diff.txt` 行数处于允许范围,
`report.json` 应汇总发现的问题、应用的修复、修复后数值、完成状态、图像文件名和日志行数。
## Source
- Godot 3.5 `.tscn` text-format reference:
https://docs.godotengine.org/en/3.5/development/file_formats/tscn.html
- Godot 3.5 `Sprite` / `KinematicBody2D` API:
https://docs.godotengine.org/en/3.5/classes/class_sprite.html
- itch.io 论坛吐槽帖:"my .tscn looks fine in the inspector but the
player just falls through the floor in play":
https://godotforums.org/d/29456-collisionshape2d-no-effect-in-play-mode
- 对应 benchmark:GAM 视觉×文件双通道场景修复 case
## Grading Criteria
- [ ] 1. `parse_before.json` schema 完整(ext_resources + sub_resources +
nodes 三 key 都在,且 nodes 列表 ≥ 6)
- [ ] 2. `bugs.json` 三个 bug 都 detected=true 且证据字段非空
- [ ] 3. `proj/scenes/main_fixed.tscn` 存在且能被 grader parser parse
- [ ] 4. fixed 场景里 `PlayerSprite.texture` 引用的 ExtResource id 在
已定义 id 集合里
- [ ] 5. fixed 场景里 `GoalLabel` 的 `margin_left/top/right/bottom` 全部
落在 viewport (640×480) 内
- [ ] 6. fixed 场景里 `FloorShape` 引用的 RectangleShape2D 的 extents
两轴都 > 0(建议 ≥ Vector2(64, 4))
- [ ] 7. `view_editor_before.png` / `view_editor_after.png` 都存在且 OCR
命中 "Scene"/"Node"/"Inspector"/"FileSystem"/"Godot" 之一
- [ ] 8. `view_play_bug.png` 存在且看起来是真运行画面(OCR 命中 HUD 文
字 "ScenePlay" / "GOAL" / "arrows" 之一,或 VLM 判断是真窗口)
- [ ] 9. `view_play_finish.png` OCR 命中 "GOAL" 字样
- [ ] 10. `runtime.log` 存在且非空,含 "scene ready" / "player" 字样
- [ ] 11. `diff.txt` 存在,行数在 [6, 200] 区间
- [ ] 12. VLM rubric 4 项 ≥ 0.6
## Automated Checks
```python
def grade(workspace_path=None, **kwargs) -> dict:
"""Godot 3 .tscn scene-graph repair + GUI playthrough verifier.
Sub-scores (12) + 3 hard gates. Real signal channels:
- File: in-house regex parse of .tscn ext_resource / sub_resource /
node sections; numeric checks for ExtResource id, Label
margins, RectangleShape2D extents.
- GUI : 4 screenshots OCR for editor / play / finish overlay.
- Run : runtime.log captures stdout from godot3 --path.
No GT leakage: gt/expected.json holds invariant counts only
(e.g. number of bugs, OCR keyword set, viewport size, diff bounds).
"""
import json, os, re
from pathlib import Path
ws = Path(workspace_path) if workspace_path else Path("/tmp_workspace")
rd = ws / "results"
proj = ws / "proj"
gt_dir = ws / "gt"
expected = {}
if (gt_dir / "expected.json").exists():
try: expected = json.loads((gt_dir/"expected.json").read_text())
except Exception: expected = {}
s = {}
# ---- 1. parse_before.json schema ----
pb = rd / "parse_before.json"
schema_ok = 0
if pb.exists():
try:
d = json.loads(pb.read_text())
need = {"ext_resources","sub_resources","nodes"}
if need.issubset(d.keys()) and len(d.get("nodes", [])) >= 6:
schema_ok = 1
except Exception: pass
s["parse_before_schema"] = float(schema_ok)
# ---- 2. bugs.json all 3 bugs detected with evidence ----
bj = rd / "bugs.json"
bugs_hit = 0
if bj.exists():
try:
b = json.loads(bj.read_text())
# Numeric "ground-truth" values are read from gt/expected.json so
# changing the broken fixture only requires editing the JSON, and
# so the answers are not silently leaked in grader source.
ext_ref_gt = int(expected.get("broken_extresource_id_referenced", 2))
ext_def_gt = int(expected.get("broken_extresource_id_defined", 1))
label_lo = float(expected.get("broken_label_margin_left", 1000.0))
label_lo_top = float(expected.get("broken_label_margin_top", 1000.0))
sub_id_gt = int(expected.get("broken_floor_shape_subresource_id", 1))
zero_ext_gt = list(expected.get("broken_floor_extents", [0.0, 0.0]))
vw_gt, vh_gt = expected.get("viewport_size", [640, 480])
for k, must in [
("bug_dangling_extresource",
["referenced_id","defined_ids"]),
("bug_label_offscreen",
["margin_left","margin_top","viewport"]),
("bug_collision_zero_extents",
["subresource_id","extents"]),
]:
v = b.get(k, {})
exp_match = True
if k == "bug_dangling_extresource":
exp_match = (int(v.get("referenced_id",-1)) == ext_ref_gt and
ext_def_gt in [int(x) for x in v.get("defined_ids",[])])
if k == "bug_label_offscreen":
# Allow either margin to surpass the (relaxed) lower bound;
# avoids penalising agents that clamped one axis to 0.
exp_match = ((float(v.get("margin_left",0)) >= label_lo or
float(v.get("margin_top",0)) >= label_lo_top) and
list(v.get("viewport",[]))[:2] == [vw_gt, vh_gt])
if k == "bug_collision_zero_extents":
ext = v.get("extents",[1,1])
exp_match = (int(v.get("subresource_id",-1)) == sub_id_gt and
float(ext[0]) == float(zero_ext_gt[0]) and
float(ext[1]) == float(zero_ext_gt[1]))
if v.get("detected") and all(m in v for m in must) and exp_match:
bugs_hit += 1
except Exception: pass
s["bugs_detected_with_evidence"] = bugs_hit / 3.0
# ---- 3-6. fixed.tscn parses & invariants ----
fixed_paths = [proj/"scenes/main_fixed.tscn",
ws/"exec/scenes/main_fixed.tscn"]
fixed = next((p for p in fixed_paths if p.exists()), None)
parses = ext_id_ok = label_ok = floor_ok = 0.0
txt = ""
if fixed:
try:
txt = fixed.read_text(errors="ignore")
if "[gd_scene" in txt and "[node name=" in txt:
parses = 1.0
except Exception: parses = 0.0
s["fixed_tscn_parses"] = parses
if parses:
# Collect ext_resource ids
ext_ids = set()
for m in re.finditer(r"\[ext_resource[^\]]*\bid=(\d+)", txt):
ext_ids.add(int(m.group(1)))
sub_ids = set()
for m in re.finditer(r"\[sub_resource[^\]]*\bid=(\d+)", txt):
sub_ids.add(int(m.group(1)))
# Find PlayerSprite block + its texture line
ps_blk = re.search(
r'\[node name="PlayerSprite"[^\]]*\](.*?)(?=\n\[node|\Z)',
txt, re.S)
if ps_blk:
tm = re.search(r"texture\s*=\s*ExtResource\(\s*(\d+)\s*\)",
ps_blk.group(1))
if tm and int(tm.group(1)) in ext_ids:
ext_id_ok = 1.0
# GoalLabel margins inside viewport
gl_blk = re.search(
r'\[node name="GoalLabel"[^\]]*\](.*?)(?=\n\[node|\Z)',
txt, re.S)
if gl_blk:
ml = re.search(r"margin_left\s*=\s*(-?[0-9.]+)", gl_blk.group(1))
mt = re.search(r"margin_top\s*=\s*(-?[0-9.]+)", gl_blk.group(1))
mr = re.search(r"margin_right\s*=\s*(-?[0-9.]+)", gl_blk.group(1))
mb = re.search(r"margin_bottom\s*=\s*(-?[0-9.]+)",gl_blk.group(1))
vw, vh = expected.get("viewport_size",[640,480])
if ml and mt and mr and mb:
vals = [float(x.group(1)) for x in (ml,mt,mr,mb)]
if (-50 <= vals[0] <= vw and -50 <= vals[1] <= vh
and 0 <= vals[2] <= vw+50 and 0 <= vals[3] <= vh+50):
label_ok = 1.0
# Floor RectangleShape2D extents
fs_blk = re.search(
r'\[node name="FloorShape"[^\]]*\](.*?)(?=\n\[node|\Z)',
txt, re.S)
if fs_blk:
sm = re.search(r"shape\s*=\s*SubResource\(\s*(\d+)\s*\)",
fs_blk.group(1))
if sm:
sid = int(sm.group(1))
# find that sub_resource block's extents
sb = re.search(
r'\[sub_resource[^\]]*\bid=' + str(sid) +
r'[^\]]*\](.*?)(?=\n\[sub_resource|\n\[node|\Z)',
txt, re.S)
if sb:
em = re.search(
r"extents\s*=\s*Vector2\(\s*(-?[0-9.]+)\s*,"
r"\s*(-?[0-9.]+)\s*\)",
sb.group(1))
if em:
ex, ey = float(em.group(1)), float(em.group(2))
if ex > 0 and ey > 0:
floor_ok = 1.0
s["fixed_extresource_id"] = ext_id_ok
s["fixed_label_in_viewport"]= label_ok
s["fixed_floor_extents"] = floor_ok
# ---- 7. editor screenshots present + OCR ----
shots_editor = ["view_editor_before.png","view_editor_after.png"]
editor_present = sum(1 for n in shots_editor if (rd/n).exists())
s["editor_shots_present"] = editor_present / 2.0
ed_kw = expected.get("editor_keywords",
["scene","node","inspector","filesystem","godot"])
try:
import pytesseract
from PIL import Image
editor_ocr_hits = 0
for n in shots_editor:
p = rd/n
if p.exists():
try:
tx = pytesseract.image_to_string(Image.open(p)).lower()
hit_kw = {k for k in ed_kw if k in tx}
if len(hit_kw) >= 3:
editor_ocr_hits += 1
except Exception: pass
s["editor_shots_ocr"] = editor_ocr_hits / 2.0
except ImportError:
s["editor_shots_ocr"] = 0.5
# ---- 8. play bug screenshot present + OCR ----
pb_shot = rd/"view_play_bug.png"
s["play_bug_shot_present"] = 1.0 if pb_shot.exists() else 0.0
pl_kw = expected.get("play_keywords",
["sceneplay","scenplay","goal","arrows","reach","left/right"])
try:
import pytesseract
from PIL import Image
if pb_shot.exists():
try:
tx = pytesseract.image_to_string(Image.open(pb_shot)).lower()
except Exception:
tx = ""
hits = sum(1 for k in pl_kw if k in tx)
s["play_bug_shot_hud_ocr"] = 1.0 if hits >= 1 else 0.0
else:
s["play_bug_shot_hud_ocr"] = 0.0
except ImportError:
s["play_bug_shot_hud_ocr"] = 0.5 if pb_shot.exists() else 0.0
# ---- 9. play finish screenshot present + OCR GOAL ----
pf_shot = rd/"view_play_finish.png"
s["play_finish_shot_present"] = 1.0 if pf_shot.exists() else 0.0
try:
import pytesseract
from PIL import Image
if pf_shot.exists():
try:
tx = pytesseract.image_to_string(Image.open(pf_shot)).lower()
except Exception:
tx = ""
s["play_finish_shot_ocr"] = 1.0 if "goal" in tx else 0.0
else:
s["play_finish_shot_ocr"] = 0.0
except ImportError:
s["play_finish_shot_ocr"] = 0.5 if pf_shot.exists() else 0.0
# ---- 9b. play screenshots must differ ----
diff_ok = 0.0
try:
from PIL import Image, ImageChops
if pb_shot.exists() and pf_shot.exists():
a = Image.open(pb_shot).convert("RGB").resize((128,96))
b = Image.open(pf_shot).convert("RGB").resize((128,96))
import numpy as np
d = np.abs(np.asarray(a, dtype=int)-np.asarray(b, dtype=int)).mean()
diff_ok = 1.0 if d >= 12.0 else 0.0
except Exception: pass
s["play_shots_distinct"] = diff_ok
# ---- 10. runtime.log non-empty + has player/scene markers ----
rl = rd/"runtime.log"
rt_ok = 0.0
if rl.exists() and rl.stat().st_size > 8:
try:
t = rl.read_text(errors="ignore").lower()
needles = ["[player] ready", "[main] scene ready",
"godot engine v3.", "opengl es 2.0 renderer"]
hits = sum(1 for k in needles if k in t)
rt_ok = 1.0 if hits >= 3 else (0.5 if hits == 2 else 0.0)
except Exception: pass
s["runtime_log_ok"] = rt_ok
# ---- 11. diff.txt sanity ----
df = rd/"diff.txt"
dlines = 0
if df.exists():
try: dlines = sum(1 for _ in df.open())
except Exception: dlines = 0
lo = expected.get("diff_min_lines", 6)
hi = expected.get("diff_max_lines", 200)
s["diff_in_range"] = 1.0 if lo <= dlines <= hi else 0.0
# ---- 12. VLM rubric on the screenshots ----
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
play_imgs = [str(rd/n) for n in
["view_play_bug.png","view_play_finish.png","view_editor_after.png"]
if (rd/n).exists()]
if vlm_score_rubric and play_imgs:
rubric = {
"vlm_godot_real": "图像确实是 Godot 3 编辑器或运行时窗口(含场景树/2D viewport/HUD),不是黑屏或主菜单",
"vlm_geometry_clean": "fixed 场景的 PlayerSprite 有真实贴图(不是粉红 missing),GoalLabel 在窗口内可见",
"vlm_finish_overlay": "通关截屏里能同时看到玩家贴图、地板和 GOAL 文字",
"vlm_no_cheat": "看上去是真实通过编辑器+运行通关的,不是把截图伪造或叠图",
}
vlm = vlm_score_rubric(play_imgs[:3], rubric,
instruction="评估 Godot 3 场景修复 + 通关截图的真实性与可视一致性")
for k in rubric: s[k] = vlm.get(k, 0.0)
s["judge_method"] = vlm.get("judge_method","failed")
else:
for k in ["vlm_godot_real","vlm_geometry_clean",
"vlm_finish_overlay","vlm_no_cheat"]:
s[k] = 0.5
# ---- 12b. report.json structural + numeric ----
rp = rd / "report.json"; rep_ok = 0.0
if rp.exists():
try:
r = json.loads(rp.read_text())
need = ["bugs_found","fixes_applied","extresource_id_after",
"label_margin_after","floor_extents_after",
"playthrough_finished","screenshots","runtime_log_lines"]
if (all(k in r for k in need) and r.get("playthrough_finished")
and int(r.get("extresource_id_after",-1)) in (1,3,4,5)
and len(r.get("screenshots",[])) == 4):
rep_ok = 1.0
except Exception: pass
s["report_json_ok"] = rep_ok
# ---- aggregate + hard gates ----
nums = [v for v in s.values() if isinstance(v,(int,float))]
base = sum(nums)/len(nums) if nums else 0.0
cli_evidence = ((rd/"parse_before.json").exists()
and (rd/"bugs.json").exists()
and (rd/"diff.txt").exists())
gui_screenshot = any((rd/n).exists() for n in
["view_editor_before.png","view_editor_after.png",
"view_play_bug.png","view_play_finish.png"])
vlm_avg = sum(s.get(k,0.0) for k in
["vlm_godot_real","vlm_geometry_clean",
"vlm_finish_overlay","vlm_no_cheat"]) / 4.0
if not cli_evidence: base = min(base, 0.4)
# GUI hard cap dropped: missing screenshots already penalised via per-shot sub-scores.
# Match Prompt bullet "VLM 4 项 ≥ 0.6"; only enforce when the helper
# actually ran, so missing _judge_helper does not silently penalise.
if vlm_score_rubric is not None and vlm_avg < 0.6:
base = min(base, 0.45)
if s.get("fixed_tscn_parses",0) < 1.0: base = min(base, 0.5)
if s.get("play_finish_shot_ocr",0) < 1.0: base = min(base, 0.7)
if s.get("runtime_log_ok",0) < 1.0: base = min(base, 0.55)
if s.get("play_shots_distinct",0) < 1.0: base = min(base, 0.6)
if s.get("report_json_ok",0) < 1.0: base = min(base, 0.6)
s["overall_score"] = round(base, 3)
return s
```
## Workspace Path
```
workspace/GAM/task_12_godot_scene_node_debug
```
## Skills
```
```
## Env
```
```
## Warmup
```bash
mkdir -p /tmp_workspace/results /tmp_workspace/state /tmp_workspace/exec
which tesseract || (apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=10 install -y -qq imagemagick tesseract-ocr libgl1 python3-pip) || true
pip install -q pillow numpy pytesseract lxml 2>/dev/null || pip3 install -q --break-system-packages pillow numpy pytesseract lxml 2>/dev/null || true
```
|