Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 2323)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 2341)
@@ -104,6 +104,4 @@
 }
 
-
-
 //-------------------------------------------------------------------------
 //	Repaint the FPS label.
@@ -156,4 +154,5 @@
 										cb_menuFileSave_i(o,v);
 }
+
 
 //-------------------------------------------------------------------------
@@ -1086,4 +1085,7 @@
 				stripify();
 
+				//	Debug.
+				//writeStrips(mGeoMesh);
+
 				break;
 
@@ -1298,6 +1300,9 @@
 {
 	char					*file_name	=	NULL;
+	char					*ptr;
+	char					message[255];
 	GeoMeshSaver	*mesh_saver;
 	Serializer		*oSerializer;
+	int						answer_yes;
 
 	//	Sets the progress bar to process bar.
@@ -1320,52 +1325,82 @@
 			if (file_name)
 			{
-				//	Undo the simplification changes.
-				undo();
-
-				//	Stripify the mesh object.
-				stripify();
-
-				//	Reset the build bar.
-				mBuildBar->position(0);
-
-				//	Simplification sequence.
-				oMeshSimpSequence =	mMeshSimplifier->GetSimplificationSequence();
-
-				//	If the simplification sequence and the mesh exist.
-				if (oMeshSimpSequence && mGeoMesh)
-				{
-					oLodStrip	=	new LodStripsConstructor(	mGeoMesh,
-																								oMeshSimpSequence,
-																								idMeshLeaves,
-																								progress_function);
-
-					oLodStrip->UpdateMesh();
-
-					//	Deletes the previous mesh.
-					delete mUndoMesh;
-
-					mUndoMesh	=	new Mesh();
-
-					//	Sets the undo mesh.
-					*mUndoMesh	=	*mGeoMesh;
-
-					delete	mGeoMesh;
-
-					mGeoMesh	=	oLodStrip->GetMesh();
-
-					geoMeshView->setMesh(mGeoMesh);
-
-					mesh_saver	=	new	GeoMeshSaver();
-
-					mesh_saver->leavesSubMesh	=	idMeshLeaves;
-					mesh_saver->leavesVB			=	origSubMeshVB;
-					mesh_saver->numindices		=	orig_numindices;
-					mesh_saver->indices				=	orig_indices;
-
-					mesh_saver->save(mGeoMesh,file_name);
-
-					delete	mesh_saver;
-
-					oLodStrip->Save(file_name);
+				//	Cut extension.
+				ptr	=	strtok(file_name,".");
+
+				//	If has extension.
+				if (ptr)
+				{
+					strcpy(file_name,ptr);
+				}
+
+				//	Adds mesh extension.
+				strcat(file_name,".mesh");
+
+				//	If File Exists.
+				if (fileExists(file_name))
+				{
+					//	Compose message.
+					strcpy(message,"Do you want to replace ");
+					strcat(message,filename_name(file_name));
+					strcat(message,"?");
+
+					//	Question.
+					answer_yes	=	fltk::ask(message);
+				}
+
+				//	If answer yes to replace question
+				//	or if file not exists.
+				if (answer_yes)
+				{
+
+					//	Undo the simplification changes.
+					undo();
+
+					//	Stripify the mesh object.
+					stripify();
+
+					//	Reset the build bar.
+					mBuildBar->position(0);
+
+					//	Simplification sequence.
+					oMeshSimpSequence =	mMeshSimplifier->GetSimplificationSequence();
+
+					//	If the simplification sequence and the mesh exist.
+					if (oMeshSimpSequence && mGeoMesh)
+					{
+						oLodStrip	=	new LodStripsConstructor(	mGeoMesh,
+								oMeshSimpSequence,
+								idMeshLeaves,
+								progress_function);
+
+						oLodStrip->UpdateMesh();
+
+						//	Deletes the previous mesh.
+						delete mUndoMesh;
+
+						mUndoMesh	=	new Mesh();
+
+						//	Sets the undo mesh.
+						*mUndoMesh	=	*mGeoMesh;
+
+						delete	mGeoMesh;
+
+						mGeoMesh	=	oLodStrip->GetMesh();
+
+						geoMeshView->setMesh(mGeoMesh);
+
+						mesh_saver	=	new	GeoMeshSaver();
+
+						mesh_saver->leavesSubMesh	=	idMeshLeaves;
+						mesh_saver->leavesVB			=	origSubMeshVB;
+						mesh_saver->numindices		=	orig_numindices;
+						mesh_saver->indices				=	orig_indices;
+
+						mesh_saver->save(mGeoMesh,file_name);
+
+						delete	mesh_saver;
+
+						oLodStrip->Save(file_name);
+					}
 				}
 				else
@@ -1837,7 +1872,9 @@
 {
 	char						type[10];
+
 	unsigned	int		group_index;
 	unsigned	int		group_count;
 	unsigned	int		bone_count;
+
 	fltk::ItemGroup **info_group;
 	
@@ -1867,4 +1904,5 @@
 			char	*skel_name		=	new char[256];
 			char	*bone_assig		=	new char[256];
+
 			sprintf(group_name,"Skeleton");
 			info_group[group_index]	= new fltk::ItemGroup(group_name);
@@ -1879,4 +1917,5 @@
 				bone_count	+=	mGeoMesh->mSubMesh[i].mBones.size();
 			}
+
 			sprintf(bone_assig,"Bone assignamets: %d",bone_count);
 			new fltk::Item(bone_assig);
@@ -1886,5 +1925,5 @@
 		}
 
-		for(int i=0; i<mGeoMesh->mSubMeshCount;i++)
+		for(int i	=	0; i < mGeoMesh->mSubMeshCount;	i++)
 		{
 			char	*group_name	=	new char[256];
@@ -1907,9 +1946,14 @@
 
 			//	Submesh identifier.
-			sprintf(group_name,"SubMesh %d %s",i,type);
+			sprintf(group_name,
+							"SubMesh %d %s:%s",
+							i,
+							type,
+							mGeoMesh->mSubMesh[i].mName);
 			
 			info_group[group_index] = new fltk::ItemGroup(group_name);
 			info_group[group_index]->begin();
 			fltk::Item *sharedGeometry;
+
 			if (mGeoMesh->mSubMesh[i].mSharedVertexBuffer)
 			{
@@ -1922,47 +1966,59 @@
 
 			//	Adds material name.
-			char *cadena2=new char[100];
+			char *cadena2	=	new char[100];
 			sprintf(cadena2, "Material: %s",mGeoMesh->mSubMesh[i].mMaterialName);
 			
 			fltk::Item	*geomaterial	=	new fltk::Item(cadena2);
 			
-			char *cadena3=new char[100];
+			char *cadena3	=	new char[100];
 			
-			sprintf(cadena3, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount);
+			sprintf(cadena3,
+							"Number of indexes: %d",
+							mGeoMesh->mSubMesh[i].mIndexCount);
+
 			fltk::Item *numberIndex = new fltk::Item(cadena3);
+
 			if (mGeoMesh->mSubMesh[i].mType==Geometry::GEO_TRIANGLE_LIST)
 			{
-				fltk::Item *type = new fltk::Item("Triangle List");
+				fltk::Item	*type	=	new fltk::Item("Triangle List");
 			}
 			else
 			{
-				fltk::Item *type = new fltk::Item("Triangle Strips");
+				fltk::Item	*type	=	new fltk::Item("Triangle Strips");
 			}
 
-			char *cadenavertex=new char[30];
-			sprintf(cadenavertex, "Number of vertices: %d",mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount);
-			fltk::Item *numberVertex = new fltk::Item(cadenavertex);
-
-			if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
+			char *cadenavertex	=	new char[30];
+
+			sprintf(cadenavertex,
+							"Number of vertices: %d",
+							mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount);
+
+			fltk::Item	*numberVertex	=	new fltk::Item(cadenavertex);
+
+			if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo
+					&
+					Geometry::VERTEX_NORMAL)
 			{
-				fltk::Item *normals = new fltk::Item("Normals: Yes");
+				fltk::Item	*normals	=	new fltk::Item("Normals: Yes");
 			}
 			else
 			{
-				fltk::Item *normals = new fltk::Item("Normals: No");
+				fltk::Item *normals	=	new fltk::Item("Normals: No");
 			}
 
-			if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
+			if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo
+					&
+					Geometry::VERTEX_TEXCOORDS)
 			{
-				fltk::Item *textures = new fltk::Item("Textures: Yes");
+				fltk::Item	*textures	=	new fltk::Item("Textures: Yes");
 			}
 			else
 			{
-				fltk::Item *textures = new fltk::Item("Textures: No");
+				fltk::Item	*textures	=	new fltk::Item("Textures: No");
 			}
 
-
 			info_group[group_index]->end();
 		}
+
 		ogeometry->end();
 		this->mMeshInfo->add(ogeometry);
@@ -2057,5 +2113,7 @@
 					break;
 				case	GEO_TRIANGLE_STRIPS:
-					triangle_count	+=	geoSubMesh->mIndexCount - 2;
+					triangle_count	+=	geoSubMesh->mIndexCount
+															-
+															2;
 					break;
 			}
@@ -2064,4 +2122,57 @@
 
 	return	triangle_count;
+}
+
+//-------------------------------------------------------------------------
+//	Get the number of degenerated triangles.
+//-------------------------------------------------------------------------
+size_t	GeoMeshViewUI::getDegeneratedCount(Geometry::Mesh	*geoMesh)
+{
+	size_t	degenerated;
+	size_t	same_index;
+	SubMesh	*geoSubMesh;
+
+	//	Initialize the degenerated count.
+	degenerated	=	0;
+
+	//	Initiazlize same index count.
+	same_index = 1;
+
+	//	For each submesh.
+	for (size_t	submesh	=	0; submesh < geoMesh->mSubMeshCount; submesh++)
+	{
+		//	Gets the actual submesh.
+		geoSubMesh	=	&geoMesh->mSubMesh[submesh];
+
+		if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS)
+		{
+			//	Find degenerated triangles.
+			for (size_t	i = 0; i < (geoSubMesh->mIndexCount - 1); i++)
+			{
+				if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i + 1])
+				{
+					same_index++;
+				}
+				else
+				{
+					if (same_index > 1)
+					{
+						degenerated	+=	same_index;
+					}
+					else if (i < (geoSubMesh->mIndexCount - 2))
+					{
+						if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i + 2])
+						{
+							degenerated++;
+						}
+					}
+
+					same_index	= 1;
+				}
+			}
+		}
+	}
+
+	return	degenerated;
 }
 
@@ -2460,4 +2571,5 @@
 	static char	vertices_value[50];
 	static char	triangles_value[50];
+	static char	degenerated_value[50];
 	static char	strips_value[50];
 	
@@ -2471,4 +2583,9 @@
 
 	mTriangles->label(triangles_value);
+
+	//	Translate the degenerated count to a char value.
+	sprintf(degenerated_value,"Degenerated %d",getDegeneratedCount(mGeoMesh));
+
+	mDegenerated->label(degenerated_value);
 
 	//	Translate the triangle count to a char value.
@@ -2679,5 +2796,7 @@
 }
 
+//-------------------------------------------------------------------------
 //	Set textures to mesh model.
+//-------------------------------------------------------------------------
 void GeoMeshViewUI::setTextures()
 {
@@ -3241,5 +3360,13 @@
 			{
 				fltk::Widget* o;
-				o = mStrips = new fltk::Widget(354, 3, 30, 15, "Strips");
+				o = mDegenerated = new fltk::Widget(354, 3, 30, 15, "Degenerated");
+				o->box(fltk::NO_BOX);
+				o->labelfont(fltk::HELVETICA_BOLD);
+				o->color((fltk::Color)0xe0dfe300);
+			}
+
+			{
+				fltk::Widget* o;
+				o = mStrips = new fltk::Widget(454, 3, 30, 15, "Strips");
 				o->box(fltk::NO_BOX);
 				o->labelfont(fltk::HELVETICA_BOLD);
@@ -3320,2 +3447,50 @@
 }
 
+//-------------------------------------------------------------------------
+//	Write file of strips.
+//-------------------------------------------------------------------------
+void	GeoMeshViewUI::writeStrips(Mesh	*geomesh)
+{
+	Index			*index;
+	Index			*indexBegin;
+	Index			*indexEnd;
+	SubMesh		*geosubmesh;
+
+	ofstream	out ("strips.txt");
+
+	//	For each submesh.
+	for	(size_t	submesh	=	0;	submesh < geomesh->mSubMeshCount;	submesh++)
+	{
+		geosubmesh	=	&geomesh->mSubMesh[submesh];
+
+		//	For each one of the strips.
+		for (size_t strip = 0; strip < geosubmesh->mStripCount; strip++)
+		{
+			//	First index of the strip.
+			indexBegin	=	geosubmesh->mStrip[strip];
+
+			//	If is the final strip
+			if (strip	== (geosubmesh->mStripCount - 1))
+			{
+				//	The end of the index array.
+				indexEnd	=	&geosubmesh->mIndex[geosubmesh->mIndexCount];
+			}
+			else
+			{
+				//	The beginning of the next strip.
+				indexEnd	= geosubmesh->mStrip[strip + 1];
+			}
+
+			for (index = indexBegin; index < indexEnd; index++)
+			{
+				out <<	index[0]
+						<<	" ";
+			}
+
+			out	<<	endl;
+		}
+	}
+
+	out.close();
+}
+
