Skip to content

Commit

Permalink
[geometry] Install meshcat data files
Browse files Browse the repository at this point in the history
Without this, Meshcat worked fine in the source tree, but was unable to locate it's resources in the installation directory.
  • Loading branch information
RussTedrake committed Aug 29, 2021
1 parent 33145e7 commit c392a83
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 4 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ install(
deps = [
"//bindings/pydrake:install",
"//common:install",
"//doc:install",
"//examples:install",
"//geometry:install",
"//lcmtypes:install",
"//manipulation/models:install_data",
"//setup:install",
Expand Down
16 changes: 16 additions & 0 deletions doc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ load(
"DEFAULT_TEST_TAGS",
"enumerate_filegroup",
)
load("@drake//tools/install:install.bzl", "install", "install_files")
load("//tools/lint:lint.bzl", "add_lint_tests")

drake_py_library(
Expand Down Expand Up @@ -82,6 +83,13 @@ filegroup(
],
)

# favicon.ico is used by //geometry:meshcat.
install_files(
name = "install_favicon",
dest = "share/drake/doc",
files = ["favicon.ico"],
)

enumerate_filegroup(
name = "pages_input.txt",
data = [":pages_input"],
Expand Down Expand Up @@ -143,4 +151,12 @@ test_suite(
],
)

install(
name = "install",
visibility = ["//visibility:public"],
deps = [
":install_favicon",
],
)

add_lint_tests()
22 changes: 21 additions & 1 deletion geometry/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_binary",
)
load("@drake//tools/install:install.bzl", "install", "install_files")
load("//tools/lint:lint.bzl", "add_lint_tests")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -360,8 +361,8 @@ drake_cc_library(
srcs = ["meshcat.cc"],
hdrs = ["meshcat.h"],
data = [
"meshcat.html",
"//doc:favicon",
"@meshcat//:dist/index.html",
"@meshcat//:dist/main.min.js",
],
deps = [
Expand All @@ -378,6 +379,17 @@ drake_cc_library(
],
)

exports_files(
["meshcat.html"],
visibility = ["//visibility:public"],
)

install_files(
name = "install_meshcat_html",
dest = "share/drake/geometry",
files = ["meshcat.html"],
)

drake_cc_binary(
name = "meshcat_manual_test",
testonly = True,
Expand Down Expand Up @@ -652,4 +664,12 @@ drake_cc_googletest(
],
)

install(
name = "install",
visibility = ["//visibility:public"],
deps = [
":install_meshcat_html",
],
)

add_lint_tests()
3 changes: 1 addition & 2 deletions geometry/meshcat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ const std::string& GetUrlContent(std::string_view url_path) {
LoadResource("drake/external/meshcat/dist/main.min.js"));
static const drake::never_destroyed<std::string> favicon_ico(
LoadResource("drake/doc/favicon.ico"));
// TODO(russt): Set the different default background color for Drake.
static const drake::never_destroyed<std::string> index_html(
LoadResource("drake/external/meshcat/dist/index.html"));
LoadResource("drake/geometry/meshcat.html"));
if (url_path == "/main.min.js") {
return main_min_js.access();
}
Expand Down
38 changes: 38 additions & 0 deletions geometry/meshcat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Drake MeshCat</title>
</head>
<body>
<div id="meshcat-pane">
</div>

<script type="text/javascript" src="main.min.js"></script>
<script>
var viewer = new MeshCat.Viewer(document.getElementById("meshcat-pane"));
// Set background to match Drake Visualizer.
viewer.set_property(['Background'],'top_color', [242, 242, 255])
viewer.set_property(['Background'], "bottom_color", [77, 77, 89])
try {
viewer.connect();
} catch (e) {
console.info("Not connected to MeshCat websocket server: ", e);
}
</script>


<style>
body {
margin: 0;
}

#meshcat-pane {
width: 100vw;
height: 100vh;
overflow: hidden;
}
</style>
<script id="embedded-json"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions tools/install/bazel/generate_installed_files_manifest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def _impl(ctx):
known_non_runfiles = [
# These are installed in share/drake, but are not runfiles (at least,
# not with these paths).
"doc/favicon.ico",
"external/meshcat/dist/index.html",
"external/meshcat/dist/main.min.js",
"geometry/meshcat.html",
"setup/Brewfile",
"setup/install_prereqs",
"setup/packages-bionic.txt",
Expand Down
12 changes: 11 additions & 1 deletion tools/workspace/meshcat/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ install_files(
files = VIEWER_FILES,
)

# main.min.js is used by //geometry:meshcat.
install_files(
name = "install_viewer_to_share",
dest = "share/drake/external/meshcat",
files = VIEWER_FILES,
)

install(
name = "install",
docs = ["LICENSE"],
visibility = ["//visibility:public"],
deps = [":install_viewer"],
deps = [
":install_viewer",
":install_viewer_to_share",
],
)

0 comments on commit c392a83

Please sign in to comment.