Changeset 3277 for GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
- Timestamp:
- 01/15/09 04:52:43 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
r3274 r3277 231 231 232 232 //if (!LoadSolution(bvhInputFilename)) 233 if (!LoadSolution Test(bvhInputFilename))233 if (!LoadSolution(bvhInputFilename)) 234 234 { 235 235 cerr << "could not read solution file" << endl; … … 270 270 bool VisibilitySolutionConverter::ReadScene(const string &filename) 271 271 { 272 /* 272 273 VertexArray vertices; 273 274 VertexArray normals; … … 278 279 ConstructBvhObjects(vertices, normals, texCoords); 279 280 return true; 280 } 281 }*/ 282 283 vector<CHCDemoEngine::Triangle3 *> triangles; 284 285 if (ReadObjSimple(filename, triangles)) 286 { 287 ConstructBvhObjects2(triangles); 288 return true; 289 } 290 291 /*for (size_t i = 0; i < triangles.size(); ++ i) 292 delete triangles[i]; 293 */ 281 294 282 295 return false; … … 417 430 418 431 bool alphaTestEnabled = false; 419 //bool cullFaceEnabled = true;420 bool cullFaceEnabled = false;432 bool cullFaceEnabled = true; 433 //bool cullFaceEnabled = false; 421 434 422 435 str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); … … 929 942 return true; 930 943 } 944 945 946 bool VisibilitySolutionConverter::ReadObjSimple(const string &filename, 947 vector<CHCDemoEngine::Triangle3 *> &triangles 948 ) 949 { 950 FILE *file; 951 952 if ((file = fopen(filename.c_str(), "r")) == NULL) return false; 953 954 VertexArray vertices; 955 956 int line = 0; 957 const int len = 10000; 958 char str[len]; 959 960 const string binFilename = ReplaceSuffix(filename, ".obj", ".bn"); 961 962 cout << "binary dump " << binFilename << " not available, loading ascii obj" << endl; 963 964 while (fgets(str, len, file) != NULL) 965 { 966 if (line % 500000 == 0) 967 cout << line << " " << str; 968 969 ++ line; 970 971 switch (str[0]) 972 { 973 case 'v': // vertex or normal 974 { 975 float x, y, z; 976 977 sscanf(str + 1, "%f %f %f", &x, &y, &z); 978 CHCDemoEngine::Vector3 v = CHCDemoEngine::Vector3(x, -z, y) * sScale; 979 vertices.push_back(v); 980 981 if (vertices.size() == 3) 982 { 983 CHCDemoEngine::Triangle3 *tri = 984 new CHCDemoEngine::Triangle3(vertices[0], vertices[1], vertices[2]); 985 986 triangles.push_back(tri); 987 vertices.clear(); 988 } 989 break; 990 } 991 default: 992 // throw away line 993 break; 994 } 995 } 996 997 fclose(file); 998 999 return !triangles.empty(); 1000 } 1001 1002 1003 void VisibilitySolutionConverter::ConstructBvhObjects2(const vector<CHCDemoEngine::Triangle3 *> &triangles) 1004 { 1005 CHCDemoEngine::AxisAlignedBox3 testBox; 1006 testBox.Initialize(); 1007 1008 for (size_t i = 0; i < triangles.size(); ++ i) 1009 { 1010 testBox.Include(triangles[i]->mVertices[0]); 1011 testBox.Include(triangles[i]->mVertices[1]); 1012 testBox.Include(triangles[i]->mVertices[2]); 1013 } 1014 1015 cout << "geometry bounds: " << testBox << endl; 1016 1017 mGeometry.reserve(mBvhLeaves.size()); 1018 mNumShapes = (int)mBvhLeaves.size(); 1019 1020 VertexArray _vertices; 1021 VertexArray _normals; 1022 vector<TexCoord> _texCoords; 1023 1024 int total = 0; 1025 for (size_t i = 0; i < mBvhLeaves.size(); ++ i) 1026 { 1027 BvhLeaf *node = mBvhLeaves[i]; 1028 const int size = node->last - node->first + 1; 1029 1030 total += size; 1031 1032 if (i % 1000 == 0) 1033 cout << "o " << i << " " << size << " " << total << endl; 1034 1035 _vertices.clear(); 1036 _normals.clear(); 1037 _texCoords.clear(); 1038 1039 //cout << "vtx: " << size << endl; 1040 for (int j = node->first; j <= node->last; ++ j) 1041 { 1042 const int idx = mGlobalTriangleIds[j]; 1043 1044 //cout << "idx: " << 3 * mGlobalTriangleIds[j] << " j " << j << " " << vertices.size()<< endl; 1045 for (int k = 0; k < 3; ++ k) 1046 { 1047 _vertices.push_back(triangles[idx]->mVertices[k]); 1048 } 1049 1050 const CHCDemoEngine::Vector3 n = triangles[idx]->GetNormal(); 1051 1052 _normals.push_back(n); 1053 _normals.push_back(n); 1054 _normals.push_back(n); 1055 1056 delete triangles[idx]; 1057 } 1058 1059 LoadShape(_vertices, _normals, _texCoords); 1060 1061 // we store geometry in our bvh => change first and last pointer 1062 // from triangles to geometry 1063 node->first = (int)mGeometry.size() - 1; 1064 node->last = (int)mGeometry.size() - 1; 1065 1066 //_vertices.clear(); 1067 //_normals.clear(); 1068 //_texCoords.clear(); 1069 } 1070 }
Note: See TracChangeset
for help on using the changeset viewer.