opengl - Parametrize 3D Model -



opengl - Parametrize 3D Model -

i working grouping on developing application captures 2d image of human , convert 3d model. have used stasm library asm http://www.milbo.org/stasm-files/stasm4.pdf , on limited time plan need finish project end of november, learning trying opengl not our best thought because has advanced learning curve

what trying parametrize features of face according info stasm, have model classified nose object on blender obj file added comments above keypoints in nose

then developed parser

int str2num(string s){ if (s.length() > 2){ string str= s.substr((s.length()-2), s.find(' ')); int value = (int)atof(str.c_str()); homecoming value; } else homecoming 0; } void rokko::objtotxt(const string ainfilename,const string aoutfilename,bool averbose) { if(averbose) cout << "loading obj file <" << ainfilename << ">" << endl; // open file ifstream objfile(ainfilename.c_str()); if(objfile.fail()) { cout << "error: not open file <" << ainfilename << ">" << endl; exit(1); } // extract verts, normals, textures, , faces vector<int> verts, norms, textures; vector<int> faces; // map<int,int> facehash; vector<int> finalverts, finalnorms, finaltextures; vector<int> finalfaces; string line; int line_size=0; int hashindex = 0; if(averbose) cout << "extracting values file" << endl; // visit each line of obj file while(getline(objfile, line)) { // extract vertex // line starts v[space]... if(line[0] == 'v' && line[1] == ' ') { string linevals = line.substr(2); float val; string val0 = linevals.substr(0, linevals.find(' ')); val = (float)atof(val0.c_str()); verts.push_back(val); line_size = val0.size(); string val1 = linevals.substr(val0.length() + 1, linevals.find(' ')); val = (float)atof(val1.c_str()); verts.push_back(val); string val2 = linevals.substr(linevals.find_last_of(' ') + 1); val = (float)atof(val2.c_str()); verts.push_back(val); } // extract textures // line starts vt[space]... else if(line[0] == 'v' && line[1] == 't' && line[2] == ' ') { string linevals = line.substr(3); float val; string val0 = linevals.substr(0, linevals.find(' ')); val = (float)atof(val0.c_str()); textures.push_back(val); string val1 = linevals.substr(val0.length() + 1, linevals.find(' ')); val = (float)atof(val1.c_str()); textures.push_back(val); } // extract normals // line starts vn[space]... else if(line[0] == 'v' && line[1] == 'n' && line[2] == ' ') { string linevals = line.substr(3); float val; string val0 = linevals.substr(0, linevals.find(' ')); val = (float)atof(val0.c_str()); norms.push_back(val); string val1 = linevals.substr(val0.length() + 1, linevals.find(' ')); val = (float)atof(val1.c_str()); norms.push_back(val); string val2 = linevals.substr(linevals.find_last_of(' ') + 1); val = (float)atof(val2.c_str()); norms.push_back(val); } } (int i=0; i<verts.size();i++){ cout << "verts " << << ": " << verts[i] << endl;} (int i=0; i<verts.size();i++) { verts[i] = * 2; cout << "verts_new " << << ": " << verts[i] << endl;} // parametrizing nose part ifstream model ("test.obj"); ofstream out ("out.obj"); int test = 1; string str; string line1, line2,line3; int replace_size = (line_size *3) + 2; string linev; float val_x, val_y, val_z; string val0, val1, val2; while(!model.eof()) { getline(model,line1); out<<line1<<endl; while(line1 =="o n") { getline(model,line2); if (line2 =="o h"){ line1 = "o h"; out<<line2<<endl; } else { string compare = line2.substr(0, line2.find(' ')); switch(str2num(compare)){ case 48: // "#nose_48 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x+0.1<<" "<<val_y<<" "<<val_z<<endl; break; case 49: // "#nose_49 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x<<" "<<val_y<<" "<<val_z<<endl; break; case 50: // "#nose_50 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x-0.1<<" "<<val_y<<" "<<val_z<<endl; break; case 51: // "#nose_51 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x<<" "<<val_y-0.1<<" "<<val_z<<endl; break; case 52: // "#nose_52 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x<<" "<<val_y<<" "<<val_z<<endl; break; case 53: // "#nose_53 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x<<" "<<val_y-0.1<<" "<<val_z<<endl; break; case 54: // "#nose_54 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x+0.1<<" "<<val_y<<" "<<val_z<<endl; break; case 55: // "#nose_55 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x+0.1<<" "<<val_y<<" "<<val_z<<endl; break; case 56: // "#nose_56 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x<<" "<<val_y-0.2<<" "<<val_z<<endl; break; case 57: // "#nose_57 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x-0.1<<" "<<val_y<<" "<<val_z<<endl; break; case 58: // "#nose_58 getline(model,line3); linev = line3.substr(2); val0 = linev.substr(0, linev.find(' ')); val_x = (float)atof(val0.c_str()); line_size = val0.size(); val1 = linev.substr(val0.length() + 1,linev.find(' ')); val_y= (float)atof(val1.c_str()); val2 = linev.substr(linev.find_last_of(' ') + 1); val_z= (float)atof(val2.c_str()); out<<"v "<<val_x-0.1<<" "<<val_y<<" "<<val_z<<endl; break; // default: out<<line2<<endl; break; } } } } model.close(); out.close(); }

and can't seem right

any help of alternative approach without using libraries hard learn.

opengl 3d texture-mapping 3d-model

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -