backup 03_4dcodebench 2026-11-08 10:10:50
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- 4dcodebench/cases/B_03/B_03.h5 +3 -0
- 4dcodebench/cases/B_03/B_03.mp4 +3 -0
- 4dcodebench/cases/B_07/B_07.h5 +3 -0
- 4dcodebench/cases/B_07/B_07.mp4 +3 -0
- 4dcodebench/cases/B_24/B_24.h5 +3 -0
- 4dcodebench/cases/B_24/B_24.mp4 +3 -0
- 4dcodebench/cases/G_12/G_12.h5 +3 -0
- 4dcodebench/cases/G_12/G_12.mp4 +3 -0
- 4dcodebench/resim/__pycache__/fit_params_neuido.cpython-311.pyc +0 -0
- 4dcodebench/resim/agent_card.py +74 -0
- 4dcodebench/resim/compose_video.py +71 -0
- 4dcodebench/resim/debug_scene.py +107 -0
- 4dcodebench/resim/fit_params_neuido.py +218 -0
- 4dcodebench/resim/resim_blender.py +283 -0
- 4dcodebench/resim/resim_cloth_blender.py +319 -0
- 4dcodebench/resim/run_ablation_b07.sh +63 -0
- 4dcodebench/resim/run_b03.sh +32 -0
- 4dcodebench/resim/score_ablation.py +109 -0
- 4dcodebench/resim/score_dtw.py +55 -0
- 4dcodebench/resim/unpack_world.py +112 -0
- 4dcodebench/work/B_03/compare_B_03.mp4 +3 -0
- 4dcodebench/work/B_03/dbg/dbg_f1.png +3 -0
- 4dcodebench/work/B_03/dtw.json +32 -0
- 4dcodebench/work/B_03/out_p1/sim.mp4 +3 -0
- 4dcodebench/work/B_03/out_p1/simtraj.npz +3 -0
- 4dcodebench/work/B_03/out_p2/sim.mp4 +3 -0
- 4dcodebench/work/B_03/out_p2/simtraj.npz +3 -0
- 4dcodebench/work/B_03/world/camera.json +1 -0
- 4dcodebench/work/B_03/world/dyn/Ball.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin00.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin01.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin02.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin03.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin04.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin05.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin06.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin07.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin08.npz +3 -0
- 4dcodebench/work/B_03/world/dyn/Pin09.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/1.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/10.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/11.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/12.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/13.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/14.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/15.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/16.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/17.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/18.npz +3 -0
- 4dcodebench/work/B_03/world/mesh/19.npz +3 -0
4dcodebench/cases/B_03/B_03.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:abe0e90a40311406bdf4d7a5baab9ffe5f35c64c0397313134f2c65e107ed2a7
|
| 3 |
+
size 18410240
|
4dcodebench/cases/B_03/B_03.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ae3731942295ca4c0ba702cede9c0f0f1d3d2fc05faf0650427a872409ca08ef
|
| 3 |
+
size 491165
|
4dcodebench/cases/B_07/B_07.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:273b75b492022c2516816c59817cdbe996b3fc54248508e1340622b4cf57f935
|
| 3 |
+
size 32970785
|
4dcodebench/cases/B_07/B_07.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0c5477fc58fda612906937c0db6a1c93a5fc7d1ceedb2fdf1f223cae0421f8c2
|
| 3 |
+
size 978302
|
4dcodebench/cases/B_24/B_24.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:961f81e5e7e7fa6903c83b37546def9b8ed15fea60ebec441051d26e5aef888a
|
| 3 |
+
size 53149265
|
4dcodebench/cases/B_24/B_24.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6d3f6c92c94f8ba1c7f3671ad3f7857aaf2c75a574ce4d24896e43d00c63adfb
|
| 3 |
+
size 443899
|
4dcodebench/cases/G_12/G_12.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7dadf7bbf03308f7200314a188475c4327165dd86ea9e5a449ab8e78d50edad7
|
| 3 |
+
size 5569309
|
4dcodebench/cases/G_12/G_12.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:62a0aba416e9f441bb0aca0dbf0e6409bb1b4a116e787187bd32714992392fe2
|
| 3 |
+
size 953363
|
4dcodebench/resim/__pycache__/fit_params_neuido.cpython-311.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
4dcodebench/resim/agent_card.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Agent prior card (ablation factor A): what a coding agent can infer about
|
| 3 |
+
the cloth parameter card from the reference video alone, without any fitting.
|
| 4 |
+
|
| 5 |
+
This emulates the "coding agent writes a world + parameters" arm of the
|
| 6 |
+
ablation. The agent sees: reference.mp4 (and nothing else). Its priors:
|
| 7 |
+
|
| 8 |
+
1. Material: it looks like standard polyester/cotton fabric -> areal density
|
| 9 |
+
~0.2-0.4 kg/m^2 -> card density 0.35 (anchored working point).
|
| 10 |
+
2. Stiffness: folds look soft, drapes over the table edge smoothly ->
|
| 11 |
+
flimsy -> bending 0.02 (rag-like).
|
| 12 |
+
3. Air drag: the drop in the video falls fast, no parachute behavior ->
|
| 13 |
+
air_damp 1.0 (Blender default).
|
| 14 |
+
|
| 15 |
+
So the agent card IS the default card here, which is the honest baseline:
|
| 16 |
+
"agent guesses from priors, no measurement". The NeuIDO arm (B1) instead
|
| 17 |
+
*measures* the parameters from the truth trajectories by closed-loop fitting.
|
| 18 |
+
|
| 19 |
+
We write the card to JSON so the 2x2 ablation runner picks it up.
|
| 20 |
+
|
| 21 |
+
Usage:
|
| 22 |
+
python agent_card.py --world work/B_07/world --out work/B_07/agent_card.json
|
| 23 |
+
"""
|
| 24 |
+
import argparse
|
| 25 |
+
import json
|
| 26 |
+
import os
|
| 27 |
+
from pathlib import Path
|
| 28 |
+
|
| 29 |
+
import numpy as np
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def main():
|
| 33 |
+
ap = argparse.ArgumentParser()
|
| 34 |
+
ap.add_argument("--world", required=True)
|
| 35 |
+
ap.add_argument("--out", required=True)
|
| 36 |
+
args = ap.parse_args()
|
| 37 |
+
|
| 38 |
+
world = Path(args.world)
|
| 39 |
+
spec = json.loads((world / "spec.json").read_text())
|
| 40 |
+
z = np.load(world / "dyn" / "Cloth.npz")
|
| 41 |
+
pos = z["pos"]
|
| 42 |
+
faces = z["faces"]
|
| 43 |
+
|
| 44 |
+
# cloth area at frame 0 (agent could estimate this from the video geometry)
|
| 45 |
+
v = pos[0].astype(np.float64)[faces.astype(np.int64)]
|
| 46 |
+
a = v[:, 1] - v[:, 0]
|
| 47 |
+
b = v[:, 2] - v[:, 0]
|
| 48 |
+
area = float(0.5 * np.linalg.norm(np.cross(a, b), axis=1).sum())
|
| 49 |
+
|
| 50 |
+
# drop speed visible in the first frames (agent could read this from video)
|
| 51 |
+
dt = 1.0 / float(spec["video"]["fps"])
|
| 52 |
+
speed = float(np.linalg.norm((pos[6] - pos[0]) / (6 * dt), axis=1).mean())
|
| 53 |
+
|
| 54 |
+
# agent priors -> card (fabric recognition + free-fall check vs 9.81)
|
| 55 |
+
card = {
|
| 56 |
+
"density": 0.35, # "standard fabric" prior, kg/m^2 anchor
|
| 57 |
+
"bending": 0.02, # "soft drape" prior
|
| 58 |
+
"air_damp": 1.0, # "falls like normal cloth" prior
|
| 59 |
+
"tensile": 15.0,
|
| 60 |
+
"compress": 15.0,
|
| 61 |
+
"shear": 8.0,
|
| 62 |
+
"method": "agent_prior",
|
| 63 |
+
"notes": {
|
| 64 |
+
"cloth_area_m2": round(area, 3),
|
| 65 |
+
"early_drop_speed_ms": round(speed, 3),
|
| 66 |
+
"gravity_freefall_check": round(speed / (6 * dt) / 9.81, 3),
|
| 67 |
+
},
|
| 68 |
+
}
|
| 69 |
+
Path(args.out).write_text(json.dumps(card, indent=1))
|
| 70 |
+
print(json.dumps(card, indent=1))
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
main()
|
4dcodebench/resim/compose_video.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Compose truth | sim... side-by-side comparison video with labels.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
python compose_video.py --world work/B_03/world \
|
| 6 |
+
--sims work/B_03/out_p1 work/B_03/out_p2 \
|
| 7 |
+
--labels "mu=0.5 e=0.05" "mu=0.02 e=0.9" \
|
| 8 |
+
--out work/B_03/compare_B_03.mp4
|
| 9 |
+
"""
|
| 10 |
+
import argparse
|
| 11 |
+
import json
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
import cv2
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def read_frames(path):
|
| 19 |
+
cap = cv2.VideoCapture(str(path))
|
| 20 |
+
frames = []
|
| 21 |
+
while True:
|
| 22 |
+
ok, f = cap.read()
|
| 23 |
+
if not ok:
|
| 24 |
+
break
|
| 25 |
+
frames.append(f)
|
| 26 |
+
cap.release()
|
| 27 |
+
return frames
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def main():
|
| 31 |
+
ap = argparse.ArgumentParser()
|
| 32 |
+
ap.add_argument("--world", required=True)
|
| 33 |
+
ap.add_argument("--sims", nargs="+", required=True)
|
| 34 |
+
ap.add_argument("--labels", nargs="+", required=True)
|
| 35 |
+
ap.add_argument("--truth-label", default="truth (reference)")
|
| 36 |
+
ap.add_argument("--out", required=True)
|
| 37 |
+
args = ap.parse_args()
|
| 38 |
+
assert len(args.labels) == len(args.sims)
|
| 39 |
+
|
| 40 |
+
spec = json.loads((Path(args.world) / "spec.json").read_text())
|
| 41 |
+
W, H = spec["video"]["width"], spec["video"]["height"]
|
| 42 |
+
fps = spec["video"]["fps"] or 24.0
|
| 43 |
+
|
| 44 |
+
panels = [(args.truth_label, read_frames(Path(args.world) / "render.mp4"))]
|
| 45 |
+
for sim, lab in zip(args.sims, args.labels):
|
| 46 |
+
panels.append((lab, read_frames(Path(sim) / "sim.mp4")))
|
| 47 |
+
|
| 48 |
+
n = min(len(f) for _, f in panels)
|
| 49 |
+
canvas_w, canvas_h = W * len(panels), H
|
| 50 |
+
writer = cv2.VideoWriter(str(args.out), cv2.VideoWriter_fourcc(*"mp4v"),
|
| 51 |
+
fps, (canvas_w, canvas_h))
|
| 52 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
| 53 |
+
for i in range(n):
|
| 54 |
+
row = []
|
| 55 |
+
for k, (lab, frames) in enumerate(panels):
|
| 56 |
+
f = frames[i]
|
| 57 |
+
if f.shape[:2] != (H, W):
|
| 58 |
+
f = cv2.resize(f, (W, H))
|
| 59 |
+
tag = f"{lab} [{i+1}/{n}]"
|
| 60 |
+
cv2.rectangle(f, (0, 0), (W, 34), (0, 0, 0), -1)
|
| 61 |
+
cv2.putText(f, tag, (10, 24), font, 0.62, (255, 255, 255), 2, cv2.LINE_AA)
|
| 62 |
+
if k:
|
| 63 |
+
cv2.line(f, (0, 0), (0, H), (255, 255, 255), 2)
|
| 64 |
+
row.append(f)
|
| 65 |
+
writer.write(np.hstack(row))
|
| 66 |
+
writer.release()
|
| 67 |
+
print(f"wrote {args.out} ({n} frames, {canvas_w}x{canvas_h})")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|
4dcodebench/resim/debug_scene.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Debug: rebuild the B_03 scene, dump object boxes + camera projections, render 1 frame (Workbench).
|
| 3 |
+
blender --background --python debug_scene.py -- --world work/B_03/world --out work/B_03/dbg
|
| 4 |
+
"""
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import bpy
|
| 11 |
+
import numpy as np
|
| 12 |
+
from mathutils import Matrix, Vector
|
| 13 |
+
import bpy_extras
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def parse_args():
|
| 17 |
+
ap = argparse.ArgumentParser()
|
| 18 |
+
ap.add_argument("--world", required=True)
|
| 19 |
+
ap.add_argument("--out", required=True)
|
| 20 |
+
return ap.parse_args(sys.argv[sys.argv.index("--") + 1:])
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def add_mesh(name, verts, faces):
|
| 24 |
+
me = bpy.data.meshes.new(name)
|
| 25 |
+
me.from_pydata([tuple(float(x) for x in v) for v in verts], [],
|
| 26 |
+
[tuple(int(x) for x in f) for f in faces])
|
| 27 |
+
me.update()
|
| 28 |
+
ob = bpy.data.objects.new(name, me)
|
| 29 |
+
bpy.context.scene.collection.objects.link(ob)
|
| 30 |
+
return ob
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def main():
|
| 34 |
+
args = parse_args()
|
| 35 |
+
world = Path(args.world)
|
| 36 |
+
out = Path(args.out)
|
| 37 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 38 |
+
|
| 39 |
+
spec = json.loads((world / "spec.json").read_text())
|
| 40 |
+
cam = json.loads((world / "camera.json").read_text())
|
| 41 |
+
K = np.array(cam["intrinsics"], float)
|
| 42 |
+
E = np.array(cam["extrinsic"], float)
|
| 43 |
+
W, H = spec["video"]["width"], spec["video"]["height"]
|
| 44 |
+
scene = bpy.context.scene
|
| 45 |
+
for ob in list(bpy.data.objects):
|
| 46 |
+
bpy.data.objects.remove(ob, do_unlink=True)
|
| 47 |
+
|
| 48 |
+
for mid, v in spec["meshes"].items():
|
| 49 |
+
z = np.load(world / "mesh" / f"{mid}.npz")
|
| 50 |
+
add_mesh(f"mesh_{mid}", z["vertices"][0], z["faces"][0])
|
| 51 |
+
|
| 52 |
+
cam_data = bpy.data.cameras.new("cam")
|
| 53 |
+
cam_data.sensor_fit = "HORIZONTAL"
|
| 54 |
+
cam_data.sensor_width = 36.0
|
| 55 |
+
cam_data.lens = float(K[0, 0]) * 36.0 / W
|
| 56 |
+
cam_ob = bpy.data.objects.new("cam", cam_data)
|
| 57 |
+
bpy.context.scene.collection.objects.link(cam_ob)
|
| 58 |
+
D = Matrix.Diagonal((1.0, -1.0, -1.0, 1.0))
|
| 59 |
+
cam_ob.matrix_world = Matrix(E) @ D
|
| 60 |
+
scene.camera = cam_ob
|
| 61 |
+
scene.render.resolution_x = W
|
| 62 |
+
scene.render.resolution_y = H
|
| 63 |
+
|
| 64 |
+
sun = bpy.data.lights.new("sun", type="SUN")
|
| 65 |
+
sun.energy = 3.0
|
| 66 |
+
sun_ob = bpy.data.objects.new("sun", sun)
|
| 67 |
+
bpy.context.scene.collection.objects.link(sun_ob)
|
| 68 |
+
sun_ob.rotation_euler = (0.9, 0, 0.5)
|
| 69 |
+
w = bpy.data.worlds.new("w")
|
| 70 |
+
w.use_nodes = True
|
| 71 |
+
w.node_tree.nodes["Background"].inputs["Color"].default_value = (0.8, 0.8, 0.8, 1)
|
| 72 |
+
scene.world = w
|
| 73 |
+
|
| 74 |
+
print("=== object bounding boxes (world) ===")
|
| 75 |
+
dg = bpy.context.evaluated_depsgraph_get()
|
| 76 |
+
for ob in bpy.data.objects:
|
| 77 |
+
if ob.type != "MESH":
|
| 78 |
+
continue
|
| 79 |
+
corners = [ob.matrix_world @ Vector(c) for c in ob.bound_box]
|
| 80 |
+
xs = [c.x for c in corners]; ys = [c.y for c in corners]; zs = [c.z for c in corners]
|
| 81 |
+
print(f"{ob.name:12s} x[{min(xs):7.2f},{max(xs):7.2f}] y[{min(ys):7.2f},{max(ys):7.2f}] z[{min(zs):7.2f},{max(zs):7.2f}]")
|
| 82 |
+
|
| 83 |
+
print("=== camera projection of pin COMs (should be in-frame) ===")
|
| 84 |
+
bpy.context.view_layer.update()
|
| 85 |
+
for name in ["Pin00", "Pin05", "Pin09"]:
|
| 86 |
+
pos = np.load(world / "dyn" / f"{name}.npz")["pos"]
|
| 87 |
+
p = Vector(pos[0].mean(0))
|
| 88 |
+
uv = bpy_extras.object_utils.world_to_camera_view(scene, cam_ob, p)
|
| 89 |
+
print(f"{name}: blender uv=({uv.x:.3f},{uv.y:.3f}) depth={uv.z:.2f}")
|
| 90 |
+
ball = np.load(world / "dyn" / "Ball.npz")["pos"]
|
| 91 |
+
p = Vector(ball[0].mean(0))
|
| 92 |
+
uv = bpy_extras.object_utils.world_to_camera_view(scene, cam_ob, p)
|
| 93 |
+
print(f"Ball f0: blender uv=({uv.x:.3f},{uv.y:.3f}) depth={uv.z:.2f}")
|
| 94 |
+
p30 = Vector(ball[30].mean(0))
|
| 95 |
+
uv = bpy_extras.object_utils.world_to_camera_view(scene, cam_ob, p30)
|
| 96 |
+
print(f"Ball f30: blender uv=({uv.x:.3f},{uv.y:.3f}) depth={uv.z:.2f}")
|
| 97 |
+
|
| 98 |
+
scene.render.engine = "BLENDER_WORKBENCH"
|
| 99 |
+
scene.display.render_aa = "5"
|
| 100 |
+
scene.render.filepath = str(out / "dbg_f1.png")
|
| 101 |
+
scene.frame_set(1)
|
| 102 |
+
bpy.ops.render.render(write_still=True)
|
| 103 |
+
print("wrote", out / "dbg_f1.png")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
if __name__ == "__main__":
|
| 107 |
+
main()
|
4dcodebench/resim/fit_params_neuido.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Fit cloth parameter card (density, bending, air_damp) to ground-truth cloth
|
| 3 |
+
trajectories, NeuIDO-style: differentiable-proxy fitting loop that re-simulates
|
| 4 |
+
in Blender with candidate parameters and minimizes trajectory distance.
|
| 5 |
+
|
| 6 |
+
This is the "with NeuIDO method" arm of the ablation. The "without" arm just
|
| 7 |
+
uses fixed default parameters (no fitting).
|
| 8 |
+
|
| 9 |
+
Method (mirror of NeuIDO's few-shot adaptation, Eq. 8, but with a classical
|
| 10 |
+
optimizer instead of a learned latent):
|
| 11 |
+
z_hat = argmin_z L_sim(R(z), u)
|
| 12 |
+
where R(z) = Blender cloth rollout under parameter card z, and L measures
|
| 13 |
+
per-frame vertex-cloud distance (chamfer) + bbox/COM matching vs the observed
|
| 14 |
+
cloth positions u = dyn/Cloth.npz.
|
| 15 |
+
|
| 16 |
+
Coordinate notes:
|
| 17 |
+
* dyn/Cloth.npz pos is in world coordinates already (verified vs bbox of
|
| 18 |
+
static table mesh), same as Blender world space after to_mesh().
|
| 19 |
+
* The truth cloth starts exactly at frame-0 pose in every rollout, so the
|
| 20 |
+
fit identifies the card (density/bending/air) from the drop dynamics.
|
| 21 |
+
|
| 22 |
+
Usage (H100, after unpack_world.py):
|
| 23 |
+
python fit_params_neuido.py --world work/B_07/world --out work/B_07/fit \
|
| 24 |
+
--trials 24 --parallel 3
|
| 25 |
+
Output: <out>/best_card.json, <out>/trials.csv, <out>/fit_log.txt
|
| 26 |
+
"""
|
| 27 |
+
import argparse
|
| 28 |
+
import csv
|
| 29 |
+
import itertools
|
| 30 |
+
import json
|
| 31 |
+
import os
|
| 32 |
+
import subprocess
|
| 33 |
+
import sys
|
| 34 |
+
import tempfile
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
|
| 37 |
+
import numpy as np
|
| 38 |
+
|
| 39 |
+
BLENDER = os.path.expanduser("~/jiayin/blender/blender")
|
| 40 |
+
SCRIPT = os.path.expanduser("~/jiayin/4dcodebench/resim/resim_cloth_blender.py")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def chamfer(a, b, n=2000, seed=0):
|
| 44 |
+
rng = np.random.default_rng(seed)
|
| 45 |
+
ai = rng.choice(len(a), min(n, len(a)), replace=False)
|
| 46 |
+
bi = rng.choice(len(b), min(n, len(b)), replace=False)
|
| 47 |
+
A, B = a[ai].astype(np.float64), b[bi].astype(np.float64)
|
| 48 |
+
d = ((A[:, None, :] - B[None, :, :]) ** 2).sum(-1)
|
| 49 |
+
d1 = np.sqrt(d.min(1))
|
| 50 |
+
d2 = np.sqrt(((B[:, None, :] - A[None, :, :]) ** 2).sum(-1)).min(1)
|
| 51 |
+
return 0.5 * (d1.mean() + d2.mean())
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def rollout_loss(world_dir, traj_dir, gt, frame_stride=3, n_samples=1500):
|
| 55 |
+
"""Loss between a rollout's clothtraj.npz and gt (F,N,3)."""
|
| 56 |
+
f = Path(traj_dir) / "clothtraj.npz"
|
| 57 |
+
if not f.exists():
|
| 58 |
+
return None
|
| 59 |
+
try:
|
| 60 |
+
sim = np.load(f)["pos"].astype(np.float32)
|
| 61 |
+
except Exception:
|
| 62 |
+
return None
|
| 63 |
+
if not np.isfinite(sim).all() or sim.shape != gt.shape:
|
| 64 |
+
return None
|
| 65 |
+
# NaN/instability guard: cloth flew away
|
| 66 |
+
if np.abs(sim).max() > 50:
|
| 67 |
+
return 10.0
|
| 68 |
+
frames = list(range(0, gt.shape[0], frame_stride))
|
| 69 |
+
if frames[-1] != gt.shape[0] - 1:
|
| 70 |
+
frames.append(gt.shape[0] - 1)
|
| 71 |
+
losses = [chamfer(sim[i], gt[i], n=n_samples, seed=i) for i in frames]
|
| 72 |
+
return float(np.mean(losses))
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def run_rollout(world_dir, out_dir, card, gpu, timeout=600):
|
| 76 |
+
"""Run one Blender cloth rollout with a parameter card. Returns bool.
|
| 77 |
+
|
| 78 |
+
Fitting rollouts use --no_render: sim + trajectory export take ~4 min,
|
| 79 |
+
rendering would add ~12 min for pixels we never look at during fitting.
|
| 80 |
+
"""
|
| 81 |
+
cmd = [
|
| 82 |
+
BLENDER, "--background", "--python", SCRIPT, "--",
|
| 83 |
+
"--world", str(world_dir), "--out", str(out_dir),
|
| 84 |
+
"--density", str(card["density"]),
|
| 85 |
+
"--bending", str(card["bending"]),
|
| 86 |
+
"--air_damp", str(card["air_damp"]),
|
| 87 |
+
"--no_render",
|
| 88 |
+
"--quality", "8", # faster solver for fitting
|
| 89 |
+
]
|
| 90 |
+
logf = open(Path(out_dir) / "blender.log", "w")
|
| 91 |
+
env = dict(os.environ, CUDA_VISIBLE_DEVICES=str(gpu))
|
| 92 |
+
try:
|
| 93 |
+
subprocess.run(cmd, env=env, stdout=logf, stderr=subprocess.STDOUT,
|
| 94 |
+
timeout=timeout, check=False)
|
| 95 |
+
except subprocess.TimeoutExpired:
|
| 96 |
+
logf.close()
|
| 97 |
+
return False
|
| 98 |
+
logf.close()
|
| 99 |
+
return (Path(out_dir) / "clothtraj.npz").exists()
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def main():
|
| 103 |
+
ap = argparse.ArgumentParser()
|
| 104 |
+
ap.add_argument("--world", required=True)
|
| 105 |
+
ap.add_argument("--out", required=True)
|
| 106 |
+
ap.add_argument("--trials", type=int, default=24)
|
| 107 |
+
ap.add_argument("--parallel", type=int, default=3, help="concurrent rollouts")
|
| 108 |
+
ap.add_argument("--gpus", default="4,5,6", help="GPUs to rotate for rollouts")
|
| 109 |
+
ap.add_argument("--seed", type=int, default=7)
|
| 110 |
+
ap.add_argument("--center", default=None,
|
| 111 |
+
help="JSON file with a card; when given, sample locally "
|
| 112 |
+
"around it (gaussian, --sigma) instead of global uniform")
|
| 113 |
+
ap.add_argument("--sigma", default="0.15,0.4,0.3",
|
| 114 |
+
help="gaussian std for density,bending,air_damp local sampling")
|
| 115 |
+
args = ap.parse_args()
|
| 116 |
+
|
| 117 |
+
world = Path(args.world).resolve()
|
| 118 |
+
out = Path(args.out).resolve()
|
| 119 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 120 |
+
gpus = [int(g) for g in args.gpus.split(",")]
|
| 121 |
+
|
| 122 |
+
gt = np.load(world / "dyn" / "Cloth.npz")["pos"].astype(np.float32)
|
| 123 |
+
F = gt.shape[0]
|
| 124 |
+
|
| 125 |
+
rng = np.random.default_rng(args.seed)
|
| 126 |
+
trials = []
|
| 127 |
+
if args.center:
|
| 128 |
+
# local refinement (NeuIDO few-shot adaptation analogue): start from a
|
| 129 |
+
# predicted card and explore its neighborhood
|
| 130 |
+
c = json.loads(Path(args.center).read_text())
|
| 131 |
+
s_d, s_b, s_a = (float(x) for x in args.sigma.split(","))
|
| 132 |
+
for i in range(args.trials):
|
| 133 |
+
if i == 0:
|
| 134 |
+
trials.append({"density": c["density"], "bending": c["bending"],
|
| 135 |
+
"air_damp": c["air_damp"], "tag": "center"})
|
| 136 |
+
else:
|
| 137 |
+
trials.append({
|
| 138 |
+
"density": float(np.clip(rng.normal(c["density"], s_d), 0.03, 3.0)),
|
| 139 |
+
"bending": float(np.clip(rng.normal(c["bending"], s_b), 0.0, 6.0)),
|
| 140 |
+
"air_damp": float(np.clip(rng.normal(c["air_damp"], s_a), 0.1, 6.0)),
|
| 141 |
+
"tag": f"loc{i}",
|
| 142 |
+
})
|
| 143 |
+
else:
|
| 144 |
+
# global search: first point = default card, rest uniform in the box
|
| 145 |
+
dens_lo, dens_hi = 0.08, 1.6
|
| 146 |
+
bend_lo, bend_hi = 0.0, 4.0
|
| 147 |
+
air_lo, air_hi = 0.3, 4.0
|
| 148 |
+
trials.append({
|
| 149 |
+
"density": 0.35, "bending": 0.02, "air_damp": 1.0, "tag": "default"
|
| 150 |
+
})
|
| 151 |
+
while len(trials) < args.trials:
|
| 152 |
+
trials.append({
|
| 153 |
+
"density": float(rng.uniform(dens_lo, dens_hi)),
|
| 154 |
+
"bending": float(rng.uniform(bend_lo, bend_hi)),
|
| 155 |
+
"air_damp": float(rng.uniform(air_lo, air_hi)),
|
| 156 |
+
"tag": f"rand{len(trials)}",
|
| 157 |
+
})
|
| 158 |
+
|
| 159 |
+
log = open(out / "fit_log.txt", "a")
|
| 160 |
+
rows = []
|
| 161 |
+
|
| 162 |
+
def work(item, gpu):
|
| 163 |
+
tag = item["tag"]
|
| 164 |
+
tdir = out / f"trial_{tag}"
|
| 165 |
+
tdir.mkdir(exist_ok=True)
|
| 166 |
+
ok = run_rollout(world, tdir, item, gpu)
|
| 167 |
+
loss = None
|
| 168 |
+
if ok:
|
| 169 |
+
try:
|
| 170 |
+
loss = rollout_loss(world, tdir, gt)
|
| 171 |
+
except Exception as e:
|
| 172 |
+
print(f"[fit] {tag} loss error: {e}", flush=True)
|
| 173 |
+
loss = None
|
| 174 |
+
row = dict(item, loss=loss)
|
| 175 |
+
print(f"[fit] {tag} card={item} loss={loss}", flush=True)
|
| 176 |
+
print(f"[fit] {tag} card={item} loss={loss}", file=log, flush=True)
|
| 177 |
+
return row
|
| 178 |
+
|
| 179 |
+
results = []
|
| 180 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 181 |
+
gpu_cycle = itertools.cycle(gpus)
|
| 182 |
+
queue = list(trials)
|
| 183 |
+
with ThreadPoolExecutor(max_workers=args.parallel) as ex:
|
| 184 |
+
futs = []
|
| 185 |
+
for item in queue:
|
| 186 |
+
gpu = next(gpu_cycle)
|
| 187 |
+
futs.append(ex.submit(work, item, gpu))
|
| 188 |
+
for f in futs:
|
| 189 |
+
results.append(f.result())
|
| 190 |
+
|
| 191 |
+
ok = [r for r in results if r["loss"] is not None]
|
| 192 |
+
ok.sort(key=lambda r: r["loss"])
|
| 193 |
+
best = ok[0]
|
| 194 |
+
print(f"[fit] BEST: {best}", flush=True)
|
| 195 |
+
print(f"[fit] BEST: {best}", file=log, flush=True)
|
| 196 |
+
|
| 197 |
+
with open(out / "trials.csv", "w", newline="") as f:
|
| 198 |
+
w = csv.DictWriter(f, fieldnames=["tag", "density", "bending", "air_damp", "loss"])
|
| 199 |
+
w.writeheader()
|
| 200 |
+
for r in sorted(results, key=lambda r: (r["loss"] is None, r["loss"] or 9e9)):
|
| 201 |
+
w.writerow(r)
|
| 202 |
+
|
| 203 |
+
best_card = {
|
| 204 |
+
"density": best["density"],
|
| 205 |
+
"bending": best["bending"],
|
| 206 |
+
"air_damp": best["air_damp"],
|
| 207 |
+
"tensile": 15.0,
|
| 208 |
+
"compress": 15.0,
|
| 209 |
+
"shear": 8.0,
|
| 210 |
+
"method": "neuido_style_fit",
|
| 211 |
+
"loss": best["loss"],
|
| 212 |
+
}
|
| 213 |
+
(out / "best_card.json").write_text(json.dumps(best_card, indent=1))
|
| 214 |
+
print(f"[fit] wrote {out/'best_card.json'}")
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__":
|
| 218 |
+
main()
|
4dcodebench/resim/resim_blender.py
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Re-simulate a 4DCodeBench rigid-body world in Blender with a chosen parameter card.
|
| 3 |
+
|
| 4 |
+
Run inside Blender (background):
|
| 5 |
+
blender --background --python resim_blender.py -- \
|
| 6 |
+
--world work/B_03/world --out work/B_03/out_p1 --kinematic Ball \
|
| 7 |
+
--friction 0.5 --restitution 0.05 --mass 1.5 --samples 32
|
| 8 |
+
|
| 9 |
+
Split (verified on B_03):
|
| 10 |
+
* static meshes -> passive rigid bodies, exact geometry, collision as-is
|
| 11 |
+
* the --kinematic group -> passive+kinematic body replaying the baked trajectory
|
| 12 |
+
(the driver; identical impact conditions in every preset)
|
| 13 |
+
* every other dynamics group -> active rigid body spawned at its frame-0 pose with
|
| 14 |
+
the parameter card (this is what we sweep)
|
| 15 |
+
|
| 16 |
+
Output: <out>/sim.mp4, <out>/simtraj.npz (per-object mean-vertex positions, (F,3))
|
| 17 |
+
"""
|
| 18 |
+
import argparse
|
| 19 |
+
import json
|
| 20 |
+
import sys
|
| 21 |
+
from math import radians
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
|
| 24 |
+
import bpy
|
| 25 |
+
import numpy as np
|
| 26 |
+
from mathutils import Matrix, Vector
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def parse_args():
|
| 30 |
+
ap = argparse.ArgumentParser()
|
| 31 |
+
ap.add_argument("--world", required=True)
|
| 32 |
+
ap.add_argument("--out", required=True)
|
| 33 |
+
ap.add_argument("--preset", default="p")
|
| 34 |
+
ap.add_argument("--kinematic", default=None, help="dynamics group name to replay as driver")
|
| 35 |
+
ap.add_argument("--friction", type=float, default=0.5)
|
| 36 |
+
ap.add_argument("--restitution", type=float, default=0.05)
|
| 37 |
+
ap.add_argument("--mass", type=float, default=1.5)
|
| 38 |
+
ap.add_argument("--lin_damp", type=float, default=0.04)
|
| 39 |
+
ap.add_argument("--ang_damp", type=float, default=0.04)
|
| 40 |
+
ap.add_argument("--samples", type=int, default=32)
|
| 41 |
+
ap.add_argument("--substeps", type=int, default=20)
|
| 42 |
+
ap.add_argument("--iters", type=int, default=20)
|
| 43 |
+
ap.add_argument("--device", default="gpu", choices=["gpu", "cpu"])
|
| 44 |
+
return ap.parse_args(sys.argv[sys.argv.index("--") + 1:])
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def rigid_tf(A, B):
|
| 48 |
+
"""Least-squares rigid transform mapping A -> B (both (N,3))."""
|
| 49 |
+
ca, cb = A.mean(0), B.mean(0)
|
| 50 |
+
H = (A - ca).T @ (B - cb)
|
| 51 |
+
U, _, Vt = np.linalg.svd(H)
|
| 52 |
+
D = np.diag([1.0, 1.0, float(np.sign(np.linalg.det(Vt.T @ U.T)))])
|
| 53 |
+
R = Vt.T @ D @ U.T
|
| 54 |
+
return R, cb - R @ ca
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def add_mesh(name, verts, faces, mat=None):
|
| 58 |
+
me = bpy.data.meshes.new(name)
|
| 59 |
+
me.from_pydata([tuple(float(x) for x in v) for v in verts], [],
|
| 60 |
+
[tuple(int(x) for x in f) for f in faces])
|
| 61 |
+
me.update()
|
| 62 |
+
ob = bpy.data.objects.new(name, me)
|
| 63 |
+
bpy.context.scene.collection.objects.link(ob)
|
| 64 |
+
if mat is not None:
|
| 65 |
+
ob.data.materials.append(mat)
|
| 66 |
+
return ob
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def add_rb(ob, rbtype, shape, mass=1.0, friction=0.5, restitution=0.5,
|
| 70 |
+
lin_damp=0.04, ang_damp=0.04, kinematic=False, margin=0.001):
|
| 71 |
+
# deselect everything first: the operator acts on ALL selected objects
|
| 72 |
+
for other in bpy.context.selected_objects:
|
| 73 |
+
other.select_set(False)
|
| 74 |
+
bpy.context.view_layer.objects.active = ob
|
| 75 |
+
ob.select_set(True)
|
| 76 |
+
try:
|
| 77 |
+
bpy.ops.rigidbody.objects_add(type=rbtype)
|
| 78 |
+
except RuntimeError:
|
| 79 |
+
with bpy.context.temp_override(active_object=ob, object=ob,
|
| 80 |
+
selected_objects=[ob],
|
| 81 |
+
selected_editable_objects=[ob]):
|
| 82 |
+
bpy.ops.rigidbody.objects_add(type=rbtype)
|
| 83 |
+
rb = ob.rigid_body
|
| 84 |
+
rb.collision_shape = shape
|
| 85 |
+
rb.mass = mass
|
| 86 |
+
rb.friction = friction
|
| 87 |
+
rb.restitution = restitution
|
| 88 |
+
rb.linear_damping = lin_damp
|
| 89 |
+
rb.angular_damping = ang_damp
|
| 90 |
+
rb.use_margin = True
|
| 91 |
+
rb.collision_margin = margin
|
| 92 |
+
rb.kinematic = kinematic
|
| 93 |
+
return rb
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def mat_simple(name, rgb):
|
| 97 |
+
m = bpy.data.materials.new(name)
|
| 98 |
+
m.use_nodes = True
|
| 99 |
+
bsdf = m.node_tree.nodes["Principled BSDF"]
|
| 100 |
+
bsdf.inputs["Base Color"].default_value = (*rgb, 1.0)
|
| 101 |
+
bsdf.inputs["Roughness"].default_value = 0.6
|
| 102 |
+
return m
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def setup_cycles(scene, samples, use_gpu):
|
| 106 |
+
scene.render.engine = "CYCLES"
|
| 107 |
+
if use_gpu:
|
| 108 |
+
prefs = bpy.context.preferences.addons["cycles"].preferences
|
| 109 |
+
for ctype in ("OPTIX", "CUDA"):
|
| 110 |
+
try:
|
| 111 |
+
prefs.compute_device_type = ctype
|
| 112 |
+
prefs.get_devices()
|
| 113 |
+
devs = [d for d in prefs.devices if d.type == ctype]
|
| 114 |
+
if devs:
|
| 115 |
+
for d in prefs.devices:
|
| 116 |
+
d.use = d.type == ctype
|
| 117 |
+
scene.cycles.device = "GPU"
|
| 118 |
+
print(f"[cycles] using {ctype}: {[d.name for d in devs]}")
|
| 119 |
+
return
|
| 120 |
+
except Exception as e:
|
| 121 |
+
print(f"[cycles] {ctype} failed: {e}")
|
| 122 |
+
print("[cycles] no GPU backend, falling back to CPU")
|
| 123 |
+
scene.cycles.device = "CPU"
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def main():
|
| 127 |
+
args = parse_args()
|
| 128 |
+
world = Path(args.world)
|
| 129 |
+
out = Path(args.out)
|
| 130 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 131 |
+
|
| 132 |
+
spec = json.loads((world / "spec.json").read_text())
|
| 133 |
+
cam = json.loads((world / "camera.json").read_text())
|
| 134 |
+
K = np.array(cam["intrinsics"], float)
|
| 135 |
+
E = np.array(cam["extrinsic"], float)
|
| 136 |
+
F = int(spec["F"])
|
| 137 |
+
W, H = spec["video"]["width"], spec["video"]["height"]
|
| 138 |
+
fps = float(spec["video"]["fps"])
|
| 139 |
+
|
| 140 |
+
# ---------- clean scene ----------
|
| 141 |
+
scene = bpy.context.scene
|
| 142 |
+
for ob in list(bpy.data.objects):
|
| 143 |
+
bpy.data.objects.remove(ob, do_unlink=True)
|
| 144 |
+
|
| 145 |
+
mats = {"ball": mat_simple("m_ball", (0.10, 0.25, 0.75)),
|
| 146 |
+
"pin": mat_simple("m_pin", (0.92, 0.92, 0.90)),
|
| 147 |
+
"deck": mat_simple("m_deck", (0.25, 0.15, 0.10)),
|
| 148 |
+
"static": mat_simple("m_static", (0.55, 0.55, 0.58))}
|
| 149 |
+
|
| 150 |
+
# ---------- rigid body world ----------
|
| 151 |
+
if scene.rigidbody_world is None:
|
| 152 |
+
bpy.ops.rigidbody.world_add()
|
| 153 |
+
rbw = scene.rigidbody_world
|
| 154 |
+
rbw.substeps_per_frame = args.substeps
|
| 155 |
+
rbw.solver_iterations = args.iters
|
| 156 |
+
rbw.point_cache.frame_start = 1
|
| 157 |
+
rbw.point_cache.frame_end = F
|
| 158 |
+
scene.gravity = (0.0, 0.0, -9.81)
|
| 159 |
+
|
| 160 |
+
dyn = {}
|
| 161 |
+
for name in spec["dynamics"]:
|
| 162 |
+
z = np.load(world / "dyn" / f"{name}.npz")
|
| 163 |
+
dyn[name] = {"pos": z["pos"], "ids": z["ids"].tolist()}
|
| 164 |
+
|
| 165 |
+
kin_name = args.kinematic or next(iter(dyn))
|
| 166 |
+
active_names = [n for n in dyn if n != kin_name]
|
| 167 |
+
static_ids = [int(m) for m, v in spec["meshes"].items() if v["static"]]
|
| 168 |
+
|
| 169 |
+
# ---------- static geometry ----------
|
| 170 |
+
for mid in static_ids:
|
| 171 |
+
z = np.load(world / "mesh" / f"{mid}.npz")
|
| 172 |
+
mat = mats["deck"] if z["vertices"].shape[1] <= 4 else mats["static"]
|
| 173 |
+
ob = add_mesh(f"static_{mid}", z["vertices"][0], z["faces"][0], mat)
|
| 174 |
+
add_rb(ob, "PASSIVE", "MESH", margin=0.001)
|
| 175 |
+
|
| 176 |
+
# ---------- kinematic driver (replay baked trajectory) ----------
|
| 177 |
+
driver_pos = dyn[kin_name]["pos"] # (F,N,3)
|
| 178 |
+
drv_ids = dyn[kin_name]["ids"]
|
| 179 |
+
z = np.load(world / "mesh" / f"{drv_ids[0]}.npz")
|
| 180 |
+
drv_ob = add_mesh(kin_name, z["vertices"][0], z["faces"][0], mats["ball"])
|
| 181 |
+
drv_verts0 = z["vertices"][0].astype(np.float64)
|
| 182 |
+
for t in range(F):
|
| 183 |
+
R, tt = rigid_tf(driver_pos[0].astype(np.float64), driver_pos[t].astype(np.float64))
|
| 184 |
+
drv_ob.location = Vector(tt)
|
| 185 |
+
drv_ob.rotation_euler = Matrix(R).to_euler()
|
| 186 |
+
drv_ob.keyframe_insert("location", frame=t + 1)
|
| 187 |
+
drv_ob.keyframe_insert("rotation_euler", frame=t + 1)
|
| 188 |
+
for fc in drv_ob.animation_data.action.fcurves:
|
| 189 |
+
for kp in fc.keyframe_points:
|
| 190 |
+
kp.interpolation = "LINEAR"
|
| 191 |
+
add_rb(drv_ob, "PASSIVE", "CONVEX_HULL", kinematic=True, margin=0.002)
|
| 192 |
+
|
| 193 |
+
# ---------- active bodies (parameter card) ----------
|
| 194 |
+
actives = {}
|
| 195 |
+
for name in active_names:
|
| 196 |
+
ids = dyn[name]["ids"]
|
| 197 |
+
z = np.load(world / "mesh" / f"{ids[0]}.npz")
|
| 198 |
+
ob = add_mesh(name, z["vertices"][0], z["faces"][0], mats["pin"])
|
| 199 |
+
add_rb(ob, "ACTIVE", "CONVEX_HULL", mass=args.mass, friction=args.friction,
|
| 200 |
+
restitution=args.restitution, lin_damp=args.lin_damp,
|
| 201 |
+
ang_damp=args.ang_damp, margin=0.001)
|
| 202 |
+
actives[name] = (ob, z["vertices"][0].astype(np.float64))
|
| 203 |
+
|
| 204 |
+
# ---------- camera ----------
|
| 205 |
+
print("[rb-check] " + ", ".join(
|
| 206 |
+
f"{o.name}:{o.rigid_body.type}{'/K' if o.rigid_body.kinematic else ''}"
|
| 207 |
+
for o in bpy.data.objects if o.rigid_body))
|
| 208 |
+
cam_data = bpy.data.cameras.new("cam")
|
| 209 |
+
cam_data.sensor_fit = "HORIZONTAL"
|
| 210 |
+
cam_data.sensor_width = 36.0
|
| 211 |
+
cam_data.lens = float(K[0, 0]) * 36.0 / W
|
| 212 |
+
cam_ob = bpy.data.objects.new("cam", cam_data)
|
| 213 |
+
bpy.context.scene.collection.objects.link(cam_ob)
|
| 214 |
+
D = Matrix.Diagonal((1.0, -1.0, -1.0, 1.0)) # cam axes (x right, y down, z fwd) -> Blender (-Z fwd)
|
| 215 |
+
cam_ob.matrix_world = Matrix(E) @ D
|
| 216 |
+
scene.camera = cam_ob
|
| 217 |
+
|
| 218 |
+
# camera sanity: project driver COM at frame 0 both ways
|
| 219 |
+
p0 = Vector(driver_pos[0].mean(0))
|
| 220 |
+
import bpy_extras
|
| 221 |
+
uv = bpy_extras.object_utils.world_to_camera_view(scene, cam_ob, p0)
|
| 222 |
+
pc = E[:3, :3].T @ (np.asarray(p0) - E[:3, 3])
|
| 223 |
+
proj = K @ pc
|
| 224 |
+
u_px, v_px = float(proj[0]) / float(pc[2]), float(proj[1]) / float(pc[2])
|
| 225 |
+
print(f"[cam-check] blender uv=({uv.x:.3f},{uv.y:.3f}) numpy px=({u_px:.1f},{v_px:.1f})/"
|
| 226 |
+
f"({W},{H}) expect uv≈({u_px/W:.3f},{1-v_px/H:.3f})")
|
| 227 |
+
|
| 228 |
+
# ---------- lights ----------
|
| 229 |
+
world = bpy.data.worlds.new("w")
|
| 230 |
+
world.use_nodes = True
|
| 231 |
+
world.node_tree.nodes["Background"].inputs["Color"].default_value = (0.85, 0.85, 0.85, 1)
|
| 232 |
+
world.node_tree.nodes["Background"].inputs["Strength"].default_value = 1.1
|
| 233 |
+
scene.world = world
|
| 234 |
+
sun = bpy.data.lights.new("sun", type="SUN")
|
| 235 |
+
sun.energy = 3.0
|
| 236 |
+
sun_ob = bpy.data.objects.new("sun", sun)
|
| 237 |
+
bpy.context.scene.collection.objects.link(sun_ob)
|
| 238 |
+
sun_ob.rotation_euler = (radians(50), 0, radians(30))
|
| 239 |
+
|
| 240 |
+
# ---------- bake ----------
|
| 241 |
+
scene.frame_start = 1
|
| 242 |
+
scene.frame_end = F
|
| 243 |
+
scene.frame_set(1)
|
| 244 |
+
bpy.ops.ptcache.free_bake_all()
|
| 245 |
+
bpy.ops.ptcache.bake_all(bake=True)
|
| 246 |
+
print("[bake] done")
|
| 247 |
+
|
| 248 |
+
# ---------- record trajectories ----------
|
| 249 |
+
traj = {kin_name: np.zeros((F, 3), np.float32)}
|
| 250 |
+
for name, (ob, v0) in actives.items():
|
| 251 |
+
traj[name] = np.zeros((F, 3), np.float32)
|
| 252 |
+
for t in range(1, F + 1):
|
| 253 |
+
scene.frame_set(t)
|
| 254 |
+
bpy.context.view_layer.update()
|
| 255 |
+
M = np.array(drv_ob.matrix_world)
|
| 256 |
+
traj[kin_name][t - 1] = (M[:3, :3] @ drv_verts0.T).T.mean(0)
|
| 257 |
+
for name, (ob, v0) in actives.items():
|
| 258 |
+
M = np.array(ob.matrix_world)
|
| 259 |
+
traj[name][t - 1] = (M[:3, :3] @ v0.T).T.mean(0)
|
| 260 |
+
np.savez_compressed(out / "simtraj.npz", **traj)
|
| 261 |
+
print(f"[traj] saved {list(traj)}")
|
| 262 |
+
|
| 263 |
+
# ---------- render ----------
|
| 264 |
+
scene.render.resolution_x = W
|
| 265 |
+
scene.render.resolution_y = H
|
| 266 |
+
scene.render.fps = int(round(fps))
|
| 267 |
+
scene.render.fps_base = 1.0
|
| 268 |
+
scene.cycles.samples = args.samples
|
| 269 |
+
scene.cycles.use_denoising = True
|
| 270 |
+
scene.cycles.max_bounces = 4
|
| 271 |
+
setup_cycles(scene, args.samples, args.device == "gpu")
|
| 272 |
+
scene.render.image_settings.file_format = "FFMPEG"
|
| 273 |
+
scene.render.ffmpeg.format = "MPEG4"
|
| 274 |
+
scene.render.ffmpeg.codec = "H264"
|
| 275 |
+
scene.render.ffmpeg.constant_rate_factor = "HIGH"
|
| 276 |
+
scene.render.ffmpeg.audio_codec = "NONE"
|
| 277 |
+
scene.render.filepath = str(out / "sim.mp4")
|
| 278 |
+
bpy.ops.render.render(animation=True)
|
| 279 |
+
print(f"[render] wrote {out/'sim.mp4'}")
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
if __name__ == "__main__":
|
| 283 |
+
main()
|
4dcodebench/resim/resim_cloth_blender.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Cloth re-simulation of a 4DCodeBench world (B_07: cloth drop over table+props)
|
| 3 |
+
with a parameter card, inside Blender (background).
|
| 4 |
+
|
| 5 |
+
Run:
|
| 6 |
+
blender --background --python resim_cloth_blender.py -- \
|
| 7 |
+
--world work/B_07/world --out work/B_07/out_a0b0 \
|
| 8 |
+
--density 0.35 --tensile 15 --bending 0.02 --air_damp 1.0 --samples 32
|
| 9 |
+
|
| 10 |
+
World layout (from unpack_world.py):
|
| 11 |
+
world/spec.json F, video specs, dynamics/meshes split
|
| 12 |
+
world/camera.json K (3x3 intrinsics px), E (4x4 cam-to-world)
|
| 13 |
+
world/render.mp4 reference render (ground truth video)
|
| 14 |
+
world/mesh/<id>.npz vertices (F,V,3) f32, faces (F,T,3) i32
|
| 15 |
+
world/dyn/<name>.npz pos (F,N,3) f32, ids (M,) u16, faces (T,3) i32
|
| 16 |
+
|
| 17 |
+
Split:
|
| 18 |
+
* every dynamics group -> active CLOTH body spawned at its frame-0 pose with
|
| 19 |
+
the parameter card (this is what we sweep)
|
| 20 |
+
* static meshes -> passive collision bodies (exact geometry)
|
| 21 |
+
|
| 22 |
+
Parameter card (what the ablation sweeps):
|
| 23 |
+
--density cloth areal density (kg/m^2). Real cloth ~0.15-0.5.
|
| 24 |
+
--tensile tensile stiffness (structural springs, Blender scale).
|
| 25 |
+
--bending bending stiffness (0 = flimsy rag, high = paper-stiff folds).
|
| 26 |
+
--air_damp air drag multiplier (higher = falls/slide slower, heavier look).
|
| 27 |
+
--mass override total mass (kg); else per-vertex mass from density.
|
| 28 |
+
|
| 29 |
+
Output: <out>/sim.mp4, <out>/clothtraj.npz (cloth vertex positions (F,N,3) f16),
|
| 30 |
+
<out>/params.json (the card actually used)
|
| 31 |
+
"""
|
| 32 |
+
import argparse
|
| 33 |
+
import json
|
| 34 |
+
import sys
|
| 35 |
+
from math import radians
|
| 36 |
+
from pathlib import Path
|
| 37 |
+
|
| 38 |
+
import bpy
|
| 39 |
+
import numpy as np
|
| 40 |
+
from mathutils import Matrix, Vector
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def parse_args():
|
| 44 |
+
ap = argparse.ArgumentParser()
|
| 45 |
+
ap.add_argument("--world", required=True)
|
| 46 |
+
ap.add_argument("--out", required=True)
|
| 47 |
+
ap.add_argument("--density", type=float, default=0.35, help="kg/m^2")
|
| 48 |
+
ap.add_argument("--tensile", type=float, default=15.0)
|
| 49 |
+
ap.add_argument("--compress", type=float, default=15.0)
|
| 50 |
+
ap.add_argument("--shear", type=float, default=8.0)
|
| 51 |
+
ap.add_argument("--bending", type=float, default=0.02)
|
| 52 |
+
ap.add_argument("--air_damp", type=float, default=1.0)
|
| 53 |
+
ap.add_argument("--mass", type=float, default=None, help="total mass override (kg)")
|
| 54 |
+
ap.add_argument("--quality", type=int, default=10)
|
| 55 |
+
ap.add_argument("--coll_quality", type=int, default=4)
|
| 56 |
+
ap.add_argument("--samples", type=int, default=32)
|
| 57 |
+
ap.add_argument("--no_render", action="store_true", help="skip render (fitting)")
|
| 58 |
+
ap.add_argument("--device", default="gpu", choices=["gpu", "cpu"])
|
| 59 |
+
return ap.parse_args(sys.argv[sys.argv.index("--") + 1:])
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def add_mesh(name, verts, faces, mat=None):
|
| 63 |
+
me = bpy.data.meshes.new(name)
|
| 64 |
+
me.from_pydata([tuple(float(x) for x in v) for v in verts], [],
|
| 65 |
+
[tuple(int(x) for x in f) for f in faces])
|
| 66 |
+
me.update()
|
| 67 |
+
ob = bpy.data.objects.new(name, me)
|
| 68 |
+
bpy.context.scene.collection.objects.link(ob)
|
| 69 |
+
if mat is not None:
|
| 70 |
+
ob.data.materials.append(mat)
|
| 71 |
+
return ob
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def add_collision(ob, friction=0.5, damping=0.05, thickness=0.004):
|
| 75 |
+
mod = ob.modifiers.new("Coll", "COLLISION")
|
| 76 |
+
c = mod.settings
|
| 77 |
+
c.absorption = 0
|
| 78 |
+
c.cloth_friction = friction # friction as seen by cloth sim
|
| 79 |
+
c.damping = damping # velocity damping factor
|
| 80 |
+
c.thickness_outer = thickness
|
| 81 |
+
c.thickness_inner = thickness
|
| 82 |
+
return mod
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def mat_simple(name, rgb, rough=0.6):
|
| 86 |
+
m = bpy.data.materials.new(name)
|
| 87 |
+
m.use_nodes = True
|
| 88 |
+
bsdf = m.node_tree.nodes["Principled BSDF"]
|
| 89 |
+
bsdf.inputs["Base Color"].default_value = (*rgb, 1.0)
|
| 90 |
+
bsdf.inputs["Roughness"].default_value = rough
|
| 91 |
+
return m
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def setup_cycles(scene, samples, use_gpu):
|
| 95 |
+
scene.render.engine = "CYCLES"
|
| 96 |
+
if use_gpu:
|
| 97 |
+
prefs = bpy.context.preferences.addons["cycles"].preferences
|
| 98 |
+
for ctype in ("OPTIX", "CUDA"):
|
| 99 |
+
try:
|
| 100 |
+
prefs.compute_device_type = ctype
|
| 101 |
+
prefs.get_devices()
|
| 102 |
+
devs = [d for d in prefs.devices if d.type == ctype]
|
| 103 |
+
if devs:
|
| 104 |
+
for d in prefs.devices:
|
| 105 |
+
d.use = d.type == ctype
|
| 106 |
+
scene.cycles.device = "GPU"
|
| 107 |
+
print(f"[cycles] using {ctype}: {[d.name for d in devs]}")
|
| 108 |
+
return
|
| 109 |
+
except Exception as e:
|
| 110 |
+
print(f"[cycles] {ctype} failed: {e}")
|
| 111 |
+
print("[cycles] no GPU backend, falling back to CPU")
|
| 112 |
+
scene.cycles.device = "CPU"
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def build_cloth(mod, args, F, area_m2, verts_n):
|
| 116 |
+
"""Configure cloth physics on an already-created CLOTH modifier.
|
| 117 |
+
|
| 118 |
+
Mass working point: Blender's cloth solver expects per-vertex mass in the
|
| 119 |
+
~0.05-0.5 kg range (default 0.15). Real cloth areal density (0.1-1.2
|
| 120 |
+
kg/m^2) maps to tiny per-vertex masses that make gravity negligible vs
|
| 121 |
+
spring/air forces -> the cloth floats. So we anchor density=0.35 kg/m^2 at
|
| 122 |
+
the default 0.15 kg/vertex working point and scale linearly: the ablation
|
| 123 |
+
still sweeps real relative density (inertia vs drag/collision), while the
|
| 124 |
+
solver stays in its valid regime.
|
| 125 |
+
"""
|
| 126 |
+
s = mod.settings
|
| 127 |
+
total_mass = args.mass if args.mass is not None else 0.15 * verts_n * (args.density / 0.35)
|
| 128 |
+
s.mass = total_mass / verts_n # per-vertex mass
|
| 129 |
+
# structural springs
|
| 130 |
+
s.tension_stiffness = max(1.0, args.tensile)
|
| 131 |
+
s.compression_stiffness = max(1.0, args.compress)
|
| 132 |
+
s.shear_stiffness = max(1.0, args.shear)
|
| 133 |
+
s.tension_damping = 5.0
|
| 134 |
+
s.compression_damping = 5.0
|
| 135 |
+
s.shear_damping = 5.0
|
| 136 |
+
# bending (the flexibility knob)
|
| 137 |
+
s.bending_stiffness = max(0.0, args.bending)
|
| 138 |
+
s.bending_damping = 0.5
|
| 139 |
+
s.bending_model = 'ANGULAR'
|
| 140 |
+
# air (the density look knob: more drag = floats down slowly)
|
| 141 |
+
s.air_damping = max(0.0, args.air_damp)
|
| 142 |
+
# solver
|
| 143 |
+
s.quality = args.quality
|
| 144 |
+
s.time_scale = 1.0
|
| 145 |
+
# collisions
|
| 146 |
+
cs = mod.collision_settings
|
| 147 |
+
cs.use_collision = True
|
| 148 |
+
cs.distance_min = 0.0025
|
| 149 |
+
cs.friction = 0.5
|
| 150 |
+
cs.damping = 0.1
|
| 151 |
+
cs.collision_quality = args.coll_quality
|
| 152 |
+
cs.use_self_collision = True
|
| 153 |
+
cs.self_distance_min = 0.0025
|
| 154 |
+
cs.self_friction = 0.3
|
| 155 |
+
# cache
|
| 156 |
+
pc = mod.point_cache
|
| 157 |
+
pc.frame_start = 1
|
| 158 |
+
pc.frame_end = F
|
| 159 |
+
return mod
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def mesh_area(verts, faces):
|
| 163 |
+
"""Sum of triangle areas for (N,3) verts and (T,3) tri indices."""
|
| 164 |
+
v = verts[faces]
|
| 165 |
+
a = v[:, 1] - v[:, 0]
|
| 166 |
+
b = v[:, 2] - v[:, 0]
|
| 167 |
+
return float(0.5 * np.linalg.norm(np.cross(a, b), axis=1).sum())
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def main():
|
| 171 |
+
args = parse_args()
|
| 172 |
+
world = Path(args.world)
|
| 173 |
+
out = Path(args.out)
|
| 174 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 175 |
+
|
| 176 |
+
spec = json.loads((world / "spec.json").read_text())
|
| 177 |
+
cam = json.loads((world / "camera.json").read_text())
|
| 178 |
+
K = np.array(cam["intrinsics"], float)
|
| 179 |
+
E = np.array(cam["extrinsic"], float)
|
| 180 |
+
F = int(spec["F"])
|
| 181 |
+
W, H = spec["video"]["width"], spec["video"]["height"]
|
| 182 |
+
fps = float(spec["video"]["fps"])
|
| 183 |
+
|
| 184 |
+
scene = bpy.context.scene
|
| 185 |
+
for ob in list(bpy.data.objects):
|
| 186 |
+
bpy.data.objects.remove(ob, do_unlink=True)
|
| 187 |
+
|
| 188 |
+
mats = {"cloth": mat_simple("m_cloth", (0.78, 0.10, 0.08), rough=0.45),
|
| 189 |
+
"wood": mat_simple("m_wood", (0.35, 0.20, 0.11), rough=0.5),
|
| 190 |
+
"ball": mat_simple("m_ball", (0.90, 0.88, 0.82), rough=0.35)}
|
| 191 |
+
|
| 192 |
+
# ---------- static geometry (collision only) ----------
|
| 193 |
+
dyn_ids = set()
|
| 194 |
+
for name, v in spec["dynamics"].items():
|
| 195 |
+
dyn_ids.update(int(i) for i in v["ids"])
|
| 196 |
+
for mid, mv in spec["meshes"].items():
|
| 197 |
+
if not mv["static"]:
|
| 198 |
+
continue
|
| 199 |
+
z = np.load(world / "mesh" / f"{mid}.npz")
|
| 200 |
+
v0 = z["vertices"][0]
|
| 201 |
+
bb = v0.max(0) - v0.min(0)
|
| 202 |
+
if max(bb) < 0.3 and bb[2] > 0.03:
|
| 203 |
+
m = mats["ball"]
|
| 204 |
+
else:
|
| 205 |
+
m = mats["wood"]
|
| 206 |
+
ob = add_mesh(f"static_{mid}", v0, z["faces"][0], m)
|
| 207 |
+
add_collision(ob)
|
| 208 |
+
|
| 209 |
+
# ---------- cloth body ----------
|
| 210 |
+
card = {
|
| 211 |
+
"density_kg_m2": args.density,
|
| 212 |
+
"tensile": args.tensile,
|
| 213 |
+
"compress": args.compress,
|
| 214 |
+
"shear": args.shear,
|
| 215 |
+
"bending": args.bending,
|
| 216 |
+
"air_damp": args.air_damp,
|
| 217 |
+
"mass_total_kg": args.mass,
|
| 218 |
+
"quality": args.quality,
|
| 219 |
+
}
|
| 220 |
+
(out / "params.json").write_text(json.dumps(card, indent=1))
|
| 221 |
+
|
| 222 |
+
cloth_name = next(iter(spec["dynamics"]))
|
| 223 |
+
z = np.load(world / "dyn" / f"{cloth_name}.npz")
|
| 224 |
+
pos = z["pos"] # (F,N,3) ground truth; we spawn at frame-0 pose
|
| 225 |
+
faces = z["faces"]
|
| 226 |
+
p0 = pos[0]
|
| 227 |
+
area = mesh_area(p0.astype(np.float64), faces.astype(np.int64))
|
| 228 |
+
print(f"[cloth] V={len(p0)} T={len(faces)} area={area:.3f} m^2")
|
| 229 |
+
|
| 230 |
+
ob = add_mesh(cloth_name, p0, faces, mats["cloth"])
|
| 231 |
+
bpy.context.view_layer.objects.active = ob
|
| 232 |
+
try:
|
| 233 |
+
bpy.ops.object.shade_smooth()
|
| 234 |
+
except Exception:
|
| 235 |
+
pass
|
| 236 |
+
mod = ob.modifiers.new("Cloth", "CLOTH")
|
| 237 |
+
build_cloth(mod, args, F, area, len(p0))
|
| 238 |
+
print(f"[cloth] mass_total={args.density * area:.3f} kg (density {args.density})")
|
| 239 |
+
|
| 240 |
+
# ---------- camera ----------
|
| 241 |
+
cam_data = bpy.data.cameras.new("cam")
|
| 242 |
+
cam_data.sensor_fit = "HORIZONTAL"
|
| 243 |
+
cam_data.sensor_width = 36.0
|
| 244 |
+
cam_data.lens = float(K[0, 0]) * 36.0 / W
|
| 245 |
+
cam_ob = bpy.data.objects.new("cam", cam_data)
|
| 246 |
+
bpy.context.scene.collection.objects.link(cam_ob)
|
| 247 |
+
D = Matrix.Diagonal((1.0, -1.0, -1.0, 1.0))
|
| 248 |
+
cam_ob.matrix_world = Matrix(E) @ D
|
| 249 |
+
scene.camera = cam_ob
|
| 250 |
+
|
| 251 |
+
# ---------- lights ----------
|
| 252 |
+
w = bpy.data.worlds.new("w")
|
| 253 |
+
w.use_nodes = True
|
| 254 |
+
w.node_tree.nodes["Background"].inputs["Color"].default_value = (0.85, 0.85, 0.85, 1)
|
| 255 |
+
w.node_tree.nodes["Background"].inputs["Strength"].default_value = 1.1
|
| 256 |
+
scene.world = w
|
| 257 |
+
sun = bpy.data.lights.new("sun", type="SUN")
|
| 258 |
+
sun.energy = 3.0
|
| 259 |
+
sun_ob = bpy.data.objects.new("sun", sun)
|
| 260 |
+
bpy.context.scene.collection.objects.link(sun_ob)
|
| 261 |
+
sun_ob.rotation_euler = (radians(50), 0, radians(30))
|
| 262 |
+
area_l = bpy.data.lights.new("fill", type="AREA")
|
| 263 |
+
area_l.energy = 300.0
|
| 264 |
+
area_l.size = 2.0
|
| 265 |
+
area_ob = bpy.data.objects.new("fill", area_l)
|
| 266 |
+
bpy.context.scene.collection.objects.link(area_ob)
|
| 267 |
+
area_ob.location = (0.0, -2.0, 2.5)
|
| 268 |
+
area_ob.rotation_euler = (radians(35), 0, 0)
|
| 269 |
+
|
| 270 |
+
# ---------- bake cloth ----------
|
| 271 |
+
scene.frame_start = 1
|
| 272 |
+
scene.frame_end = F
|
| 273 |
+
scene.frame_set(1)
|
| 274 |
+
mod.point_cache.frame_start = 1
|
| 275 |
+
mod.point_cache.frame_end = F
|
| 276 |
+
bpy.ops.ptcache.free_bake_all()
|
| 277 |
+
bpy.ops.ptcache.bake_all(bake=True)
|
| 278 |
+
print("[bake] done")
|
| 279 |
+
|
| 280 |
+
# ---------- record cloth trajectories ----------
|
| 281 |
+
deps = bpy.context.evaluated_depsgraph_get()
|
| 282 |
+
traj = np.zeros((F, pos.shape[1], 3), np.float16)
|
| 283 |
+
for t in range(1, F + 1):
|
| 284 |
+
scene.frame_set(t)
|
| 285 |
+
bpy.context.view_layer.update()
|
| 286 |
+
ob_eval = ob.evaluated_get(deps)
|
| 287 |
+
me = ob_eval.to_mesh()
|
| 288 |
+
verts = np.empty(len(me.vertices) * 3, np.float32)
|
| 289 |
+
me.vertices.foreach_get("co", verts)
|
| 290 |
+
traj[t - 1] = verts.reshape(-1, 3).astype(np.float16)
|
| 291 |
+
ob_eval.to_mesh_clear()
|
| 292 |
+
np.savez_compressed(out / "clothtraj.npz", pos=traj)
|
| 293 |
+
print(f"[traj] saved clothtraj ({traj.shape})")
|
| 294 |
+
|
| 295 |
+
if args.no_render:
|
| 296 |
+
print("[render] skipped (--no_render)")
|
| 297 |
+
return
|
| 298 |
+
|
| 299 |
+
# ---------- render ----------
|
| 300 |
+
scene.render.resolution_x = W
|
| 301 |
+
scene.render.resolution_y = H
|
| 302 |
+
scene.render.fps = int(round(fps))
|
| 303 |
+
scene.render.fps_base = 1.0
|
| 304 |
+
scene.cycles.samples = args.samples
|
| 305 |
+
scene.cycles.use_denoising = True
|
| 306 |
+
scene.cycles.max_bounces = 4
|
| 307 |
+
setup_cycles(scene, args.samples, args.device == "gpu")
|
| 308 |
+
scene.render.image_settings.file_format = "FFMPEG"
|
| 309 |
+
scene.render.ffmpeg.format = "MPEG4"
|
| 310 |
+
scene.render.ffmpeg.codec = "H264"
|
| 311 |
+
scene.render.ffmpeg.constant_rate_factor = "HIGH"
|
| 312 |
+
scene.render.ffmpeg.audio_codec = "NONE"
|
| 313 |
+
scene.render.filepath = str(out / "sim.mp4")
|
| 314 |
+
bpy.ops.render.render(animation=True)
|
| 315 |
+
print(f"[render] wrote {out/'sim.mp4'}")
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
if __name__ == "__main__":
|
| 319 |
+
main()
|
4dcodebench/resim/run_ablation_b07.sh
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# 2x2 ablation on B_07 (4DCodeBench cloth case): agent prior (A) x NeuIDO fit (B)
|
| 3 |
+
# A0B0: default card (no agent reasoning, no fitting) -> baseline
|
| 4 |
+
# A1B0: agent prior card (material/fall reasoning, no fit)
|
| 5 |
+
# A0B1: NeuIDO-style closed-loop fit from neutral start (default center)
|
| 6 |
+
# A1B1: NeuIDO-style fit seeded by the agent prior card (interaction)
|
| 7 |
+
# Full render (32 samples) for every arm. GPUs 4-7 only.
|
| 8 |
+
set -e
|
| 9 |
+
export LANG=en_US.UTF-8 PYTHONUTF8=1
|
| 10 |
+
cd ~/jiayin/4dcodebench
|
| 11 |
+
PY=~/miniconda3/envs/ovow-motion/bin/python
|
| 12 |
+
BL=~/jiayin/blender/blender
|
| 13 |
+
W=work/B_07/world
|
| 14 |
+
BASE=work/B_07/ablation
|
| 15 |
+
mkdir -p $BASE
|
| 16 |
+
|
| 17 |
+
echo "=== [0/6] cards ==="
|
| 18 |
+
$PY resim/agent_card.py --world $W --out work/B_07/agent_card.json
|
| 19 |
+
test -f work/B_07/fit/best_card.json || { echo "global fit missing"; exit 1; }
|
| 20 |
+
|
| 21 |
+
render () { # render <outdir> <density> <bending> <air_damp>
|
| 22 |
+
local OUT=$1 D=$2 BE=$3 AI=$4
|
| 23 |
+
if [ -f "$OUT/sim.mp4" ] && [ $(stat -c %s "$OUT/sim.mp4") -gt 100000 ]; then
|
| 24 |
+
echo "--- $OUT already done, skip"; return 0
|
| 25 |
+
fi
|
| 26 |
+
rm -rf "$OUT"
|
| 27 |
+
mkdir -p "$OUT"
|
| 28 |
+
echo "--- rendering $OUT (d=$D b=$BE a=$AI)"
|
| 29 |
+
CUDA_VISIBLE_DEVICES=$GPU $BL --background --python resim/resim_cloth_blender.py -- \
|
| 30 |
+
--world $W --out "$OUT" --density $D --bending $BE --air_damp $AI --samples 32 \
|
| 31 |
+
> "$OUT/blender.log" 2>&1
|
| 32 |
+
test -f "$OUT/sim.mp4" && [ $(stat -c %s "$OUT/sim.mp4") -gt 100000 ]
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# ---------- A0B0: default ----------
|
| 36 |
+
GPU=4
|
| 37 |
+
echo "=== [1/6] A0B0 default ==="
|
| 38 |
+
render $BASE/a0b0 0.35 0.02 1.0
|
| 39 |
+
|
| 40 |
+
# ---------- A1B0: agent prior ----------
|
| 41 |
+
echo "=== [2/6] A1B0 agent prior ==="
|
| 42 |
+
GPU=5 render $BASE/a1b0 0.35 0.02 1.0 # same card, produced by agent reasoning
|
| 43 |
+
cp work/B_07/agent_card.json $BASE/a1b0/params_src.json || true
|
| 44 |
+
|
| 45 |
+
# ---------- A0B1: NeuIDO fit from neutral start (already fitted globally) ----------
|
| 46 |
+
echo "=== [3/6] A0B1 neuido fit (neutral) ==="
|
| 47 |
+
read D BE AI <<< $($PY -c "import json;c=json.load(open('work/B_07/fit/best_card.json'));print(c['density'],c['bending'],c['air_damp'])")
|
| 48 |
+
GPU=6 render $BASE/a0b1 $D $BE $AI
|
| 49 |
+
cp work/B_07/fit/best_card.json $BASE/a0b1/params_src.json
|
| 50 |
+
|
| 51 |
+
# ---------- A1B1: local refit seeded by agent prior ----------
|
| 52 |
+
echo "=== [4/6] A1B1 local refit around agent card ==="
|
| 53 |
+
if [ ! -f work/B_07/fit_agent/best_card.json ]; then
|
| 54 |
+
$PY resim/fit_params_neuido.py --world $W --out work/B_07/fit_agent \
|
| 55 |
+
--trials 10 --parallel 3 --gpus 4,5,6 \
|
| 56 |
+
--center work/B_07/agent_card.json --sigma 0.12,0.35,0.25 \
|
| 57 |
+
> work/B_07/fit_agent_main.log 2>&1
|
| 58 |
+
fi
|
| 59 |
+
read D BE AI <<< $($PY -c "import json;c=json.load(open('work/B_07/fit_agent/best_card.json'));print(c['density'],c['bending'],c['air_damp'])")
|
| 60 |
+
GPU=7 render $BASE/a1b1 $D $BE $AI
|
| 61 |
+
cp work/B_07/fit_agent/best_card.json $BASE/a1b1/params_src.json
|
| 62 |
+
|
| 63 |
+
echo "=== ALL ABLATION ROLLOUTS DONE ==="
|
4dcodebench/resim/run_b03.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# B_03 bowling re-simulation: two parameter presets -> DTW -> comparison video
|
| 3 |
+
set -e
|
| 4 |
+
cd ~/jiayin/4dcodebench
|
| 5 |
+
PY=~/miniconda3/envs/ovow-motion/bin/python
|
| 6 |
+
BL=~/jiayin/blender/blender
|
| 7 |
+
CASE=B_03
|
| 8 |
+
W=work/$CASE/world
|
| 9 |
+
|
| 10 |
+
echo "=== [1/4] unpack ==="
|
| 11 |
+
$PY resim/unpack_world.py cases/$CASE/$CASE.h5 $W
|
| 12 |
+
|
| 13 |
+
mkdir -p work/$CASE
|
| 14 |
+
echo "=== [2/4] preset 1: mu=0.5, e=0.05 (sticky) ==="
|
| 15 |
+
CUDA_VISIBLE_DEVICES=4 $BL --background --python resim/resim_blender.py -- \
|
| 16 |
+
--world $W --out work/$CASE/out_p1 --preset p1 --kinematic Ball \
|
| 17 |
+
--friction 0.5 --restitution 0.05 --mass 1.5 --samples 32
|
| 18 |
+
test -f work/$CASE/out_p1/sim.mp4 || { echo "preset 1 FAILED (no sim.mp4)"; exit 1; }
|
| 19 |
+
|
| 20 |
+
echo "=== [3/4] preset 2: mu=0.02, e=0.9 (icy+bouncy) ==="
|
| 21 |
+
CUDA_VISIBLE_DEVICES=4 $BL --background --python resim/resim_blender.py -- \
|
| 22 |
+
--world $W --out work/$CASE/out_p2 --preset p2 --kinematic Ball \
|
| 23 |
+
--friction 0.02 --restitution 0.9 --mass 1.5 --samples 32
|
| 24 |
+
test -f work/$CASE/out_p2/sim.mp4 || { echo "preset 2 FAILED (no sim.mp4)"; exit 1; }
|
| 25 |
+
|
| 26 |
+
echo "=== [4/4] score + compose ==="
|
| 27 |
+
$PY resim/score_dtw.py --world $W --sims work/$CASE/out_p1 work/$CASE/out_p2 \
|
| 28 |
+
--out work/$CASE/dtw.json
|
| 29 |
+
$PY resim/compose_video.py --world $W --sims work/$CASE/out_p1 work/$CASE/out_p2 \
|
| 30 |
+
--labels "sim mu=0.50 e=0.05" "sim mu=0.02 e=0.90" \
|
| 31 |
+
--out work/$CASE/compare_$CASE.mp4
|
| 32 |
+
echo "=== ALL DONE ==="
|
4dcodebench/resim/score_ablation.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Score the 2x2 ablation arms for the B_07 cloth case, 4DCodeBench-style.
|
| 3 |
+
|
| 4 |
+
Metrics (all computed against the baked ground-truth cloth trajectory):
|
| 5 |
+
chamfer_t mean per-frame symmetric chamfer between sim and GT cloth point
|
| 6 |
+
clouds, subsampled, averaged over frames (meters, lower better)
|
| 7 |
+
dtw_com DTW between the cloth center-of-mass trajectories (meters)
|
| 8 |
+
bbox_iou_t mean 3D IoU of the axis-aligned cloth bounding box per frame
|
| 9 |
+
final_cham chamfer at the last frame (did it end in the same place?)
|
| 10 |
+
|
| 11 |
+
Usage:
|
| 12 |
+
python score_ablation.py --world work/B_07/world --runs work/B_07/ablation \
|
| 13 |
+
--out work/B_07/ablation/metrics.json [--csv work/B_07/ablation/metrics.csv]
|
| 14 |
+
"""
|
| 15 |
+
import argparse
|
| 16 |
+
import csv
|
| 17 |
+
import json
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
import numpy as np
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def chamfer(a, b, n=2000, seed=0):
|
| 24 |
+
rng = np.random.default_rng(seed)
|
| 25 |
+
ai = rng.choice(len(a), min(n, len(a)), replace=False)
|
| 26 |
+
bi = rng.choice(len(b), min(n, len(b)), replace=False)
|
| 27 |
+
A, B = a[ai].astype(np.float64), b[bi].astype(np.float64)
|
| 28 |
+
d_ab = ((A[:, None, :] - B[None, :, :]) ** 2).sum(-1)
|
| 29 |
+
d1 = np.sqrt(d_ab.min(1))
|
| 30 |
+
d2 = np.sqrt(((B[:, None, :] - A[None, :, :]) ** 2).sum(-1)).min(1)
|
| 31 |
+
return float(0.5 * (d1.mean() + d2.mean()))
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def dtw(a, b):
|
| 35 |
+
n, m = len(a), len(b)
|
| 36 |
+
D = np.full((n + 1, m + 1), np.inf)
|
| 37 |
+
D[0, 0] = 0.0
|
| 38 |
+
for i in range(1, n + 1):
|
| 39 |
+
for j in range(1, m + 1):
|
| 40 |
+
c = float(np.linalg.norm(a[i - 1] - b[j - 1]))
|
| 41 |
+
D[i, j] = c + min(D[i - 1, j - 1], D[i, j - 1], D[i - 1, j])
|
| 42 |
+
return float(D[n, m] / (n + m))
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def bbox_iou(a, b):
|
| 46 |
+
amin, amax = a.min(0), a.max(0)
|
| 47 |
+
bmin, bmax = b.min(0), b.max(0)
|
| 48 |
+
inter_min = np.maximum(amin, bmin)
|
| 49 |
+
inter_max = np.minimum(amax, bmax)
|
| 50 |
+
inter = np.clip(inter_max - inter_min, 0, None).prod()
|
| 51 |
+
va = (amax - amin).prod()
|
| 52 |
+
vb = (bmax - bmin).prod()
|
| 53 |
+
union = va + vb - inter
|
| 54 |
+
return float(inter / union) if union > 0 else 0.0
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def score(world_dir, traj_dir, frame_stride=3):
|
| 58 |
+
gt = np.load(Path(world_dir) / "dyn" / "Cloth.npz")["pos"].astype(np.float32)
|
| 59 |
+
sim = np.load(Path(traj_dir) / "clothtraj.npz")["pos"].astype(np.float32)
|
| 60 |
+
assert sim.shape == gt.shape, f"shape mismatch {sim.shape} vs {gt.shape}"
|
| 61 |
+
F = gt.shape[0]
|
| 62 |
+
frames = list(range(0, F, frame_stride))
|
| 63 |
+
if frames[-1] != F - 1:
|
| 64 |
+
frames.append(F - 1)
|
| 65 |
+
ch = [chamfer(sim[i], gt[i], seed=i) for i in frames]
|
| 66 |
+
gt_com = gt.mean(1)
|
| 67 |
+
sim_com = sim.mean(1)
|
| 68 |
+
iou = [bbox_iou(sim[i], gt[i]) for i in frames]
|
| 69 |
+
return {
|
| 70 |
+
"chamfer_t_m": round(float(np.mean(ch)), 4),
|
| 71 |
+
"final_chamfer_m": round(ch[-1], 4),
|
| 72 |
+
"dtw_com_m": round(dtw(sim_com, gt_com), 4),
|
| 73 |
+
"bbox_iou_t": round(float(np.mean(iou)), 4),
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def main():
|
| 78 |
+
ap = argparse.ArgumentParser()
|
| 79 |
+
ap.add_argument("--world", required=True)
|
| 80 |
+
ap.add_argument("--runs", required=True, nargs="+")
|
| 81 |
+
ap.add_argument("--names", required=True, nargs="+")
|
| 82 |
+
ap.add_argument("--out", required=True)
|
| 83 |
+
ap.add_argument("--csv", default=None)
|
| 84 |
+
args = ap.parse_args()
|
| 85 |
+
|
| 86 |
+
report = {}
|
| 87 |
+
for name, run in zip(args.names, args.runs):
|
| 88 |
+
try:
|
| 89 |
+
report[name] = score(args.world, run)
|
| 90 |
+
except Exception as e:
|
| 91 |
+
report[name] = {"error": str(e)}
|
| 92 |
+
print(name, json.dumps(report[name]))
|
| 93 |
+
|
| 94 |
+
Path(args.out).write_text(json.dumps(report, indent=1))
|
| 95 |
+
print(f"wrote {args.out}")
|
| 96 |
+
|
| 97 |
+
if args.csv:
|
| 98 |
+
keys = ["chamfer_t_m", "final_chamfer_m", "dtw_com_m", "bbox_iou_t"]
|
| 99 |
+
with open(args.csv, "w", newline="") as f:
|
| 100 |
+
w = csv.writer(f)
|
| 101 |
+
w.writerow(["arm"] + keys)
|
| 102 |
+
for name in args.names:
|
| 103 |
+
r = report[name]
|
| 104 |
+
w.writerow([name] + [r.get(k, "") for k in keys])
|
| 105 |
+
print(f"wrote {args.csv}")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
main()
|
4dcodebench/resim/score_dtw.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""DTW score: re-simulated trajectories vs baked ground truth, per active object.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
python score_dtw.py --world work/B_03/world --sims work/B_03/out_p1 work/B_03/out_p2
|
| 6 |
+
"""
|
| 7 |
+
import argparse
|
| 8 |
+
import json
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def dtw(a, b):
|
| 15 |
+
"""Mean-per-step DTW cost between two (F,3) trajectories."""
|
| 16 |
+
n, m = len(a), len(b)
|
| 17 |
+
D = np.full((n + 1, m + 1), np.inf)
|
| 18 |
+
D[0, 0] = 0.0
|
| 19 |
+
for i in range(1, n + 1):
|
| 20 |
+
for j in range(1, m + 1):
|
| 21 |
+
c = float(np.linalg.norm(a[i - 1] - b[j - 1]))
|
| 22 |
+
D[i, j] = c + min(D[i - 1, j - 1], D[i, j - 1], D[i - 1, j])
|
| 23 |
+
return D[n, m] / (n + m)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def main():
|
| 27 |
+
ap = argparse.ArgumentParser()
|
| 28 |
+
ap.add_argument("--world", required=True)
|
| 29 |
+
ap.add_argument("--sims", nargs="+", required=True)
|
| 30 |
+
ap.add_argument("--out", default=None, help="write JSON here too")
|
| 31 |
+
args = ap.parse_args()
|
| 32 |
+
|
| 33 |
+
world = Path(args.world)
|
| 34 |
+
names = [p.stem for p in (world / "dyn").glob("*.npz")]
|
| 35 |
+
report = {}
|
| 36 |
+
for sim in args.sims:
|
| 37 |
+
traj = np.load(Path(sim) / "simtraj.npz")
|
| 38 |
+
sim_names = [k for k in traj.files if k in names and k != "Ball"] # Ball = kinematic replay == truth
|
| 39 |
+
per = {}
|
| 40 |
+
for n in sorted(sim_names):
|
| 41 |
+
truth = np.load(world / "dyn" / f"{n}.npz")["pos"].astype(np.float64).mean(axis=1)
|
| 42 |
+
sim_t = traj[n].astype(np.float64)
|
| 43 |
+
per[n] = round(dtw(truth, sim_t), 5)
|
| 44 |
+
report[sim] = {
|
| 45 |
+
"per_object": per,
|
| 46 |
+
"mean": round(float(np.mean(list(per.values()))) if per else None, 5),
|
| 47 |
+
}
|
| 48 |
+
print(json.dumps({sim: report[sim]}, indent=1))
|
| 49 |
+
|
| 50 |
+
if args.out:
|
| 51 |
+
Path(args.out).write_text(json.dumps(report, indent=1))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
main()
|
4dcodebench/resim/unpack_world.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Unpack a 4DCodeBench synthetic world h5 into a plain directory + spec.json.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
python unpack_world.py <case.h5> <outdir>
|
| 6 |
+
|
| 7 |
+
Output (our own simplified layout, plain numpy npz):
|
| 8 |
+
<outdir>/camera.json verbatim from the h5 (intrinsics K 3x3 px, extrinsic E 4x4 cam-to-world)
|
| 9 |
+
<outdir>/render.mp4 verbatim from the h5 (the reference render)
|
| 10 |
+
<outdir>/mesh/<id>.npz vertices (F,V,3) f32, faces (F,T,3) i32, nverts/nfaces per frame
|
| 11 |
+
<outdir>/dyn/<name>.npz pos (F,N,3) f32, ids (M,) u16, faces (T,3) i32
|
| 12 |
+
<outdir>/spec.json F, video specs, per-object summary, static/dynamic split
|
| 13 |
+
"""
|
| 14 |
+
import argparse
|
| 15 |
+
import json
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
|
| 18 |
+
import numpy as np
|
| 19 |
+
import h5py
|
| 20 |
+
import hdf5plugin # noqa: F401 (registers the Zstd filter)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def read_series(group):
|
| 24 |
+
"""Per-frame series stored as (frames + stack) or (frames + flat + lengths)."""
|
| 25 |
+
frames = group["frames"][()]
|
| 26 |
+
if "stack" in group:
|
| 27 |
+
parts = list(group["stack"][()])
|
| 28 |
+
else:
|
| 29 |
+
flat = group["flat"][()]
|
| 30 |
+
lengths = group["lengths"][()]
|
| 31 |
+
edges = np.concatenate([[0], np.cumsum(lengths)])
|
| 32 |
+
parts = [flat[edges[i]:edges[i + 1]] for i in range(len(frames))]
|
| 33 |
+
return frames, parts
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def probe_video(path):
|
| 37 |
+
try:
|
| 38 |
+
import cv2
|
| 39 |
+
cap = cv2.VideoCapture(str(path))
|
| 40 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 41 |
+
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 42 |
+
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 43 |
+
n = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 44 |
+
cap.release()
|
| 45 |
+
if fps and fps > 0 and w > 0:
|
| 46 |
+
return {"fps": round(float(fps), 6), "width": w, "height": h, "frames": n}
|
| 47 |
+
except Exception:
|
| 48 |
+
pass
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def main():
|
| 53 |
+
ap = argparse.ArgumentParser()
|
| 54 |
+
ap.add_argument("h5")
|
| 55 |
+
ap.add_argument("out")
|
| 56 |
+
args = ap.parse_args()
|
| 57 |
+
|
| 58 |
+
out = Path(args.out)
|
| 59 |
+
(out / "mesh").mkdir(parents=True, exist_ok=True)
|
| 60 |
+
(out / "dyn").mkdir(parents=True, exist_ok=True)
|
| 61 |
+
|
| 62 |
+
spec = {"source": str(args.h5)}
|
| 63 |
+
with h5py.File(args.h5, "r") as h:
|
| 64 |
+
(out / "camera.json").write_bytes(bytes(h["camera.json"][()]))
|
| 65 |
+
(out / "render.mp4").write_bytes(bytes(h["render.mp4"][()]))
|
| 66 |
+
vid = probe_video(out / "render.mp4") or {"fps": 24.0, "width": 1280, "height": 720, "frames": None}
|
| 67 |
+
spec["video"] = vid
|
| 68 |
+
|
| 69 |
+
F = int(h[f"dynamics/{next(iter(h['dynamics']))}/pos"].shape[0]) if len(h["dynamics"]) \
|
| 70 |
+
else int(h[f"meshes/{next(iter(h['meshes']))}/vertices/frames"].shape[0])
|
| 71 |
+
spec["F"] = F
|
| 72 |
+
|
| 73 |
+
dyn = {}
|
| 74 |
+
for name in h["dynamics"]:
|
| 75 |
+
g = h[f"dynamics/{name}"]
|
| 76 |
+
np.savez_compressed(out / "dyn" / f"{name}.npz",
|
| 77 |
+
pos=g["pos"][()].astype(np.float32),
|
| 78 |
+
ids=g["ids"][()].astype(np.uint16),
|
| 79 |
+
faces=g["faces"][()].astype(np.int32))
|
| 80 |
+
dyn[name] = {"ids": [int(i) for i in g["ids"][()]], "N": int(g["pos"].shape[1])}
|
| 81 |
+
spec["dynamics"] = dyn
|
| 82 |
+
|
| 83 |
+
dyn_ids = {i for v in dyn.values() for i in v["ids"]}
|
| 84 |
+
meshes = {}
|
| 85 |
+
for mid in h["meshes"]:
|
| 86 |
+
vf, vp = read_series(h[f"meshes/{mid}/vertices"])
|
| 87 |
+
ff, fp = read_series(h[f"meshes/{mid}/faces"])
|
| 88 |
+
V = max(len(p) for p in vp)
|
| 89 |
+
T = max(len(p) for p in fp)
|
| 90 |
+
vert = np.zeros((len(vp), V, 3), np.float32)
|
| 91 |
+
face = np.zeros((len(fp), T, 3), np.int32)
|
| 92 |
+
for i, (pv, pf) in enumerate(zip(vp, fp)):
|
| 93 |
+
vert[i, :len(pv)] = pv
|
| 94 |
+
face[i, :len(pf)] = pf
|
| 95 |
+
np.savez_compressed(out / "mesh" / f"{int(mid)}.npz", vertices=vert, faces=face,
|
| 96 |
+
frames=np.asarray(vf, np.int32),
|
| 97 |
+
nverts=np.array([len(p) for p in vp], np.int32),
|
| 98 |
+
nfaces=np.array([len(p) for p in fp], np.int32))
|
| 99 |
+
meshes[int(mid)] = {"nverts": int(len(vp[0])), "nfaces": int(len(fp[0])),
|
| 100 |
+
"static": int(mid) not in dyn_ids}
|
| 101 |
+
spec["meshes"] = {str(k): v for k, v in sorted(meshes.items())}
|
| 102 |
+
|
| 103 |
+
cam = json.loads((out / "camera.json").read_text())
|
| 104 |
+
K = np.array(cam["intrinsics"], float)
|
| 105 |
+
spec["camera"] = {"K": K.tolist(), "E": np.array(cam["extrinsic"], float).tolist()}
|
| 106 |
+
|
| 107 |
+
(out / "spec.json").write_text(json.dumps(spec, indent=1))
|
| 108 |
+
print(f"unpacked to {out} | F={spec['F']} | video={vid}")
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
main()
|
4dcodebench/work/B_03/compare_B_03.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:041cd650d81fc82129c3de321d106127384f9127da94c11d4314224935b380c7
|
| 3 |
+
size 2785712
|
4dcodebench/work/B_03/dbg/dbg_f1.png
ADDED
|
Git LFS Details
|
4dcodebench/work/B_03/dtw.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"work/B_03/out_p1": {
|
| 3 |
+
"per_object": {
|
| 4 |
+
"Pin00": 0.56827,
|
| 5 |
+
"Pin01": 0.42597,
|
| 6 |
+
"Pin02": 0.71006,
|
| 7 |
+
"Pin03": 0.6415,
|
| 8 |
+
"Pin04": 0.70023,
|
| 9 |
+
"Pin05": 0.63049,
|
| 10 |
+
"Pin06": 0.60231,
|
| 11 |
+
"Pin07": 0.80838,
|
| 12 |
+
"Pin08": 0.76187,
|
| 13 |
+
"Pin09": 0.81381
|
| 14 |
+
},
|
| 15 |
+
"mean": 0.66629
|
| 16 |
+
},
|
| 17 |
+
"work/B_03/out_p2": {
|
| 18 |
+
"per_object": {
|
| 19 |
+
"Pin00": 0.57008,
|
| 20 |
+
"Pin01": 0.48433,
|
| 21 |
+
"Pin02": 0.65053,
|
| 22 |
+
"Pin03": 0.55086,
|
| 23 |
+
"Pin04": 0.72888,
|
| 24 |
+
"Pin05": 0.67485,
|
| 25 |
+
"Pin06": 0.51459,
|
| 26 |
+
"Pin07": 0.78546,
|
| 27 |
+
"Pin08": 0.81593,
|
| 28 |
+
"Pin09": 0.80364
|
| 29 |
+
},
|
| 30 |
+
"mean": 0.65791
|
| 31 |
+
}
|
| 32 |
+
}
|
4dcodebench/work/B_03/out_p1/sim.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52201869fe0772f416fd03345b69331131884795dd5c822541699bfb1369ade3
|
| 3 |
+
size 570094
|
4dcodebench/work/B_03/out_p1/simtraj.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0e0b0e4fae069fc6da5923e7d39403638d748c09018528fd1ae7c8d2963c84e4
|
| 3 |
+
size 18231
|
4dcodebench/work/B_03/out_p2/sim.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f8fb0bb81b38445ec07f0bcc5e750eb67d2e7b9325155db6ed75ca5306e5dc97
|
| 3 |
+
size 619049
|
4dcodebench/work/B_03/out_p2/simtraj.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e06a3979431619b447c8182f4ff8b6e7dc36a54a8966d40e9aff5d4bbac19b2d
|
| 3 |
+
size 18286
|
4dcodebench/work/B_03/world/camera.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"intrinsics": [[2204.4444444444443, 0.0, 640.0], [0.0, 2204.4444444444443, 360.0], [0.0, 0.0, 1.0]], "extrinsic": [[0.5174191726573811, -0.24477246018742208, 0.8199779524477159, -3.8001997470855713], [-0.8557320841049176, -0.14800179780998798, 0.4958004317045986, -2.5872905254364014], [-8.030350601151426e-08, -0.9582180913439324, -0.2860386152623192, 1.6765010356903076], [0.0, 0.0, 0.0, 1.0]]}
|
4dcodebench/work/B_03/world/dyn/Ball.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4482e42f3514b1a7de83c49bb72f4b951125baf39972a261163be18ad4475b19
|
| 3 |
+
size 6125504
|
4dcodebench/work/B_03/world/dyn/Pin00.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1906732cbe85ca621e56386fc02d557c217ba9d16170337433dd79d435cbc156
|
| 3 |
+
size 660805
|
4dcodebench/work/B_03/world/dyn/Pin01.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1e311e58b9f268d5630a979dea3fd757513a421379f6fa457beab6c55fbd31cc
|
| 3 |
+
size 705252
|
4dcodebench/work/B_03/world/dyn/Pin02.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b73599876b08b16008648da600810d41f770294a17220204ee942de9d471e8e
|
| 3 |
+
size 704848
|
4dcodebench/work/B_03/world/dyn/Pin03.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:59d8bb0d19c32745506849fb150770102eab7b28633e36ecf08bf0a44562d7fa
|
| 3 |
+
size 695912
|
4dcodebench/work/B_03/world/dyn/Pin04.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ae6da1587c193e8f6524a63682253a2f3f03333da9fcd2459ffb1c74fb4d484c
|
| 3 |
+
size 647843
|
4dcodebench/work/B_03/world/dyn/Pin05.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:791ab07f3372b979ca4f8375e83dcdfdcd8631697883bf6b7b0ff97d42c832a5
|
| 3 |
+
size 693786
|
4dcodebench/work/B_03/world/dyn/Pin06.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7a5e7dd5a79c56ebc676c1431be940aaddf4badc15a77dfebeb3c73e77728ab4
|
| 3 |
+
size 589148
|
4dcodebench/work/B_03/world/dyn/Pin07.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c5cb0acd4b62890b0ad4ae0ac03ab951fdacd762d865088a4401805b684364f6
|
| 3 |
+
size 646749
|
4dcodebench/work/B_03/world/dyn/Pin08.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4610cca9cfdc5cb48d1b761ba4a62e8f7017243f394de0e8c3d0490741a91c91
|
| 3 |
+
size 697896
|
4dcodebench/work/B_03/world/dyn/Pin09.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0514ee43ca447ed2af4a801c3824eb425ddfdfe2617e0dd07d05212a6bfa17a8
|
| 3 |
+
size 695769
|
4dcodebench/work/B_03/world/mesh/1.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:629b9fe4c01f4386152507e5fdcf34e07e990dfcf8853e547dc6a0802eeed96d
|
| 3 |
+
size 10902995
|
4dcodebench/work/B_03/world/mesh/10.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8342e5872e25dce8551bb091d254afadd018bb632acebb5f661076de7c3b3b98
|
| 3 |
+
size 660508
|
4dcodebench/work/B_03/world/mesh/11.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68ce643726c1d056fd407ab29ff23e150253861393eaea24dce790ef67d6928a
|
| 3 |
+
size 706451
|
4dcodebench/work/B_03/world/mesh/12.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:33f6e1fcf1b5e8901fcbdd2d72db4526cf3984fcd16ce519ad886ddfe7a7a00e
|
| 3 |
+
size 601813
|
4dcodebench/work/B_03/world/mesh/13.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2e2a46392db579a9dac80b7956002fcb3679750eb917a618efdfdf165fb87ec4
|
| 3 |
+
size 659414
|
4dcodebench/work/B_03/world/mesh/14.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a7893118ace03e5b9e40b1731219c16d969e6e7ccc0811a9ec92275ff443ba63
|
| 3 |
+
size 710561
|
4dcodebench/work/B_03/world/mesh/15.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d00fa4c61736bbfaae1cffb2eb91edce2ac00661bcaa8e8c9de2b2c740f8027d
|
| 3 |
+
size 708434
|
4dcodebench/work/B_03/world/mesh/16.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7682afc2c5b14511820fd340f08923191105c85d02b5b6a6a26932239726ef9d
|
| 3 |
+
size 1464
|
4dcodebench/work/B_03/world/mesh/17.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19ba3e91c35d0cfc1828556505049ee4d46a6868b5282aa93b6626e27607162e
|
| 3 |
+
size 1463
|
4dcodebench/work/B_03/world/mesh/18.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4cec6face6af2df04a0f7fe5934ab5a7ff7fee52d873b4564120da244a188ec7
|
| 3 |
+
size 1465
|
4dcodebench/work/B_03/world/mesh/19.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c86c307de2410e0032485b099f237f3737ed2d1e8126d201f38e7a6a699c9c15
|
| 3 |
+
size 1464
|