int main(int argc, char * argv[]) { using namespace std; using namespace Eigen; using namespace igl; string filename = "../shared/truck.obj"; switch(argc) { case 3: out_filename = argv[2]; case 2: // Read and prepare mesh filename = argv[1]; break; default: cerr<<"Usage:"<<endl<<" ./example input.obj (output.obj)"<<endl; cout<<endl<<"Opening default mesh..."<<endl; break; } // print key commands cout<<"[Click] and [drag] Rotate model using trackball."<<endl; cout<<"[Z,z] Snap rotation to canonical view."<<endl; cout<<"[Command+Z] Undo."<<endl; cout<<"[Shift+Command+Z] Redo."<<endl; cout<<"[^C,ESC] Exit."<<endl; // dirname, basename, extension and filename string d,b,ext,f; pathinfo(filename,d,b,ext,f); // Convert extension to lower case transform(ext.begin(), ext.end(), ext.begin(), ::tolower); vector<vector<double > > vV,vN,vTC; vector<vector<int > > vF,vFTC,vFN; if(ext == "obj") { // Convert extension to lower case if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN)) { return 1; } }else if(ext == "off") { // Convert extension to lower case if(!igl::readOFF(filename,vV,vF,vN)) { return 1; } }else if(ext == "ply") { // Convert extension to lower case if(!igl::readPLY(filename,vV,vF,vN,vTC)) { return 1; } }else if(ext == "wrl") { // Convert extension to lower case if(!igl::readWRL(filename,vV,vF)) { return 1; } //}else //{ // // Convert extension to lower case // MatrixXi T; // if(!igl::readMESH(filename,V,T,F)) // { // return 1; // } // //if(F.size() > T.size() || F.size() == 0) // { // boundary_facets(T,F); // } } if(vV.size() > 0) { if(!list_to_matrix(vV,V)) { return 1; } polygon_mesh_to_triangle_mesh(vF,F); } MatrixXi F_unique; unique_simplices(F, F_unique); F = F_unique; init_patches(); init_relative(); randomly_color(CC,s.C); // Init glut glutInit(&argc,argv); if( !TwInit(TW_OPENGL, NULL) ) { // A fatal error occured fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError()); return 1; } // Create a tweak bar rebar.TwNewBar("bar"); TwDefine("bar label='Patches' size='200 550' text=light alpha='200' color='68 68 68'"); rebar.TwAddVarRW("camera_rotation", TW_TYPE_QUAT4D, s.camera.m_rotation_conj.coeffs().data(), "open readonly=true"); TwType RotationTypeTW = igl::anttweakbar::ReTwDefineEnumFromString("RotationType", "igl_trackball,two-axis-valuator-fixed-up"); rebar.TwAddVarCB( "rotation_type", RotationTypeTW, set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=["); TwType CenterTypeTW = igl::anttweakbar::ReTwDefineEnumFromString("CenterType","orbit,fps"); rebar.TwAddVarRW("center_type", CenterTypeTW,¢er_type, "keyIncr={ keyDecr=}"); TwType OrientMethodTW = igl::anttweakbar::ReTwDefineEnumFromString("OrientMethod", "outward,ambient-occlusion"); rebar.TwAddVarCB( "orient_method", OrientMethodTW, set_orient_method,get_orient_method,NULL,"keyIncr=< keyDecr=>"); rebar.TwAddVarRW("wireframe_visible",TW_TYPE_BOOLCPP,&wireframe_visible,"key=l"); rebar.TwAddVarRW("fill_visible",TW_TYPE_BOOLCPP,&fill_visible,"key=f"); rebar.TwAddButton("randomize_colors",randomize_colors,NULL,"key=c"); if(out_filename != "") { rebar.TwAddButton("save", saveCB,NULL, C_STR("label='Save to `"<<out_filename<<"`' "<< "key=s")); } rebar.load(REBAR_NAME); animation_from_quat = Quaterniond(1,0,0,0); s.camera.m_rotation_conj = animation_from_quat; animation_start_time = get_seconds(); // Init antweakbar #ifdef __APPLE__ glutInitDisplayString( "rgba depth double samples>=8"); #else glutInitDisplayString( "rgba depth double "); // samples>=8 somehow not supported on Kenshi's machines...? #endif glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0); glutCreateWindow("patches"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutMouseFunc(mouse); glutMotionFunc(mouse_drag); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutMainLoop(); return 0; }