Download physworld_p1_20261018/patch_isolate.py from AIGeeksGroup/PhysicalWM: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/datasets/AIGeeksGroup/PhysicalWM/resolve/main/physworld_p1_20261018/patch_isolate.py
- Command line
-
hf download hf://datasets/AIGeeksGroup/PhysicalWM/physworld_p1_20261018/patch_isolate.py
-
curl -L -o patch_isolate.py https://huggingface.co/datasets/AIGeeksGroup/PhysicalWM/resolve/main/physworld_p1_20261018/patch_isolate.py
2.22 kB
| # -*- coding: utf-8 -*- | |
| """给 glb_to_sim_v2.run 加 keep_bodies 参数(隔离模式),并修 b0_check_v3 的 0 值判定。""" | |
| import io | |
| p = "scripts/glb_to_sim_v2.py" | |
| s = io.open(p, encoding="utf-8").read() | |
| old_sig = ("def run(glb, outdir, push_body=None, push_dir=\"+x\", impulse=0.8, settle_s=1.5,\n" | |
| " run_s=2.0, render=True, physicalize=True, anim=False, layout=None,\n" | |
| " travel=0.6):") | |
| new_sig = ("def run(glb, outdir, push_body=None, push_dir=\"+x\", impulse=0.8, settle_s=1.5,\n" | |
| " run_s=2.0, render=True, physicalize=True, anim=False, layout=None,\n" | |
| " travel=0.6, keep_bodies=None):") | |
| if old_sig in s: | |
| s = s.replace(old_sig, new_sig, 1) | |
| old_load = (" objs, table_bounds = load_objects(glb, do_physicalize=physicalize)\n") | |
| new_load = (" objs, table_bounds = load_objects(glb, do_physicalize=physicalize)\n" | |
| " if keep_bodies:\n" | |
| " kept = [o for o in objs if o[\"name\"] in keep_bodies or \"table\" in o[\"name\"].lower()]\n" | |
| " log(f\" [isolate] 保留 {len(kept)}/{len(objs)} 个物体\")\n" | |
| " objs = kept\n") | |
| if "keep_bodies" in s and old_load in s and "if keep_bodies:" not in s: | |
| s = s.replace(old_load, new_load, 1) | |
| io.open(p, "w", encoding="utf-8").write(s) | |
| print("run(keep_bodies) patched:", "keep_bodies" in s) | |
| # --- 修 b0_check_v3 的 0 值误判 --- | |
| q = "scripts/b0_check_v3.py" | |
| if __import__("os").path.exists(q): | |
| t = io.open(q, encoding="utf-8").read() | |
| t = t.replace(' no_hit = (n["min_distance_m"] or 0) > 0.02\n' | |
| ' light_hit = (l["min_distance_m"] or 1) <= 0.02\n' | |
| ' hard_hit = (h["min_distance_m"] or 1) <= 0.02\n', | |
| ' def _d(r, default):\n' | |
| ' v = r["min_distance_m"]\n' | |
| ' return default if v is None else v\n' | |
| ' no_hit = _d(n, 0) > 0.02\n' | |
| ' light_hit = _d(l, 1) <= 0.02\n' | |
| ' hard_hit = _d(h, 1) <= 0.02\n') | |
| io.open(q, "w", encoding="utf-8").write(t) | |
| print("b0_check_v3 zero-guard patched") | |