Changeset 3358 for GTP/trunk/App
- Timestamp:
- 04/16/09 18:55:13 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3342 r3358 14 14 const VertexArray &vertices, 15 15 const VertexArray &normals, 16 const vector<pair<float, float> >&texcoords,16 const TexcoordArray &texcoords, 17 17 VertexArray &faceVertices, 18 18 VertexArray &faceNormals, 19 vector<Texcoord>&faceTexcoords19 TexcoordArray &faceTexcoords 20 20 ) 21 21 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h
r3261 r3358 23 23 typedef std::map<std::string, Material *> MaterialTable; 24 24 typedef std::map<std::string, int> TextureTable; 25 25 typedef std::vector<Texcoord> TexcoordArray; 26 26 typedef std::vector<std::string> TextureArray; 27 27 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp
r3342 r3358 12 12 const VertexArray &vertices, 13 13 const VertexArray &normals, 14 const vector<Texcoord>&texcoords,14 const TexcoordArray &texcoords, 15 15 VertexArray &faceVertices, 16 16 VertexArray &faceNormals, 17 vector<Texcoord>&faceTexcoords17 TexcoordArray &faceTexcoords 18 18 ) 19 19 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.h
r3261 r3358 23 23 typedef std::map<std::string, Material *> MaterialTable; 24 24 typedef std::map<std::string, int> TextureTable; 25 25 typedef std::vector<Texcoord> TexcoordArray; 26 26 typedef std::vector<std::string> TextureArray; 27 27 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.cpp
r3357 r3358 14 14 VertexArray sVertices; 15 15 VertexArray sNormals; 16 FaceArray sFaces; 17 16 18 17 19 … … 23 25 24 26 25 void PlyConverter::LoadShape(const VertexArray &faceVertices, 26 const VertexArray &faceNormals, 27 const vector<Texcoord> &faceTexcoords 27 void PlyConverter::LoadShape(const VertexArray &vertices, 28 const VertexArray &normals, 29 const TexcoordArray &texcoords, 30 const FaceArray &faces 28 31 ) 29 32 { 30 int numElements = (int)faceVertices.size();31 33 Geometry *geom = new Geometry(); 32 /* 33 // convert the triangles to geometry 34 geom->mVertices = new SimpleVec[numElements]; 35 geom->mNormals = new SimpleVec[numElements]; 36 geom->mTexcoords = new Texcoord[numElements]; 37 38 geom->mVertexCount = numElements; 39 geom->mTexcoordCount = (int)faceTexcoords.size(); 40 41 cout << "creating new geometry with " << numElements << " vertices" << endl; 42 43 for (int i = 0; i < numElements; ++ i) 44 { 45 geom->mVertices[i] = faceVertices[i] 46 geom->mNormals[i] = faceNormals[i]; 47 48 /*if (i < geom->mTexcoordCount) 34 size_t idx = 0; 35 36 for (size_t i = 0; i < faces.size(); ++ i) 37 { 38 if (i % 1000 == 0) 39 cout << "converted " << i << " lines" << endl; 40 41 Face face = faces[i]; 42 43 //cout << "size: " << face.indices.size() << endl; 44 for (size_t j = 0; j < face.indices.size(); ++ j) 49 45 { 50 geom->mTexcoords[i].first = faceTexcoords[i].first; 51 geom->mTexcoords[i].second = faceTexcoords[i].second; 46 geom->mVertices.push_back(vertices[faces[i].indices[j]]); 47 48 /*if (!normals.empty()) 49 { 50 for (int j = 0; j < 3; ++ j) 51 faceNormals.push_back(Normalize(normals[nIndices[idx[j]]])); 52 } 53 else 54 { 55 // no face normals? => create normals 56 const SimpleTri tri(vertices[indices[idx[0]]], 57 vertices[indices[idx[1]]], 58 vertices[indices[idx[2]]]); 59 60 const SimpleVec n = tri.GetNormal(); 61 62 faceNormals.push_back(n); 63 faceNormals.push_back(n); 64 faceNormals.push_back(n); 65 }*/ 52 66 } 53 } 54 */ 67 68 //cout << "idx: " << idx << " " << geom->mVertices.size() << endl; 69 70 // no face normals? => create normals 71 const SimpleTri tri(geom->mVertices[idx], 72 geom->mVertices[idx + 1], 73 geom->mVertices[idx + 2]); 74 75 const SimpleVec n = tri.GetNormal(); 76 77 geom->mNormals.push_back(n); 78 geom->mNormals.push_back(n); 79 geom->mNormals.push_back(n); 80 81 idx += faces[i].indices.size(); 82 } 83 55 84 mGeometry.push_back(geom); 85 mNumShapes = 1; 56 86 } 57 87 … … 86 116 ply_get_argument_user_data(argument, NULL, &eol); 87 117 88 static int mainIndex = 0;118 static SimpleVec v; 89 119 static int i = 0; 90 120 91 static SimpleVec v; 92 93 v[i] = (float)ply_get_argument_value(argument); 121 v[i ++] = (float)ply_get_argument_value(argument); 94 122 //printf("here3 %g", ply_get_argument_value(argument)); 95 123 96 if (eol) sVertices.push_back(v); 97 i = (i + 1) % 3; 98 //else printf(" "); 124 if (eol) 125 { 126 sVertices.push_back(v); 127 if (sVertices.size() % 10000 == 0) cout << "read in " << sVertices.size() << " vertices" << endl; 128 i = 0; 129 } 99 130 100 131 return 1; … … 107 138 ply_get_argument_property(argument, NULL, &length, &value_index); 108 139 140 static Face face; 141 109 142 switch (value_index) 110 143 { 111 144 case 0: 112 145 case 1: 113 printf("here4 %g ", ply_get_argument_value(argument)); 146 //printf("here4 %g ", ply_get_argument_value(argument)); 147 face.indices.push_back((int)ply_get_argument_value(argument)); 114 148 break; 115 149 case 2: 116 printf("here5 %g\n", ply_get_argument_value(argument)); 150 //printf("here5 %g\n", ply_get_argument_value(argument)); 151 face.indices.push_back((int)ply_get_argument_value(argument)); 152 sFaces.push_back(face); 153 if (sFaces.size() % 10000 == 0) cout << "read in " << sFaces.size() << " faces" << endl; 154 155 face.indices.clear(); 117 156 break; 118 157 default: 119 158 break; 120 159 } 160 161 121 162 return 1; 122 163 } … … 140 181 ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0); 141 182 142 printf("%ld\n%ld\n", nvertices, ntriangles); 143 144 if (!ply_read(ply)) return 1; 183 cout << "vertices: " << nvertices << endl; 184 cout << "triangles: " << ntriangles << endl; 185 186 if (!ply_read(ply)) return false; 145 187 ply_close(ply); 146 188 147 return 0; 189 TexcoordArray texCoords; 190 LoadShape(sVertices, sNormals, texCoords, sFaces); 191 192 return true; 148 193 } 149 194 … … 152 197 void PlyConverter::WriteGeometry(ogzstream &str, Geometry *geom) 153 198 { 154 int vertexCount = (int)geom->mVertices.size();199 size_t vertexCount = (int)geom->mVertices.size(); 155 200 str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 156 157 SimpleVec hvertices[3]; 158 SimpleVec hnormals[3]; 159 160 for (int i = 0; i < 3; ++ i) 161 { 162 hvertices[i] = geom->mVertices[i]; 163 hnormals[i] = geom->mNormals[i]; 164 } 201 202 cout << "writing geometry" << endl; 203 204 //SimpleVec vertices = new SimpleVec[vertexCount]; 205 //for (size_t i = 0; i < vertexCount; ++ i) vertices[i] = geom->mVertices[i]; 206 //for (size_t i = 0; i < vertexCount; ++ i) vertices[i] = geom->mNormals[i]; 207 208 for (size_t i = 0; i < vertexCount; ++ i) 209 str.write(reinterpret_cast<char *>(&geom->mVertices[i]), sizeof(SimpleVec)); 210 211 for (size_t i = 0; i < vertexCount; ++ i) 212 str.write(reinterpret_cast<char *>(&geom->mNormals[i]), sizeof(SimpleVec)); 213 214 cout << "finished writing geometry" << endl; 215 //if (texCoordCount) str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2); 216 217 cout << "here34 " << geom->mNormals.back() << endl; 165 218 166 219 int texCoordCount = 0; 167 168 str.write(reinterpret_cast<char *>(hvertices), sizeof(SimpleVec) * vertexCount);169 str.write(reinterpret_cast<char *>(hnormals), sizeof(SimpleVec) * vertexCount);170 220 str.write(reinterpret_cast<char *>(&texCoordCount), sizeof(int)); 171 221 … … 177 227 { 178 228 ogzstream ofile(filename.c_str()); 179 180 229 if (!ofile.is_open()) return false; 181 230 231 232 mNumShapes = (int)mGeometry.size(); 182 233 183 234 ///////// … … 218 269 { 219 270 WriteGeometry(ofile, *it); 271 272 273 /////// 274 //-- texture 275 276 int texId = 0; 277 ofile.write(reinterpret_cast<char *>(&texId), sizeof(int)); 278 279 bool alphaTestEnabled = false; 280 //bool cullFaceEnabled = false; 281 bool cullFaceEnabled = true; 282 283 ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 284 ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool)); 285 286 // material 287 bool hasMaterial = false; 288 ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 220 289 } 221 290 … … 238 307 float dist = 0; 239 308 ofile.write(reinterpret_cast<char *>(&dist), sizeof(float)); 240 241 309 ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int)); 310 242 311 243 312 // all shapes belong to this scene entity -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.h
r3357 r3358 13 13 typedef std::vector<SimpleVec> VertexArray; 14 14 typedef std::pair<float, float> Texcoord; 15 typedef std::vector< SimpleVec> TexcoordArray;15 typedef std::vector<Texcoord> TexcoordArray; 16 16 typedef std::map<std::string, int> TextureTable; 17 17 typedef std::vector<std::string> TextureArray; 18 19 20 struct Face 21 { 22 std::vector<int> indices; 23 }; 24 25 26 typedef std::vector<Face> FaceArray; 27 18 28 19 29 … … 37 47 protected: 38 48 39 void LoadShape(const VertexArray &faceVertices, 40 const VertexArray &faceNormals, 41 const std::vector<Texcoord> &faceTexcoords 49 void LoadShape(const VertexArray &vertices, 50 const VertexArray &normals, 51 const TexcoordArray &texcoords, 52 const FaceArray &faces 42 53 ); 43 54 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3274 r3358 346 346 int vertexCount; 347 347 str.read(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 348 348 cout << "vertices: " << vertexCount << endl; 349 349 350 // end of file reached 350 351 if (str.eof()) return NULL; … … 381 382 texcoords = NULL; 382 383 } 384 385 cout << "here3: " << normals[vertexCount-1] << endl; 386 cout << "texCoordCount: " << texCoordCount << endl; 387 383 388 384 389 const bool delGeometry = true; … … 415 420 igzstream istr(filename.c_str()); 416 421 417 if (!istr.is_open()) 418 return 0; 419 422 if (!istr.is_open()) return 0; 423 424 cout << "here7" << endl; 420 425 cout << "loading textures" << endl; 421 426 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3353 r3358 656 656 Matrix4x4 transl = TranslationMatrix(positions[0]); 657 657 658 LoadModel("hbuddha.dem", dynamicObjects); 658 //LoadModel("hbuddha.dem", dynamicObjects); 659 //LoadModel("horse.dem", dynamicObjects); 660 LoadModel("happy.dem", dynamicObjects); 659 661 //LoadModel("torus.dem", dynamicObjects); 660 662 //LoadModel("venusm.dem", dynamicObjects);
Note: See TracChangeset
for help on using the changeset viewer.