[1009] | 1 | /*==========================================================================
|
---|
[774] | 2 | * (C) 2005 Universitat Jaume I
|
---|
[1009] | 3 | *==========================================================================
|
---|
[774] | 4 | * PROYECT: GAME TOOLS
|
---|
[1009] | 5 | *==========================================================================
|
---|
| 6 | * CONTENT:
|
---|
| 7 | *
|
---|
| 8 | *
|
---|
| 9 | * @file GeoLodStripsLibrary.cpp
|
---|
| 10 | *===========================================================================*/
|
---|
[774] | 11 |
|
---|
| 12 | #include "GeoLodStripsLibrary.h"
|
---|
| 13 |
|
---|
| 14 | using namespace Geometry;
|
---|
[1541] | 15 | using namespace std;
|
---|
[774] | 16 |
|
---|
| 17 | //-----------------------------------------------------------------------------
|
---|
[1526] | 18 | // Constructor.
|
---|
[774] | 19 | //-----------------------------------------------------------------------------
|
---|
[1560] | 20 | LodStripsLibrary::LodStripsLibrary( const LodStripsLibraryData *lodstripsdata,
|
---|
| 21 | Mesh *geomesh,
|
---|
| 22 | IndexData *userindexdata)
|
---|
[774] | 23 | {
|
---|
| 24 | // Sets the current lod.
|
---|
| 25 | mCurrentLod = 0;
|
---|
| 26 |
|
---|
| 27 | // Sets the global mesh.
|
---|
| 28 | mGeoMesh = geomesh;
|
---|
[1018] | 29 |
|
---|
[1560] | 30 | delete_indexdata = false;
|
---|
| 31 | dataRetrievalInterface = userindexdata;
|
---|
| 32 | indices_x_submesh = NULL;
|
---|
| 33 | offsets_x_submesh = NULL;
|
---|
| 34 | mStripsSubmesh = NULL;
|
---|
| 35 | submesh_x_strip = NULL;
|
---|
| 36 | lodFactor = 1.0f;
|
---|
| 37 | current_triangle_count = 0;
|
---|
[1526] | 38 |
|
---|
[774] | 39 | // Loads the Level Of Detail file.
|
---|
[1078] | 40 | LodStripsLibrary::LoadStripMesh(lodstripsdata,mGeoMesh);
|
---|
[1058] | 41 |
|
---|
[1560] | 42 | GoToLod(0.0f);
|
---|
| 43 |
|
---|
| 44 | minFaces = 0;
|
---|
| 45 |
|
---|
[1058] | 46 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
[1560] | 47 | {
|
---|
| 48 | minFaces += int(mStrips[strip].size() - 2);
|
---|
| 49 | }
|
---|
[1058] | 50 |
|
---|
| 51 | GoToLod(1.0f);
|
---|
[1560] | 52 |
|
---|
| 53 | maxFaces = 0;
|
---|
| 54 |
|
---|
[1058] | 55 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
[1560] | 56 | {
|
---|
| 57 | maxFaces += int(mStrips[strip].size() - 2);
|
---|
| 58 | }
|
---|
[774] | 59 | }
|
---|
| 60 |
|
---|
| 61 | //-----------------------------------------------------------------------------
|
---|
[1526] | 62 | // Destructor
|
---|
[774] | 63 | //-----------------------------------------------------------------------------
|
---|
| 64 | LodStripsLibrary::~LodStripsLibrary()
|
---|
| 65 | {
|
---|
[1014] | 66 | delete [] mStrips;
|
---|
[1526] | 67 | if (delete_indexdata)
|
---|
[1018] | 68 | delete dataRetrievalInterface;
|
---|
[1078] | 69 | if (indices_x_submesh)
|
---|
| 70 | delete[] indices_x_submesh;
|
---|
[1083] | 71 | if (offsets_x_submesh)
|
---|
| 72 | delete[] offsets_x_submesh;
|
---|
[1090] | 73 | if (mStripsSubmesh)
|
---|
| 74 | delete[] mStripsSubmesh;
|
---|
[1526] | 75 | if (submesh_x_strip)
|
---|
| 76 | delete[] submesh_x_strip;
|
---|
[774] | 77 | }
|
---|
| 78 |
|
---|
| 79 | //-----------------------------------------------------------------------------
|
---|
| 80 | // Public.
|
---|
| 81 | //-----------------------------------------------------------------------------
|
---|
| 82 |
|
---|
[1009] | 83 | //-----------------------------------------------------------------------------
|
---|
| 84 | // Go to the level of detail.
|
---|
| 85 | //-----------------------------------------------------------------------------
|
---|
[1058] | 86 | void LodStripsLibrary::GoToLod(float lodfactor)
|
---|
[774] | 87 | {
|
---|
[1541] | 88 | register int j;
|
---|
| 89 | register int offset;
|
---|
[1526] | 90 | long int i;
|
---|
| 91 | long int k;
|
---|
| 92 | long int b_change_ok = 1;
|
---|
[1541] | 93 | unsigned long int lod;
|
---|
[1526] | 94 | long int t;
|
---|
| 95 | long int r;
|
---|
| 96 | long int next;
|
---|
| 97 | long int el1;
|
---|
| 98 | long int el2;
|
---|
| 99 | long int total_changes;
|
---|
| 100 | long int totalR;
|
---|
[1541] | 101 | SmallIntVector *strip;
|
---|
[774] | 102 | SmallIntVector::iterator start;
|
---|
| 103 |
|
---|
[1526] | 104 | if (lodfactor<0.0f) lodfactor=0.0f;
|
---|
| 105 | if (lodfactor>1.0f) lodfactor=1.0f;
|
---|
| 106 |
|
---|
[1070] | 107 | uint32 newLOD = (uint32)((1.0f - lodfactor) * mLods);
|
---|
[1526] | 108 |
|
---|
| 109 | lodFactor=lodfactor;
|
---|
[1058] | 110 |
|
---|
[774] | 111 | if (newLOD != mCurrentLod)
|
---|
| 112 | {
|
---|
| 113 | if (newLOD > mCurrentLod)
|
---|
| 114 | {
|
---|
[1014] | 115 | // Forwards.
|
---|
[1530] | 116 | // Increments LOD (decreases level of detail)
|
---|
[1541] | 117 | for ( lod = mCurrentLod;
|
---|
| 118 | (lod < newLOD)
|
---|
| 119 | ||
|
---|
| 120 | ((mCurrentRegLOD->obligatory == 1) && (lod < (mLods - 1)));
|
---|
| 121 | lod++)
|
---|
[774] | 122 | {
|
---|
[1541] | 123 | next = mVertex[lod];
|
---|
[774] | 124 | total_changes = mPChanges[lod];
|
---|
| 125 |
|
---|
| 126 | for (i = 0; i < total_changes; i++)
|
---|
| 127 | {
|
---|
[1014] | 128 | // Strip change.
|
---|
[1541] | 129 | t = mCurrentRegLOD->strip;
|
---|
[774] | 130 | strip = &(mStrips[t]);
|
---|
[1541] | 131 | start = strip->begin();
|
---|
| 132 |
|
---|
[1526] | 133 | int stripsize_ini = strip->size();
|
---|
[774] | 134 |
|
---|
| 135 | // Position.
|
---|
| 136 | totalR = mCurrentRegLOD->position;
|
---|
| 137 |
|
---|
| 138 | for (j = totalR - 1; j >= 0; j--)
|
---|
| 139 | {
|
---|
[1526] | 140 | start[*mCurrentData] = next;
|
---|
[774] | 141 | ++mCurrentData;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | // L1.
|
---|
| 145 | totalR = mCurrentRegLOD->vertexRepetition;
|
---|
| 146 |
|
---|
| 147 | for (j = totalR - 1; j >= 0; j--)
|
---|
| 148 | {
|
---|
| 149 | offset = *mCurrentData + 1;
|
---|
| 150 |
|
---|
| 151 | strip->erase( start + offset,
|
---|
| 152 | start
|
---|
| 153 | +
|
---|
| 154 | offset
|
---|
| 155 | +
|
---|
| 156 | (*(mCurrentData + 1)));
|
---|
| 157 |
|
---|
| 158 | ++mCurrentData;
|
---|
| 159 | ++mCurrentData;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | // L2
|
---|
| 163 | totalR = mCurrentRegLOD->edgeRepetition;
|
---|
| 164 |
|
---|
| 165 | for (j = totalR - 1; j >= 0; j--)
|
---|
| 166 | {
|
---|
| 167 | offset = *mCurrentData + 2;
|
---|
| 168 | strip->erase( start + offset,
|
---|
| 169 | start
|
---|
| 170 | +
|
---|
| 171 | offset
|
---|
| 172 | +
|
---|
| 173 | 2*(*(mCurrentData + 1)));
|
---|
| 174 |
|
---|
[1014] | 175 | mCurrentData++;
|
---|
| 176 | mCurrentData++;
|
---|
[774] | 177 | }
|
---|
| 178 |
|
---|
[1530] | 179 | // lastLOD = mCurrentRegLOD;
|
---|
[1014] | 180 | mCurrentRegLOD++;
|
---|
[774] | 181 |
|
---|
| 182 | mStripsChanges[t] = 1;
|
---|
[1526] | 183 |
|
---|
| 184 | int stripsize_end = strip->size();
|
---|
| 185 | indices_x_submesh[submesh_x_strip[t]] -= (stripsize_ini - stripsize_end);
|
---|
[774] | 186 |
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | mCurrentLod = lod + 1;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | }
|
---|
[1014] | 193 | // If LOD is less than actual.
|
---|
[774] | 194 | else
|
---|
| 195 | {
|
---|
[1014] | 196 | mCurrentRegLOD--;
|
---|
| 197 | mCurrentData--;
|
---|
[1541] | 198 |
|
---|
| 199 |
|
---|
[1014] | 200 | // Decrements LOD.
|
---|
[1541] | 201 | for ( lod = mCurrentLod;
|
---|
| 202 | (lod > newLOD)
|
---|
| 203 | ||
|
---|
| 204 | ((mCurrentRegLOD->obligatory == 1) && (lod > 0))
|
---|
| 205 | ||
|
---|
| 206 | ((mCurrentRegLOD[1].obligatory == 1) && (lod > 0));
|
---|
| 207 | lod--)
|
---|
[774] | 208 | {
|
---|
[1541] | 209 |
|
---|
[774] | 210 | total_changes = mPChanges[lod - 1];
|
---|
| 211 |
|
---|
| 212 | for (i = 0; i < total_changes; i++)
|
---|
| 213 | {
|
---|
| 214 | t = mCurrentRegLOD->strip;
|
---|
| 215 | strip = &(mStrips[t]);
|
---|
| 216 | start = mStrips[t].begin();
|
---|
[1526] | 217 | int stripsize_ini = strip->size();
|
---|
[774] | 218 |
|
---|
| 219 | // L2.
|
---|
| 220 | totalR = mCurrentRegLOD->edgeRepetition;
|
---|
| 221 |
|
---|
| 222 | for (j = 0; j < totalR; j++)
|
---|
| 223 | {
|
---|
| 224 | el1 = (*strip)[*(mCurrentData - 1)];
|
---|
| 225 | el2 = (*strip)[*(mCurrentData - 1) + 1];
|
---|
| 226 | r = *(mCurrentData);
|
---|
| 227 |
|
---|
| 228 | for (k = 0; k < r; k++)
|
---|
| 229 | {
|
---|
| 230 | (*strip).insert(start+*(mCurrentData - 1),el2);
|
---|
| 231 | (*strip).insert(start+*(mCurrentData - 1),el1);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[1014] | 234 | mCurrentData--;
|
---|
| 235 | mCurrentData--;
|
---|
[774] | 236 | }
|
---|
| 237 |
|
---|
| 238 | // Vertex Repetition.
|
---|
| 239 | totalR = mCurrentRegLOD->vertexRepetition;
|
---|
| 240 |
|
---|
| 241 | for (j = 0; j < totalR; j++)
|
---|
| 242 | {
|
---|
| 243 | el1 = (*strip)[*(mCurrentData-1)];
|
---|
| 244 | r = *(mCurrentData);
|
---|
| 245 |
|
---|
| 246 | for (k = 0; k < r; k++)
|
---|
| 247 | {
|
---|
| 248 | (*strip).insert(start+*(mCurrentData-1),el1);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[1014] | 251 | mCurrentData--;
|
---|
| 252 | mCurrentData--;
|
---|
[774] | 253 | }
|
---|
| 254 |
|
---|
| 255 | // POS.
|
---|
| 256 | totalR = mCurrentRegLOD->position;
|
---|
| 257 |
|
---|
| 258 | for (j = 0; j < totalR; j++)
|
---|
| 259 | {
|
---|
| 260 | (*strip)[*mCurrentData] = lod - 1;
|
---|
[1014] | 261 | mCurrentData--;
|
---|
[774] | 262 | }
|
---|
| 263 |
|
---|
[1530] | 264 | // lastLOD = mCurrentRegLOD;
|
---|
[1014] | 265 | mCurrentRegLOD--;
|
---|
[774] | 266 | mStripsChanges[t] = 1;
|
---|
[1526] | 267 |
|
---|
| 268 | int stripsize_end = strip->size();
|
---|
| 269 | indices_x_submesh[submesh_x_strip[t]] += (stripsize_end - stripsize_ini);
|
---|
[774] | 270 | }
|
---|
| 271 |
|
---|
[1541] | 272 | // Update LOD.
|
---|
[774] | 273 | mCurrentLod = lod - 1;
|
---|
[1541] | 274 |
|
---|
| 275 | // Debug.
|
---|
| 276 | cout << "Obligatory: "
|
---|
| 277 | << (int)mCurrentRegLOD->obligatory
|
---|
| 278 | << endl;
|
---|
[774] | 279 | }
|
---|
| 280 |
|
---|
[1014] | 281 | mCurrentData++;
|
---|
| 282 | mCurrentRegLOD++;
|
---|
[774] | 283 | }
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[1552] | 286 | /* // debug!
|
---|
| 287 | FILE *f = fopen("lodstrips_lodinfo.txt","wt");
|
---|
| 288 | fprintf(f,"mCurrentLOD: %d",mCurrentLod);
|
---|
| 289 | fprintf(f,"mLods: %d",mLods);
|
---|
| 290 | for (int i=0; i<mTotalStrips; i++)
|
---|
| 291 | {
|
---|
| 292 | fprintf(f,"\nstrip: %d - ",i);
|
---|
| 293 | for (int j=0; j<mStrips[i].size(); j++)
|
---|
| 294 | {
|
---|
| 295 | int ind = mStrips[i][j];
|
---|
| 296 | fprintf(f,"%d ",ind);
|
---|
| 297 | }
|
---|
| 298 | }
|
---|
| 299 | fclose(f);*/
|
---|
| 300 |
|
---|
[1018] | 301 | UpdateDataRetrievalInterface();
|
---|
[1058] | 302 | // return return_value;
|
---|
[774] | 303 | }
|
---|
| 304 |
|
---|
[1009] | 305 | //-----------------------------------------------------------------------------
|
---|
| 306 | // Returns the number of vertices of the highest LOD.
|
---|
| 307 | //-----------------------------------------------------------------------------
|
---|
[774] | 308 | uint32 LodStripsLibrary::MaxVertices()
|
---|
| 309 | {
|
---|
[1007] | 310 | return mMaxVerticesLOD;
|
---|
[774] | 311 | }
|
---|
| 312 |
|
---|
[1009] | 313 | //-----------------------------------------------------------------------------
|
---|
| 314 | // Returns the number of vertices of the lowest LOD.
|
---|
| 315 | //-----------------------------------------------------------------------------
|
---|
[774] | 316 | uint32 LodStripsLibrary::MinVertices()
|
---|
| 317 | {
|
---|
| 318 | uint32 number_of_vertices;
|
---|
| 319 |
|
---|
[1014] | 320 | // Total vertices of minimum lod.
|
---|
[1007] | 321 | number_of_vertices = mMaxVerticesLOD - (mMinLod + 1);
|
---|
[774] | 322 |
|
---|
| 323 | return number_of_vertices;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[1009] | 326 | //-----------------------------------------------------------------------------
|
---|
| 327 | // Returns the number of triangles of the highest LOD.
|
---|
| 328 | //-----------------------------------------------------------------------------
|
---|
[774] | 329 | uint32 LodStripsLibrary::MaxFaces()
|
---|
| 330 | {
|
---|
[1058] | 331 | /* uint32 number_of_faces;
|
---|
[774] | 332 |
|
---|
| 333 | uint32 current_lod;
|
---|
| 334 |
|
---|
| 335 | current_lod = GoToLod(MaxLod());
|
---|
| 336 |
|
---|
| 337 | // Initialize number of faces count.
|
---|
| 338 | number_of_faces = 0;
|
---|
| 339 |
|
---|
| 340 | // For each strip.
|
---|
[985] | 341 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
[774] | 342 | {
|
---|
[985] | 343 | number_of_faces += int(mStrips[strip].size() - 2);
|
---|
[774] | 344 | }
|
---|
| 345 |
|
---|
| 346 | GoToLod(current_lod);
|
---|
| 347 |
|
---|
[1058] | 348 | return number_of_faces;*/
|
---|
| 349 |
|
---|
| 350 | return maxFaces;
|
---|
[774] | 351 | }
|
---|
| 352 |
|
---|
[1009] | 353 | //-----------------------------------------------------------------------------
|
---|
| 354 | // Returns the number of triangles of the lowest LOD.
|
---|
| 355 | //-----------------------------------------------------------------------------
|
---|
[774] | 356 | uint32 LodStripsLibrary::MinFaces()
|
---|
| 357 | {
|
---|
[1058] | 358 | /* uint32 current_lod;
|
---|
[774] | 359 | uint32 number_of_faces;
|
---|
| 360 |
|
---|
| 361 | current_lod = GoToLod(MinLod());
|
---|
| 362 |
|
---|
| 363 | // Initialize number of faces count.
|
---|
| 364 | number_of_faces = 0;
|
---|
| 365 |
|
---|
| 366 | // For each strip.
|
---|
[985] | 367 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
[774] | 368 | {
|
---|
[985] | 369 | number_of_faces += int(mStrips[strip].size() - 2);
|
---|
[774] | 370 | }
|
---|
| 371 |
|
---|
| 372 | GoToLod(current_lod);
|
---|
| 373 |
|
---|
[1058] | 374 | return number_of_faces;*/
|
---|
| 375 |
|
---|
| 376 | return minFaces;
|
---|
[774] | 377 | }
|
---|
| 378 |
|
---|
[1009] | 379 | //-----------------------------------------------------------------------------
|
---|
| 380 | // Establishes the new LOD range.
|
---|
| 381 | // Only the LODs in that range are stored and used.
|
---|
| 382 | //-----------------------------------------------------------------------------
|
---|
[774] | 383 | void LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod)
|
---|
| 384 | {
|
---|
[1007] | 385 | // Refresh number of vercies of the max lod.
|
---|
| 386 | mMaxVerticesLOD += mMaxLod - maxLod;
|
---|
| 387 |
|
---|
[774] | 388 | mMinLod = minLod;
|
---|
| 389 | mMaxLod = maxLod;
|
---|
| 390 | }
|
---|
[1018] | 391 | /*
|
---|
[1009] | 392 | //-----------------------------------------------------------------------------
|
---|
| 393 | // Get strip count.
|
---|
| 394 | //-----------------------------------------------------------------------------
|
---|
[829] | 395 | uint32 LodStripsLibrary::GetStripCount() const
|
---|
[774] | 396 | {
|
---|
| 397 | return (uint32) mTotalStrips;
|
---|
| 398 | }
|
---|
| 399 |
|
---|
[1009] | 400 | //-----------------------------------------------------------------------------
|
---|
| 401 | // Get Index by strip.
|
---|
| 402 | //-----------------------------------------------------------------------------
|
---|
[829] | 403 | uint32 LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const
|
---|
| 404 | {
|
---|
| 405 | return (uint32) mStrips[istrip].size();
|
---|
| 406 | }
|
---|
[1018] | 407 | */
|
---|
[774] | 408 | //-----------------------------------------------------------------------------
|
---|
| 409 | // Private.
|
---|
| 410 | //-----------------------------------------------------------------------------
|
---|
| 411 |
|
---|
[1009] | 412 | //-----------------------------------------------------------------------------
|
---|
| 413 | // Copy a STL vector to a C array.
|
---|
| 414 | //-----------------------------------------------------------------------------
|
---|
[1526] | 415 | void LodStripsLibrary::CopyVectors2Arrays(void)
|
---|
[774] | 416 | {
|
---|
| 417 | SmallInt max;
|
---|
| 418 | SmallInt t;
|
---|
| 419 | SmallInt *data_array;
|
---|
| 420 | SmallIntVector tira;
|
---|
| 421 | LODRegisterType *changes_array;
|
---|
| 422 | LODRegisterVector list_changes;
|
---|
| 423 |
|
---|
[985] | 424 | mTotalStrips = int(mFileStrips.size());
|
---|
[774] | 425 | mVertex = new SmallInt[mTotalVertices];
|
---|
| 426 | mStripsChanges = new SmallInt[mTotalChanges];
|
---|
| 427 | mStrips = new SmallIntVector[mTotalStrips];
|
---|
| 428 | data_array = new SmallInt[mData.size()];
|
---|
| 429 |
|
---|
| 430 | max = 0;
|
---|
| 431 | mTotalFaces = 0;
|
---|
[1018] | 432 |
|
---|
[1069] | 433 | // unsigned int * strip_sizes = new unsigned int[mFileStrips.size()];
|
---|
| 434 | unsigned int total_strip_size = 0;
|
---|
[1070] | 435 |
|
---|
| 436 | for (unsigned int i = 0; i < mFileStrips.size(); i++)
|
---|
[774] | 437 | {
|
---|
[1069] | 438 | total_strip_size += t = int(mFileStrips[i].size());
|
---|
[774] | 439 | if (t>max)
|
---|
| 440 | max = t;
|
---|
| 441 | mTotalFaces += t - 2;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | changes_array = new LODRegisterType[mFileChangesLOD.size()];
|
---|
| 445 |
|
---|
[1014] | 446 | // Fill up changes array.
|
---|
[1070] | 447 | for (unsigned int i = 0; i < mFileChangesLOD.size(); ++i)
|
---|
[774] | 448 | {
|
---|
| 449 | changes_array[i] = mFileChangesLOD[i];
|
---|
| 450 | }
|
---|
| 451 |
|
---|
| 452 | mCurrentRegLOD = changes_array;
|
---|
| 453 |
|
---|
[1014] | 454 | // Copy strips.
|
---|
[1325] | 455 | // unsigned int numDegenerated = 2*mTotalStrips - 2;
|
---|
[1526] | 456 | // dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal!
|
---|
[1070] | 457 |
|
---|
[1526] | 458 | // dataRetrievalInterface->Init(total_strip_size);
|
---|
| 459 | /* dataRetrievalInterface->numinds=total_strip_size;
|
---|
| 460 | dataRetrievalInterface->numvalidinds=total_strip_size;*/
|
---|
| 461 | // dataRetrievalInterface->Begin();
|
---|
| 462 |
|
---|
[1070] | 463 | unsigned int ii = 0;
|
---|
| 464 |
|
---|
| 465 | for (unsigned int i = 0; i < mFileStrips.size(); i++)
|
---|
[774] | 466 | {
|
---|
[1070] | 467 | for (unsigned int j = 0; j < mFileStrips[i].size(); j++,ii++)
|
---|
[774] | 468 | {
|
---|
| 469 | mStrips[i].push_back(mFileStrips[i][j]);
|
---|
[1526] | 470 | // dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]);
|
---|
[774] | 471 | }
|
---|
| 472 |
|
---|
[1014] | 473 | // Reset flags of strips changed.
|
---|
[774] | 474 | mStripsChanges[i] = 0;
|
---|
| 475 | }
|
---|
[1552] | 476 |
|
---|
[1526] | 477 | // dataRetrievalInterface->End();
|
---|
[774] | 478 |
|
---|
[1070] | 479 | for (unsigned int i = 0; i < mData.size(); i++)
|
---|
[774] | 480 | {
|
---|
| 481 | data_array[i] = mData[i];
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | mCurrentData = data_array;
|
---|
| 485 |
|
---|
[1014] | 486 | // Fill up mVertex.
|
---|
[1070] | 487 | for(unsigned int i = 0; i < mFileVertices.size(); i++)
|
---|
[774] | 488 | {
|
---|
| 489 | mVertex[i] = mFileVertices[i];
|
---|
| 490 | }
|
---|
[1018] | 491 |
|
---|
[1069] | 492 | // delete[] strip_sizes;
|
---|
[774] | 493 | }
|
---|
| 494 |
|
---|
| 495 | //-----------------------------------------------------------------------------
|
---|
[1009] | 496 | // LoadStripMesh
|
---|
[774] | 497 | //-----------------------------------------------------------------------------
|
---|
[1083] | 498 | void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh)
|
---|
[774] | 499 | {
|
---|
[1136] | 500 | //FILE *fp;
|
---|
[774] | 501 | SmallIntVector strip_aux;
|
---|
[1136] | 502 | //LODRegisterType lod_register;
|
---|
[774] | 503 | std::vector <LODRegisterType> list_pos;
|
---|
| 504 | std::vector <unsigned int> p_changes;
|
---|
[1136] | 505 | //int value;
|
---|
[1014] | 506 | int v = 0;
|
---|
| 507 | int t = -1;
|
---|
| 508 | int s = 0;
|
---|
| 509 | int next = 0;
|
---|
| 510 | int c = -1;
|
---|
[1136] | 511 | //char buff[80];
|
---|
[774] | 512 | Index *index;
|
---|
| 513 | Index *indexBegin;
|
---|
| 514 | Index *indexEnd;
|
---|
| 515 | SubMesh *geoSubMesh;
|
---|
| 516 |
|
---|
| 517 | // For each one of the submeshes.
|
---|
[1078] | 518 | indices_x_submesh = new int[geomesh->mSubMeshCount];
|
---|
[1083] | 519 | offsets_x_submesh = new int[geomesh->mSubMeshCount];
|
---|
[1526] | 520 |
|
---|
| 521 | int totaltiras = 0;
|
---|
| 522 | for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
|
---|
| 523 | for (unsigned int strip = 0; strip < geomesh->mSubMesh[submesh].mStripCount; strip++)
|
---|
| 524 | totaltiras++;
|
---|
| 525 |
|
---|
| 526 | submesh_x_strip = new int[totaltiras];
|
---|
| 527 |
|
---|
| 528 | int istrip = 0;
|
---|
[985] | 529 | for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
|
---|
[774] | 530 | {
|
---|
| 531 | geoSubMesh = &geomesh->mSubMesh[submesh];
|
---|
[1526] | 532 | indices_x_submesh[submesh] = 0;
|
---|
[774] | 533 |
|
---|
| 534 | // For each one of the strips.
|
---|
[1526] | 535 | for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++)
|
---|
[774] | 536 | {
|
---|
| 537 | // Insert an empty strip.
|
---|
[1526] | 538 | submesh_x_strip[istrip] = submesh;
|
---|
[774] | 539 | t++;
|
---|
| 540 | strip_aux.clear();
|
---|
| 541 | mFileStrips.push_back(strip_aux);
|
---|
| 542 |
|
---|
| 543 | // First index of the strip.
|
---|
| 544 | indexBegin = geoSubMesh->mStrip[strip];
|
---|
| 545 |
|
---|
[1552] | 546 | // If the strips is not the first. (DEG!)
|
---|
| 547 | if (strip != 0)
|
---|
[774] | 548 | indexBegin++;
|
---|
| 549 |
|
---|
| 550 | // If is the final strip
|
---|
| 551 | if (strip == (geoSubMesh->mStripCount - 1))
|
---|
| 552 | {
|
---|
| 553 | // The end of the index array.
|
---|
| 554 | indexEnd = &geoSubMesh->mIndex[geoSubMesh->mIndexCount];
|
---|
| 555 | }
|
---|
| 556 | else
|
---|
| 557 | {
|
---|
| 558 | // The beginning of the next strip.
|
---|
| 559 | indexEnd = geoSubMesh->mStrip[strip + 1];
|
---|
| 560 |
|
---|
[1552] | 561 | // Remove degenerated (DEG!)
|
---|
| 562 | indexEnd--;
|
---|
[774] | 563 | }
|
---|
| 564 |
|
---|
| 565 | int i;
|
---|
| 566 | i = 0;
|
---|
[1526] | 567 |
|
---|
[1083] | 568 | if (submesh==0)
|
---|
| 569 | offsets_x_submesh[submesh] = 0;
|
---|
| 570 | else
|
---|
| 571 | offsets_x_submesh[submesh] = indices_x_submesh[submesh-1];
|
---|
| 572 |
|
---|
[774] | 573 | // For each index of the strip.
|
---|
| 574 | for (index = indexBegin; index < indexEnd; index++)
|
---|
| 575 | {
|
---|
| 576 | mFileStrips[t].push_back(indexBegin[i]);
|
---|
[1078] | 577 | indices_x_submesh[submesh]++;
|
---|
[774] | 578 | i++;
|
---|
[1083] | 579 | }
|
---|
[774] | 580 | }
|
---|
| 581 | }
|
---|
| 582 |
|
---|
[1070] | 583 | // TODO: LOD file loaded in load file mesh process.
|
---|
[774] | 584 | // Open the LOD file.
|
---|
[1078] | 585 | /* if ((fp = fopen (name, "r")) == NULL)
|
---|
[774] | 586 | {
|
---|
| 587 | // Error in open.
|
---|
| 588 | }
|
---|
| 589 | else
|
---|
| 590 | {
|
---|
| 591 | mTotalChanges = 0;
|
---|
| 592 |
|
---|
| 593 | while (!feof (fp))
|
---|
| 594 | {
|
---|
| 595 | fgets (buff, 80, fp);
|
---|
| 596 |
|
---|
| 597 | if (*buff == 'v')
|
---|
| 598 | {
|
---|
| 599 | sscanf (buff+2,"%d",&value);
|
---|
| 600 |
|
---|
| 601 | mFileVertices.push_back(value);
|
---|
| 602 | v++;
|
---|
| 603 | }
|
---|
| 604 | else if ( (*buff == 'c') || (*buff == 'd'))
|
---|
| 605 | {
|
---|
| 606 | if (*buff == 'c')
|
---|
| 607 | {
|
---|
| 608 | c++;
|
---|
| 609 | }
|
---|
| 610 | else
|
---|
| 611 | {
|
---|
| 612 | unsigned int a;
|
---|
| 613 | unsigned int b;
|
---|
| 614 | unsigned int c;
|
---|
| 615 | unsigned int d;
|
---|
| 616 |
|
---|
| 617 | sscanf (buff+2,"%u %u %u %u\n",&a,&b,&c,&d);
|
---|
| 618 | lod_register.strip = a;
|
---|
| 619 | lod_register.position = b;
|
---|
| 620 | lod_register.vertexRepetition = c;
|
---|
| 621 | lod_register.edgeRepetition = d;
|
---|
| 622 |
|
---|
| 623 | mFileChangesLOD.push_back(lod_register);
|
---|
| 624 | }
|
---|
| 625 | }
|
---|
| 626 | else if (*buff=='b')
|
---|
| 627 | {
|
---|
| 628 | sscanf(buff+2,"%u",&value);
|
---|
| 629 | mData.push_back(value);
|
---|
| 630 | }
|
---|
| 631 | else if (*buff=='p')
|
---|
| 632 | {
|
---|
| 633 | sscanf (buff+2,"%u",&value);
|
---|
| 634 | p_changes.push_back(value);
|
---|
[1014] | 635 | }
|
---|
| 636 | }
|
---|
[774] | 637 |
|
---|
[1078] | 638 | fclose(fp);*/
|
---|
| 639 |
|
---|
[1083] | 640 | mFileVertices = lodstripsdata->mFileVertices;
|
---|
| 641 | mFileChangesLOD = lodstripsdata->mFileChangesLOD;
|
---|
| 642 | mData = lodstripsdata->mData;
|
---|
| 643 | p_changes = lodstripsdata->p_changes;
|
---|
[774] | 644 |
|
---|
[1090] | 645 | mStripsSubmesh = new int [geomesh->mSubMeshCount];
|
---|
[1136] | 646 | for (size_t submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
|
---|
[1090] | 647 | {
|
---|
| 648 | mStripsSubmesh[submesh]=0;
|
---|
| 649 | }
|
---|
[774] | 650 |
|
---|
[1090] | 651 |
|
---|
| 652 | // Max / Min values for LOD.
|
---|
| 653 | mLods = int(p_changes.size());
|
---|
| 654 | mMaxLod = 0;
|
---|
| 655 | mMinLod = mLods;
|
---|
[774] | 656 |
|
---|
[1090] | 657 | mPChanges = new SmallInt[mLods];
|
---|
| 658 |
|
---|
| 659 | for (unsigned int i = 0; i < mLods; i++)
|
---|
| 660 | mPChanges[i] = p_changes[i];
|
---|
| 661 |
|
---|
| 662 | mTotalVertices = int(mFileVertices.size());
|
---|
| 663 | mMaxVerticesLOD = mTotalVertices;
|
---|
| 664 | mTotalStrips = int(mFileStrips.size());
|
---|
| 665 | mTotalChanges = int(mFileChangesLOD.size());
|
---|
| 666 |
|
---|
| 667 | //Copy the data to the structure we will use
|
---|
| 668 | CopyVectors2Arrays();
|
---|
[774] | 669 | }
|
---|
| 670 |
|
---|
[1018] | 671 | void LodStripsLibrary::UpdateDataRetrievalInterface(void)
|
---|
| 672 | {
|
---|
[1560] | 673 | int target_submesh = 0;
|
---|
| 674 | size_t strip_count = 0;
|
---|
| 675 | unsigned int ii_submesh = 0;
|
---|
| 676 |
|
---|
[1552] | 677 | current_triangle_count = 0;
|
---|
[1078] | 678 |
|
---|
[1552] | 679 | // indices_x_submesh is calculated without degenerates,
|
---|
| 680 | // we must add the degenerate indices added here
|
---|
[1560] | 681 | uint32 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount * 2 - 2;
|
---|
[1325] | 682 |
|
---|
[1560] | 683 | dataRetrievalInterface->Begin(target_submesh,
|
---|
| 684 | indices_x_submesh[target_submesh] + numdeg);
|
---|
[1526] | 685 |
|
---|
[1560] | 686 | current_triangle_count += indices_x_submesh[target_submesh] + numdeg;
|
---|
| 687 |
|
---|
| 688 | // For each strip.
|
---|
[1552] | 689 | for (unsigned int i = 0; i < mTotalStrips; i++, strip_count++)
|
---|
[1018] | 690 | {
|
---|
[1078] | 691 | if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount)
|
---|
| 692 | {
|
---|
[1560] | 693 | if (target_submesh == 0)
|
---|
| 694 | {
|
---|
[1083] | 695 | offsets_x_submesh[target_submesh] = 0;
|
---|
[1560] | 696 | }
|
---|
[1083] | 697 | else
|
---|
[1560] | 698 | {
|
---|
| 699 | offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1]
|
---|
| 700 | +
|
---|
| 701 | offsets_x_submesh[target_submesh-1];
|
---|
| 702 | }
|
---|
[1083] | 703 |
|
---|
[1136] | 704 | mStripsSubmesh[target_submesh] = (int)strip_count;
|
---|
[1325] | 705 | strip_count = 0;
|
---|
[1136] | 706 |
|
---|
[1078] | 707 | target_submesh++;
|
---|
[1526] | 708 | ii_submesh = 0;
|
---|
| 709 | dataRetrievalInterface->End();
|
---|
[1560] | 710 |
|
---|
| 711 | numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2;
|
---|
| 712 |
|
---|
| 713 | dataRetrievalInterface->Begin(target_submesh,
|
---|
| 714 | indices_x_submesh[target_submesh] + numdeg);
|
---|
[1552] | 715 |
|
---|
[1560] | 716 | current_triangle_count += indices_x_submesh[target_submesh] + numdeg;
|
---|
[1078] | 717 | }
|
---|
[1560] | 718 |
|
---|
[1087] | 719 | int lastindex = -1;
|
---|
[1560] | 720 |
|
---|
| 721 | for ( SmallIntVector::iterator it = mStrips[i].begin();
|
---|
| 722 | it != mStrips[i].end();
|
---|
| 723 | it++, ii_submesh++)
|
---|
[1078] | 724 | {
|
---|
[1552] | 725 | // repeat the first index of the strip: degenerate (DEG!)
|
---|
| 726 | // except for the first strip in a mesh
|
---|
[1560] | 727 | if ((lastindex == -1) && (strip_count > 0))
|
---|
[1087] | 728 | {
|
---|
[1560] | 729 | lastindex = *it;
|
---|
| 730 |
|
---|
[1552] | 731 | dataRetrievalInterface->SetIndex(ii_submesh,*it);
|
---|
| 732 | ii_submesh++;
|
---|
| 733 | }
|
---|
[1560] | 734 |
|
---|
| 735 | lastindex = *it;
|
---|
[1526] | 736 | dataRetrievalInterface->SetIndex(ii_submesh,*it);
|
---|
[1078] | 737 | }
|
---|
[1087] | 738 |
|
---|
[1552] | 739 | // repeat last vertex of the strip: degenerate (DEG!)
|
---|
| 740 | // except for the last strip in a mesh
|
---|
[1560] | 741 | if (strip_count < mGeoMesh->mSubMesh[target_submesh].mStripCount-1)
|
---|
[1552] | 742 | {
|
---|
| 743 | dataRetrievalInterface->SetIndex(ii_submesh,lastindex);
|
---|
| 744 | ii_submesh++;
|
---|
| 745 | }
|
---|
[1018] | 746 | }
|
---|
[1078] | 747 |
|
---|
| 748 | if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount)
|
---|
| 749 | {
|
---|
[1560] | 750 | if (target_submesh == 0)
|
---|
| 751 | {
|
---|
[1083] | 752 | offsets_x_submesh[target_submesh] = 0;
|
---|
[1560] | 753 | }
|
---|
[1083] | 754 | else
|
---|
[1560] | 755 | {
|
---|
| 756 | offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1]
|
---|
| 757 | +
|
---|
| 758 | offsets_x_submesh[target_submesh-1];
|
---|
| 759 | }
|
---|
[1083] | 760 |
|
---|
[1560] | 761 | mStripsSubmesh[target_submesh] = (int)strip_count;
|
---|
| 762 | strip_count = 0;
|
---|
| 763 |
|
---|
[1078] | 764 | target_submesh++;
|
---|
| 765 | }
|
---|
| 766 |
|
---|
[1018] | 767 | dataRetrievalInterface->End();
|
---|
[1070] | 768 | }
|
---|
[1560] | 769 |
|
---|