Changeset 3012 for GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter
- Timestamp:
- 10/08/08 10:45:08 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r2965 r3012 1 1 #include "ObjConverter.h" 2 #include "SimpleTri.h" 3 #include "SimpleVec.h" 2 4 #include "gzstream.h" 3 5 #include <iostream> … … 35 37 for (size_t i = 0; i < substrings.size(); ++ i) 36 38 { 37 // vertex, normal andtexture indices39 // vertex, normal, texture indices 38 40 char *str = strtok_s(substrings[i], "/", &next_token); 39 41 int index = (int)strtol(str, NULL, 10) - 1; … … 42 44 int nIndex = index; 43 45 44 /*str = strtok_s(substrings[i], "/", &next_token);45 int tIndex = (int)strtol(str, NULL, 10) - 1;46 47 46 str = strtok_s(substrings[i], "/", &next_token); 48 int nIndex = (int)strtol(str, NULL, 10) - 1; 49 */ 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; 59 } 60 50 61 // store indices 51 62 if (index >= 0) … … 59 70 if (indices.size() > 2) 60 71 { 61 #if 172 #if 0 62 73 int idx1 = 0; 63 74 int idx2 = (int)indices.size() - 2; … … 71 82 faceVertices.push_back(vertices[indices[idx2]]); 72 83 faceVertices.push_back(vertices[indices[idx3]]); 73 74 Vector3 dummy(1, 0, 0); 75 faceNormals.push_back(dummy); 76 faceNormals.push_back(dummy); 77 faceNormals.push_back(dummy); 78 79 /* 80 const Vector3 v2 = mVertices[2] - mVertices[1]; 81 Normalize(CrossProd(v2, v1)); 82 83 faceNormals.push_back(normals[nIndices[idx1]]); 84 faceNormals.push_back(normals[nIndices[idx2]]); 85 faceNormals.push_back(normals[nIndices[idx3]]); 86 87 faceTexcoords.push_back(texcoords[tIndices[idx1]]); 88 faceTexcoords.push_back(texcoords[tIndices[idx2]]); 89 faceTexcoords.push_back(texcoords[tIndices[idx3]]); 90 */ 84 85 if (!normals.empty()) 86 { 87 faceNormals.push_back(normals[nIndices[idx1]]); 88 faceNormals.push_back(normals[nIndices[idx2]]); 89 faceNormals.push_back(normals[nIndices[idx3]]); 90 } 91 else 92 { 93 // no face normals? 94 const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 95 const SimpleVec n = tri.GetNormal(); 96 97 faceNormals.push_back(n); 98 faceNormals.push_back(n); 99 faceNormals.push_back(n); 100 } 101 102 if (!texcoords.empty()) 103 { 104 faceTexcoords.push_back(texcoords[tIndices[idx1]]); 105 faceTexcoords.push_back(texcoords[tIndices[idx2]]); 106 faceTexcoords.push_back(texcoords[tIndices[idx3]]); 107 } 91 108 } 92 109 } … … 121 138 122 139 // convert the triangles to geometry 123 geom->mVertices = new Vector3[numElements];124 geom->mNormals = new Vector3[numElements];140 geom->mVertices = new SimpleVec[numElements]; 141 geom->mNormals = new SimpleVec[numElements]; 125 142 geom->mTexcoords = new Texcoord[numElements]; 126 143 … … 132 149 for (int i = 0; i < numElements; ++ i) 133 150 { 151 #if 0 134 152 geom->mVertices[i].x = faceVertices[i].x; 135 153 geom->mVertices[i].y = -faceVertices[i].z; 136 154 geom->mVertices[i].z = faceVertices[i].y; 137 155 138 156 geom->mNormals[i].x = faceNormals[i].x; 139 157 geom->mNormals[i].y = -faceNormals[i].z; 140 158 geom->mNormals[i].z = faceNormals[i].y; 141 159 #else 160 geom->mVertices[i].x = faceVertices[i].x; 161 geom->mVertices[i].y = faceVertices[i].y; 162 geom->mVertices[i].z = faceVertices[i].z; 163 164 geom->mNormals[i].x = faceNormals[i].x; 165 geom->mNormals[i].y = faceNormals[i].y; 166 geom->mNormals[i].z = faceNormals[i].z; 167 168 #endif 142 169 if (i < geom->mTexcoordCount) 143 170 { … … 220 247 case 'n' : 221 248 sscanf(str + 2, "%f %f %f", &x, &y, &z); 222 normals.push_back( Vector3(x, y, z));249 normals.push_back(SimpleVec(x, y, z)); 223 250 break; 224 251 case 't': … … 228 255 default: 229 256 sscanf(str + 1, "%f %f %f", &x, &y, &z); 230 vertices.push_back( Vector3(x, y, z));257 vertices.push_back(SimpleVec(x, y, z)); 231 258 //cout <<"v " << x << " " << y << " "<< z << " "; 232 259 } … … 242 269 faceVertices, faceNormals, faceTexcoords); 243 270 244 if ( ((line % 1000) == 999) &&245 !faceVertices.empty())271 if (0 && 272 (((line % 1000) == 999) && !faceVertices.empty())) 246 273 { 247 274 ++ mNumShapes; … … 299 326 str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 300 327 301 str.write(reinterpret_cast<char *>(geom->mVertices), sizeof( Vector3) * vertexCount);302 str.write(reinterpret_cast<char *>(geom->mNormals), sizeof( Vector3) * vertexCount);328 str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(SimpleVec) * vertexCount); 329 str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(SimpleVec) * vertexCount); 303 330 304 331 int texCoordCount = geom->mTexcoordCount; … … 330 357 if (hasMaterial) 331 358 { 332 Vector3ambient, diffuse, black;359 SimpleVec ambient, diffuse, black; 333 360 334 361 ambient.x = ambient.y = ambient.z = 0.2f; … … 337 364 338 365 // only write rgb part of the material 339 str.write(reinterpret_cast<char *>(&ambient), sizeof( Vector3));340 str.write(reinterpret_cast<char *>(&diffuse), sizeof( Vector3));341 str.write(reinterpret_cast<char *>(&black), sizeof( Vector3));342 str.write(reinterpret_cast<char *>(&black), sizeof( Vector3));366 str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 367 str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 368 str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 369 str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 343 370 } 344 371 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h
r2961 r3012 2 2 #define _OBJCONVERTER_H 3 3 4 #include "SimpleVec.h" 4 5 #include <string> 5 6 #include <vector> 6 7 7 struct Vector3 8 /*struct SimpleVec 8 9 { 9 Vector3() {}10 Vector3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {}10 SimpleVec() {} 11 SimpleVec(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 11 12 12 13 float x, y, z; 13 }; 14 };*/ 14 15 15 typedef std::vector< Vector3> VertexArray;16 typedef std::vector<SimpleVec> VertexArray; 16 17 typedef std::pair<float, float> Texcoord; 17 18 … … 36 37 struct Geometry 37 38 { 38 Vector3*mVertices;39 Vector3*mNormals;39 SimpleVec *mVertices; 40 SimpleVec *mNormals; 40 41 Texcoord *mTexcoords; 41 42 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp
r2963 r3012 15 15 cout << "converting obj to dem format" << endl; 16 16 17 /*if (!converter.Convert(model_path + argv[1], model_path + argv[2]))17 if (!converter.Convert(model_path + argv[1], model_path + argv[2])) 18 18 { 19 19 cerr << "conversion failed" << endl; 20 20 exit(0); 21 21 } 22 */23 //if (!converter.Convert(model_path + "toyplane.obj", model_path + "toyplane.dem"))24 // cerr << "conversion failed" << endl;25 26 //if (!converter.Convert(model_path + "sky.obj", model_path + "sky.dem"))27 // cerr << "conversion failed" << endl;28 29 if (!converter.Convert(model_path + "city_full.obj", model_path + "city_full.dem"))30 cerr << "conversion failed" << endl;31 22 32 23 cout << "conversion successful" << endl;
Note: See TracChangeset
for help on using the changeset viewer.