Index: /GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
===================================================================
--- /GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp	(revision 1526)
+++ /GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp	(revision 1578)
@@ -71,103 +71,52 @@
 void	MeshSimplifier::sortBones()
 {
-	bool									shared_found;
-	int										n;
-	int 									o;
-	int										p;
-	VertexBoneAssignment	assign;
 	VertexBuffer					*mesh_vb;
 	VertexBuffer					*copy_vb;
-	SubMesh								*geosubmesh;
-	SubMesh								*copysubmesh;
 
 	std::vector<VertexBoneAssignment>	*mesh_bones;
 	std::vector<VertexBoneAssignment>	*copy_bones;
-	
-	//	Initialize shared flag.
-	shared_found	=	false;
-
-	//	For each submesh.
-	for (size_t	i	=	0; i < mGeoMesh->mSubMeshCount; i++)
-	{
-		geosubmesh	=	&mGeoMesh->mSubMesh[i];
-		copysubmesh	=	&mInitialMesh->mSubMesh[i];
-
-		//	If submesh has shared vertex.
-		if (geosubmesh->mSharedVertexBuffer)
-		{
-			if (shared_found)
+
+	// After simplifying, the object always is shared vertex
+	// so, the bones must be placed in the GeoMesh
+	mesh_bones	=	&mGeoMesh->mBones;
+	mesh_vb	=	mGeoMesh->mVertexBuffer;
+
+	// we assume the original mesh is shared vertex 
+	// because before the simplification process
+	// the mesh becomes converted to shared vertex
+	// so, the original bones must be searched in the
+	// Mesh, not in every submesh
+
+	mesh_bones->clear();
+
+	//	Vertex buffers.
+	copy_vb	=	mInitialMesh->mVertexBuffer;
+
+	//	Bones.
+	copy_bones = &mInitialMesh->mBones;
+	
+	//	If there are submesh bones.
+	for (int b = 0; b < copy_bones->size(); b++)
+	{
+		VertexBoneAssignment	assign;
+
+		int n	=	(*copy_bones)[b].vertexIndex;
+
+		//	Initialize o.
+		
+		int o=0;
+		for (o=0; o<mesh_vb->mVertexCount; o++)
+		{
+			if (mesh_vb->mPosition[o].x == copy_vb->mPosition[n].x &&
+				mesh_vb->mPosition[o].y == copy_vb->mPosition[n].y &&
+				mesh_vb->mPosition[o].z == copy_vb->mPosition[n].z)
 			{
-				continue;
-			}
-
-			shared_found	=	true;
-			
-			//	Vertex buffers.
-			mesh_vb	=	mGeoMesh->mVertexBuffer;
-			copy_vb	=	mInitialMesh->mVertexBuffer;
-
-			//	Bones.
-			mesh_bones	=	&mGeoMesh->mBones;
-			copy_bones	=	&mInitialMesh->mBones;
-		}
-		else
-		{
-			//	Vertex buffers.
-			mesh_vb	=	geosubmesh->mVertexBuffer;
-			copy_vb	=	copysubmesh->mVertexBuffer;
-
-			//	Bones.
-			mesh_bones	=	&geosubmesh->mBones;
-			copy_bones	=	&copysubmesh->mBones;
-		}
-		
-		//	If there is submesh bones.
-		if (!mesh_bones->empty())
-		{
-			assign.boneIndex	=	0;
-			assign.weight			=	1;
-
-			mesh_bones->clear();
-
-			for (size_t	m	=	0;	m < mesh_vb->mVertexCount;	m++)
-			{
-				assign.vertexIndex	=	(int)m;
-				
+				assign.vertexIndex = o;
+				assign.boneIndex   = (*copy_bones)[b].boneIndex;
+				assign.weight	   = 1.0f;
 				mesh_bones->push_back(assign);
-			}
-
-			//	Change bones.
-			for (size_t	m = 0;	m < mesh_bones->size();	m++)
-			{
-				n	=	(*mesh_bones)[m].vertexIndex;
-
-				//	Initialize o.
-				o	=	0;
-
-				while (!(
-							(mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x)
-							&&
-							(mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y)
-							&&
-							(mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z)
-							))
-				{
-					o++;
-				}
-
-				//	Initialize p.
-				p	=	0;
-
-				while ((*copy_bones)[p].vertexIndex != o)
-				{
-					p++;
-				}
-
-				//	Same bone for 'm' and 'p'.
-				(*mesh_bones)[m].boneIndex	=	(*copy_bones)[p].boneIndex;
-			}
-		}
-	}
-
+			}			
+		}
+	}
 }
 
@@ -207,4 +156,17 @@
 	mGeoMesh	=	m_qslim->GetMesh();
 	
+	// if the initial mesh had shared vertex, 
+	// convert the mesh to shared vertex
+	for (int i=0; i<mInitialMesh->mSubMeshCount; i++)
+	{
+		if (mInitialMesh->mSubMesh[i].mSharedVertexBuffer)
+		{
+			Mesh *sharedMesh = mGeoMesh->toSharedVertex();
+			delete mGeoMesh;
+			mGeoMesh = sharedMesh;
+			break;
+		}
+	}
+
 	//	Sort bones.
 	sortBones();
@@ -226,4 +188,17 @@
 	mGeoMesh	=	m_qslim->GetMesh();
 	
+	// if the initial mesh had shared vertex, 
+	// convert the mesh to shared vertex
+	for (int i=0; i<mInitialMesh->mSubMeshCount; i++)
+	{
+		if (mInitialMesh->mSubMesh[i].mSharedVertexBuffer)
+		{
+			Mesh *sharedMesh = mGeoMesh->toSharedVertex();
+			delete mGeoMesh;
+			mGeoMesh = sharedMesh;
+			break;
+		}
+	}
+
 	//	Sort bones.
 	sortBones();
Index: /GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp
===================================================================
--- /GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp	(revision 1552)
+++ /GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp	(revision 1578)
@@ -522,7 +522,4 @@
 	
 	this->GenerarModeloCompleto(upb);
-
-	//	Sort submesh bones.
-	this->sortBones();
 }
 
@@ -974,11 +971,4 @@
 void LodStripsConstructor::sortBones()
 {
-	bool									shared_found;
-	int										n;
-	int										o;
-	int										p;
-	VertexBoneAssignment	assign;
-	SubMesh								*submesh;
-	SubMesh								*copysubmesh;
 	VertexBuffer					*mesh_vb;
 	VertexBuffer					*copy_vb;
@@ -987,109 +977,44 @@
 	std::vector<VertexBoneAssignment>	*copy_bones;
 
-	//	Initialize shared vertex flag.
-	shared_found	=	false;
-
-	//	For each submesh.
-	for (size_t	i = 0;	i	<	mGeoMesh->mSubMeshCount;	i++)
-	{
-		submesh			=	&mGeoMesh->mSubMesh[i];
-		copysubmesh	=	&mInitialMesh->mSubMesh[i];
-
-		//	If submesh has shared vertex.
-		if (submesh->mSharedVertexBuffer)
-		{
-			if (shared_found)
-			{
-				continue;
-			}
-
-			shared_found	=	true;
-			
-			//	Vertex buffers.
-			mesh_vb	=	mGeoMesh->mVertexBuffer;
-			copy_vb	=	mInitialMesh->mVertexBuffer;
-
-			//	Bones.
-			mesh_bones	=	&mGeoMesh->mBones;
-			copy_bones	=	&mInitialMesh->mBones;
-		}
-		else
-		{
-			//	Vertex buffers.
-			mesh_vb	=	submesh->mVertexBuffer;
-			copy_vb	=	copysubmesh->mVertexBuffer;
-
-			//	Bones.
-			mesh_bones	=	&submesh->mBones;
-			copy_bones	=	&copysubmesh->mBones;
-		}
+	// After simplifying, the object always is shared vertex
+	// so, the bones must be placed in the GeoMesh
+	mesh_bones	=	&mGeoMesh->mBones;
+	mesh_vb	=	mGeoMesh->mVertexBuffer;
+
+	// we assume the original mesh is shared vertex 
+	// because before the simplification process
+	// the mesh becomes converted to shared vertex
+	// so, the original bones must be searched in the
+	// Mesh, not in every submesh
+
+	mesh_bones->clear();
+
+	//	Vertex buffers.
+	copy_vb	=	mInitialMesh->mVertexBuffer;
+
+	//	Bones.
+	copy_bones = &mInitialMesh->mBones;
+	
+	//	If there are submesh bones.
+	for (int b = 0; b < copy_bones->size(); b++)
+	{
+		VertexBoneAssignment	assign;
+
+		int n	=	(*copy_bones)[b].vertexIndex;
+
+		//	Initialize o.
 		
-		if (!mesh_bones->empty())
-		{
-			assign.boneIndex	=	0;
-			assign.weight		=	1;
-
-			for (size_t	m = copy_vb->mVertexCount;
-						m < mesh_vb->mVertexCount;
-						m++)
-			{
-				assign.vertexIndex	=	(unsigned int)m;
+		int o=0;
+		for (o=0; o<mesh_vb->mVertexCount; o++)
+		{
+			if (mesh_vb->mPosition[o].x == copy_vb->mPosition[n].x &&
+				mesh_vb->mPosition[o].y == copy_vb->mPosition[n].y &&
+				mesh_vb->mPosition[o].z == copy_vb->mPosition[n].z)
+			{
+				assign.vertexIndex = o;
+				assign.boneIndex   = (*copy_bones)[b].boneIndex;
+				assign.weight	   = 1.0f;
 				mesh_bones->push_back(assign);
-			}
-
-			//	Change bones.
-			for (size_t	m = 0;	m < mesh_bones->size();	m++)
-			{
-				n	=	(*mesh_bones)[m].vertexIndex;
-				o	=	0;
-				
-				while (!(	(mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x)	&&
-							(mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y)	&&
-							(mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z)))
-				{
-					o++;
-				}
-
-				p = 0;
-				
-				while ((*copy_bones)[p].vertexIndex != o)
-					p++;
-
-				//	Same bone for 'm' and 'p'.
-				(*mesh_bones)[m].boneIndex	=	(*copy_bones)[p].boneIndex;
-			}
-
-			//	Look for repeated bones.
-			for (size_t	m	=	0;	m < mesh_vb->mVertexCount;	m++)
-			{
-				for (size_t	n	=	m + 1;	n < mesh_vb->mVertexCount;	n++)
-				{
-					if ((mesh_vb->mPosition[m].x == mesh_vb->mPosition[n].x)
-							&&
-							(mesh_vb->mPosition[m].y == mesh_vb->mPosition[n].y)
-							&&
-							(mesh_vb->mPosition[m].z == mesh_vb->mPosition[n].z))
-					{
-						o	=	0;
-						
-						while ((*mesh_bones)[o].vertexIndex != m)
-						{
-							o++;
-						}
-
-						p	=	0;
-						
-						while ((*mesh_bones)[p].vertexIndex != n)
-						{
-							p++;
-						}
-
-						if ((*mesh_bones)[o].boneIndex != (*mesh_bones)[p].boneIndex)
-						{
-							printf("-->Error en los vertices %d y %d\n",m,n);
-						}
-					}
-				}
-			}
+			}			
 		}
 	}
@@ -1286,4 +1211,7 @@
 		}
 	}
+
+	//	Sort submesh bones.
+	this->sortBones();
 }
 
