Changeset 3146 for GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter
- Timestamp:
- 11/20/08 10:12:28 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3128 r3146 7 7 8 8 using namespace std; 9 10 //#define USE_TEXTURE 9 11 10 12 … … 18 20 ) 19 21 { 20 vector< char *> substrings;22 vector<string> triples; 21 23 22 24 char *next_token; … … 25 27 char *pch = strtok_s(str + 1, " ", &next_token); 26 28 27 while (pch != NULL) 28 { 29 substrings.push_back(pch); 29 while (pch) 30 { 31 string s(pch); 32 //s += "\n", 33 triples.push_back(s); 34 30 35 pch = strtok_s(NULL, " ", &next_token); 31 36 } … … 35 40 vector<int> tIndices; 36 41 37 for (size_t i = 0; i < substrings.size(); ++ i) 38 { 42 char seps[] = " /\t\n"; 43 44 for (size_t i = 0; i < triples.size(); ++ i) 45 { 46 static int dummy = 0; 47 48 size_t found; 49 found = triples[i].find_first_of(seps); 50 size_t prevfound = 0; 39 51 // vertex, normal, texture indices 40 char *str = strtok_s(substrings[i], "/", &next_token); 41 int index = (int)strtol(str, NULL, 10) - 1; 52 string str = triples[i].substr(prevfound, found); 53 54 int index = (int)strtol(str.c_str(), NULL, 10) - 1; 42 55 43 56 int tIndex = index; 44 int nIndex = index; 45 46 str = strtok_s(substrings[i], "/", &next_token); 47 48 if (str != NULL) 49 { 50 int idx = (int)strtol(str, NULL, 10) - 1; 51 if (idx) tIndex = idx; 52 } 53 str = strtok_s(substrings[i], "/", &next_token); 54 55 if (str != NULL) 56 { 57 int idx = (int)strtol(str, NULL, 10) - 1; 58 if (idx) nIndex = idx; 57 int nIndex = index; 58 59 prevfound = found; 60 found = triples[i].find_first_of(seps, found + 1); 61 62 if (found != string::npos) 63 { 64 str = triples[i].substr(prevfound, found); 65 66 int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 67 if (idx > 0) tIndex = idx; 68 } 69 70 if ((found + 1) < triples[i].size()) 71 { 72 str = triples[i].substr(found + 1); 73 74 int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 75 if (idx > 0) nIndex = idx; 59 76 } 60 77 … … 84 101 faceVertices.push_back(vertices[indices[idx3]]); 85 102 103 86 104 if (!normals.empty()) 87 105 { 106 //if (dummy < 3) cout << nIndices[idx1] << " " << nIndices[idx2] << " " << nIndices[idx3] << endl; 88 107 faceNormals.push_back(normals[nIndices[idx1]]); 89 108 faceNormals.push_back(normals[nIndices[idx2]]); … … 92 111 else 93 112 { 94 // no face normals? 95 const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 113 // no face normals? => create normals 114 const SimpleTri tri(vertices[indices[idx1]], 115 vertices[indices[idx2]], 116 vertices[indices[idx3]]); 96 117 const SimpleVec n = tri.GetNormal(); 97 118 … … 101 122 } 102 123 124 ++ dummy; 103 125 if (!texcoords.empty()) 104 126 { … … 150 172 for (int i = 0; i < numElements; ++ i) 151 173 { 152 #if 0174 #if 1 153 175 // convert to our camera system: change y and z 154 176 geom->mVertices[i].x = faceVertices[i].x; … … 159 181 geom->mNormals[i].y = -faceNormals[i].z; 160 182 geom->mNormals[i].z = faceNormals[i].y; 183 161 184 #else 162 185 geom->mVertices[i].x = faceVertices[i].x; … … 169 192 170 193 #endif 171 geom->mVertices[i].x += 470.398f;172 geom->mVertices[i].y += 240.364f;173 geom->mVertices[i].z += 182.5f;174 194 175 195 if (i < geom->mTexcoordCount) … … 236 256 237 257 int line = 0; 238 239 258 const int len = 10000; 240 259 char str[len]; … … 242 261 while (fgets(str, len, file) != NULL) 243 262 { 244 // if (1)//(line % 100) == 0) 245 // cout << "read line " << line << " " << str; 246 switch (str[0]) 263 switch (str[0]) 247 264 { 248 265 case 'v': // vertex or normal … … 262 279 default: 263 280 sscanf(str + 1, "%f %f %f", &x, &y, &z); 264 vertices.push_back(SimpleVec(x, y, z)); 281 const float scale = 5e-3f; 282 vertices.push_back(SimpleVec(x * scale, y * scale, z* scale)); 265 283 //cout <<"v " << x << " " << y << " "<< z << " "; 266 284 } … … 305 323 break; 306 324 default: 325 // throw away line 307 326 break; 308 327 } … … 346 365 //-- texture 347 366 348 //int texId = -1; 367 #ifdef USE_TEXTURE 349 368 int texId = 0; 369 #else 370 int texId = -1; 371 #endif 372 350 373 str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 351 374 352 375 bool alphaTestEnabled = false; 353 bool cullFaceEnabled = false;354 //bool cullFaceEnabled = true;376 //bool cullFaceEnabled = false; 377 bool cullFaceEnabled = true; 355 378 356 379 str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); … … 368 391 ambient.x = ambient.y = ambient.z = 0.2f; 369 392 diffuse.x = diffuse.y = diffuse.z = 1.0f; 370 spec.x = spec.y = spec.z= .0f;393 spec.x = spec.y = spec.z = .0f; 371 394 emm = spec; 372 395 … … 391 414 //-- write textures 392 415 416 #ifdef USE_TEXTURE 393 417 int textureCount = 1; 394 //int textureCount = 0; 395 418 #else 419 int textureCount = 0; 420 #endif 396 421 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 397 422 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp
r3076 r3146 22 22 exit(0); 23 23 } 24 24 //std::cin.get(); 25 25 cout << "conversion successful" << endl; 26 26
Note: See TracChangeset
for help on using the changeset viewer.