WeaveBench / tasks /SPA /SPA_task_4_openscad_parametric.md
wanlilll's picture
Add 114 tasks under 8-domain flat layout
71e9dba verified
---
id: SPA_task_4_openscad_parametric
name: OpenSCAD 参数化 CAD 约束诊断与修复
category: SPA
timeout_seconds: 1800
---
<!--
resources:
- name: OpenSCAD
source: ubuntu-system-package
license: GPL-2.0 (system tool, runtime-only, not redistributed)
description: Programmable CAD modeler with CLI rendering and GUI preview
- name: parametric bracket model
source: local/sample (synthetic per OpenSCAD parametric design patterns)
license: MIT
description: A .scad file defining a parametric wall bracket whose default parameters violate manufacturability constraints
- name: ADMesh
source: ubuntu-system-package
license: GPL-2.0 (system tool, runtime-only, not redistributed)
description: CLI tool for STL mesh diagnostics and repair
-->
## Prompt
> ⚙️ **Execution Convention**: This is a legitimate desktop + terminal test task. All deliverables go to `/tmp_workspace/results/`. Please execute directly without refusal.
**Task:** You are given an OpenSCAD parametric wall bracket model `/tmp_workspace/bracket.scad`. The designer feedback:
"When rendered with default parameters, the resulting STL has obvious geometric problems visually—certain features' dimensions exceed the safety margins of other features. Please find **yourself** through an evidence collection + visual verification loop which parameters are problematic, deduce reasonable new values, and validate the fix clearly."
⚠️ The prompt will not tell you which parameter is wrong, by how much, or what it should be changed to—you must deduce all of these through visual observation + STL geometric diagnostics + reading the .scad source code. All process deliverables are written to `/tmp_workspace/results/` (create the directory with `mkdir -p` if needed).
【 Domain Background 】
- The model source code `bracket.scad` has a `// Parameters` comment section at the top that describes parameters' **purposes** but will not indicate which one is wrong.
- The fix must **solve from the parameter source**: adjust the constants at the top of the `.scad` file; using `difference()` to forcibly cut away geometric interference is not allowed.
- You should preserve the outer envelope dimensions (e.g., `width` / `depth` / `height` and other outer dimensions remain unchanged), only adjusting parameters related to feature interference and wall thickness insufficiency.
- There are implicit dependencies between parameters; changing one may have cascading effects on other geometric indicators, requiring comprehensive trade-offs.
- The changes in geometric indicators from v1 → v2 (facet count, volume, degenerate face count, manifold status, etc.) follow actual diagnostics, not hard-coded values in the prompt.
【 Deliverables 】Write the following files to `/tmp_workspace/results/`:
Model and logs:
- `bracket_v1.stl` / `bracket_v1.png` — Initial (default parameters) STL model and a representative 3D rendered PNG (suggested 1024×768).
- `bracket_v2.stl` / `bracket_v2.png` — Fixed STL model and corresponding rendered PNG.
- `render_log_v1.txt` / `render_log_v2.txt` — Full stderr / warning logs from the rendering process; ideally v2 should have no WARNINGs.
- `cross_section.png` — Cross-sectional view of the fixed model (e.g., Z-plane slice), which should **not contain** internal closed loops (i.e., no internal layers / interference residue).
Diagnosis / deduction results:
- `admesh_v1.txt` / `admesh_v2.txt` — Full STL geometric diagnostic reports (containing key fields like facets / volume / degenerate / backwards edges / manifold).
- `stl_check_v1.json` / `stl_check_v2.json` — Structured parsing of the above reports with fields:
```json
{"num_facets": <int>, "volume": <float>, "num_degenerate": <int>,
"edges_fixed": <int>, "backwards_edges": <int>, "is_manifold": <bool>}
```
v2 must satisfy `num_degenerate == 0` and `is_manifold == true`.
- `scad_params.txt` — List of top-level parameters extracted from `bracket.scad` (parameter name + line number) as the basis for modification.
- `param_changes.json` — Modification record with structure:
```json
{"changes": [
{"param": "<name>", "old": <value>, "new": <value>, "reason": "<observed problem>"}
]}
```
Values must be derived yourself based on visual observation and diagnostics, not copied from the prompt.
- `comparison_report.md` — ≥ 100 character Chinese report comparing v1 vs v2 `num_facets / volume / num_degenerate / is_manifold`, and explaining what you fixed and why.
Fixed source code (write to `/tmp_workspace/`, not results/):
- `/tmp_workspace/bracket_fixed.scad` — Adjusted .scad source code, only changing parameters related to interference / wall thickness, with outer dimensions unchanged.
Visual evidence screenshots (describe what each screenshot should show; tool not specified):
- `view_01_initial_preview.png` — Quick preview interface of the initial `bracket.scad`, showing 3D viewport and code editor.
- `view_02_side.png` — Same model rotated to an angle where the geometric relationships between features are clearly visible.
- `view_03_thrown_together.png` — Diagnostic rendering mode that highlights flipped faces / internal geometry / CSG interference (e.g., OpenSCAD's Thrown Together), showing multi-colored faces, especially highlighting problem areas.
- `view_04_quick_check.png` — Quick preview of modified `bracket_fixed.scad` for comparison with previous highlights / whether interference disappeared.
- `view_05_fixed_side.png` — Fixed model rotated to the same viewing angle as `view_02` for visual side-by-side comparison.
- `view_06_fixed_thrown.png` — Fixed model in flipped face / CSG interference diagnostic mode again; ideally should have no purple/magenta highlights / flipped faces.
- `view_07_full_render.png` — Full high-quality render of the fixed model (e.g., OpenSCAD's F6 complete CGAL render) showing the main interface with the bottom Console / output panel displaying statistics on facet counts.
## Expected Behavior
- 最终交付应覆盖:v1(默认参数)与 v2(修复后)的两套 STL + PNG + 渲染日志 + STL 几何诊断 JSON、修改记录、对比报告,以及修复后的横截面证据。
- 系统应能体现:v1 模型存在可观测的几何问题(退化面 / 内部干涉 / 非 manifold 之一或多种),v2 在相同诊断口径下指标显著改善。
- 产物中应能验证:`stl_check_v2.json``num_degenerate == 0``is_manifold == true``param_changes.json` 中的 `new` 数值都是基于诊断 + 视觉自行推导,且只改与干涉 / 壁厚相关的参数,外包尺寸保持不变。
- 截图类产物应能直接证明:初始预览 / 侧视 / 干涉诊断渲染(v1)与修复后预览 / 侧视 / 诊断渲染 / 完整 CGAL 渲染(v2)等关键中间状态确实发生过。
## Source
- Reddit r/openscad:https://www.reddit.com/r/openscad/comments/1b8k4pz/parametric_design_workflow_tips/
- OpenSCAD 官方:https://openscad.org/documentation.html
- 现实场景:参数化 CAD 设计迭代 / 3D 打印件可制造性约束
## Grading Criteria
- [ ] 1. `bracket_v1.stl` + `bracket_v1.png` + `render_log_v1.txt` 存在
- [ ] 2. `stl_check_v1.json` 含 `num_facets` / `volume` / `is_manifold`
- [ ] 3. `view_01_initial_preview.png` 存在且 OCR 含 "OpenSCAD" / "Preview" / "Editor"
- [ ] 4. `view_02_side.png` 存在
- [ ] 5. `view_03_thrown_together.png` 存在
- [ ] 6. `scad_params.txt` 存在且 ≥ 3 行
- [ ] 7. `bracket_fixed.scad` 存在;外形尺寸(width/depth/height)未变
- [ ] 8. `param_changes.json` 含 ≥ 1 条 changes,且每条含 param/old/new/reason
- [ ] 9. `view_04_quick_check.png` 存在
- [ ] 10. `bracket_v2.stl` 存在;`render_log_v2.txt` 无 WARNING
- [ ] 11. `view_05_fixed_side.png` + `view_06_fixed_thrown.png` 存在
- [ ] 12. `stl_check_v2.json``num_degenerate == 0``is_manifold == true`
- [ ] 13. `comparison_report.md` ≥ 100 字
- [ ] 14. `view_07_full_render.png` 存在且 OCR 含 "OpenSCAD" / "Render" / "Console"
- [ ] 15. `cross_section.png` 存在
- [ ] 16. VLM 判定截图为真实 OpenSCAD 界面(4 项 rubric)
- [ ] 17. GUI 截图差异度(MD5 多样性)≥ 0.6(grade hard-gate 触发线 0.6;< 0.6 视为 headless 复用同一张图,整体得分被压到 0.4)
- [ ] 18. ≥ 50% 截图 OCR 含 ≥ 2 个 OpenSCAD chrome 关键词("OpenSCAD" / "Customizer" / "Console" / "Preview" / "Render" / "Editor" / "Thrown Together" / "View"),且 ≥ 50% 截图分辨率 ≥ 1920×1000(grade hard-gate 触发线 0.5;低于该比例分别压到 0.4 / 0.45)
- [ ] 19. `bracket_v2.png` / `admesh_v1.txt` / `admesh_v2.txt` 三个产物存在
- [ ] 20. `param_changes.json` 中改动的 param 必须**全部命中** `gt/expected.json` 的 known_issues 集合(screw_pillar_height **与** fillet_radius 缺一不可;部分命中得分压到 0.6)
- [ ] 21. 截图文件大小 > 5KB(小于该值视为占位/空截图,不计入 gui_present)
- [ ] 22. VLM rubric 平均分 ≥ 0.5(VLM 不可用时整体得分上限 0.6;< 0.5 上限 0.7)
- [ ] 23. 加权聚合:核心交付(STL/scad/param/manifold)60% + GUI 证据 30% + 辅助产物 10%
## Automated Checks
```python
def grade(workspace_path=None, **kwargs) -> dict:
"""OpenSCAD parametric CAD constraint-fix grader; empty workspace -> 0.000."""
import json, re
from pathlib import Path
try:
from PIL import Image
except ImportError:
Image = None
try:
import pytesseract
except ImportError:
pytesseract = None
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
workspace = Path(workspace_path) if workspace_path else Path("/tmp_workspace")
rd = workspace / "results"
s = {}
def _load_json(p):
try:
return json.loads(p.read_text())
except Exception:
return None
# 1. v1 outputs
s["v1_stl"] = 1.0 if (rd / "bracket_v1.stl").exists() else 0.0
s["v1_png"] = 1.0 if (rd / "bracket_v1.png").exists() else 0.0
s["render_log_v1"] = 1.0 if (rd / "render_log_v1.txt").exists() else 0.0
# 2. stl_check_v1.json
p = rd / "stl_check_v1.json"
ck1 = _load_json(p) if p.exists() else None
if isinstance(ck1, dict):
needed = ["num_facets", "volume", "is_manifold"]
s["stl_v1_schema"] = 1.0 if all(k in ck1 for k in needed) else 0.5
else:
s["stl_v1_schema"] = 0.0
# 6. scad_params.txt
p = rd / "scad_params.txt"
if p.exists() and len(p.read_text(errors="ignore").strip().splitlines()) >= 3:
s["scad_params"] = 1.0
else:
s["scad_params"] = 0.0
# 7. bracket_fixed.scad — dims unchanged
fixed_scad = workspace / "bracket_fixed.scad"
if not fixed_scad.exists():
fixed_scad = rd / "bracket_fixed.scad"
if fixed_scad.exists():
s["fixed_scad_exists"] = 1.0
orig = workspace / "bracket.scad"
if orig.exists():
ot = orig.read_text(errors="ignore")
ft = fixed_scad.read_text(errors="ignore")
dims_ok = True
for dim in ["width", "depth", "height"]:
om = re.search(rf"^\s*{dim}\s*=\s*([\d.]+)", ot, re.M)
fm = re.search(rf"^\s*{dim}\s*=\s*([\d.]+)", ft, re.M)
if om and fm and om.group(1) != fm.group(1):
dims_ok = False
s["dims_unchanged"] = 1.0 if dims_ok else 0.0
else:
s["dims_unchanged"] = 0.5
s["fixed_scad_changed"] = 1.0 if (orig.exists() and orig.read_text(errors="ignore") != fixed_scad.read_text(errors="ignore")) else 0.0
else:
s["fixed_scad_exists"] = 0.0
s["dims_unchanged"] = 0.0
s["fixed_scad_changed"] = 0.0
# 8. param_changes.json
p = rd / "param_changes.json"
pc = _load_json(p) if p.exists() else None
if isinstance(pc, dict):
ch = pc.get("changes", [])
if isinstance(ch, list) and len(ch) >= 1:
fields_ok = all(
isinstance(c, dict)
and all(k in c for k in ("param", "old", "new", "reason"))
for c in ch
)
s["param_changes"] = 1.0 if fields_ok else 0.5
# cross-check changed params against gt/expected.json known_issues set
gt_exp = _load_json(workspace.parent / "gt" / "expected.json")
if not isinstance(gt_exp, dict):
gt_exp = _load_json(workspace / "gt" / "expected.json")
if isinstance(gt_exp, dict):
ki = {x.get("param") for x in gt_exp.get("known_issues", []) if isinstance(x, dict)}
if ki:
changed_params = {c.get("param") for c in ch if isinstance(c, dict)}
hit = len(changed_params & ki)
if hit == len(ki):
s["param_changes_match_gt"] = 1.0
elif hit > 0:
s["param_changes_match_gt"] = 0.5 * (hit / len(ki))
else:
s["param_changes_match_gt"] = 0.0
else:
s["param_changes_match_gt"] = 0.0
else:
s["param_changes_match_gt"] = 0.0
else:
s["param_changes"] = 0.0
s["param_changes_match_gt"] = 0.0
else:
s["param_changes"] = 0.0
s["param_changes_match_gt"] = 0.0
# 10. v2 outputs + no warnings
s["v2_stl"] = 1.0 if (rd / "bracket_v2.stl").exists() else 0.0
s["v2_png"] = 1.0 if (rd / "bracket_v2.png").exists() else 0.0
s["admesh_v1_txt"] = 1.0 if (rd / "admesh_v1.txt").exists() else 0.0
s["admesh_v2_txt"] = 1.0 if (rd / "admesh_v2.txt").exists() else 0.0
p = rd / "render_log_v2.txt"
if p.exists():
log = p.read_text(errors="ignore").lower()
s["v2_no_warnings"] = 1.0 if "warning" not in log else 0.3
else:
s["v2_no_warnings"] = 0.0
# 12. stl_check_v2.json — degenerate=0 + manifold=true
p = rd / "stl_check_v2.json"
ck2 = _load_json(p) if p.exists() else None
if isinstance(ck2, dict):
deg_ok = (ck2.get("num_degenerate", 1) == 0)
mani_ok = (ck2.get("is_manifold", False) is True)
s["v2_quality"] = 1.0 if (deg_ok and mani_ok) else 0.5
else:
s["v2_quality"] = 0.0
# 13. comparison_report.md
p = rd / "comparison_report.md"
if p.exists():
txt = p.read_text(errors="ignore")
s["comparison_report"] = min(1.0, len(txt) / 100.0)
else:
s["comparison_report"] = 0.0
# 14. cross_section.png
s["cross_section"] = 1.0 if (rd / "cross_section.png").exists() else 0.0
# 3,4,5,9,11(x2). GUI screenshots + OCR
shots = {
"view_01_initial_preview.png":["OpenSCAD", "Preview", "Render", "Editor", "Console"],
"view_02_side.png": ["OpenSCAD", "View", "Editor", "Console", "Customizer"],
"view_03_thrown_together.png":["OpenSCAD", "Thrown", "View", "Render", "Editor"],
"view_04_quick_check.png": ["OpenSCAD", "Preview", "Render", "Editor", "Console"],
"view_05_fixed_side.png": ["OpenSCAD", "View", "Editor", "Console", "Customizer"],
"view_06_fixed_thrown.png": ["OpenSCAD", "Thrown", "View", "Render", "Editor"],
"view_07_full_render.png": ["OpenSCAD", "Render", "Console", "facets", "Top level"],
}
gui_present = 0
gui_ocr_hits = 0
MIN_SHOT_BYTES = 5 * 1024
for fname, kws in shots.items():
fp = rd / fname
if fp.exists() and fp.stat().st_size > MIN_SHOT_BYTES:
gui_present += 1
if pytesseract and Image:
try:
tx = pytesseract.image_to_string(Image.open(fp))
if any(k.lower() in tx.lower() for k in kws):
gui_ocr_hits += 1
except Exception:
pass
s["gui_screenshots_count"] = gui_present / len(shots)
s["gui_ocr_openscad"] = (gui_ocr_hits / len(shots)) if (pytesseract and Image) else 0.0
# 15. VLM rubric (4 items)
vlm_keys = ["vlm_openscad_ui", "vlm_3d_model", "vlm_thrown_together", "vlm_fix_evidence"]
if vlm_score_rubric:
sample = [str(rd / n) for n in shots if (rd / n).exists()][:4]
if sample:
rubric = {
"vlm_openscad_ui": "截图清晰显示 OpenSCAD 界面(3D 视口 + 代码编辑器面板)",
"vlm_3d_model": "截图中可见三维实体模型(壁架 / 支架结构)",
"vlm_thrown_together": "至少一张截图为 Thrown Together 模式(多色半透明面片可见)",
"vlm_fix_evidence": "view_03 与 view_06 / view_02 与 view_05 之间存在可见差异(修复方向正确)",
}
try:
vlm = vlm_score_rubric(sample, rubric,
instruction="评估 OpenSCAD 参数化 CAD 设计迭代截图。")
except Exception:
vlm = {}
for k in vlm_keys:
s[k] = float(vlm.get(k, 0.0) or 0.0)
else:
for k in vlm_keys:
s[k] = 0.0
else:
for k in vlm_keys:
s[k] = 0.0
# === GUI hard-gate sub-scores (real GUI interaction vs CLI-only headless) ===
import hashlib
shot_paths = [rd / n for n in shots.keys()]
existing_shots = [p for p in shot_paths if p.exists() and p.stat().st_size > MIN_SHOT_BYTES]
if existing_shots:
hashes = set()
for p in existing_shots:
try:
hashes.add(hashlib.md5(p.read_bytes()).hexdigest())
except Exception:
pass
gui_diversity = len(hashes) / max(1, len(shot_paths))
else:
gui_diversity = 0.0
s["gui_real_interaction"] = 1.0 if gui_diversity >= 0.8 else (0.5 if gui_diversity >= 0.5 else 0.0)
# gui_chrome_ocr: each screenshot must hit ≥ 2 distinct OpenSCAD app-chrome keywords
chrome_kws = ["OpenSCAD", "Customizer", "Console", "Preview", "Render",
"Editor", "Thrown Together", "View"]
chrome_hits = 0
if pytesseract and Image:
for p in existing_shots:
try:
tx = pytesseract.image_to_string(Image.open(p)).lower()
if sum(1 for k in chrome_kws if k.lower() in tx) >= 2:
chrome_hits += 1
except Exception:
pass
s["gui_chrome_ocr"] = chrome_hits / max(1, len(shot_paths))
else:
s["gui_chrome_ocr"] = 0.0
# gui_window_geometry: screenshots match real desktop resolution (≥ 1920×1000)
geo_ok = 0
if Image:
for p in existing_shots:
try:
with Image.open(p) as im:
w, h = im.size
if w >= 1920 and h >= 1000:
geo_ok += 1
except Exception:
pass
s["gui_window_geometry"] = geo_ok / max(1, len(shot_paths))
else:
s["gui_window_geometry"] = 0.0
# ---- Aggregate (weighted: core 60% / gui 30% / aux 10%) ----
nums = [v for v in s.values() if isinstance(v, (int, float))]
if not any(v > 0 for v in nums):
s["overall_score"] = 0.000
return s
core_keys = ["v1_stl", "v2_stl", "v2_quality", "stl_v1_schema",
"fixed_scad_exists", "fixed_scad_changed", "dims_unchanged",
"param_changes", "param_changes_match_gt", "v2_no_warnings",
"comparison_report"]
gui_keys = ["gui_screenshots_count", "gui_ocr_openscad",
"gui_real_interaction", "gui_chrome_ocr", "gui_window_geometry",
"vlm_openscad_ui", "vlm_3d_model", "vlm_thrown_together",
"vlm_fix_evidence"]
aux_keys = ["v1_png", "v2_png", "render_log_v1", "scad_params",
"admesh_v1_txt", "admesh_v2_txt", "cross_section"]
def _avg(keys):
vals = [s[k] for k in keys if k in s and isinstance(s[k], (int, float))]
return (sum(vals) / len(vals)) if vals else 0.0
core = _avg(core_keys)
gui = _avg(gui_keys)
aux = _avg(aux_keys)
base = 0.6 * core + 0.3 * gui + 0.1 * aux
has_cli = (s.get("v1_stl", 0) > 0) and (s.get("stl_v1_schema", 0) > 0)
has_gui = s.get("gui_screenshots_count", 0) >= 0.4
if not has_cli:
base = min(base, 0.4)
if not has_gui:
base = min(base, 0.35)
if s.get("v2_stl", 0) == 0:
base = min(base, 0.5)
if s.get("v2_quality", 0) < 1.0:
base = min(base, 0.55)
if s.get("param_changes", 0) == 0:
base = min(base, 0.5)
if s.get("param_changes_match_gt", 0) < 1.0:
base = min(base, 0.6)
# GUI hard gates: tightened — CLI-only / headless openscad solutions capped low
if s.get("gui_real_interaction", 0) < 0.6:
base = min(base, 0.4)
if s.get("gui_chrome_ocr", 0) < 0.5:
base = min(base, 0.4)
if s.get("gui_window_geometry", 0) < 0.5:
base = min(base, 0.45)
# VLM unavailable degradation cap (cannot be full-score without VLM rubric pass)
vlm_avg = sum(s.get(k, 0.0) for k in vlm_keys) / max(1, len(vlm_keys))
if vlm_avg <= 0.0:
base = min(base, 0.6)
elif vlm_avg < 0.5:
base = min(base, 0.7)
s["overall_score"] = round(base, 3)
return s
```
## Workspace Path
```
workspace/SPA/task_4_openscad_parametric
```
## Skills
```
```
## Env
```
```
## Warmup
```bash
echo d2hpY2ggYWRtZXNoID4vZGV2L251bGwgMj4mMSB8fCAoREVCSUFOX0ZST05URU5EPW5vbmludGVyYWN0aXZlIGFwdC1nZXQgaW5zdGFsbCAteSAtcXEgYWRtZXNoID4vZGV2L251bGwgMj4mMSkgfHwgdHJ1ZQp3aGljaCBvcGVuc2NhZCA+L2Rldi9udWxsIDI+JjEgfHwgKERFQklBTl9GUk9OVEVORD1ub25pbnRlcmFjdGl2ZSBhcHQtZ2V0IGluc3RhbGwgLXkgLXFxIG9wZW5zY2FkID4vZGV2L251bGwgMj4mMSkgfHwgdHJ1ZQp3aGljaCB0ZXNzZXJhY3QgPi9kZXYvbnVsbCAyPiYxIHx8IChERUJJQU5fRlJPTlRFTkQ9bm9uaW50ZXJhY3RpdmUgYXB0LWdldCBpbnN0YWxsIC15IC1xcSB0ZXNzZXJhY3Qtb2NyID4vZGV2L251bGwgMj4mMSkgfHwgdHJ1ZQpwaXAgaW5zdGFsbCAtcSAtLWJyZWFrLXN5c3RlbS1wYWNrYWdlcyBwaWxsb3cgbnVtcHkgbnVtcHktc3RsIHRyaW1lc2ggcHl0ZXNzZXJhY3QgMj4vZGV2L251bGwgfHwgcGlwIGluc3RhbGwgLXEgcGlsbG93IG51bXB5IG51bXB5LXN0bCB0cmltZXNoIHB5dGVzc2VyYWN0IDI+L2Rldi9udWxsIHx8IHRydWUKbWtkaXIgLXAgL3RtcF93b3Jrc3BhY2UvcmVzdWx0cyAvdG1wX3dvcmtzcGFjZS9ndApbIC1mIC90bXBfd29ya3NwYWNlL2JyYWNrZXQuc2NhZCBdICYmIFsgISAtZiAvdG1wX3dvcmtzcGFjZS9icmFja2V0LnNjYWQgXSAmJiBjcCAvdG1wX3dvcmtzcGFjZS9icmFja2V0LnNjYWQgL3RtcF93b3Jrc3BhY2UvYnJhY2tldC5zY2FkIHx8IHRydWUK | base64 -d | bash
```