Shows how to import a scene and query a list of the instance objects inside the scene. Note that querying only works for MUJIN COLLADA scenes.
#include <iostream>
using namespace mujinclient;
int main(
int argc,
char ** argv)
{
if( argc < 2 ) {
std::cout << "need username:password. Example: mujinclienttest myuser:mypass [url]\n\nurl - [optional] For example https://controller.mujin.co.jp/" << std::endl;
return 1;
}
try {
if( argc >= 5 ) {
}
if( argc == 4 ) {
}
else if( argc == 3 ) {
}
else {
}
std::cout << "connected to controller v" << controller->GetVersion() << std::endl;
controller->SyncUpload_UTF8("../share/mujincontrollerclient/robodia_demo1/robodia_demo1.xml", "mujin:/robodia_demo1/", "cecrobodiaxml");
std::string sceneuri = "mujin:/robodia_demo1.mujin.dae";
try {
controller->ImportSceneToCOLLADA_UTF8("mujin:/robodia_demo1/robodia_demo1.xml", "cecrobodiaxml", sceneuri);
}
if( ex.
message().find(
"need to remove it first") != std::string::npos ) {
std::cout << "file already imported, would you like to delete and re-import? (yes/no) ";
std::string answer;
std::cin >> answer;
if( answer == std::string("yes") ) {
std::cout << "try removing the file and importing again" << std::endl;
controller->ImportSceneToCOLLADA_UTF8("mujin:/robodia_demo1/robodia_demo1.xml", "cecrobodiaxml", sceneuri);
}
}
else {
std::cout <<
"error importing scene" << ex.
message() << std::endl;
}
}
std::string scenepk = controller->GetScenePrimaryKeyFromURI_UTF8(sceneuri);
std::vector<SceneResource::InstObjectPtr> instobjects;
std::cout << "scene instance objects: ";
for(size_t i = 0; i < instobjects.size(); ++i) {
std::cout << instobjects[i]->name << ", ";
}
std::cout << std::endl;
}
std::cout <<
"exception thrown: " << ex.
message() << std::endl;
}
}