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

Displaying point cloud using a c++ function #81

Open
ad1t7a opened this issue Mar 9, 2021 · 2 comments
Open

Displaying point cloud using a c++ function #81

ad1t7a opened this issue Mar 9, 2021 · 2 comments

Comments

@ad1t7a
Copy link

ad1t7a commented Mar 9, 2021

I was writing a c++ wrapper for meshcat and and was successfully able to display meshes. I ran into trouble while displaying a 3d point cloud and have been stuck at it for the past few days. Although it appears that meshcat is able to receive the json object when sent using ZMQ, it isn't displaying anything on the display. My guess is that json format is incorrect. Could you please let me know if I am missing a parameter to display a 3d point cloud (or messing up the expected data format) :

void PointCloud::loadPointCloud(const char *path) {
    double worldPos[3] = {0, 0, 0};
    int colorRGB = 0xFFFFFF;
    std::string geomUID = generateUUID();
    std::string materialUID = generateUUID();
    std::string objectUID = generateUUID();
    // these are the points
    std::array<std::array<float, 3>, 3> arr = {{{0.5207591 , 0.07896397, 0.89273536}, {0.88037544, 0.75724393, 0.33980307}, {0.36066929, 0.9843244 , 0.67521834}}};
    std::stringstream ss;
    msgpack::pack(ss, arr);

nlohmann::json setPointCloudCmd = {
    {"type", "set_object"},
    {"path", path},
    {"object",
    {{"metadata", {{"type", "Object"}, {"version", 4.5}}},
        {"geometries",
            {
                {
                    {"type", "BufferGeometry"},
                    {"uuid", geomUID},
                    {"data", 
                        {"attributes",  
                            {"position", 
                                {"itemSize", 3},
                                {"type", "Float32Array"},
                                {"normalized", 0},
                                {"array", arr}
                            }
                        }
                    },
                }
            }
        },
        {"materials",
            {
                {
                    {"vertexColors", 2},
                    {"size", 0.1},
                    {"color", colorRGB},
                    {"type", "PointsMaterial"},
                    {"uuid", materialUID}
                }
            }
        },
        {"object",
            {
                {"geometry", geomUID},
                {"material", materialUID},
                {"matrix", {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, worldPos[0], worldPos[1], worldPos[2], 1.0}},
                {"type", "Points"},
                {"uuid", objectUID}
            },
        }
    }}
};
// this part has been tested on other jsons and is known to work
sendZMQ(setPointCloudCmd, true);
  }
@ad1t7a
Copy link
Author

ad1t7a commented Mar 9, 2021

Any pointers on how to debug would help too!

@RussTedrake
Copy link
Collaborator

RussTedrake commented Oct 4, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants