Skip to content

Commit e1da28f

Browse files
committed
sample script for markers
1 parent 489cf2d commit e1da28f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

examples/markers_demo.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import mujoco
2+
import mujoco_viewer
3+
import numpy as np
4+
5+
MODEL_XML = """
6+
<?xml version="1.0" ?>
7+
<mujoco>
8+
<asset>
9+
<texture name="body" type="cube" builtin="flat" mark="cross" width="127" height="1278"
10+
rgb1="0.8 0.6 0.4" rgb2="0.8 0.6 0.4" markrgb="1 1 1" random="0.01"/>
11+
<material name="body" texture="body" texuniform="true" rgba="0.8 0.6 .4 1"/>
12+
<texture name="grid" type="2d" builtin="checker" width="512" height="512" rgb1=".1 .2 .3" rgb2=".2 .3 .4"/>
13+
<material name="grid" texture="grid" texrepeat="1 1" texuniform="true" reflectance=".2"/>
14+
</asset>
15+
<worldbody>
16+
<geom name="floor" size="0 0 .05" type="plane" material="grid" condim="3"/>
17+
<body name="box" pos="0 0 1">
18+
<freejoint name="root"/>
19+
<geom size="0.15 0.15 0.15" type="box" material="body" />
20+
</body>
21+
</worldbody>
22+
</mujoco>
23+
"""
24+
25+
model = mujoco.MjModel.from_xml_string(MODEL_XML)
26+
data = mujoco.MjData(model)
27+
28+
# create the viewer object
29+
viewer = mujoco_viewer.MujocoViewer(model, data)
30+
31+
for _ in range(10000):
32+
# sim step
33+
mujoco.mj_step(model, data)
34+
35+
# draw origin
36+
x_dir = [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]
37+
y_dir = [[1, 0, 0], [0, 0, 1], [0, -1, 0]]
38+
z_dir = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
39+
viewer.add_marker(pos=[0, 0, 0], size=[0.05, 0.05, 0.05], rgba=[1, 1, 1, 1], type=mujoco.mjtGeom.mjGEOM_SPHERE, label="origin")
40+
viewer.add_marker(pos=[0, 0, 0], mat=x_dir, size=[0.01, 0.01, 2], rgba=[1, 0, 0, 0.2], type=mujoco.mjtGeom.mjGEOM_ARROW, label="")
41+
viewer.add_marker(pos=[0, 0, 0], mat=y_dir, size=[0.01, 0.01, 2], rgba=[0, 1, 0, 0.2], type=mujoco.mjtGeom.mjGEOM_ARROW, label="")
42+
viewer.add_marker(pos=[0, 0, 0], mat=z_dir, size=[0.01, 0.01, 2], rgba=[0, 0, 1, 0.2], type=mujoco.mjtGeom.mjGEOM_ARROW, label="")
43+
44+
# render
45+
viewer.render()
46+
47+
# close
48+
viewer.close()

0 commit comments

Comments
 (0)