forgecad 0.10.1 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/assets/{AdminPage-DcCnj0qo.js → AdminPage-CK7ObBz3.js} +1 -1
- package/dist/assets/{BenchmarkPage-BVEpJSVk.js → BenchmarkPage-Ds7Z2doN.js} +1 -1
- package/dist/assets/{BlogPage-DHaGP50_.js → BlogPage-DlPbpt6A.js} +1 -1
- package/dist/assets/{DocsPage-CDoxHkz8.js → DocsPage-vZb3b3Y0.js} +9 -14
- package/dist/assets/{EditorApp-BpjZgzk0.css → EditorApp-C5f24ZN9.css} +8 -0
- package/dist/assets/{EditorApp-BJ0Dloyh.js → EditorApp-HLoKfe15.js} +152 -21
- package/dist/assets/{EmbedViewer-CRKZbY0y.js → EmbedViewer--KnqBKrJ.js} +3 -3
- package/dist/assets/{LandingPageProofDriven-BxHkYRE7.js → LandingPageProofDriven-C_LssmnA.js} +1 -1
- package/dist/assets/{LegalPage-B-u6FrVv.js → LegalPage-DGsyo4n1.js} +1 -1
- package/dist/assets/{PricingPage-CzpZ6-Ce.js → PricingPage-BOE27B-R.js} +1 -1
- package/dist/assets/{SettingsPage-CIZSSAd0.js → SettingsPage-f47cnk39.js} +1 -1
- package/dist/assets/{app-DaTMg3nH.js → app-D6ccu2Xx.js} +7826 -7559
- package/dist/assets/{scalar-sampling-budget-prBw_s8t.js → backendInit-DbTkQN9J.js} +87141 -78777
- package/dist/assets/cli/{render-DPf4AYJK.js → render-BsngirjC.js} +147 -186
- package/dist/assets/{constructionHistoryWorker-AwMMWSxg.js → constructionHistoryWorker-PCwXrTDB.js} +8419 -1447
- package/dist/assets/{evalWorker-CjZZWRWW.js → evalWorker-CS63PfZu.js} +25501 -17997
- package/dist/assets/{forgecad_geometry-Dgceylq9.js → forgecad_geometry-CZ_IfuvA.js} +120 -9
- package/dist/assets/forgecad_geometry_bg-C3rQHfwg.wasm +0 -0
- package/dist/assets/{inspectWorker-CZsCFtQT.js → inspectWorker-Y4cOzNyA.js} +37208 -34464
- package/dist/assets/{jointPose-DzQOViQH.js → jointPose-AMvCywzS.js} +1 -1
- package/dist/assets/{manifold-DgXo0T5P.js → manifold-CBry38ly.js} +2 -2
- package/dist/assets/{manifold-K1SkarlQ.js → manifold-Crd_F2qx.js} +1 -1
- package/dist/assets/{manifold-BYlzU521.js → manifold-k2kRcc85.js} +1 -1
- package/dist/assets/{reportWorker-B9nWwSrB.js → reportWorker-CWvn0CEv.js} +46635 -44646
- package/dist/cli/render.html +1 -1
- package/dist/docs/index.html +2 -2
- package/dist/docs-raw/AI/usage.md +2 -4
- package/dist/docs-raw/CLI.md +34 -20
- package/dist/docs-raw/README.md +1 -1
- package/dist/docs-raw/component-model.md +1 -1
- package/dist/docs-raw/generated/assembly.md +2 -2
- package/dist/docs-raw/generated/concepts.md +6 -4
- package/dist/docs-raw/generated/core.md +71 -2
- package/dist/docs-raw/generated/curves.md +8 -1
- package/dist/docs-raw/generated/lib.md +1 -1
- package/dist/docs-raw/generated/output.md +0 -64
- package/dist/docs-raw/generated/runtime-names.md +6 -6
- package/dist/docs-raw/generated/sdf.md +2 -2
- package/dist/docs-raw/generated/viewport.md +3 -12
- package/dist/docs-raw/guides/inspection-bundles.md +1 -1
- package/dist/docs-raw/guides/simready-quickstart.md +3 -1
- package/dist/docs-raw/simulation-workflow.md +58 -0
- package/dist/docs-raw/skills/forgecad-blockout-model.md +1 -1
- package/dist/docs-raw/skills/forgecad-image-replicator.md +2 -2
- package/dist/docs-raw/skills/forgecad-mujoco-verify.md +78 -0
- package/dist/docs-raw/skills/forgecad-spec-by-walking-through-it.md +145 -0
- package/dist/docs-raw/skills/forgecad-visual-spec.md +1 -1
- package/dist/docs-raw/skills/forgecad.md +24 -24
- package/dist/docs-raw/skills/index.md +2 -3
- package/dist/index.html +1 -1
- package/dist/sitemap.xml +15 -15
- package/dist-cli/{check-compiler-II7NLPAB.js → check-compiler-HPF2T2FS.js} +1 -1
- package/dist-cli/{check-query-propagation-7462TR3R.js → check-query-propagation-HYSLTXAB.js} +1 -1
- package/dist-cli/{chunk-UWTJCGXF.js → chunk-WLUKAW3H.js} +51134 -43247
- package/dist-cli/forgecad.js +5467 -1451
- package/dist-cli/{forgecad_geometry-QOQIIP53.js → forgecad_geometry-2IMYCUWW.js} +119 -8
- package/dist-cli/forgecad_geometry_bg.wasm +0 -0
- package/dist-skill/CONTEXT.md +98 -86
- package/dist-skill/SKILL.md +1 -1
- package/dist-skill/docs/API/core/concepts.md +1 -1
- package/dist-skill/docs/CLI.md +34 -20
- package/dist-skill/docs/generated/assembly.md +2 -2
- package/dist-skill/docs/generated/core.md +71 -2
- package/dist-skill/docs/generated/curves.md +8 -1
- package/dist-skill/docs/generated/lib.md +1 -1
- package/dist-skill/docs/generated/output.md +0 -64
- package/dist-skill/docs/generated/runtime-names.md +6 -6
- package/dist-skill/docs/generated/sdf.md +2 -2
- package/dist-skill/docs/generated/viewport.md +3 -12
- package/dist-skill/docs/guides/inspection-bundles.md +1 -1
- package/dist-skill/library/README.md +2 -3
- package/dist-skill/library/forgecad-blockout-model/SKILL.md +1 -1
- package/dist-skill/library/forgecad-image-replicator/SKILL.md +2 -2
- package/dist-skill/library/forgecad-mujoco-verify/SKILL.md +66 -0
- package/dist-skill/library/forgecad-mujoco-verify/scripts/mujoco_verify.py +385 -0
- package/dist-skill/library/forgecad-spec-by-walking-through-it/SKILL.md +132 -0
- package/dist-skill/library/forgecad-visual-spec/SKILL.md +1 -1
- package/dist-skill/website/skills/forgecad-blockout-model.md +1 -1
- package/dist-skill/website/skills/forgecad-image-replicator.md +2 -2
- package/dist-skill/website/skills/forgecad-mujoco-verify.md +78 -0
- package/dist-skill/website/skills/forgecad-spec-by-walking-through-it.md +145 -0
- package/dist-skill/website/skills/forgecad-visual-spec.md +1 -1
- package/dist-skill/website/skills/forgecad.md +24 -24
- package/dist-skill/website/skills/index.md +2 -3
- package/examples/analysis/clearance-fit.forge.js +31 -0
- package/examples/analysis/lever-arm-actuator.forge.js +43 -0
- package/examples/analysis/tipping-tripod.forge.js +35 -0
- package/examples/api/gyroid-voronoi-blend.forge.js +1 -1
- package/examples/api/organic-noise-sculpture.forge.js +1 -1
- package/examples/api/sdf-circular-array-knurling.forge.js +1 -1
- package/examples/api/{sdf-custom-raymarch.forge.js → sdf-custom-field-mesh-preview.forge.js} +3 -4
- package/examples/api/sdf-materialize-tree.forge.js +2 -2
- package/examples/api/sdf-plain-return.forge.js +3 -2
- package/examples/api/sdf-shapes.forge.js +2 -2
- package/examples/api/sdf-surface-basket-weave.forge.js +2 -2
- package/examples/generative/twisted-lattice-tower.forge.js +1 -1
- package/examples/generative/voronoi-lampshade.forge.js +1 -1
- package/examples/products/sportscar.forge.js +77 -0
- package/package.json +2 -4
- package/dist/assets/forgecad_geometry_bg-dD4RNQF1.wasm +0 -0
- package/dist/assets/manifold-CzYf_iub.js +0 -3023
- package/dist/docs-raw/skills/forgecad-high-level-spec.md +0 -101
- package/dist/docs-raw/skills/forgecad-lld.md +0 -41
- package/dist/docs-raw/skills/forgecad-prepare-prompt.md +0 -63
- package/dist-skill/library/forgecad-high-level-spec/SKILL.md +0 -94
- package/dist-skill/library/forgecad-lld/SKILL.md +0 -34
- package/dist-skill/library/forgecad-prepare-prompt/SKILL.md +0 -50
- package/dist-skill/website/skills/forgecad-high-level-spec.md +0 -101
- package/dist-skill/website/skills/forgecad-lld.md +0 -41
- package/dist-skill/website/skills/forgecad-prepare-prompt.md +0 -63
- /package/dist-skill/library/{forgecad-prepare-prompt → forgecad-spec-by-walking-through-it}/references/default-profiles.md +0 -0
- /package/dist-skill/library/{forgecad-prepare-prompt → forgecad-spec-by-walking-through-it}/references/master-prompt.md +0 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Verify a ForgeCAD MJCF package by running MuJoCo dynamics and rendering frames."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
from collections import Counter
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Iterable
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def parse_actuator(value: str) -> tuple[str, float]:
|
|
15
|
+
if "=" not in value:
|
|
16
|
+
raise argparse.ArgumentTypeError("expected NAME=VALUE")
|
|
17
|
+
name, raw = value.split("=", 1)
|
|
18
|
+
name = name.strip()
|
|
19
|
+
if not name:
|
|
20
|
+
raise argparse.ArgumentTypeError("actuator name is empty")
|
|
21
|
+
try:
|
|
22
|
+
ctrl = float(raw)
|
|
23
|
+
except ValueError as exc:
|
|
24
|
+
raise argparse.ArgumentTypeError(f"invalid actuator value {raw!r}") from exc
|
|
25
|
+
return name, ctrl
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def parse_joint_range(value: str) -> tuple[str, float, float]:
|
|
29
|
+
if "=" not in value:
|
|
30
|
+
raise argparse.ArgumentTypeError("expected JOINT=MIN:MAX")
|
|
31
|
+
name, raw_range = value.split("=", 1)
|
|
32
|
+
name = name.strip()
|
|
33
|
+
if not name:
|
|
34
|
+
raise argparse.ArgumentTypeError("joint name is empty")
|
|
35
|
+
if ":" not in raw_range:
|
|
36
|
+
raise argparse.ArgumentTypeError("expected range as MIN:MAX")
|
|
37
|
+
raw_min, raw_max = raw_range.split(":", 1)
|
|
38
|
+
try:
|
|
39
|
+
min_value = float(raw_min)
|
|
40
|
+
max_value = float(raw_max)
|
|
41
|
+
except ValueError as exc:
|
|
42
|
+
raise argparse.ArgumentTypeError(f"invalid numeric range {raw_range!r}") from exc
|
|
43
|
+
if min_value > max_value:
|
|
44
|
+
raise argparse.ArgumentTypeError(f"range minimum {min_value} is greater than maximum {max_value}")
|
|
45
|
+
return name, min_value, max_value
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def cycles_from_radians(value: float) -> float:
|
|
49
|
+
return value / math.tau
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def resolve_scene(path: Path) -> Path:
|
|
53
|
+
if path.is_file():
|
|
54
|
+
return path
|
|
55
|
+
scene = path / "scene.xml"
|
|
56
|
+
if scene.is_file():
|
|
57
|
+
return scene
|
|
58
|
+
raise SystemExit(f"Could not find scene.xml at {path}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def geom_name(mujoco, model, geom_id: int) -> str:
|
|
62
|
+
return mujoco.mj_id2name(model, mujoco.mjtObj.mjOBJ_GEOM, geom_id) or f"geom#{geom_id}"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def joint_name(mujoco, model, joint_id: int) -> str:
|
|
66
|
+
return mujoco.mj_id2name(model, mujoco.mjtObj.mjOBJ_JOINT, joint_id) or f"joint#{joint_id}"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def contact_counts(mujoco, model, data, limit: int) -> list[dict[str, object]]:
|
|
70
|
+
counts: Counter[tuple[str, str]] = Counter()
|
|
71
|
+
for i in range(data.ncon):
|
|
72
|
+
contact = data.contact[i]
|
|
73
|
+
a = geom_name(mujoco, model, int(contact.geom1))
|
|
74
|
+
b = geom_name(mujoco, model, int(contact.geom2))
|
|
75
|
+
if a > b:
|
|
76
|
+
a, b = b, a
|
|
77
|
+
counts[(a, b)] += 1
|
|
78
|
+
return [{"geom1": a, "geom2": b, "count": count} for (a, b), count in counts.most_common(limit)]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def qpos_for_joint(model, joint_id: int) -> float:
|
|
82
|
+
return float(model.jnt_qposadr[joint_id])
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def first_freejoint(mujoco, model) -> int | None:
|
|
86
|
+
for joint_id in range(model.njnt):
|
|
87
|
+
if model.jnt_type[joint_id] == mujoco.mjtJoint.mjJNT_FREE:
|
|
88
|
+
return joint_id
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def make_camera(mujoco, lookat: Iterable[float], distance: float, azimuth: float, elevation: float):
|
|
93
|
+
camera = mujoco.MjvCamera()
|
|
94
|
+
camera.type = mujoco.mjtCamera.mjCAMERA_FREE
|
|
95
|
+
camera.lookat[:] = list(lookat)
|
|
96
|
+
camera.distance = distance
|
|
97
|
+
camera.azimuth = azimuth
|
|
98
|
+
camera.elevation = elevation
|
|
99
|
+
return camera
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def render_frame(mujoco, renderer, model, data, camera, label: str, path: Path) -> None:
|
|
103
|
+
from PIL import Image, ImageDraw
|
|
104
|
+
|
|
105
|
+
mujoco.mj_forward(model, data)
|
|
106
|
+
renderer.update_scene(data, camera=camera)
|
|
107
|
+
image = Image.fromarray(renderer.render())
|
|
108
|
+
draw = ImageDraw.Draw(image)
|
|
109
|
+
draw.rectangle((12, 12, min(image.width - 12, 1120), 72), fill=(255, 255, 255))
|
|
110
|
+
draw.text((22, 22), label, fill=(0, 0, 0))
|
|
111
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
112
|
+
image.save(path)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def render_camera_preview_grid(mujoco, renderer, model, data, args, path: Path) -> str:
|
|
116
|
+
from PIL import Image, ImageDraw
|
|
117
|
+
|
|
118
|
+
images = []
|
|
119
|
+
for azimuth in args.camera_preview_azimuths:
|
|
120
|
+
camera = make_camera(mujoco, args.camera_lookat, args.camera_distance, azimuth, args.camera_elevation)
|
|
121
|
+
mujoco.mj_forward(model, data)
|
|
122
|
+
renderer.update_scene(data, camera=camera)
|
|
123
|
+
image = Image.fromarray(renderer.render())
|
|
124
|
+
draw = ImageDraw.Draw(image)
|
|
125
|
+
label = f"azimuth {azimuth:g}"
|
|
126
|
+
draw.rectangle((12, 12, min(image.width - 12, 260), 52), fill=(255, 255, 255))
|
|
127
|
+
draw.text((22, 22), label, fill=(0, 0, 0))
|
|
128
|
+
images.append(image)
|
|
129
|
+
|
|
130
|
+
if not images:
|
|
131
|
+
return ""
|
|
132
|
+
|
|
133
|
+
cols = min(3, len(images))
|
|
134
|
+
rows = int(math.ceil(len(images) / cols))
|
|
135
|
+
width, height = images[0].size
|
|
136
|
+
canvas = Image.new("RGB", (cols * width, rows * height), (255, 255, 255))
|
|
137
|
+
for index, image in enumerate(images):
|
|
138
|
+
canvas.paste(image, ((index % cols) * width, (index // cols) * height))
|
|
139
|
+
|
|
140
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
141
|
+
canvas.save(path)
|
|
142
|
+
return str(path)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def main() -> int:
|
|
146
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
147
|
+
parser.add_argument("package_or_scene", type=Path, help="MJCF package directory or scene.xml path")
|
|
148
|
+
parser.add_argument("--settle-seconds", type=float, default=2.0)
|
|
149
|
+
parser.add_argument("--seconds", type=float, default=6.0)
|
|
150
|
+
parser.add_argument("--actuator", action="append", type=parse_actuator, default=[], help="Control as NAME=VALUE")
|
|
151
|
+
parser.add_argument("--watch-joint", action="append", default=[], help="Joint name whose motion should be reported")
|
|
152
|
+
parser.add_argument("--assert-min-joint-delta", type=float, default=0.0)
|
|
153
|
+
parser.add_argument(
|
|
154
|
+
"--expect-drive-delta",
|
|
155
|
+
action="append",
|
|
156
|
+
type=parse_joint_range,
|
|
157
|
+
default=[],
|
|
158
|
+
help="Require signed post-settle joint delta as JOINT=MIN:MAX in MuJoCo qpos units",
|
|
159
|
+
)
|
|
160
|
+
parser.add_argument(
|
|
161
|
+
"--expect-drive-cycles",
|
|
162
|
+
action="append",
|
|
163
|
+
type=parse_joint_range,
|
|
164
|
+
default=[],
|
|
165
|
+
help="Require signed post-settle revolute joint travel as JOINT=MIN:MAX in cycles/turns",
|
|
166
|
+
)
|
|
167
|
+
parser.add_argument(
|
|
168
|
+
"--expect-final-qvel",
|
|
169
|
+
action="append",
|
|
170
|
+
type=parse_joint_range,
|
|
171
|
+
default=[],
|
|
172
|
+
help="Require final joint velocity as JOINT=MIN:MAX in MuJoCo qvel units",
|
|
173
|
+
)
|
|
174
|
+
parser.add_argument("--max-root-drop", type=float, default=0.02, help="Maximum allowed root Z drop in meters for free-root models")
|
|
175
|
+
parser.add_argument("--contact-top-n", type=int, default=12)
|
|
176
|
+
parser.add_argument("--render-dir", type=Path)
|
|
177
|
+
parser.add_argument("--fps", type=float, default=6.0)
|
|
178
|
+
parser.add_argument("--camera-lookat", nargs=3, type=float, default=[0.0, 0.0, 0.0])
|
|
179
|
+
parser.add_argument("--camera-distance", type=float, default=0.35)
|
|
180
|
+
parser.add_argument("--camera-azimuth", type=float, default=-45.0)
|
|
181
|
+
parser.add_argument("--camera-elevation", type=float, default=-20.0)
|
|
182
|
+
parser.add_argument(
|
|
183
|
+
"--camera-preview-grid",
|
|
184
|
+
action="store_true",
|
|
185
|
+
help="Write a labeled azimuth grid to render-dir/camera_preview_grid.png before choosing/reporting a view",
|
|
186
|
+
)
|
|
187
|
+
parser.add_argument(
|
|
188
|
+
"--camera-preview-azimuths",
|
|
189
|
+
nargs="+",
|
|
190
|
+
type=float,
|
|
191
|
+
default=[-90, 0, 45, 90, 135, 180],
|
|
192
|
+
help="Azimuths in degrees to include in --camera-preview-grid",
|
|
193
|
+
)
|
|
194
|
+
args = parser.parse_args()
|
|
195
|
+
if args.camera_preview_grid and not args.render_dir:
|
|
196
|
+
parser.error("--camera-preview-grid requires --render-dir")
|
|
197
|
+
|
|
198
|
+
import mujoco
|
|
199
|
+
|
|
200
|
+
scene_path = resolve_scene(args.package_or_scene)
|
|
201
|
+
model = mujoco.MjModel.from_xml_path(str(scene_path))
|
|
202
|
+
data = mujoco.MjData(model)
|
|
203
|
+
|
|
204
|
+
actuator_ids: list[tuple[str, int, float]] = []
|
|
205
|
+
for name, ctrl in args.actuator:
|
|
206
|
+
actuator_id = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_ACTUATOR, name)
|
|
207
|
+
if actuator_id < 0:
|
|
208
|
+
raise SystemExit(f"Unknown actuator {name!r}")
|
|
209
|
+
actuator_ids.append((name, actuator_id, ctrl))
|
|
210
|
+
|
|
211
|
+
watch_names = list(dict.fromkeys(
|
|
212
|
+
args.watch_joint
|
|
213
|
+
+ [name for name, _min_value, _max_value in args.expect_drive_delta]
|
|
214
|
+
+ [name for name, _min_value, _max_value in args.expect_drive_cycles]
|
|
215
|
+
+ [name for name, _min_value, _max_value in args.expect_final_qvel]
|
|
216
|
+
))
|
|
217
|
+
watch_joints: list[tuple[str, int, int, int]] = []
|
|
218
|
+
for name in watch_names:
|
|
219
|
+
joint_id = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_JOINT, name)
|
|
220
|
+
if joint_id < 0:
|
|
221
|
+
raise SystemExit(f"Unknown joint {name!r}")
|
|
222
|
+
watch_joints.append((name, joint_id, int(model.jnt_qposadr[joint_id]), int(model.jnt_dofadr[joint_id])))
|
|
223
|
+
|
|
224
|
+
free_joint_id = first_freejoint(mujoco, model)
|
|
225
|
+
free_qadr = int(model.jnt_qposadr[free_joint_id]) if free_joint_id is not None else None
|
|
226
|
+
|
|
227
|
+
renderer = None
|
|
228
|
+
camera = None
|
|
229
|
+
if args.render_dir:
|
|
230
|
+
renderer = mujoco.Renderer(model, height=900, width=1200)
|
|
231
|
+
camera = make_camera(mujoco, args.camera_lookat, args.camera_distance, args.camera_azimuth, args.camera_elevation)
|
|
232
|
+
|
|
233
|
+
def snapshot(label: str) -> dict[str, object]:
|
|
234
|
+
root_pos = None
|
|
235
|
+
if free_qadr is not None:
|
|
236
|
+
root_pos = [float(x) for x in data.qpos[free_qadr : free_qadr + 3]]
|
|
237
|
+
return {
|
|
238
|
+
"label": label,
|
|
239
|
+
"time": float(data.time),
|
|
240
|
+
"root_pos": root_pos,
|
|
241
|
+
"watched": {
|
|
242
|
+
name: {"qpos": float(data.qpos[qadr]), "qvel": float(data.qvel[dadr])}
|
|
243
|
+
for name, _joint_id, qadr, dadr in watch_joints
|
|
244
|
+
},
|
|
245
|
+
"ncon": int(data.ncon),
|
|
246
|
+
"contacts": contact_counts(mujoco, model, data, args.contact_top_n),
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
mujoco.mj_forward(model, data)
|
|
250
|
+
initial = snapshot("initial")
|
|
251
|
+
initial_joint_qpos = {name: float(data.qpos[qadr]) for name, _joint_id, qadr, _dadr in watch_joints}
|
|
252
|
+
initial_root_z = float(data.qpos[free_qadr + 2]) if free_qadr is not None else None
|
|
253
|
+
if renderer and camera:
|
|
254
|
+
camera_preview_grid = None
|
|
255
|
+
if args.camera_preview_grid:
|
|
256
|
+
camera_preview_grid = render_camera_preview_grid(
|
|
257
|
+
mujoco,
|
|
258
|
+
renderer,
|
|
259
|
+
model,
|
|
260
|
+
data,
|
|
261
|
+
args,
|
|
262
|
+
args.render_dir / "camera_preview_grid.png",
|
|
263
|
+
)
|
|
264
|
+
render_frame(mujoco, renderer, model, data, camera, "initial", args.render_dir / "00_initial.png")
|
|
265
|
+
else:
|
|
266
|
+
camera_preview_grid = None
|
|
267
|
+
|
|
268
|
+
settle_steps = max(0, int(round(args.settle_seconds / model.opt.timestep)))
|
|
269
|
+
for _ in range(settle_steps):
|
|
270
|
+
mujoco.mj_step(model, data)
|
|
271
|
+
settled = snapshot("settled")
|
|
272
|
+
settled_joint_qpos = {name: float(data.qpos[qadr]) for name, _joint_id, qadr, _dadr in watch_joints}
|
|
273
|
+
if renderer and camera:
|
|
274
|
+
render_frame(mujoco, renderer, model, data, camera, "settled", args.render_dir / "01_settled.png")
|
|
275
|
+
|
|
276
|
+
total_steps = max(0, int(round(args.seconds / model.opt.timestep)))
|
|
277
|
+
frame_interval = max(1, int(round((1.0 / max(args.fps, 1e-9)) / model.opt.timestep)))
|
|
278
|
+
rendered = []
|
|
279
|
+
for step in range(total_steps):
|
|
280
|
+
for _name, actuator_id, ctrl in actuator_ids:
|
|
281
|
+
data.ctrl[actuator_id] = ctrl
|
|
282
|
+
mujoco.mj_step(model, data)
|
|
283
|
+
if renderer and camera and step % frame_interval == 0:
|
|
284
|
+
frame_path = args.render_dir / f"drive_{step:06d}.png"
|
|
285
|
+
render_frame(mujoco, renderer, model, data, camera, f"drive t={data.time:.2f}s", frame_path)
|
|
286
|
+
rendered.append(str(frame_path))
|
|
287
|
+
|
|
288
|
+
final = snapshot("final")
|
|
289
|
+
if renderer and camera:
|
|
290
|
+
render_frame(mujoco, renderer, model, data, camera, "final", args.render_dir / "99_final.png")
|
|
291
|
+
renderer.close()
|
|
292
|
+
|
|
293
|
+
joint_delta = {
|
|
294
|
+
name: float(data.qpos[qadr]) - initial_joint_qpos[name]
|
|
295
|
+
for name, _joint_id, qadr, _dadr in watch_joints
|
|
296
|
+
}
|
|
297
|
+
joint_drive_delta = {
|
|
298
|
+
name: float(data.qpos[qadr]) - settled_joint_qpos[name]
|
|
299
|
+
for name, _joint_id, qadr, _dadr in watch_joints
|
|
300
|
+
}
|
|
301
|
+
joint_cycles = {name: cycles_from_radians(value) for name, value in joint_delta.items()}
|
|
302
|
+
joint_drive_cycles = {name: cycles_from_radians(value) for name, value in joint_drive_delta.items()}
|
|
303
|
+
final_joint_qvel = {
|
|
304
|
+
name: float(data.qvel[dadr])
|
|
305
|
+
for name, _joint_id, _qadr, dadr in watch_joints
|
|
306
|
+
}
|
|
307
|
+
root_drop = None
|
|
308
|
+
if free_qadr is not None and initial_root_z is not None:
|
|
309
|
+
root_drop = initial_root_z - float(data.qpos[free_qadr + 2])
|
|
310
|
+
|
|
311
|
+
summary = {
|
|
312
|
+
"scene": str(scene_path),
|
|
313
|
+
"counts": {"nbody": int(model.nbody), "njnt": int(model.njnt), "nu": int(model.nu), "ngeom": int(model.ngeom)},
|
|
314
|
+
"free_joint": joint_name(mujoco, model, free_joint_id) if free_joint_id is not None else None,
|
|
315
|
+
"actuators": [{"name": name, "ctrl": ctrl} for name, _actuator_id, ctrl in actuator_ids],
|
|
316
|
+
"joint_delta": joint_delta,
|
|
317
|
+
"joint_drive_delta": joint_drive_delta,
|
|
318
|
+
"joint_cycles": joint_cycles,
|
|
319
|
+
"joint_drive_cycles": joint_drive_cycles,
|
|
320
|
+
"final_joint_qvel": final_joint_qvel,
|
|
321
|
+
"expectations": {
|
|
322
|
+
"drive_delta": [
|
|
323
|
+
{"joint": name, "min": min_value, "max": max_value}
|
|
324
|
+
for name, min_value, max_value in args.expect_drive_delta
|
|
325
|
+
],
|
|
326
|
+
"drive_cycles": [
|
|
327
|
+
{"joint": name, "min": min_value, "max": max_value}
|
|
328
|
+
for name, min_value, max_value in args.expect_drive_cycles
|
|
329
|
+
],
|
|
330
|
+
"final_qvel": [
|
|
331
|
+
{"joint": name, "min": min_value, "max": max_value}
|
|
332
|
+
for name, min_value, max_value in args.expect_final_qvel
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
"root_drop_m": root_drop,
|
|
336
|
+
"camera": {
|
|
337
|
+
"lookat": args.camera_lookat,
|
|
338
|
+
"distance": args.camera_distance,
|
|
339
|
+
"azimuth": args.camera_azimuth,
|
|
340
|
+
"elevation": args.camera_elevation,
|
|
341
|
+
"preview_grid": camera_preview_grid,
|
|
342
|
+
},
|
|
343
|
+
"snapshots": [initial, settled, final],
|
|
344
|
+
"render_dir": str(args.render_dir) if args.render_dir else None,
|
|
345
|
+
"rendered_frames": rendered[:5] + (["..."] if len(rendered) > 5 else []),
|
|
346
|
+
}
|
|
347
|
+
print(json.dumps(summary, indent=2))
|
|
348
|
+
|
|
349
|
+
failures = []
|
|
350
|
+
if root_drop is not None and root_drop > args.max_root_drop:
|
|
351
|
+
failures.append(f"root dropped {root_drop:.6f}m > {args.max_root_drop:.6f}m")
|
|
352
|
+
if args.assert_min_joint_delta > 0:
|
|
353
|
+
max_delta = max((abs(value) for value in joint_delta.values()), default=0.0)
|
|
354
|
+
if max_delta < args.assert_min_joint_delta:
|
|
355
|
+
failures.append(f"watched joints moved only {max_delta:.6f}; expected {args.assert_min_joint_delta:.6f}")
|
|
356
|
+
for name, min_value, max_value in args.expect_drive_delta:
|
|
357
|
+
value = joint_drive_delta[name]
|
|
358
|
+
if not min_value <= value <= max_value:
|
|
359
|
+
failures.append(
|
|
360
|
+
f"{name} drive delta {value:.6f} outside expected range [{min_value:.6f}, {max_value:.6f}]"
|
|
361
|
+
)
|
|
362
|
+
for name, min_value, max_value in args.expect_drive_cycles:
|
|
363
|
+
value = joint_drive_cycles[name]
|
|
364
|
+
if not min_value <= value <= max_value:
|
|
365
|
+
failures.append(
|
|
366
|
+
f"{name} drive cycles {value:.6f} outside expected range [{min_value:.6f}, {max_value:.6f}]"
|
|
367
|
+
)
|
|
368
|
+
for name, min_value, max_value in args.expect_final_qvel:
|
|
369
|
+
value = final_joint_qvel[name]
|
|
370
|
+
if not min_value <= value <= max_value:
|
|
371
|
+
failures.append(
|
|
372
|
+
f"{name} final qvel {value:.6f} outside expected range [{min_value:.6f}, {max_value:.6f}]"
|
|
373
|
+
)
|
|
374
|
+
if any(math.isnan(value) or math.isinf(value) for value in data.qpos):
|
|
375
|
+
failures.append("qpos contains NaN or Inf")
|
|
376
|
+
|
|
377
|
+
if failures:
|
|
378
|
+
for failure in failures:
|
|
379
|
+
print(f"FAIL: {failure}")
|
|
380
|
+
return 2
|
|
381
|
+
return 0
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
if __name__ == "__main__":
|
|
385
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: forgecad-spec-by-walking-through-it
|
|
3
|
+
description: Design a ForgeCAD model, mechanism, or assembly by fixing WHAT before HOW in a git-reviewed design document, validated by mentally operating the thing step by step. Covers fuzzy-request intake and process choice, high-level design (HLD), and low-level design (LLD). Use on "spec this out", "plan the design", "write the HLD/LLD", a vague build request that needs concrete decisions, or any moment the right move is a reviewable spec before code.
|
|
4
|
+
forgecad-public: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Spec by Walking Through It
|
|
8
|
+
|
|
9
|
+
The design document — a git-committed, diff-reviewed markdown file — is the source of truth. Not the code, not the chat, not your head. You iterate it by commit-and-review, and the `git diff` is the review artifact.
|
|
10
|
+
|
|
11
|
+
**Validate the design by mentally operating the thing, step by step.** Walk it as someone assembles, uses, or moves it. The step with no answer — *"how does the servo get inside the housing?"* — is the real design gap. A spec that reads complete on the page can still hide a hole that only surfaces when you try to put it together in your head. State each gap falsifiably: not "tolerances might be tight" but "the 12mm arm cantilevers under gripping load, may flex >0.5mm."
|
|
12
|
+
|
|
13
|
+
**Every number has a reason; the narrative comes before the numbers.** Describe the object as if over the phone, then derive each value and show its math: `wallThickness = 2.4mm = 6 × 0.4mm nozzle`. The design is **implementation-blind** — shaped by the object, never by what the ForgeCAD API makes easy. **Manufacturing process is one of those reasons** — a design decision you weigh, never a default you inherit (never assume FDM/printing).
|
|
14
|
+
|
|
15
|
+
**A vague request is a set of decisions you make honestly, not information to extract.** No placeholders ("appropriate motor"); choose a defensible value, show why, continue. The Decisions table fills only after user review, so the loop stays in the document.
|
|
16
|
+
|
|
17
|
+
## Altitude — three phases, one document trail
|
|
18
|
+
|
|
19
|
+
| Phase | When | Output |
|
|
20
|
+
|-------|------|--------|
|
|
21
|
+
| Intake | request is fuzzy / process unspecified | engineering brief + master prompt |
|
|
22
|
+
| HLD | design is wrong in *approach*, alternatives exist | `<name>-hld.md` |
|
|
23
|
+
| LLD | decisions locked, or a simple single-body part | `<name>-lld.md` |
|
|
24
|
+
|
|
25
|
+
The HLD carries only decision-driving dimensions and genuinely-different alternatives; the LLD carries enough that someone builds from it alone. Speccing every tolerance in an HLD, or revisiting locked decisions in an LLD, is an altitude error — back up. Simple parts skip straight from HLD to code, or from a request to an LLD.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Phase 1 — Intake (fuzzy request → concrete brief)
|
|
30
|
+
|
|
31
|
+
Use when the user wants something physically real but the ask is vague ("make me a robot gripper", "make it production ready", "pick sensible numbers"). This phase owns intake; once the brief is concrete, continue to HLD or hand off to the `forgecad` skill.
|
|
32
|
+
|
|
33
|
+
**Manufacturing is a design decision, not a default.** Derive the process stack from artifact family, load path, scale, safety expectations, material, production intent, and operating story — never assume printing/plastic. If the user names a process, honor it but warn when it is unsafe or dishonest for the duty. Family→process anchors live in `references/default-profiles.md`.
|
|
34
|
+
|
|
35
|
+
**Default posture: manufacture-realistic prototype** — real materials, purchased-part boundaries, assembly logic, validation; no claims of production tooling or certification. Other postures only when justified: `production-realistic`, `printable`, `visual-CAD`, or a specific process posture (`sheet-metal`, `CNC-machined`, `laser-cut`, `welded-tube`, `injection-molded`, `cast`, `hybrid purchased-hardware`). Pick the posture honest for the artifact, not the easiest CAD surface.
|
|
36
|
+
|
|
37
|
+
**Family-scoped numbers.** Every starter assumption is scoped to one artifact family; never reuse numbers across families.
|
|
38
|
+
|
|
39
|
+
Workflow:
|
|
40
|
+
1. **Normalize the ask** into plain mechanism language ("6 DOF gripper" → standalone gripper, wrist+gripper, or arm+gripper).
|
|
41
|
+
2. **Build a specific operating story** — invented (non-famous) org, named program, prototype revision, review moment, mission pressure (pilot gate, demo date, investor milestone), and the generic failure mode to avoid. Prefer bold high-agency stories over modest lab exercises. Never assert the user works for a named real company; use real products only as public comparison anchors; never clone proprietary designs.
|
|
42
|
+
3. **Classify the artifact family** (`references/default-profiles.md`); use the no-family-fits escape rather than forcing one. Rideables route to human-vehicles, never chassis.
|
|
43
|
+
4. **Choose the process posture** per the taxonomy above.
|
|
44
|
+
5. **Pick qualitative levers** — duty (`light`/`general`/`sturdy`), scale (`compact`/`medium`/`large`), cost (`cheapest`/`balanced`/`performance-first`) — and translate to family-scoped starter assumptions.
|
|
45
|
+
6. **Close only critical gaps** — at most 3 grouped questions, always choice menus, never raw engineering inputs unless the architecture truly depends on them. Good: "light desk demo, useful hobby tool, or sturdier bench mechanism?" Bad: "What payload mass?"
|
|
46
|
+
7. **Write the engineering brief**: artifact + family + normalized interpretation; operating story + production reason + test setting + failure mode to avoid; output posture; intended loads, size envelope, motion/DOF; process stack + material defaults; purchased-part (BOM) boundary; validation standard; variant policy (versions are selectable params, one rendered at a time); file organization (`main.forge.js` entry for multi-file); explicit uncertainty policy.
|
|
47
|
+
8. **Emit one master prompt** — fill `references/master-prompt.md`; return the finished prompt, not notes about it. It must demand exactly `BUILD-READY` or `BEST-EFFORT BUILD CANDIDATE` (human-bearing furniture and rideables usually end the latter).
|
|
48
|
+
|
|
49
|
+
Defaults if the user stays vague: `general-duty` / `medium` / `balanced`, invent the operating story, use family starter assumptions.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Phase 2 — High-Level Design (HLD)
|
|
54
|
+
|
|
55
|
+
Aligns user and agent on *what* to build before *how*. Brevity is a readability tool, not a metric — include whatever evidence, diagrams, and dimensions a good decision needs. Write the sections top to bottom; the order is the workflow.
|
|
56
|
+
|
|
57
|
+
```markdown
|
|
58
|
+
# [Name] — High-Level Design
|
|
59
|
+
|
|
60
|
+
## Problem
|
|
61
|
+
What must this do? Hard requirements (grip 40-90mm objects, fit a 60mm
|
|
62
|
+
housing, use purchased bearings). State the problem without implying a
|
|
63
|
+
solution. Unspecified process choice is an open design dimension.
|
|
64
|
+
|
|
65
|
+
## Approach
|
|
66
|
+
How it works conceptually. ASCII diagram of key elements and their
|
|
67
|
+
spatial relationships — diagram labels stay in this markdown, never
|
|
68
|
+
carried into CAD geometry unless the real artifact needs markings.
|
|
69
|
+
|
|
70
|
+
## Key Interfaces
|
|
71
|
+
Every point where this touches another part or the outside world:
|
|
72
|
+
mating surfaces, shared dimensions, coordination points. These are the
|
|
73
|
+
contracts that constrain the design.
|
|
74
|
+
|
|
75
|
+
## Dictionary
|
|
76
|
+
| Term | What it is |
|
|
77
|
+
Define every domain term in plain words, with dimensions where relevant.
|
|
78
|
+
Write for a developer without a mechanical-engineering background.
|
|
79
|
+
|
|
80
|
+
## Alternatives
|
|
81
|
+
| Option | Description | Tradeoff |
|
|
82
|
+
2-3 genuinely different strategies, not minor variations. Mark one
|
|
83
|
+
recommended and say why. If there is honestly one approach, say so.
|
|
84
|
+
|
|
85
|
+
## Usage Guide
|
|
86
|
+
Work backwards from how someone uses, assembles, or operates the thing,
|
|
87
|
+
step by step. If a step doesn't make sense ("how does the servo get
|
|
88
|
+
inside?"), flag it inline with ⚠️ and promote it to Concerns.
|
|
89
|
+
|
|
90
|
+
## Concerns
|
|
91
|
+
1. Numbered, falsifiably specific — a reviewer must be able to say "real
|
|
92
|
+
problem" or "fine, because…".
|
|
93
|
+
|
|
94
|
+
## Decisions
|
|
95
|
+
| # | Decision | Rationale |
|
|
96
|
+
Filled ONLY after user review — never pre-decide. Each row resolves a
|
|
97
|
+
concern or alternative.
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Rules: if you're speccing every part, formula, and tolerance, you're writing an LLD — back up. If you can't draw it, you don't understand it yet.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Phase 3 — Low-Level Design (LLD)
|
|
105
|
+
|
|
106
|
+
Implements the HLD's locked Decisions table; it never revisits those decisions. Simple single-body parts skip the HLD and start here. Complex assemblies split into a numbered directory: overview, global constraints, per-component files, assembly, verification.
|
|
107
|
+
|
|
108
|
+
An LLD is **narrative-first** (reads like describing the object over the phone), **authoritative** (the single source code implements), **implementation-blind**, and shows **every number's rationale**.
|
|
109
|
+
|
|
110
|
+
Required structure:
|
|
111
|
+
1. **Narrative** — what it is, how it behaves and interacts, why it exists. Concrete comparisons ("about the size of a deck of cards"); no ungrounded vague terms.
|
|
112
|
+
2. **Technical** — typed parameter table (length / angle / count / boolean / choice / ratio / clearance — design-document vocabulary, not the runtime `Param.*` API), always with units (mm, degrees default) and a rationale for every default and range; derived dimensions shown as math; geometry and constraints, each constraint with a rationale.
|
|
113
|
+
3. **Verification** — mandatory checklist: dimensional, functional, printability/process checks.
|
|
114
|
+
|
|
115
|
+
Don'ts: never open with a parameter list (story before numbers), never leave a constraint implicit, never skip verification. Completeness gate before presenting: can someone build from this alone? Does it implement every HLD decision? Is every constraint explicit with a rationale?
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Review via git
|
|
120
|
+
|
|
121
|
+
HLDs and LLDs iterate through git, not conversation:
|
|
122
|
+
- **Commit every version.** No drafts floating in chat. After writing, commit and tell the user it's ready for review.
|
|
123
|
+
- **Feedback arrives as file edits (inline comments, strikethroughs) or chat — check both.** Read `git diff`: the diff is the review artifact.
|
|
124
|
+
- **Update, commit, repeat** until the Decisions table is filled and the user says "go."
|
|
125
|
+
|
|
126
|
+
## Pipeline
|
|
127
|
+
|
|
128
|
+
| Stage | This skill's phase | Output | Next |
|
|
129
|
+
|-------|--------------------|--------|------|
|
|
130
|
+
| Explore a fuzzy ask | Intake | engineering brief + master prompt | HLD |
|
|
131
|
+
| Decide *what* to build | HLD | `*-hld.md` (Decisions filled) | LLD |
|
|
132
|
+
| Detail *how* to build | LLD | `*-lld.md` | `forgecad-make-a-model` + `forgecad` → `.forge.js` |
|
|
@@ -8,7 +8,7 @@ forgecad-public: true
|
|
|
8
8
|
|
|
9
9
|
## Scope
|
|
10
10
|
|
|
11
|
-
Only for artifacts already concrete enough to visualize (a specific `.forge.js` model, build brief, or HLD); route vague briefs to `forgecad-
|
|
11
|
+
Only for artifacts already concrete enough to visualize (a specific `.forge.js` model, build brief, or HLD); route vague briefs to `forgecad-spec-by-walking-through-it` first. Read minimum context — entry `.forge.js`, one key helper if it delegates geometry, brief/HLD — and capture what must survive the image model: artifact type and scale, major subassemblies, actuation style, visible mechanisms, material and color cues.
|
|
12
12
|
|
|
13
13
|
## Core Rule
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ A blockout is a spatial planning artifact: 3-7 simple masses that answer where p
|
|
|
18
18
|
| Need | Skill |
|
|
19
19
|
|------|-------|
|
|
20
20
|
| High-level 3D idea using simple masses | `forgecad-blockout-model` |
|
|
21
|
-
| Written concept or architecture before CAD | `forgecad-
|
|
21
|
+
| Written concept or architecture before CAD | `forgecad-spec-by-walking-through-it` |
|
|
22
22
|
| Accurate, detailed, parametric ForgeCAD model | `forgecad-make-a-model` |
|
|
23
23
|
|
|
24
24
|
### Method
|
|
@@ -18,7 +18,7 @@ The reference image is evidence, not the deliverable. The deliverable is a real
|
|
|
18
18
|
### Companion Skills
|
|
19
19
|
|
|
20
20
|
- `forgecad` — API docs, model authoring, renderer behavior.
|
|
21
|
-
- `forgecad-
|
|
21
|
+
- `forgecad-spec-by-walking-through-it` — when the images underdetermine artifact family, process posture, scale, operating story, or validation boundary.
|
|
22
22
|
- `forgecad-make-a-model` — file placement, project structure, decomposition, definition of done.
|
|
23
23
|
- `forgecad-render-inspect` — pre-delivery inspection for multi-part, internal, mechanical, thin-wall, or fit-sensitive objects.
|
|
24
24
|
|
|
@@ -30,7 +30,7 @@ Infer the real object before matching any camera — identity, manufacture, scal
|
|
|
30
30
|
|
|
31
31
|
1. Stage references in `/tmp/<slug>-replicate/refs`, keeping originals and adding view names where possible (`front`, `side`, `rear-iso`, `top`, `detail`).
|
|
32
32
|
2. Read each image as evidence, recording: visible facts; scale cues; camera cues; unknowns (hidden/occluded geometry); conflicts across images or stylization.
|
|
33
|
-
3. Write a Real Object Brief — a hard gate before modeling: (a) artifact identity + operating story; (b) assumed scale and units; (c) process posture + part/BOM boundary (real geometry vs purchased vs ghost vs omitted); (d) inferred hidden-side geometry + expected canonical front/back/left/right/top/bottom forms; (e) validation views and inspection evidence. Use `forgecad-
|
|
33
|
+
3. Write a Real Object Brief — a hard gate before modeling: (a) artifact identity + operating story; (b) assumed scale and units; (c) process posture + part/BOM boundary (real geometry vs purchased vs ghost vs omitted); (d) inferred hidden-side geometry + expected canonical front/back/left/right/top/bottom forms; (e) validation views and inspection evidence. Use `forgecad-spec-by-walking-through-it` when these are underdetermined.
|
|
34
34
|
4. Build a coarse 3D blockout — model the object, not the image: large volumes, axes, symmetry, side depth, rear form, underside, hidden continuations. Render canonical views before any reference-camera comparison. Follow `forgecad-make-a-model` for project structure.
|
|
35
35
|
5. Calibrate one camera per usable reference, only after the blockout makes sense from canonical views. Use the object center as `target`; estimate azimuth/elevation/distance/FOV from visible faces and perspective cues; use orthographic when parallel edges stay parallel with no perspective convergence.
|
|
36
36
|
6. Render comparison boards: render the model from each calibrated reference camera and place it next to the original. Never compare from memory.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!-- Generated by scripts/build-forgecad-skill.mjs — do not edit. Edit agent-skill-library/forgecad-mujoco-verify/SKILL.md instead. -->
|
|
2
|
+
|
|
3
|
+
# forgecad-mujoco-verify
|
|
4
|
+
|
|
5
|
+
Verify ForgeCAD MJCF exports in MuJoCo with real dynamics, contacts, root behavior, controls, required joint travel, and rendered evidence before calling a model simulation-ready. Use when making a ForgeCAD assembly sim-ready, debugging MJCF contacts, checking why a body falls through the floor, validating actuator motion, or proving a mechanism moved through the intended range.
|
|
6
|
+
|
|
7
|
+
| Field | Value |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| Installed by | `forgecad skill install` |
|
|
10
|
+
| Source | `agent-skill-library/forgecad-mujoco-verify/SKILL.md` |
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## ForgeCAD MuJoCo Verify
|
|
15
|
+
|
|
16
|
+
Use this when `forgecad export mjcf ...` is part of the deliverable. A model is not sim-ready just because `forgecad check simready` passes or the MJCF file loads: it must be loaded in MuJoCo, stepped under gravity, driven with the intended controls, contact pairs inspected, and rendered from useful views.
|
|
17
|
+
|
|
18
|
+
Routing: geometry-only visual inspection -> `forgecad-render-inspect`; model authoring/API questions -> `forgecad`; building a new model -> `forgecad-make-a-model`.
|
|
19
|
+
|
|
20
|
+
### Definition Of Done
|
|
21
|
+
|
|
22
|
+
1. **Export from the exact source file.**
|
|
23
|
+
```bash
|
|
24
|
+
rm -rf /tmp/forgecad-mjcf && mkdir -p /tmp/forgecad-mjcf
|
|
25
|
+
forgecad export mjcf path/to/model.forge.js --output /tmp/forgecad-mjcf
|
|
26
|
+
```
|
|
27
|
+
2. **Load the generated scene in MuJoCo.** Use `scene.xml`, not only the model XML, so the floor/camera/package context is included.
|
|
28
|
+
3. **Check the root behavior.** If the model has a free root, it needs real support/contact geometry or an explicit fixed-root export path. Do not hide a floor failure by turning the whole shell into a giant bounding box that blocks moving internals.
|
|
29
|
+
4. **Check initial poses numerically.** For mechanisms, compute the expected body/link axes from the design source and compare them to MuJoCo `xmat`/`xpos`. Joint `ref`/default and connector frames can disagree with visual intuition.
|
|
30
|
+
5. **Keep meaningful collisions.** Do not mark moving functional parts `Sim.collider.none(...)` just to make motion pass. If full visual mesh contact is unstable, use a physically defensible simplified collider or proxy and state what physical surface it represents.
|
|
31
|
+
6. **Run the intended control with numeric acceptance criteria.** Define the expected signed post-settle joint travel before running the test: e.g. "this drive should rotate the drum -0.04 to -0.06 cycles, then stop near zero velocity" or "this wheel should move at least +1 cycle and keep spinning". Use cycles for revolute/indexing mechanisms when that is easier to reason about, and radians for direct MuJoCo qpos checks. A controller that only jitters, moves the wrong direction, overshoots through a stop, or eventually jams after skipping the intended state is a failure even when the process exits 0.
|
|
32
|
+
7. **Inspect contact pairs.** Contact names should match the physical story: floor/support, card/card, wheel/ground, stop/follower, etc. Contacts against a filled-in AABB, hidden fixture, or unrelated side plate usually indicate bad collider selection.
|
|
33
|
+
8. **Render evidence.** Save initial, settled, and driven frames from views that actually show the moving parts. If the model orientation is not obvious, generate a labeled camera preview grid first, inspect it, then rerun with the azimuth/elevation that shows the functional face. Do not report GIFs/frames before visually confirming they are not from the back, underside, or an occluded side.
|
|
34
|
+
|
|
35
|
+
### Helper Script
|
|
36
|
+
|
|
37
|
+
This skill ships a MuJoCo smoke verifier:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv run --python 3.11 --with mujoco --with pillow \
|
|
41
|
+
python <this-skill-dir>/scripts/mujoco_verify.py /tmp/forgecad-mjcf \
|
|
42
|
+
--settle-seconds 2 \
|
|
43
|
+
--seconds 8 \
|
|
44
|
+
--actuator drum_velocity=-0.75 \
|
|
45
|
+
--watch-joint drum_joint \
|
|
46
|
+
--expect-drive-cycles drum_joint=-0.06:-0.03 \
|
|
47
|
+
--expect-final-qvel drum_joint=-0.02:0.02 \
|
|
48
|
+
--render-dir /tmp/forgecad-mjcf/verify \
|
|
49
|
+
--camera-preview-grid
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use `--actuator name=value` more than once for multi-actuator models. Use `--expect-drive-cycles joint=min:max` to assert signed final-minus-settled revolute travel in cycles/turns. Use `--expect-drive-delta joint=min:max` when you want raw MuJoCo qpos units instead. Use `--expect-final-qvel joint=min:max` to assert terminal velocity when the mechanism should stop or continue at a bounded speed. The script prints JSON with root drift, initial-to-final joint delta, post-settle drive delta, derived cycle counts, final velocities, expectation ranges, and top contact pairs, then writes PNG frames if `--render-dir` is supplied.
|
|
53
|
+
|
|
54
|
+
Prefer explicit travel envelopes over loose "it moved" checks:
|
|
55
|
+
|
|
56
|
+
- Stops/latches: assert a signed drive cycle or delta range and a near-zero final velocity range.
|
|
57
|
+
- Continuous drives: assert the signed drive cycle/delta is large enough over the run and final velocity remains in the expected direction/range.
|
|
58
|
+
- Indexing mechanisms: assert the expected cycle step size, not just eventual stall. If the mechanism reaches a stop only after skipping several indices, treat that as failure.
|
|
59
|
+
- Gravity-settling mechanisms: evaluate functional travel with post-settle drive delta, not initial-to-final delta.
|
|
60
|
+
|
|
61
|
+
When rendered orientation matters, start with `--camera-preview-grid`, open `camera_preview_grid.png`, pick the azimuth that shows the mechanism face or contact interface, then rerun with `--camera-azimuth <deg>` and any needed `--camera-lookat`, `--camera-distance`, or `--camera-elevation` adjustment. For mechanism evidence, prefer front/front-quarter views for user-facing GIFs and add a side/contact view only when it explains a collision better.
|
|
62
|
+
|
|
63
|
+
### Contact Debugging Rules
|
|
64
|
+
|
|
65
|
+
- In MuJoCo UI, enable contact visualization with `Rendering` -> `Contact points` and `Contact forces`; use the right-side perturb/visualization panels if available in your build.
|
|
66
|
+
- If rotation is blocked, list contacts during the stall and sort by repeated pairs. The blocker is usually the pair that appears every step while the driven joint velocity trends to zero.
|
|
67
|
+
- If a body falls through the floor, inspect the exported geoms. Visual geoms have `contype="0" conaffinity="0"` and cannot support anything; collision geoms are usually group 3.
|
|
68
|
+
- Bounding boxes are fast but dangerous for hollow frames, windows, handles, and side plates. They collide as the filled AABB, not the visible object.
|
|
69
|
+
- Mesh collision on complex moving parts can be too exact or solver-hostile. Prefer simple physical proxies for contact-critical moving bodies, such as a slab for a flap card or cylinders for rolling contact, but keep them colliding.
|
|
70
|
+
|
|
71
|
+
### Reporting
|
|
72
|
+
|
|
73
|
+
Report the exact export command, the MuJoCo command/script, key numeric results, the most important contact pairs, and the rendered image paths. Say what was not verified. Never say "sim-ready" when only `forgecad run`, `forgecad check simready`, or a successful export was executed.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Bundled Files
|
|
77
|
+
|
|
78
|
+
- `scripts/mujoco_verify.py`
|