Skip to content

Commit

Permalink
visualizer: change set_cam_target to expect right-handed coord input
Browse files Browse the repository at this point in the history
* update docstring of set_cam_target
* fix set_cam_pos behavior
* update demo.ipynb with example on changing cam focus & position
  • Loading branch information
ManifoldFR committed Jan 24, 2023
1 parent bf37015 commit 8affad0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
49 changes: 46 additions & 3 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"## Cart-Pole\n",
"\n",
Expand Down Expand Up @@ -453,6 +455,47 @@
" time.sleep(0.01)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's set the camera position to above left of the cartpole:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vis.jupyter_cell()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vis.set_cam_pos([0.6, -1.0, 1.0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's change the focus to the leftmost 'l' character:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vis.set_cam_target([0.0, -1.0, 0.0])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -477,9 +520,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion src/meshcat/viewer
8 changes: 5 additions & 3 deletions src/meshcat/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ def set_animation(self, animation, play=True, repetitions=1):
return self.window.send(SetAnimation(animation, play=play, repetitions=repetitions))

def set_cam_target(self, value):
"""Set camera target."""
return self.window.send(SetCamTarget(value))
"""Set camera target (in right-handed coordinates (x,y,z))."""
v = list(value)
v[1], v[2] = v[2], -v[1] # convert to left-handed (x,z,-y)
return self.window.send(SetCamTarget(v))

def set_cam_pos(self, value):
"""Set camera position (in right-handed coordinates (x,y,z))."""
path = "/Cameras/default/rotated/<object>"
v = list(value)
v[1], v[2] = v[2], -v[1] # convert to left-handed (x,z,-y)
return self[path].set_property("position", value)
return self[path].set_property("position", v)

def get_image(self, w=None, h=None):
"""Save an image"""
Expand Down

0 comments on commit 8affad0

Please sign in to comment.