Giter Site home page Giter Site logo

meshcat-cpp's Introduction

meshcat-cpp

C++ Standard Size

Self-contained C++ interface for the MeshCat visualizer.

meshcat-cpp took (heavy) inspiration for C++ (drake) MeshCat interface extensively discussed here. The main purpose of this package is to have an independent (self-contained) C++ library that exposes the MeshCat interface in C++.


🚧 REPOSITORY UNDER DEVELOPMENT 🚧
The library implemented in this repository is still experimental and we cannot guarantee stable API


🏗️ Dependencies

meshcat-cpp is a self-contained library. Most dependencies can be cloned at compile time and they are statically linked to the library. The only dependencies you need is a sufficiently recent C++ compiler (full support to C++20), cmake, openssl, zlib, libuv, boost and pkg-config.

Install dependencies on Debian/Ubuntu

sudo apt install cmake pkg-config build-essential ninja-build git libssl-dev libuv1-dev libz-dev libboost-dev

Install dependencies with conda-forge

mamba create -n meshcatcppdev boost-cpp libuwebsockets cmake pkg-config compilers zlib openssl libuv msgpack-cxx

Then, execute all the other commands after activating the environment:

mamba activate meshcatcppdev

⚒️ Build the library

You can build the library coping and paste the following snippet into a terminal

git clone https://github.com/GiulioRomualdi/meshcat-cpp.git
cd meshcat-cpp
mkdir build && cd build
cmake ..
cmake --build .
[sudo] make install

🏃 Example

meshcat-cpp provides native CMake support which allows the library to be easily used in CMake projects. Please add in your CMakeLists.txt

project(foo)
find_package(MeshcatCpp REQUIRED)
add_executable(${PROJECT_NAME} src/foo.cpp)
target_link_libraries(${PROJECT_NAME} MeshcatCpp::MeshcatCpp)

Differently for the python, julia, and C++ (drake) interfaces this interface currently supports only a subset of functionalities (🚧 New functionalities will be soon implemented). The following example shows you how to display some primary shapes.

#include <MeshcatCpp/Material.h>
#include <MeshcatCpp/Meshcat.h>
#include <MeshcatCpp/Shape.h>

MeshcatCpp::MatrixView<double> array_to_matrix_view(std::array<double, 16>& array)
{
    constexpr MeshcatCpp::MatrixView<double>::index_type rows = 4;
    constexpr MeshcatCpp::MatrixView<double>::index_type cols = 4;
    constexpr auto order = MeshcatCpp::MatrixStorageOrdering::ColumnMajor;
    return MeshcatCpp::make_matrix_view(array.data(), rows, cols, order);
}

int main()
{
    MeshcatCpp::Meshcat meshcat;
    MeshcatCpp::Material m;

    std::array<double, 16> transform = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
    auto matrix_view = array_to_matrix_view(transform);

    m.set_color(66, 133, 244);
    meshcat.set_object("box", MeshcatCpp::Box(0.5, 0.5, 0.5), m);
    matrix_view(3, 1) = 1.75;
    meshcat.set_transform("box", matrix_view);

    m.set_color(234, 67, 53);
    meshcat.set_object("sphere", MeshcatCpp::Sphere(0.5), m);
    matrix_view(3, 1) = 0.75;
    meshcat.set_transform("sphere", matrix_view);

    m.set_color(251, 188, 5);
    meshcat.set_object("ellipsoid", MeshcatCpp::Ellipsoid(0.5, 0.25, 0.75), m);
    matrix_view(3, 1) = -0.75;
    meshcat.set_transform("ellipsoid", matrix_view);

    m.set_color(52, 168, 83);
    meshcat.set_object("cylinder", MeshcatCpp::Cylinder(0.25, 0.5), m);
    matrix_view(3, 1) = -1.75;
    meshcat.set_transform("cylinder", matrix_view);

    meshcat.join();

    return 0;
}

Once you have run the example, the MeshcatCpp::Meshcat class will print the URL at which the MeshCat server runs. Please open the link in your browser and you should be able to see the following screen

meshcat_screen

🐛 Bug reports and support

All types of issues are welcome.

📝 License

Materials in this repository are distributed under the following license:

All software is licensed under the BSD 3-Clause "New" or "Revised" License. See LICENSE file for details.

meshcat-cpp's People

Contributors

giulioromualdi avatar traversaro avatar

Stargazers

João Santos avatar Bilal avatar Shuang Peng avatar hiyyg avatar Guglielmo Cervettini avatar gregor avatar Ayman Damoun avatar Wei Zhang avatar Wilson avatar Louis Montaut avatar Justin Carpentier avatar  avatar Antoine Hoarau avatar  avatar Diego Ferigo avatar Prajval Kumar avatar Fabio Bergonti avatar Siddharth Deore avatar Giuseppe L'Erario avatar Yang Liu avatar Seung Hyeon Bang avatar Baljinder Singh Bal avatar Lieλ avatar  avatar Stéphane Caron avatar

Watchers

Justin Carpentier avatar Wolfgang Merkt avatar  avatar  avatar  avatar Wei Zhang avatar

meshcat-cpp's Issues

C++20

Dear developers,

Thanks a lot for extracting from Drake this very useful Meshcat interface.

I've a simple but important question regarding the choice of C++20.
Is it fully needed to run meshcat-cpp?

Thanks in advance,
Best,

Justin

[Question]: how to change the color of objects at runtime (`set_property`?)

Hi,
First of all, thanks for making this library. To the point, I wanted to change at runtime the color of some objects in the visuaslization. I see there's a set_property function in Meshcat.h, but the only value it accepts is boolean. How could I modify the code or add this functionality to change the property color of the material? (if possible).

Thanks in advance.

Unable to run the example

I installed meshcat-cpp in the robot-install folder as follows

gromualdi@iiticublap261:~/robot-code/meshcat-cpp/build (master)$ make install
[ 54%] Built target uSockets
[ 90%] Built target MeshcatCpp
Consolidate compiler generated dependencies of target example
[100%] Built target example
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /home/gromualdi/robot-install/lib/libMeshcatCpp.so.0.1.0
-- Up-to-date: /home/gromualdi/robot-install/lib/libMeshcatCpp.so
-- Up-to-date: /home/gromualdi/robot-install/include/MeshcatCpp/Meshcat.h
-- Up-to-date: /home/gromualdi/robot-install/include/MeshcatCpp/Material.h
-- Up-to-date: /home/gromualdi/robot-install/include/MeshcatCpp/MatrixView.h
-- Up-to-date: /home/gromualdi/robot-install/include/MeshcatCpp/Shape.h
-- Up-to-date: /home/gromualdi/robot-install/lib/cmake/MeshcatCpp/MeshcatCppConfigVersion.cmake
-- Up-to-date: /home/gromualdi/robot-install/lib/cmake/MeshcatCpp/MeshcatCppConfig.cmake
-- Up-to-date: /home/gromualdi/robot-install/lib/cmake/MeshcatCpp/MeshcatCppTargets.cmake
-- Up-to-date: /home/gromualdi/robot-install/lib/cmake/MeshcatCpp/MeshcatCppTargets-release.cmake
-- Up-to-date: /home/gromualdi/robot-install/share/MeshcatCpp/misc
-- Up-to-date: /home/gromualdi/robot-install/share/MeshcatCpp/misc/LICENSE_MESHCAT
-- Up-to-date: /home/gromualdi/robot-install/share/MeshcatCpp/misc/main.min.js.THIRD_PARTY_LICENSES.json
-- Up-to-date: /home/gromualdi/robot-install/share/MeshcatCpp/misc/index.html
-- Up-to-date: /home/gromualdi/robot-install/share/MeshcatCpp/misc/main.min.js
-- Up-to-date: /home/gromualdi/robot-install/share/MeshcatCpp/misc/favicon.ico

When I tried to run the example I got a runtime error. Indeed the visualizer is not able to find index.html because it is looking in the build folder build/share/MeshcatCpp

Unable to load the file in "/home/gromualdi/robot-code/meshcat-cpp/build/share/MeshcatCpp/misc/index.html"
terminate called after throwing an instance of 'std::runtime_error

still, this should not happen since I'm using https://github.com/ami-iit/reloc-cpp to locate the installation folder


cc @traversaro

Use the library from the build directory (i.e. with add_subdirectory)

First of all, thanks for making this package 😃 . I'm trying to integrate Meshcat as visualizer for an application I'm developing. I got the example file working when using the library after installation; everything so far works right. However, I'm running into some issues when trying to use the library without installing it, and instead using FetchContent to grab the source of the library and using add_subdirectory to include the project into my CMake workflow.

This also happens if I try to build the example file along the library, and try to run the example, getting the following error:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Unable to load index.html
Aborted (core dumped)

I noticed that the index.html file in the misc folder at the root of the project should be served, but the location used actually comes from the file FindResource.cpp.in, which when installing points to the installation location (e.g. /usr/local/share/MeshcatCpp/misc). This works when using the library after installing it. However, if we'd like to use the example that is being compiled along the library without installing it, I'd keep running into the error mentioned before.

Is it possible to update the FindResource.cpp.in or a similar file(s) to handle the case when we don't want to install the library into our system?.

Add CI

I think we can start supporting the conda-installation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.