|
@@ -4,27 +4,24 @@
|
|
#include <string>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
|
|
+// Add custom data to a viewer mesh
|
|
|
|
+struct MeshData
|
|
|
|
+{
|
|
|
|
+ Eigen::RowVector3d color;
|
|
|
|
+};
|
|
|
|
+
|
|
int main(int argc, char * argv[])
|
|
int main(int argc, char * argv[])
|
|
{
|
|
{
|
|
igl::opengl::glfw::Viewer viewer;
|
|
igl::opengl::glfw::Viewer viewer;
|
|
- const auto names =
|
|
|
|
|
|
+ const auto names =
|
|
{"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"};
|
|
{"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"};
|
|
for(const auto & name : names)
|
|
for(const auto & name : names)
|
|
{
|
|
{
|
|
viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
|
|
viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
|
|
|
|
+ viewer.data().attr<MeshData>().color = 0.5*Eigen::RowVector3d::Random().array() + 0.5;
|
|
}
|
|
}
|
|
|
|
|
|
- // Set colors of each mesh by selecting its index first
|
|
|
|
- viewer.selected_data_index = 0;
|
|
|
|
- viewer.data().set_colors(Eigen::RowVector3d(0.8,0.47,0.22));
|
|
|
|
- viewer.selected_data_index = 1;
|
|
|
|
- viewer.data().set_colors(Eigen::RowVector3d(0.6,0.01,0.11));
|
|
|
|
- viewer.selected_data_index = 2;
|
|
|
|
- viewer.data().set_colors(Eigen::RowVector3d(0.37,0.06,0.25));
|
|
|
|
- viewer.selected_data_index = 3;
|
|
|
|
- viewer.data().set_colors(Eigen::RowVector3d(1,1,1));
|
|
|
|
-
|
|
|
|
- viewer.callback_key_down =
|
|
|
|
|
|
+ viewer.callback_key_down =
|
|
[&](igl::opengl::glfw::Viewer &, unsigned int key, int mod)
|
|
[&](igl::opengl::glfw::Viewer &, unsigned int key, int mod)
|
|
{
|
|
{
|
|
if(key == GLFW_KEY_BACKSPACE)
|
|
if(key == GLFW_KEY_BACKSPACE)
|
|
@@ -35,6 +32,23 @@ int main(int argc, char * argv[])
|
|
return false;
|
|
return false;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // Refresh selected mesh colors
|
|
|
|
+ viewer.callback_pre_draw =
|
|
|
|
+ [&](igl::opengl::glfw::Viewer &)
|
|
|
|
+ {
|
|
|
|
+ static int last_selected = -1;
|
|
|
|
+ if (last_selected != viewer.selected_data_index)
|
|
|
|
+ {
|
|
|
|
+ for (auto &data : viewer.data_list)
|
|
|
|
+ {
|
|
|
|
+ data.set_colors(data.attr<MeshData>().color);
|
|
|
|
+ }
|
|
|
|
+ viewer.data_list[viewer.selected_data_index].set_colors(Eigen::RowVector3d(0.9,0.1,0.1));
|
|
|
|
+ last_selected = viewer.selected_data_index;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ };
|
|
|
|
+
|
|
viewer.launch();
|
|
viewer.launch();
|
|
return EXIT_SUCCESS;
|
|
return EXIT_SUCCESS;
|
|
}
|
|
}
|