1 | /*==========================================================================
|
---|
2 | * (C) 2005 Universitat Jaume I
|
---|
3 | *==========================================================================
|
---|
4 | * PROYECT: GAME TOOLS
|
---|
5 | *==========================================================================
|
---|
6 | * CONTENT:
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * @file GeoLodStripsLibrary.cpp
|
---|
10 | *===========================================================================*/
|
---|
11 |
|
---|
12 | #include "GeoLodStripsLibrary.h"
|
---|
13 |
|
---|
14 | using namespace Geometry;
|
---|
15 | using namespace std;
|
---|
16 |
|
---|
17 | //-----------------------------------------------------------------------------
|
---|
18 | // Constructor.
|
---|
19 | //-----------------------------------------------------------------------------
|
---|
20 | LodStripsLibrary::LodStripsLibrary( const LodStripsLibraryData *lodstripsdata,
|
---|
21 | Mesh *geomesh,
|
---|
22 | IndexData *userindexdata)
|
---|
23 | {
|
---|
24 | // Sets the current lod.
|
---|
25 | mCurrentLod = 0;
|
---|
26 |
|
---|
27 | // Sets the global mesh.
|
---|
28 | mGeoMesh = geomesh;
|
---|
29 |
|
---|
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;
|
---|
38 |
|
---|
39 | // Loads the Level Of Detail file.
|
---|
40 | LodStripsLibrary::LoadStripMesh(lodstripsdata,mGeoMesh);
|
---|
41 |
|
---|
42 | GoToLod(0.0f);
|
---|
43 |
|
---|
44 | minFaces = 0;
|
---|
45 |
|
---|
46 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
47 | {
|
---|
48 | minFaces += int(mStrips[strip].size() - 2);
|
---|
49 | }
|
---|
50 |
|
---|
51 | GoToLod(1.0f);
|
---|
52 |
|
---|
53 | maxFaces = 0;
|
---|
54 |
|
---|
55 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
56 | {
|
---|
57 | maxFaces += int(mStrips[strip].size() - 2);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | //-----------------------------------------------------------------------------
|
---|
62 | // Destructor
|
---|
63 | //-----------------------------------------------------------------------------
|
---|
64 | LodStripsLibrary::~LodStripsLibrary()
|
---|
65 | {
|
---|
66 | delete [] mStrips;
|
---|
67 | if (delete_indexdata)
|
---|
68 | delete dataRetrievalInterface;
|
---|
69 | if (indices_x_submesh)
|
---|
70 | delete[] indices_x_submesh;
|
---|
71 | if (offsets_x_submesh)
|
---|
72 | delete[] offsets_x_submesh;
|
---|
73 | if (mStripsSubmesh)
|
---|
74 | delete[] mStripsSubmesh;
|
---|
75 | if (submesh_x_strip)
|
---|
76 | delete[] submesh_x_strip;
|
---|
77 | }
|
---|
78 |
|
---|
79 | //-----------------------------------------------------------------------------
|
---|
80 | // Public.
|
---|
81 | //-----------------------------------------------------------------------------
|
---|
82 |
|
---|
83 | //-----------------------------------------------------------------------------
|
---|
84 | // Go to the level of detail.
|
---|
85 | //-----------------------------------------------------------------------------
|
---|
86 | void LodStripsLibrary::GoToLod(float lodfactor)
|
---|
87 | {
|
---|
88 | register int j;
|
---|
89 | register int offset;
|
---|
90 | long int i;
|
---|
91 | long int k;
|
---|
92 | long int b_change_ok = 1;
|
---|
93 | unsigned long int lod;
|
---|
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;
|
---|
101 | SmallIntVector *strip;
|
---|
102 | SmallIntVector::iterator start;
|
---|
103 |
|
---|
104 | if (lodfactor<0.0f) lodfactor=0.0f;
|
---|
105 | if (lodfactor>1.0f) lodfactor=1.0f;
|
---|
106 |
|
---|
107 | uint32 newLOD = (uint32)((1.0f - lodfactor) * mLods);
|
---|
108 |
|
---|
109 | lodFactor=lodfactor;
|
---|
110 |
|
---|
111 | if (newLOD != mCurrentLod)
|
---|
112 | {
|
---|
113 | if (newLOD > mCurrentLod)
|
---|
114 | {
|
---|
115 | // Forwards.
|
---|
116 | // Increments LOD (decreases level of detail)
|
---|
117 | for ( lod = mCurrentLod;
|
---|
118 | (lod < newLOD)
|
---|
119 | ||
|
---|
120 | ((mCurrentRegLOD->obligatory == 1) && (lod < (mLods - 1)));
|
---|
121 | lod++)
|
---|
122 | {
|
---|
123 | next = mVertex[lod];
|
---|
124 | total_changes = mPChanges[lod];
|
---|
125 |
|
---|
126 | for (i = 0; i < total_changes; i++)
|
---|
127 | {
|
---|
128 | // Strip change.
|
---|
129 | t = mCurrentRegLOD->strip;
|
---|
130 | strip = &(mStrips[t]);
|
---|
131 | start = strip->begin();
|
---|
132 |
|
---|
133 | int stripsize_ini = strip->size();
|
---|
134 |
|
---|
135 | // Position.
|
---|
136 | totalR = mCurrentRegLOD->position;
|
---|
137 |
|
---|
138 | for (j = totalR - 1; j >= 0; j--)
|
---|
139 | {
|
---|
140 | start[*mCurrentData] = next;
|
---|
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 |
|
---|
175 | mCurrentData++;
|
---|
176 | mCurrentData++;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // lastLOD = mCurrentRegLOD;
|
---|
180 | mCurrentRegLOD++;
|
---|
181 |
|
---|
182 | mStripsChanges[t] = 1;
|
---|
183 |
|
---|
184 | int stripsize_end = strip->size();
|
---|
185 | indices_x_submesh[submesh_x_strip[t]] -= (stripsize_ini - stripsize_end);
|
---|
186 |
|
---|
187 | }
|
---|
188 |
|
---|
189 | mCurrentLod = lod + 1;
|
---|
190 | }
|
---|
191 |
|
---|
192 | }
|
---|
193 | // If LOD is less than actual.
|
---|
194 | else
|
---|
195 | {
|
---|
196 | mCurrentRegLOD--;
|
---|
197 | mCurrentData--;
|
---|
198 |
|
---|
199 |
|
---|
200 | // Decrements LOD.
|
---|
201 | for ( lod = mCurrentLod;
|
---|
202 | (lod > newLOD)
|
---|
203 | ||
|
---|
204 | ((mCurrentRegLOD->obligatory == 1) && (lod > 0))
|
---|
205 | ||
|
---|
206 | ((mCurrentRegLOD[1].obligatory == 1) && (lod > 0));
|
---|
207 | lod--)
|
---|
208 | {
|
---|
209 |
|
---|
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();
|
---|
217 | int stripsize_ini = strip->size();
|
---|
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 |
|
---|
234 | mCurrentData--;
|
---|
235 | mCurrentData--;
|
---|
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 |
|
---|
251 | mCurrentData--;
|
---|
252 | mCurrentData--;
|
---|
253 | }
|
---|
254 |
|
---|
255 | // POS.
|
---|
256 | totalR = mCurrentRegLOD->position;
|
---|
257 |
|
---|
258 | for (j = 0; j < totalR; j++)
|
---|
259 | {
|
---|
260 | (*strip)[*mCurrentData] = lod - 1;
|
---|
261 | mCurrentData--;
|
---|
262 | }
|
---|
263 |
|
---|
264 | // lastLOD = mCurrentRegLOD;
|
---|
265 | mCurrentRegLOD--;
|
---|
266 | mStripsChanges[t] = 1;
|
---|
267 |
|
---|
268 | int stripsize_end = strip->size();
|
---|
269 | indices_x_submesh[submesh_x_strip[t]] += (stripsize_end - stripsize_ini);
|
---|
270 | }
|
---|
271 |
|
---|
272 | // Update LOD.
|
---|
273 | mCurrentLod = lod - 1;
|
---|
274 |
|
---|
275 | // Debug.
|
---|
276 | cout << "Obligatory: "
|
---|
277 | << (int)mCurrentRegLOD->obligatory
|
---|
278 | << endl;
|
---|
279 | }
|
---|
280 |
|
---|
281 | mCurrentData++;
|
---|
282 | mCurrentRegLOD++;
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
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 |
|
---|
301 | UpdateDataRetrievalInterface();
|
---|
302 | // return return_value;
|
---|
303 | }
|
---|
304 |
|
---|
305 | //-----------------------------------------------------------------------------
|
---|
306 | // Returns the number of vertices of the highest LOD.
|
---|
307 | //-----------------------------------------------------------------------------
|
---|
308 | uint32 LodStripsLibrary::MaxVertices()
|
---|
309 | {
|
---|
310 | return mMaxVerticesLOD;
|
---|
311 | }
|
---|
312 |
|
---|
313 | //-----------------------------------------------------------------------------
|
---|
314 | // Returns the number of vertices of the lowest LOD.
|
---|
315 | //-----------------------------------------------------------------------------
|
---|
316 | uint32 LodStripsLibrary::MinVertices()
|
---|
317 | {
|
---|
318 | uint32 number_of_vertices;
|
---|
319 |
|
---|
320 | // Total vertices of minimum lod.
|
---|
321 | number_of_vertices = mMaxVerticesLOD - (mMinLod + 1);
|
---|
322 |
|
---|
323 | return number_of_vertices;
|
---|
324 | }
|
---|
325 |
|
---|
326 | //-----------------------------------------------------------------------------
|
---|
327 | // Returns the number of triangles of the highest LOD.
|
---|
328 | //-----------------------------------------------------------------------------
|
---|
329 | uint32 LodStripsLibrary::MaxFaces()
|
---|
330 | {
|
---|
331 | /* uint32 number_of_faces;
|
---|
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.
|
---|
341 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
342 | {
|
---|
343 | number_of_faces += int(mStrips[strip].size() - 2);
|
---|
344 | }
|
---|
345 |
|
---|
346 | GoToLod(current_lod);
|
---|
347 |
|
---|
348 | return number_of_faces;*/
|
---|
349 |
|
---|
350 | return maxFaces;
|
---|
351 | }
|
---|
352 |
|
---|
353 | //-----------------------------------------------------------------------------
|
---|
354 | // Returns the number of triangles of the lowest LOD.
|
---|
355 | //-----------------------------------------------------------------------------
|
---|
356 | uint32 LodStripsLibrary::MinFaces()
|
---|
357 | {
|
---|
358 | /* uint32 current_lod;
|
---|
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.
|
---|
367 | for (unsigned int strip = 0; strip < mTotalStrips; strip++)
|
---|
368 | {
|
---|
369 | number_of_faces += int(mStrips[strip].size() - 2);
|
---|
370 | }
|
---|
371 |
|
---|
372 | GoToLod(current_lod);
|
---|
373 |
|
---|
374 | return number_of_faces;*/
|
---|
375 |
|
---|
376 | return minFaces;
|
---|
377 | }
|
---|
378 |
|
---|
379 | //-----------------------------------------------------------------------------
|
---|
380 | // Establishes the new LOD range.
|
---|
381 | // Only the LODs in that range are stored and used.
|
---|
382 | //-----------------------------------------------------------------------------
|
---|
383 | void LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod)
|
---|
384 | {
|
---|
385 | // Refresh number of vercies of the max lod.
|
---|
386 | mMaxVerticesLOD += mMaxLod - maxLod;
|
---|
387 |
|
---|
388 | mMinLod = minLod;
|
---|
389 | mMaxLod = maxLod;
|
---|
390 | }
|
---|
391 | /*
|
---|
392 | //-----------------------------------------------------------------------------
|
---|
393 | // Get strip count.
|
---|
394 | //-----------------------------------------------------------------------------
|
---|
395 | uint32 LodStripsLibrary::GetStripCount() const
|
---|
396 | {
|
---|
397 | return (uint32) mTotalStrips;
|
---|
398 | }
|
---|
399 |
|
---|
400 | //-----------------------------------------------------------------------------
|
---|
401 | // Get Index by strip.
|
---|
402 | //-----------------------------------------------------------------------------
|
---|
403 | uint32 LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const
|
---|
404 | {
|
---|
405 | return (uint32) mStrips[istrip].size();
|
---|
406 | }
|
---|
407 | */
|
---|
408 | //-----------------------------------------------------------------------------
|
---|
409 | // Private.
|
---|
410 | //-----------------------------------------------------------------------------
|
---|
411 |
|
---|
412 | //-----------------------------------------------------------------------------
|
---|
413 | // Copy a STL vector to a C array.
|
---|
414 | //-----------------------------------------------------------------------------
|
---|
415 | void LodStripsLibrary::CopyVectors2Arrays(void)
|
---|
416 | {
|
---|
417 | SmallInt max;
|
---|
418 | SmallInt t;
|
---|
419 | SmallInt *data_array;
|
---|
420 | SmallIntVector tira;
|
---|
421 | LODRegisterType *changes_array;
|
---|
422 | LODRegisterVector list_changes;
|
---|
423 |
|
---|
424 | mTotalStrips = int(mFileStrips.size());
|
---|
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;
|
---|
432 |
|
---|
433 | // unsigned int * strip_sizes = new unsigned int[mFileStrips.size()];
|
---|
434 | unsigned int total_strip_size = 0;
|
---|
435 |
|
---|
436 | for (unsigned int i = 0; i < mFileStrips.size(); i++)
|
---|
437 | {
|
---|
438 | total_strip_size += t = int(mFileStrips[i].size());
|
---|
439 | if (t>max)
|
---|
440 | max = t;
|
---|
441 | mTotalFaces += t - 2;
|
---|
442 | }
|
---|
443 |
|
---|
444 | changes_array = new LODRegisterType[mFileChangesLOD.size()];
|
---|
445 |
|
---|
446 | // Fill up changes array.
|
---|
447 | for (unsigned int i = 0; i < mFileChangesLOD.size(); ++i)
|
---|
448 | {
|
---|
449 | changes_array[i] = mFileChangesLOD[i];
|
---|
450 | }
|
---|
451 |
|
---|
452 | mCurrentRegLOD = changes_array;
|
---|
453 |
|
---|
454 | // Copy strips.
|
---|
455 | // unsigned int numDegenerated = 2*mTotalStrips - 2;
|
---|
456 | // dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal!
|
---|
457 |
|
---|
458 | // dataRetrievalInterface->Init(total_strip_size);
|
---|
459 | /* dataRetrievalInterface->numinds=total_strip_size;
|
---|
460 | dataRetrievalInterface->numvalidinds=total_strip_size;*/
|
---|
461 | // dataRetrievalInterface->Begin();
|
---|
462 |
|
---|
463 | unsigned int ii = 0;
|
---|
464 |
|
---|
465 | for (unsigned int i = 0; i < mFileStrips.size(); i++)
|
---|
466 | {
|
---|
467 | for (unsigned int j = 0; j < mFileStrips[i].size(); j++,ii++)
|
---|
468 | {
|
---|
469 | mStrips[i].push_back(mFileStrips[i][j]);
|
---|
470 | // dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]);
|
---|
471 | }
|
---|
472 |
|
---|
473 | // Reset flags of strips changed.
|
---|
474 | mStripsChanges[i] = 0;
|
---|
475 | }
|
---|
476 |
|
---|
477 | // dataRetrievalInterface->End();
|
---|
478 |
|
---|
479 | for (unsigned int i = 0; i < mData.size(); i++)
|
---|
480 | {
|
---|
481 | data_array[i] = mData[i];
|
---|
482 | }
|
---|
483 |
|
---|
484 | mCurrentData = data_array;
|
---|
485 |
|
---|
486 | // Fill up mVertex.
|
---|
487 | for(unsigned int i = 0; i < mFileVertices.size(); i++)
|
---|
488 | {
|
---|
489 | mVertex[i] = mFileVertices[i];
|
---|
490 | }
|
---|
491 |
|
---|
492 | // delete[] strip_sizes;
|
---|
493 | }
|
---|
494 |
|
---|
495 | //-----------------------------------------------------------------------------
|
---|
496 | // LoadStripMesh
|
---|
497 | //-----------------------------------------------------------------------------
|
---|
498 | void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh)
|
---|
499 | {
|
---|
500 | //FILE *fp;
|
---|
501 | SmallIntVector strip_aux;
|
---|
502 | //LODRegisterType lod_register;
|
---|
503 | std::vector <LODRegisterType> list_pos;
|
---|
504 | std::vector <unsigned int> p_changes;
|
---|
505 | //int value;
|
---|
506 | int v = 0;
|
---|
507 | int t = -1;
|
---|
508 | int s = 0;
|
---|
509 | int next = 0;
|
---|
510 | int c = -1;
|
---|
511 | //char buff[80];
|
---|
512 | Index *index;
|
---|
513 | Index *indexBegin;
|
---|
514 | Index *indexEnd;
|
---|
515 | SubMesh *geoSubMesh;
|
---|
516 |
|
---|
517 | // For each one of the submeshes.
|
---|
518 | indices_x_submesh = new int[geomesh->mSubMeshCount];
|
---|
519 | offsets_x_submesh = new int[geomesh->mSubMeshCount];
|
---|
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;
|
---|
529 | for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
|
---|
530 | {
|
---|
531 | geoSubMesh = &geomesh->mSubMesh[submesh];
|
---|
532 | indices_x_submesh[submesh] = 0;
|
---|
533 |
|
---|
534 | // For each one of the strips.
|
---|
535 | for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++)
|
---|
536 | {
|
---|
537 | // Insert an empty strip.
|
---|
538 | submesh_x_strip[istrip] = submesh;
|
---|
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 |
|
---|
546 | // If the strips is not the first. (DEG!)
|
---|
547 | if (strip != 0)
|
---|
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 |
|
---|
561 | // Remove degenerated (DEG!)
|
---|
562 | indexEnd--;
|
---|
563 | }
|
---|
564 |
|
---|
565 | int i;
|
---|
566 | i = 0;
|
---|
567 |
|
---|
568 | if (submesh==0)
|
---|
569 | offsets_x_submesh[submesh] = 0;
|
---|
570 | else
|
---|
571 | offsets_x_submesh[submesh] = indices_x_submesh[submesh-1];
|
---|
572 |
|
---|
573 | // For each index of the strip.
|
---|
574 | for (index = indexBegin; index < indexEnd; index++)
|
---|
575 | {
|
---|
576 | mFileStrips[t].push_back(indexBegin[i]);
|
---|
577 | indices_x_submesh[submesh]++;
|
---|
578 | i++;
|
---|
579 | }
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | // TODO: LOD file loaded in load file mesh process.
|
---|
584 | // Open the LOD file.
|
---|
585 | /* if ((fp = fopen (name, "r")) == NULL)
|
---|
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);
|
---|
635 | }
|
---|
636 | }
|
---|
637 |
|
---|
638 | fclose(fp);*/
|
---|
639 |
|
---|
640 | mFileVertices = lodstripsdata->mFileVertices;
|
---|
641 | mFileChangesLOD = lodstripsdata->mFileChangesLOD;
|
---|
642 | mData = lodstripsdata->mData;
|
---|
643 | p_changes = lodstripsdata->p_changes;
|
---|
644 |
|
---|
645 | mStripsSubmesh = new int [geomesh->mSubMeshCount];
|
---|
646 | for (size_t submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
|
---|
647 | {
|
---|
648 | mStripsSubmesh[submesh]=0;
|
---|
649 | }
|
---|
650 |
|
---|
651 |
|
---|
652 | // Max / Min values for LOD.
|
---|
653 | mLods = int(p_changes.size());
|
---|
654 | mMaxLod = 0;
|
---|
655 | mMinLod = mLods;
|
---|
656 |
|
---|
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();
|
---|
669 | }
|
---|
670 |
|
---|
671 | void LodStripsLibrary::UpdateDataRetrievalInterface(void)
|
---|
672 | {
|
---|
673 | int target_submesh = 0;
|
---|
674 | size_t strip_count = 0;
|
---|
675 | unsigned int ii_submesh = 0;
|
---|
676 |
|
---|
677 | current_triangle_count = 0;
|
---|
678 |
|
---|
679 | // indices_x_submesh is calculated without degenerates,
|
---|
680 | // we must add the degenerate indices added here
|
---|
681 | uint32 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount * 2 - 2;
|
---|
682 |
|
---|
683 | dataRetrievalInterface->Begin(target_submesh,
|
---|
684 | indices_x_submesh[target_submesh] + numdeg);
|
---|
685 |
|
---|
686 | current_triangle_count += indices_x_submesh[target_submesh] + numdeg;
|
---|
687 |
|
---|
688 | // For each strip.
|
---|
689 | for (unsigned int i = 0; i < mTotalStrips; i++, strip_count++)
|
---|
690 | {
|
---|
691 | if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount)
|
---|
692 | {
|
---|
693 | if (target_submesh == 0)
|
---|
694 | {
|
---|
695 | offsets_x_submesh[target_submesh] = 0;
|
---|
696 | }
|
---|
697 | else
|
---|
698 | {
|
---|
699 | offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1]
|
---|
700 | +
|
---|
701 | offsets_x_submesh[target_submesh-1];
|
---|
702 | }
|
---|
703 |
|
---|
704 | mStripsSubmesh[target_submesh] = (int)strip_count;
|
---|
705 | strip_count = 0;
|
---|
706 |
|
---|
707 | target_submesh++;
|
---|
708 | ii_submesh = 0;
|
---|
709 | dataRetrievalInterface->End();
|
---|
710 |
|
---|
711 | numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2;
|
---|
712 |
|
---|
713 | dataRetrievalInterface->Begin(target_submesh,
|
---|
714 | indices_x_submesh[target_submesh] + numdeg);
|
---|
715 |
|
---|
716 | current_triangle_count += indices_x_submesh[target_submesh] + numdeg;
|
---|
717 | }
|
---|
718 |
|
---|
719 | int lastindex = -1;
|
---|
720 |
|
---|
721 | for ( SmallIntVector::iterator it = mStrips[i].begin();
|
---|
722 | it != mStrips[i].end();
|
---|
723 | it++, ii_submesh++)
|
---|
724 | {
|
---|
725 | // repeat the first index of the strip: degenerate (DEG!)
|
---|
726 | // except for the first strip in a mesh
|
---|
727 | if ((lastindex == -1) && (strip_count > 0))
|
---|
728 | {
|
---|
729 | lastindex = *it;
|
---|
730 |
|
---|
731 | dataRetrievalInterface->SetIndex(ii_submesh,*it);
|
---|
732 | ii_submesh++;
|
---|
733 | }
|
---|
734 |
|
---|
735 | lastindex = *it;
|
---|
736 | dataRetrievalInterface->SetIndex(ii_submesh,*it);
|
---|
737 | }
|
---|
738 |
|
---|
739 | // repeat last vertex of the strip: degenerate (DEG!)
|
---|
740 | // except for the last strip in a mesh
|
---|
741 | if (strip_count < mGeoMesh->mSubMesh[target_submesh].mStripCount-1)
|
---|
742 | {
|
---|
743 | dataRetrievalInterface->SetIndex(ii_submesh,lastindex);
|
---|
744 | ii_submesh++;
|
---|
745 | }
|
---|
746 | }
|
---|
747 |
|
---|
748 | if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount)
|
---|
749 | {
|
---|
750 | if (target_submesh == 0)
|
---|
751 | {
|
---|
752 | offsets_x_submesh[target_submesh] = 0;
|
---|
753 | }
|
---|
754 | else
|
---|
755 | {
|
---|
756 | offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1]
|
---|
757 | +
|
---|
758 | offsets_x_submesh[target_submesh-1];
|
---|
759 | }
|
---|
760 |
|
---|
761 | mStripsSubmesh[target_submesh] = (int)strip_count;
|
---|
762 | strip_count = 0;
|
---|
763 |
|
---|
764 | target_submesh++;
|
---|
765 | }
|
---|
766 |
|
---|
767 | dataRetrievalInterface->End();
|
---|
768 | }
|
---|
769 |
|
---|