Skip to content

Commit

Permalink
Update notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrolho committed Mar 17, 2024
1 parent 545a917 commit 093850a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 66 deletions.
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
MeshCat = "283c5d60-a78f-5afe-a0af-af636b173e11"

[compat]
Documenter = "0.24"
Documenter = "1"
2 changes: 1 addition & 1 deletion notebooks/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Colors = "0.9, 0.10, 0.11, 0.12"
FileIO = "1"
GeometryBasics = "0.3, 0.4"
MeshIO = "0.4"
Meshing = "0.5"
Meshing = "0.5, 0.6"
28 changes: 13 additions & 15 deletions notebooks/Static HTML Visualizers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,19 @@
"outputs": [],
"source": [
"vis = Visualizer()\n",
"setobject!(vis[:box1], \n",
" Rect(Vec(0., 0, 0), Vec(0.1, 0.2, 0.3)))\n",
"setobject!(vis[:box1], Rect(Vec(0.0, 0, 0), Vec(0.1, 0.2, 0.3)))\n",
"anim = Animation()\n",
"atframe(anim, 0) do\n",
" settransform!(vis[:box1], \n",
" Translation(0., 0, -1) ∘ LinearMap(RotZ(-π/2)))\n",
" settransform!(vis[:box1],\n",
" Translation(0.0, 0, -1) ∘ LinearMap(RotZ(-π / 2)))\n",
"end\n",
"atframe(anim, 30) do\n",
" settransform!(vis[:box1], \n",
" Translation(0., 0, 0) ∘ LinearMap(RotY(π/2)) ∘\n",
" LinearMap(RotZ(π/2)))\n",
" settransform!(vis[:box1],\n",
" Translation(0.0, 0, 0) ∘ LinearMap(RotY(π / 2)) ∘ LinearMap(RotZ(π / 2)))\n",
"end\n",
"atframe(anim, 60) do\n",
" settransform!(vis[:box1], \n",
" Translation(0., 0, 1))\n",
" settransform!(vis[:box1],\n",
" Translation(0.0, 0, 1))\n",
"end\n",
"setanimation!(vis, anim)"
]
Expand Down Expand Up @@ -112,8 +110,8 @@
"metadata": {},
"outputs": [],
"source": [
"setobject!(vis[:box1], \n",
" Rect(Vec(0., 0, 0), Vec(0.1, 0.2, 0.3)),\n",
"setobject!(vis[:box1],\n",
" Rect(Vec(0.0, 0, 0), Vec(0.1, 0.2, 0.3)),\n",
" MeshPhongMaterial(color=colorant\"red\"))"
]
},
Expand Down Expand Up @@ -167,17 +165,17 @@
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.6.3",
"display_name": "Julia 1.10.2",
"language": "julia",
"name": "julia-1.6"
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.6.3"
"version": "1.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
39 changes: 18 additions & 21 deletions notebooks/animation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
"metadata": {},
"outputs": [],
"source": [
"setobject!(vis[:box1], \n",
" Rect(Vec(0., 0, 0), Vec(0.1, 0.2, 0.3)))"
"setobject!(vis[:box1], Rect(Vec(0, 0, 0), Vec(0.1, 0.2, 0.3)))"
]
},
{
Expand All @@ -99,11 +98,11 @@
" # `settransform!` and `setprop!` are intercepted\n",
" # and recorded in `anim` instead of having any\n",
" # effect on `vis`.\n",
" settransform!(vis[:box1], Translation(0., 0, 0))\n",
" settransform!(vis[:box1], Translation(0, 0, 0))\n",
"end\n",
"\n",
"atframe(anim, 30) do\n",
" settransform!(vis[:box1], Translation(0., 1, 0))\n",
" settransform!(vis[:box1], Translation(0, 1, 0))\n",
"end\n",
"\n",
"# `setanimation!()` actually sends the animation to the\n",
Expand Down Expand Up @@ -153,13 +152,13 @@
"anim = Animation()\n",
"\n",
"atframe(anim, 0) do\n",
" settransform!(vis[\"/Cameras/default\"], Translation(0., 0, 0))\n",
" settransform!(vis[\"/Cameras/default\"], Translation(0, 0, 0))\n",
"end\n",
"\n",
"atframe(anim, 30) do\n",
" settransform!(vis[\"/Cameras/default\"], Translation(0., 0, 1))\n",
" settransform!(vis[\"/Cameras/default\"], Translation(0, 0, 1))\n",
"end\n",
" \n",
"\n",
"setanimation!(vis, anim)"
]
},
Expand All @@ -179,17 +178,17 @@
"anim = Animation()\n",
"\n",
"atframe(anim, 0) do\n",
" setprop!(vis[\"/Cameras/default/rotated/<object>\"], \"zoom\", 1)\n",
" setprop!(vis[\"/Cameras/default/rotated/<object>\"], \"zoom\", 1.0)\n",
"end\n",
"\n",
"atframe(anim, 30) do\n",
" setprop!(vis[\"/Cameras/default/rotated/<object>\"], \"zoom\", 0.5)\n",
"end\n",
"\n",
"atframe(anim, 60) do\n",
" setprop!(vis[\"/Cameras/default/rotated/<object>\"], \"zoom\", 1)\n",
" setprop!(vis[\"/Cameras/default/rotated/<object>\"], \"zoom\", 1.0)\n",
"end\n",
" \n",
"\n",
"setanimation!(vis, anim)"
]
},
Expand All @@ -210,10 +209,8 @@
"metadata": {},
"outputs": [],
"source": [
"setobject!(vis[:box1], \n",
" Rect(Vec(0., 0, 0), Vec(0.1, 0.2, 0.3)))\n",
"setobject!(vis[:sphere],\n",
" HyperSphere(Point(0., 0, 0), 0.25))\n",
"setobject!(vis[:box1], Rect(Vec(0.0, 0, 0), Vec(0.1, 0.2, 0.3)))\n",
"setobject!(vis[:sphere], HyperSphere(Point(0.0, 0, 0), 0.25))\n",
"\n",
"# Start with the sphere hidden\n",
"setvisible!(vis[:sphere], false)"
Expand All @@ -228,17 +225,17 @@
"anim = Animation()\n",
"atframe(anim, 0) do\n",
" setvisible!(vis[:sphere], false)\n",
" settransform!(vis[:box1], Translation(0., 0, 0))\n",
" settransform!(vis[:box1], Translation(0.0, 0, 0))\n",
"end\n",
"\n",
"atframe(anim, 15) do\n",
" setvisible!(vis[:sphere], true)\n",
"end\n",
"\n",
"atframe(anim, 30) do\n",
" settransform!(vis[:box1], Translation(0., 1, 0))\n",
" settransform!(vis[:box1], Translation(0.0, 1, 0))\n",
"end\n",
" \n",
"\n",
"setanimation!(vis, anim)"
]
},
Expand Down Expand Up @@ -279,17 +276,17 @@
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.6.3",
"display_name": "Julia 1.10.2",
"language": "julia",
"name": "julia-1.6"
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.6.3"
"version": "1.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
48 changes: 20 additions & 28 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Activate the MeshCat package, and import some other \n",
"# useful functions\n",
"# Activate the MeshCat package, and import some other useful functions\n",
"using MeshCat\n",
"using CoordinateTransformations\n",
"using Rotations\n",
Expand Down Expand Up @@ -126,7 +125,7 @@
"outputs": [],
"source": [
"# First, we'll create a simple geometric object\n",
"box = HyperRectangle(Vec(0., 0, 0), Vec(1., 1, 1))"
"box = HyperRectangle(Vec(0.0, 0, 0), Vec(1.0, 1, 1))"
]
},
{
Expand All @@ -150,7 +149,7 @@
"# We can use settransform!() to tell the viewer to draw the box at a specific\n",
"# position. Translation() creates a CoordinateTransformations.Transformation\n",
"# corresponding to the given x; y; z translation.\n",
"settransform!(vis, Translation(0., 1, 0))"
"settransform!(vis, Translation(0.0, 1, 0))"
]
},
{
Expand All @@ -160,7 +159,7 @@
"outputs": [],
"source": [
"# We can also rotate the model by sending a different transformation\n",
"settransform!(vis, LinearMap(AngleAxis(pi/4, 0, 0, 1)))"
"settransform!(vis, LinearMap(AngleAxis(pi / 4, 0, 0, 1)))"
]
},
{
Expand Down Expand Up @@ -359,10 +358,9 @@
"# just simple boxes. Let's load a 3D mesh and visualize it:\n",
"using MeshIO\n",
"using FileIO\n",
"cat_mesh = load(joinpath(dirname(pathof(MeshCat)), \"..\", \"test\", \"data\", \"meshes\",\n",
" \"cat.obj\"))\n",
"cat_mesh = load(joinpath(dirname(pathof(MeshCat)), \"..\", \"test\", \"data\", \"meshes\", \"cat.obj\"))\n",
"setobject!(vis, cat_mesh)\n",
"settransform!(vis, LinearMap(AngleAxis(pi/2, 1, 0, 0)))"
"settransform!(vis, LinearMap(AngleAxis(pi / 2, 1, 0, 0)))"
]
},
{
Expand All @@ -373,19 +371,18 @@
"source": [
"delete!(vis)\n",
"\n",
"# Next, let's create a triangulated mesh by finding\n",
"# the 0-level set of some function. \n",
"# \n",
"# Next, let's create a triangulated mesh by finding the 0-level set of some function. \n",
"\n",
"# First, we'll define our function:\n",
"f = x -> sum(sin, 5 * x)\n",
"\n",
"# Then we pick a region of interest in which to sample the function.\n",
"# This region starts at (-1, -1, -1) and extends to (1, 1, 1):\n",
"lower_bound = Vec(-1.,-1,-1)\n",
"upper_bound = Vec(1., 1, 1)\n",
"lower_bound = Vec(-1.0, -1, -1)\n",
"upper_bound = Vec(1.0, 1, 1)\n",
"\n",
"# Those two pieces of information are all we need to construct a mesh geometry.\n",
"#\n",
"\n",
"# Using `Meshing.jl`, we can construct a mesh directly from our function:\n",
"using Meshing: MarchingCubes\n",
"\n",
Expand Down Expand Up @@ -475,8 +472,7 @@
"metadata": {},
"outputs": [],
"source": [
"image = PngImage(\n",
" joinpath(MeshCat.VIEWER_ROOT, \"..\", \"data\", \"HeadTextureMultisense.png\"))\n",
"image = PngImage(joinpath(MeshCat.VIEWER_ROOT, \"..\", \"data\", \"HeadTextureMultisense.png\"))\n",
"texture = Texture(image=image)\n",
"material = MeshLambertMaterial(map=texture)\n",
"geometry = load(joinpath(MeshCat.VIEWER_ROOT, \"..\", \"data\", \"head_multisense.obj\"))\n",
Expand All @@ -500,10 +496,8 @@
"outputs": [],
"source": [
"path = joinpath(@__DIR__, \"..\", \"test\", \"data\", \"meshes\", \"cube.dae\")\n",
"setobject!(vis[\"meshes\", \"dae_file_geometry\"], \n",
" MeshFileGeometry(path))\n",
"settransform!(vis[\"meshes\", \"dae_file_geometry\"], \n",
" Translation(0.0, 1.25, 0.0))"
"setobject!(vis[\"meshes\", \"dae_file_geometry\"], MeshFileGeometry(path))\n",
"settransform!(vis[\"meshes\", \"dae_file_geometry\"], Translation(0.0, 1.25, 0.0))"
]
},
{
Expand All @@ -525,10 +519,8 @@
"source": [
"path = joinpath(@__DIR__, \"..\", \"test\", \"data\", \"meshes\", \"cube.dae\")\n",
"\n",
"setobject!(vis[\"meshes\", \"dae_file_object\"], \n",
" MeshFileObject(path))\n",
"settransform!(vis[\"meshes\", \"dae_file_object\"], \n",
" Translation(0.0, 2.5, 0.0))"
"setobject!(vis[\"meshes\", \"dae_file_object\"], MeshFileObject(path))\n",
"settransform!(vis[\"meshes\", \"dae_file_object\"], Translation(0.0, 2.5, 0.0))"
]
}
],
Expand All @@ -538,17 +530,17 @@
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.9.0",
"display_name": "Julia 1.10.2",
"language": "julia",
"name": "julia-1.9"
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.0"
"version": "1.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit 093850a

Please sign in to comment.