Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: _meshfile_object loaders. #112

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Binary file added examples/HeadTextureMultisense.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/HeadTextureMultisenseBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/HeadTextureMultisenseRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
302 changes: 302 additions & 0 deletions examples/color_texture_collada_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "938dafc7",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"import time\n",
"\n",
"import meshcat\n",
"import urllib\n",
"import yaml\n",
"import io"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1d62c55e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You can open the visualizer by visiting the following URL:\n",
"http://127.0.0.1:7000/static/\n"
]
}
],
"source": [
"# Create a new visualizer\n",
"vis = meshcat.Visualizer()\n",
"# we'll put it in a jupyter cell further down"
]
},
{
"cell_type": "markdown",
"id": "5e3add6b",
"metadata": {},
"source": [
"# WIP `_meshfile_object` Loaders\n",
"\n",
"This notebook is an example test of functionality added to address `meshcat-python` [Issue #92](https://github.com/rdeits/meshcat-python/issues/92) and likely makes some progress on [Issue #27](https://github.com/rdeits/meshcat-python/issues/27)"
]
},
{
"cell_type": "markdown",
"id": "63ef1047",
"metadata": {},
"source": [
"# Visualize UR3e Robot In Color"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dbde04f3",
"metadata": {},
"outputs": [],
"source": [
"ur_meshdir_template = 'https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/{0}'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8aac9985",
"metadata": {},
"outputs": [],
"source": [
"# -- calculated offline with Pinocchio -- \n",
"link_poses_yaml_str = '''base.dae:\n",
"- [1.0, 2.4492935982947064e-16, 0.0, 0.0]\n",
"- [-2.4492935982947064e-16, 1.0, 0.0, 0.0]\n",
"- [0.0, 0.0, 1.0, 0.0]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"shoulder.dae:\n",
"- [1.0, 2.4492935982947064e-16, 0.0, 0.0]\n",
"- [-2.4492935982947064e-16, 1.0, 0.0, 0.0]\n",
"- [0.0, 0.0, 1.0, 0.15185]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"upperarm.dae:\n",
"- [-2.5117933221343742e-26, 1.2246467991473532e-16, 1.0, 1.4695761589768237e-17]\n",
"- [-2.0510348974767112e-10, 1.0, -1.2246467991473532e-16, 0.12]\n",
"- [-1.0, -2.0510348974767112e-10, 0.0, 0.1518499999753876]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"forearm.dae:\n",
"- [-2.5117933221343742e-26, 1.2246467991473532e-16, 1.0, 0.24355]\n",
"- [-2.0510348974767112e-10, 1.0, -1.2246467991473532e-16, 0.02699999999999997]\n",
"- [-1.0, -2.0510348974767112e-10, 0.0, 0.15184999999446222]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"wrist1.dae:\n",
"- [-1.0, 1.2246467991473535e-16, -2.5117960413965218e-26, 0.45675]\n",
"- [1.2246467991473532e-16, 1.0000000000000002, -2.051037117922761e-10, 0.02704999999999995]\n",
"- [0.0, -2.051037117922761e-10, -1.0000000000000002, 0.15184999999445198]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"wrist2.dae:\n",
"- [-1.0, 1.2246467991473532e-16, -5.0235866442687483e-26, 0.45675]\n",
"- [1.2246467991473532e-16, 1.0, -4.1020697949534224e-10, 0.13104999999999994]\n",
"- [0.0, -4.1020697949534224e-10, -1.0, 0.1518499999731212]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"wrist3.dae:\n",
"- [-1.0, 2.511789568559801e-26, -1.2246467996497122e-16, 0.45675]\n",
"- [5.0235866442687483e-26, 1.0000000000000002, -2.051037117922761e-10, 0.13104999996498878]\n",
"- [1.224646799649712e-16, -2.051037117922761e-10, -1.0000000000000002, 0.0664999999731212]\n",
"- [0.0, 0.0, 0.0, 1.0]\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "20e5be4d",
"metadata": {},
"outputs": [],
"source": [
"link_pose_transforms = {k:np.asarray(v) for k, v in yaml.safe_load(link_poses_yaml_str).items()}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0c90cc86",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/base.dae\n",
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/shoulder.dae\n",
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/upperarm.dae\n",
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/forearm.dae\n",
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/wrist1.dae\n",
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/wrist2.dae\n",
"https://raw.githubusercontent.com/Gepetto/example-robot-data/master/robots/ur_description/meshes/ur3/visual/wrist3.dae\n"
]
}
],
"source": [
"vis.delete()\n",
"link_meshes = []\n",
"for link_name, link_transform in link_pose_transforms.items():\n",
" dae_url = ur_meshdir_template.format(link_name)\n",
" print(dae_url)\n",
" response = urllib.request.urlopen(dae_url)\n",
" dae_contents_str = response.read().decode('utf-8')\n",
" link = meshcat.geometry.DaeMeshFileObject(dae_contents_str) #won't work with textured image .from_file() loads\n",
" linkpath = '/meshcat/ur3/{0}'.format(link_name)\n",
" vis[linkpath].set_object(link)\n",
" vis[linkpath].set_transform(link_transform)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e5f1deb4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div style=\"height: 600px; width: 100%; overflow-x: auto; overflow-y: hidden; resize: both\">\n",
" <iframe src=\"http://127.0.0.1:7000/static/\" style=\"width: 100%; height: 100%; border: none\"></iframe>\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vis.jupyter_cell(height=600)"
]
},
{
"cell_type": "markdown",
"id": "6ac5f370",
"metadata": {},
"source": [
"# Collada Head - New Blue png Texture"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a849e7c9",
"metadata": {},
"outputs": [],
"source": [
"head_file = 'head_multisense_png.dae'\n",
"head = meshcat.geometry.DaeMeshFileObject.from_file(head_file)\n",
"vis['robots/png_blue/head'].set_object(head)\n",
"Th = np.array([[ 0. , 0. , -1. , 0.45675],\n",
" [ 1. , 0. , 0. , 0.28105],\n",
" [ 0. , -1. , 0. , 0.0665 ],\n",
" [ 0. , 0. , 0. , 1. ]])\n",
"\n",
"vis['robots/png_blue/head'].set_transform(Th)"
]
},
{
"cell_type": "markdown",
"id": "3c49d6a1",
"metadata": {},
"source": [
"# Collada Head - New Green jpeg Texture"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "55421840",
"metadata": {},
"outputs": [],
"source": [
"robots/jpg_green/head_file = 'head_multisense_jpg.dae'\n",
"robots/jpg_green/head = meshcat.geometry.DaeMeshFileObject.from_file(robots/jpg_green/head_file)\n",
"vis['robots/jpg_green/head'].set_object(robots/jpg_green/head)\n",
"Tjh = Th.copy()\n",
"Tjh[2, 3] += 0.3\n",
"vis['robots/jpg_green/head'].set_transform(Tjh)"
]
},
{
"cell_type": "markdown",
"id": "c08ac034",
"metadata": {},
"source": [
"# Collada Head - Original Example"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "618d61dc",
"metadata": {},
"outputs": [],
"source": [
"vis['robots/valkyrie/head'].set_object(\n",
" meshcat.geometry.ObjMeshGeometry.from_file(\n",
" os.path.join(meshcat.viewer_assets_path(), 'data/head_multisense.obj')),\n",
" meshcat.geometry.MeshLambertMaterial(\n",
" map=meshcat.geometry.ImageTexture(\n",
" image=meshcat.geometry.PngImage.from_file(\n",
" os.path.join(meshcat.viewer_assets_path(), 'data/HeadTextureMultisense.png'))\n",
" )\n",
" )\n",
")\n",
"Tvh = Tjh.copy()\n",
"Tvh[0, 3] -= 0.3\n",
"# should export the other Collada heads so this extra rotation isn't necessary\n",
"Rrel = np.array([[ 0., 0., 1.],\n",
" [ 0., 1., 0.],\n",
" [-1., 0., 0.]])\n",
"Tvh[0:3, 0:3] = Rrel@Tvh[0:3, 0:3]\n",
"vis['robots/valkyrie/head'].set_transform(Tvh)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fead4b44",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading