Skip to content

Commit f2afc43

Browse files
committed
Fix demo hub GUI docking and pendulum setup
1 parent c887944 commit f2afc43

File tree

6 files changed

+58
-50
lines changed

6 files changed

+58
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ gh-pages/
8585

8686
# ImGui configuration
8787
imgui.ini
88+
DART_Demo_Hub__Python_.ini
8889

8990
# Temporary directory for dependencies
9091
.deps/

pixi.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ config-py = { cmd = [
378378
{ arg = "build_type", default = "Release" },
379379
] }
380380

381-
py-ex = { cmd = ["python", "scripts/run_py_example.py"], depends-on = [
381+
py-ex = { cmd = [
382+
"python",
383+
"scripts/run_py_example.py",
384+
], depends-on = [
382385
"build-py-dev",
383386
], env = { BUILD_TYPE = "Release", LD_LIBRARY_PATH = "$CONDA_PREFIX/lib:${LD_LIBRARY_PATH:-}" } }
384387

python/demo_hub/gui/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def _simulate(state: GuiState) -> None:
6969

7070

7171
def _render(state: GuiState) -> None: # pragma: no cover - manual UI
72+
io = imgui.get_io()
73+
io.config_flags |= imgui.ConfigFlags_.docking_enable
74+
imgui.dock_space_over_viewport(0, imgui.get_main_viewport())
75+
7276
_simulate(state)
7377

7478
imgui.begin("Demo Hub")

python/demo_hub/gui/viewport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ def draw_topdown(name: str, segments: Iterable[Segment2D], size=(0, 0)) -> None:
4242

4343
def project(pt):
4444
x, z = pt
45-
return offset_x + (x - center_x) * scale, offset_z - (z - center_z) * scale
45+
return imgui.ImVec2(offset_x + (x - center_x) * scale, offset_z - (z - center_z) * scale)
4646

4747
for seg in segs:
4848
c = seg.color
4949
col = imgui.get_color_u32(imgui.ImVec4(c[0], c[1], c[2], 1.0))
5050
p0 = project(seg.start)
5151
p1 = project(seg.end)
52-
draw_list.add_line(p0[0], p0[1], p1[0], p1[1], col, thickness=2.0)
52+
draw_list.add_line(p0, p1, col, thickness=2.0)
5353

5454
imgui.end()

python/demo_hub/scenes/pendulum/scene.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ def _build_chain(self, pendulum: dart.dynamics.Skeleton) -> None:
109109
inertia = self._make_link_inertia(length, radius, mass)
110110

111111
# Root ball joint at the origin.
112-
ball_props = dart.dynamics.BallJointProperties()
113-
ball_props.mName = "root_joint"
114-
ball_props.mRestPositions = [0.0, 0.0, 0.0]
115-
ball_props.mSpringStiffnesses = [1.5, 1.5, 1.5]
116-
ball_props.mDampingCoefficients = [0.02, 0.02, 0.02]
117-
118-
root_body_props = dart.dynamics.BodyNodeProperties()
119-
root_body_props.mName = "link0"
120-
root_body_props.mInertia = inertia
121-
122-
root_joint, root_body = pendulum.createBallJointAndBodyNodePair(None, ball_props, root_body_props)
112+
root_joint, root_body = pendulum.createBallJointAndBodyNodePair(None)
113+
root_joint.setName("root_joint")
114+
for i in range(3):
115+
root_joint.setRestPosition(i, 0.0)
116+
root_joint.setSpringStiffness(i, 1.5)
117+
root_joint.setDampingCoefficient(i, 0.02)
118+
119+
root_body.setName("link0")
120+
root_body.setInertia(inertia)
123121
self._attach_geometry(root_body, radius, length)
124122

125123
parent = root_body

scripts/run_py_example.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,47 @@
88

99

1010
def _resolve_example(args: list[str]) -> tuple[str, list[str]]:
11-
"""Return (example, remaining_args) picking the first non-flag arg or EXAMPLE env."""
12-
remaining = list(args)
13-
if remaining and not remaining[0].startswith("-"):
14-
example = remaining.pop(0)
15-
else:
16-
example = os.environ.get("EXAMPLE", "hello_world")
17-
while remaining and remaining[0] == "--":
18-
remaining.pop(0)
19-
return example, remaining
11+
"""Return (example, remaining_args) picking the first non-flag arg or EXAMPLE env."""
12+
remaining = list(args)
13+
if remaining and not remaining[0].startswith("-"):
14+
example = remaining.pop(0)
15+
else:
16+
example = os.environ.get("EXAMPLE", "hello_world")
17+
while remaining and remaining[0] == "--":
18+
remaining.pop(0)
19+
return example, remaining
2020

2121

2222
def main(argv: list[str]) -> int:
23-
repo_root = Path(__file__).resolve().parent.parent
24-
example, remaining = _resolve_example(argv)
25-
26-
script = repo_root / "python" / "examples" / example / "main.py"
27-
if not script.exists():
28-
sys.stderr.write(f"Python example not found: {script}\n")
29-
return 1
30-
31-
build_type = os.environ.get("BUILD_TYPE", "Release")
32-
env_name = os.environ.get("PIXI_ENVIRONMENT_NAME", "default")
33-
py_path = repo_root / "build" / env_name / "cpp" / build_type / "python"
34-
35-
env = os.environ.copy()
36-
existing = env.get("PYTHONPATH", "")
37-
env["PYTHONPATH"] = f"{py_path}:{existing}" if existing else str(py_path)
38-
# Ensure conda libs (glfw, imgui, OpenGL) are ahead of system paths.
39-
conda_prefix = env.get("CONDA_PREFIX")
40-
if conda_prefix:
41-
ld_paths = env.get("LD_LIBRARY_PATH", "")
42-
env["LD_LIBRARY_PATH"] = f"{conda_prefix}/lib:{ld_paths}" if ld_paths else f"{conda_prefix}/lib"
43-
preload = env.get("LD_PRELOAD", "")
44-
glfw_lib = f"{conda_prefix}/lib/libglfw.so"
45-
env["LD_PRELOAD"] = f"{glfw_lib}:{preload}" if preload else glfw_lib
46-
47-
cmd = [sys.executable, str(script), *remaining]
48-
return subprocess.call(cmd, env=env, cwd=repo_root)
23+
repo_root = Path(__file__).resolve().parent.parent
24+
example, remaining = _resolve_example(argv)
25+
26+
script = repo_root / "python" / "examples" / example / "main.py"
27+
if not script.exists():
28+
sys.stderr.write(f"Python example not found: {script}\n")
29+
return 1
30+
31+
build_type = os.environ.get("BUILD_TYPE", "Release")
32+
env_name = os.environ.get("PIXI_ENVIRONMENT_NAME", "default")
33+
py_path = repo_root / "build" / env_name / "cpp" / build_type / "python"
34+
35+
env = os.environ.copy()
36+
existing = env.get("PYTHONPATH", "")
37+
env["PYTHONPATH"] = f"{py_path}:{existing}" if existing else str(py_path)
38+
# Ensure conda libs (glfw, imgui, OpenGL) are ahead of system paths.
39+
conda_prefix = env.get("CONDA_PREFIX")
40+
if conda_prefix:
41+
ld_paths = env.get("LD_LIBRARY_PATH", "")
42+
env["LD_LIBRARY_PATH"] = (
43+
f"{conda_prefix}/lib:{ld_paths}" if ld_paths else f"{conda_prefix}/lib"
44+
)
45+
preload = env.get("LD_PRELOAD", "")
46+
glfw_lib = f"{conda_prefix}/lib/libglfw.so"
47+
env["LD_PRELOAD"] = f"{glfw_lib}:{preload}" if preload else glfw_lib
48+
49+
cmd = [sys.executable, str(script), *remaining]
50+
return subprocess.call(cmd, env=env, cwd=repo_root)
4951

5052

5153
if __name__ == "__main__":
52-
raise SystemExit(main(sys.argv[1:]))
54+
raise SystemExit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)