Send vector of points over OSC

I had to sent a point cloud and/or vector<glm::vec3> over OSC.
@roymacdonald helped me with some code that I want to add to the collective memory of this forum.

convert get the vertices from ofMesh and convert to ofBuffer:

ofxOscMessage myMessage;
        
ofBuffer myBuffer;
myBuffer.set(reinterpret_cast<const char*>(_mesh.getVertices().data()), (_mesh.getNumVertices() * sizeof(glm::vec3)) );
        
myMessage.setAddress("/Mesh");
myMessage.addBlobArg(myBuffer);
        
sender.sendMessage(myMessage, true);

receive OSC blond convert to vector<> :

if(m.getAddress() == "/Mesh"){
      ofBuffer myBuffer = m.getArgAsBlob(0);
      oscMesh_points.resize(myBuffer.size()/sizeof(glm::vec3));
      memcpy(oscMesh_points.data(), reinterpret_cast<glm::vec3*>(myBuffer.getData()), myBuffer.size());
}

So far this works well. But I have to point out that I am only sending a subsection of the original Kinect point cloud and it’s sent only to the local host (two apps on the same computer), not between different computers.

6 Likes

Nice one! it should work great between different computers. I would try to make the OSC packet less than 1500 bytes long (usually the MTU on most routers).
will you fragment the original mesh in different osc messages and rebuild it on another machine?
Thanks for sharing.

1 Like

so far I am sending the whole point cloud as one long vector and have not encountered any problems. but splitting it up in multi messages might become a good option if problems occur.
:slight_smile: