Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp	(revision 1560)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp	(revision 2085)
@@ -1,12 +1,12 @@
-/*==========================================================================
+/*========================================================================
  *	(C) 2005 Universitat Jaume I
- *==========================================================================
+ *========================================================================
  *	PROYECT:	GAME TOOLS
- *==========================================================================
+ *========================================================================
  *	CONTENT:
  *
  *
  *	@file	GeoLodStripsLibrary.cpp
- *===========================================================================*/
+ *=======================================================================*/
 
 #include "GeoLodStripsLibrary.h"
@@ -15,10 +15,11 @@
 using	namespace	std;
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Constructor.
-//-----------------------------------------------------------------------------
-LodStripsLibrary::LodStripsLibrary(	const LodStripsLibraryData	*lodstripsdata,
-																		Mesh												*geomesh,
-																		IndexData										*userindexdata)
+//-------------------------------------------------------------------------
+LodStripsLibrary::LodStripsLibrary(
+														const LodStripsLibraryData	*lodstripsdata,
+														Mesh												*geomesh,
+														IndexData										*userindexdata)
 {
 	//	Sets the current lod.
@@ -59,7 +60,7 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Destructor
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 LodStripsLibrary::~LodStripsLibrary()
 {
@@ -77,11 +78,11 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Public.
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
+
+//-------------------------------------------------------------------------
 //	Go to the level of detail.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 void LodStripsLibrary::GoToLod(float lodfactor)
 {
@@ -303,7 +304,7 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Returns the number of vertices of the highest LOD.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 uint32	LodStripsLibrary::MaxVertices()
 {
@@ -311,7 +312,7 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Returns the number of vertices of the lowest LOD.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 uint32	LodStripsLibrary::MinVertices()
 {
@@ -324,7 +325,7 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Returns the number of triangles of the highest LOD.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 uint32	LodStripsLibrary::MaxFaces()
 {
@@ -351,7 +352,7 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Returns the number of triangles of the lowest LOD.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 uint32	LodStripsLibrary::MinFaces()
 {
@@ -377,8 +378,8 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Establishes the new LOD range.
 //	Only the LODs in that range are stored and used.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 void		LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod)
 {
@@ -390,7 +391,7 @@
 }
 /*
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Get strip count.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 uint32	LodStripsLibrary::GetStripCount() const
 {
@@ -398,7 +399,7 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Get Index by strip.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 uint32	LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const
 {
@@ -406,11 +407,11 @@
 }
 */
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	Private.
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
+
+//-------------------------------------------------------------------------
 //	Copy a STL vector to a C array.
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 void LodStripsLibrary::CopyVectors2Arrays(void)
 {
@@ -452,5 +453,5 @@
 	mCurrentRegLOD	=	changes_array;
 	
-	//	Copy strips.
+//	Copy strips.
 //	unsigned int numDegenerated = 2*mTotalStrips - 2;
 //	dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal!
@@ -493,15 +494,14 @@
 }
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 //	LoadStripMesh
-//-----------------------------------------------------------------------------
-void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh)
-{
-	//FILE															*fp;
+//-------------------------------------------------------------------------
+void LodStripsLibrary::LoadStripMesh(
+														const LodStripsLibraryData *lodstripsdata,
+														Mesh *geomesh)
+{
 	SmallIntVector										strip_aux;
-	//LODRegisterType										lod_register;
 	std::vector			<LODRegisterType>	list_pos;
 	std::vector			<unsigned int>		p_changes;
-	//int																value;
 	int																v			=	0;
 	int																t			=	-1;
@@ -509,5 +509,4 @@
 	int																next	=	0;
 	int																c			=	-1;
-	//char															buff[80];
 	Index															*index;
 	Index															*indexBegin;
@@ -520,12 +519,22 @@
 
 	int totaltiras = 0;
-	for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
-		for (unsigned int strip = 0; strip < geomesh->mSubMesh[submesh].mStripCount; strip++)
+
+	for (	unsigned int submesh = 0;
+				submesh < geomesh->mSubMeshCount;
+				submesh++)
+	{
+		for (	unsigned int strip = 0;
+					strip < geomesh->mSubMesh[submesh].mStripCount;
+					strip++)
+		{
 			totaltiras++;
+		}
+	}
 
 	submesh_x_strip = new int[totaltiras];
 
 	int istrip = 0;
-	for (unsigned int submesh	=	0; submesh < geomesh->mSubMeshCount; submesh++)
+	
+	for (	size_t	submesh	=	0;	submesh < geomesh->mSubMeshCount;	submesh++)
 	{
 		geoSubMesh	=	&geomesh->mSubMesh[submesh];
@@ -533,5 +542,7 @@
 
 		//	For each one of the strips.
-		for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++)
+		for (	unsigned int strip = 0;
+					strip < geoSubMesh->mStripCount;
+					strip++, istrip++)
 		{
 			// Insert an empty strip.
@@ -546,5 +557,7 @@
 			//	If the strips is not the first.	(DEG!)
 			if (strip != 0)
+			{
 				indexBegin++;
+			}
 
 			//	If is the final strip
@@ -567,7 +580,11 @@
 			
 			if (submesh==0)
+			{
 				offsets_x_submesh[submesh] = 0;
+			}
 			else
+			{
 				offsets_x_submesh[submesh] = indices_x_submesh[submesh-1];
+			}
 
 			//	For each index of the strip.
@@ -577,77 +594,20 @@
 				indices_x_submesh[submesh]++;
 				i++;
-			}			
-		}
-	}
-
-	//	TODO:	LOD file loaded in load file mesh process.
-	//	Open the LOD file.
-/*	if ((fp = fopen (name, "r")) == NULL)
-	{
-		//	Error in open.
-	}
-	else
-	{
-		mTotalChanges	=	0;
-		
-		while (!feof (fp))
-		{
-			fgets (buff, 80, fp);
-			
-			if (*buff == 'v')
-			{
-				sscanf (buff+2,"%d",&value);
-				
-				mFileVertices.push_back(value);
-				v++;
-			}
-			else if ( (*buff == 'c') || (*buff == 'd'))
-			{
-				if (*buff == 'c')
-				{
-					c++;
-				}
-				else
-				{
-					unsigned	int	a;
-					unsigned	int	b;
-					unsigned	int	c;
-					unsigned	int	d;
-					
-					sscanf (buff+2,"%u %u %u %u\n",&a,&b,&c,&d);
-					lod_register.strip						=	a;
-					lod_register.position					=	b;
-					lod_register.vertexRepetition	=	c;
-					lod_register.edgeRepetition		=	d;
-					
-					mFileChangesLOD.push_back(lod_register);
-				}
-			}
-			else if (*buff=='b')
-			{
-				sscanf(buff+2,"%u",&value);
-				mData.push_back(value);
-			}
-			else if (*buff=='p')
-			{
-				sscanf (buff+2,"%u",&value);
-				p_changes.push_back(value);
-			}
-		}
-		
-		fclose(fp);*/
-
-	mFileVertices = lodstripsdata->mFileVertices;
-	mFileChangesLOD = lodstripsdata->mFileChangesLOD;
-	mData = lodstripsdata->mData;
-	p_changes = lodstripsdata->p_changes;
-
-	mStripsSubmesh = new int [geomesh->mSubMeshCount];
+			}
+		}
+	}
+
+	mFileVertices		= lodstripsdata->mFileVertices;
+	mFileChangesLOD	= lodstripsdata->mFileChangesLOD;
+	mData						= lodstripsdata->mData;
+	p_changes				= lodstripsdata->p_changes;
+
+	mStripsSubmesh	= new int [geomesh->mSubMeshCount];
+
 	for (size_t	submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
-	{	
-		mStripsSubmesh[submesh]=0;
-	}
-
-			
+	{
+		mStripsSubmesh[submesh]	=	0;
+	}
+
 	//	Max / Min values for LOD.
 	mLods											=	int(p_changes.size());
@@ -658,5 +618,7 @@
 	
 	for (unsigned int i = 0; i < mLods; i++)
+	{
 		mPChanges[i] = p_changes[i];
+	}
 
 	mTotalVertices		=	int(mFileVertices.size());
@@ -674,4 +636,5 @@
 	size_t				strip_count			=	0;
 	unsigned int	ii_submesh			=	0;
+	uint32 				numdeg					=	0;
 
 	current_triangle_count = 0;
@@ -679,5 +642,8 @@
 	// indices_x_submesh is calculated without degenerates, 
 	// we must add the degenerate indices added here
-	uint32 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount * 2 - 2;
+	if (mGeoMesh->mSubMesh[target_submesh].mStripCount > 0)
+	{
+		numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount * 2 - 2;
+	}
 
 	dataRetrievalInterface->Begin(target_submesh,
@@ -697,7 +663,8 @@
 			else
 			{
-				offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1]
-																						+
-																						offsets_x_submesh[target_submesh-1];
+				offsets_x_submesh[target_submesh] =
+									indices_x_submesh[target_submesh-1]
+									+
+									offsets_x_submesh[target_submesh-1];
 			}
 
@@ -709,10 +676,17 @@
 			dataRetrievalInterface->End();
 
-			numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2;
+			if (mGeoMesh->mSubMesh[target_submesh].mStripCount > 0)
+			{
+				numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2;
+			}
 
 			dataRetrievalInterface->Begin(target_submesh,
-																		indices_x_submesh[target_submesh] + numdeg);
+																		indices_x_submesh[target_submesh]
+																		+
+																		numdeg);
 			
-			current_triangle_count	+=	indices_x_submesh[target_submesh] + numdeg;
+			current_triangle_count	+=	indices_x_submesh[target_submesh]
+																	+
+																	numdeg;
 		}
 
@@ -729,5 +703,5 @@
 				lastindex	=	*it;
 
-				dataRetrievalInterface->SetIndex(ii_submesh,*it);				
+				dataRetrievalInterface->SetIndex(ii_submesh,*it);
 				ii_submesh++;
 			}
@@ -754,7 +728,8 @@
 		else
 		{
-			offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1]
-																					+
-																					offsets_x_submesh[target_submesh-1];
+			offsets_x_submesh[target_submesh] =
+									indices_x_submesh[target_submesh - 1]
+									+
+									offsets_x_submesh[target_submesh - 1];
 		}
 
