Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp	(revision 891)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp	(revision 980)
@@ -1,12 +1,13 @@
-/*	==========================================================================
+/*==========================================================================
  *	(C) 2005 Universitat Jaume I
- *	==========================================================================
+ *==========================================================================
  *	PROYECT:	GAME TOOLS
- *	==========================================================================*/
-/**	CONTENT:	
-	*
-	*
-	*	@file	GeoMeshLoader.cpp
-/*===========================================================================*/
+ *==========================================================================*/
+/*	CONTENT:	
+ *
+ *
+ *	@file	GeoMeshLoader.cpp
+ *==========================================================================*/
+
 #include	"GeoMeshLoader.h"
 
@@ -55,4 +56,5 @@
 	vType	=	static_cast<VertexElementType>(aux.type);
 
+	/*
 	if (vType == VET_FLOAT3)
 	{
@@ -69,4 +71,5 @@
 		printf("%u es float2 ",aux.type);
 	}
+	*/
 
 	// unsigned short semantic; // VertexElementSemantic
@@ -115,7 +118,4 @@
 		list.push_back(aux2);
 	}
-	
-	//	Debug.
-	cout	<<	"Finish Vertex Element"	<<	endl;
 }
 
@@ -134,6 +134,11 @@
       {
 				case M_GEOMETRY_VERTEX_ELEMENT:
-					cout	<<	"M_GEOMETRY_VERTEX_ELEMENT"	<<	endl;
+
+					//	Debug.
+					cout	<<	"		M_GEOMETRY_VERTEX_ELEMENT"
+								<<	endl;
+					
           readGeometryVertexElement(f, geoMesh);
+
           break;
       }
@@ -153,5 +158,5 @@
 
   }//	End if (!feof(f))
-}
+}//	End readGeometryVertexDeclaration.
 
 //	Read geometry vertex buffer.
@@ -172,5 +177,4 @@
 	k						=	0;
 	encontrado	=	false;
-
 	
 	if (option == GEOMESH_BUILD)
@@ -196,9 +200,4 @@
 	fread(&vertexSize,sizeof(unsigned short),1,f);
 
-	//	Debug.
-	cout	<<	"Per-vertex size: "
-				<<	vertexSize
-				<<	endl;
-	
 	// Check for vertex data header
 	headerID	=	readChunk(f);
@@ -211,5 +210,7 @@
 	else
 	{
-		cout	<<	"M_GEOMETRY_VERTEX_BUFFER_DATA"	<<	endl;
+		//	Debug.
+		cout	<<	"		M_GEOMETRY_VERTEX_BUFFER_DATA"
+					<<	endl;
 	}
 
@@ -226,20 +227,13 @@
 	}
 
-	//	Considero q los van por grupitos de vertices+normales+...
-	//	para cada uno de los vertices
 	if (encontrado)
 	{
-		FILE * salida;
-		salida=fopen(nom_salida,"a");
-		cout	<<	"----->Leo los vertices"
-					<<	endl;
-
-		for (k=0;k<numVertices;k++)
-		{
-			//Para cada uno de los elementos de ese source.
-			for(int j=0;j<list[i].list.size();j++)
-			{
-				//	Son posiciones, vertices
-				if (list[i].list[j].semantic==1)
+		for (k	=	0;	k < numVertices;	k++)
+		{
+			//	For each element in this source.
+			for(int j	=	0;	j < list[i].list.size();	j++)
+			{
+				//	Positions.
+				if (list[i].list[j].semantic == 1)
 				{
 					fread(&x,sizeof(float),1,f);
@@ -255,9 +249,8 @@
 					}
 				}
-				//	si no son vertices no lo quiero
+				//	If are not vertices.
 				else 
 				{
-					//Se tendría que hacer con un fseek
-					if (list[i].list[j].type==2) //Son 3 floats
+					if (list[i].list[j].type == 2)
 					{
 						fread(&x,sizeof(float),1,f);
@@ -273,5 +266,5 @@
 						}
 					}
-					if (list[i].list[j].type==1) //Son 2 floats
+					if (list[i].list[j].type == 1)
 					{
 						fread(&x,sizeof(float),1,f);
@@ -288,9 +281,9 @@
 			}
 		}
-		fclose(salida);
 	}
 	else
 	{
-		cout	<<	"Error"
+		//	Debug.
+		cout	<<	"Error: Source not found."
 					<<	endl;
 	}
@@ -298,5 +291,5 @@
 }
 
-//	Read geometry.
+//	Read Geometry.
 void GeoMeshLoader::readGeometry(FILE	*f, Mesh	*geoMesh, int option)
 {
@@ -350,10 +343,21 @@
 			{
 				case M_GEOMETRY_VERTEX_DECLARATION:
-					cout<<"M_GEOMETRY_VERTEX_DECLARATION\n";
+
+					//	Debug.
+					cout	<<	"		M_GEOMETRY_VERTEX_DECLARATION"
+								<<	endl;
+					
 					readGeometryVertexDeclaration(f, geoMesh);
+					
 					break;
+					
 				case M_GEOMETRY_VERTEX_BUFFER:
-					cout<<"M_GEOMETRY_VERTEX_BUFFER\n";
+					
+					//	Debug.
+					cout	<<	"		M_GEOMETRY_VERTEX_BUFFER"
+								<<	endl;
+					
 					readGeometryVertexBuffer(f, geoMesh,option);
+					
 					break;
 			}
@@ -365,4 +369,5 @@
 			}
 		}
+
 		if (!feof(f))
 		{
@@ -379,6 +384,6 @@
 {
 	unsigned	short	opType;
+	
 	fread(&opType,sizeof(unsigned short),1,f);
-	printf("\tLa render operation es %d\n",opType);
 
 	if (option == GEOMESH_BUILD)
@@ -404,5 +409,4 @@
 	unsigned	int		numIndices;
 	bool						idx32bit;
-	FILE						*salida;
 
 	switch	(option)
@@ -413,20 +417,12 @@
 		case	GEOMESH_BUILD:
 
-			//	Debug.
-			cout	<<	"Build GEOMESH"	<<	endl;
-
 			//	Initialize the new subMesh.
 			geoSubMesh	=	&geoMesh->mSubMesh[currentSubMesh];
-
-			cout	<<	"Current SubMesh: "
-						<<	currentSubMesh
-						<<	endl;
-	}
-	
-	//La vacio antes de leer el mesh
+	}
+	
 	list.clear(); 
 
+	//	Gets material name.
 	fgets(materialName,255,f);
-	printf("\tmaterialName: %s",materialName);
 
 	fread(&useSharedVertices,sizeof(bool),1,f);
@@ -434,4 +430,7 @@
 	if (option	==	GEOMESH_BUILD)
 	{
+		//	Obtain the material name.
+		strcpy(geoSubMesh->mMaterialName,materialName);
+		
 		//	Obtain the flag of vertex shared.
 		geoSubMesh->mSharedVertexBuffer	=	useSharedVertices;
@@ -441,14 +440,8 @@
 			//	The VB of the submesh points to the VB of the mesh.
 			geoSubMesh->mVertexBuffer	=	geoMesh->mVertexBuffer;
-			
-			cout	<<	"\tUse Shared Vertices"
-						<<	endl;
-
 		}
 	}
 
 	fread(&numIndices,sizeof(unsigned int),1,f);
-	printf("\tnumIndices: %u\n",numIndices);
-	printf("\tnumTriangles: %u\n",numIndices/3);
 	fread(&idx32bit,sizeof(bool),1,f);
 	
@@ -462,4 +455,5 @@
 	}
 	
+	/*
 	if (idx32bit)
 	{
@@ -470,22 +464,6 @@
 		printf("\tSon 16 bits por indice\n");
 	}
-
-	salida	=	fopen(nom_salida,"a");
-
-	fprintf(salida,"\n#----->Leo un subMesh:");
-	
-	if (useSharedVertices)
-	{
-		fprintf(salida," shared vertices");
-	}
-	else
-	{
-		fprintf(salida,
-						" no shared vertices %d triangles",
-						numIndices/3);
-	}
-
-	fprintf(salida,"\n# Indexes:");
-	
+	*/
+
 	//Sumo uno a los vertices porque en el obj no puede hacer un vertice 0
 	if (idx32bit)
@@ -518,6 +496,4 @@
 	}
 
-	fclose(salida);
-
   // M_GEOMETRY chunk 
 	// (Optional: present only if useSharedVertices = false)
@@ -528,5 +504,7 @@
 		if (chunkID != M_GEOMETRY)
 		{
-			printf("Missing geometry data in mesh file\n"); //Error
+			//	Debug.
+			cout	<<	"Error: Missing mesh geometry."
+						<<	endl;
 		}
 		
@@ -546,11 +524,27 @@
 				case M_SUBMESH_OPERATION:
 								
-					cout<<"M_SUBMESH_OPERATION\n";
+					//	Debug.
+					cout	<<	"		M_SUBMESH_OPERATION"
+								<<	endl;
 
 					readSubMeshOperation(f, geoMesh, option);
 					
 					break;
+					
 				case M_SUBMESH_BONE_ASSIGNMENT:
-					jumpChunk(f);
+					
+					//	Debug.
+					//cout	<<	"		M_SUBMESH_BONE_ASSIGNMENT"
+					//			<<	endl;
+					
+					if (option	==	GEOMESH_BUILD)
+					{
+						readSubMeshBoneAssignment(f, geoSubMesh, option);
+					}
+					else
+					{
+						jumpChunk(f);
+					}
+					
 					break;
 			}
@@ -564,5 +558,5 @@
 		if (!feof(f))
 		{
-			// Backpedal back to start of chunk
+			// Backpedal back to start of chunk.
 			fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
 		}
@@ -591,7 +585,14 @@
 		if (chunkID != M_MESH_LOD_USAGE)
 		{
-			printf("Missing M_MESH_LOD_USAGE chunk\n"); //Error
-		}
-		else printf("\tM_MESH_LOD_USAGE (%d bytes) ",long_actual);
+			//	Debug.
+			cout	<<	"Error: Missing M_MESH_LOD_USAGE chunk"
+						<<	endl;
+		}
+		else
+		{
+			cout	<<	"		M_MESH_LOD_USAGE"
+						<<	endl;
+		}
+		
 		jumpChunk(f);
 
@@ -612,5 +613,7 @@
 			while	(!feof(f) && (chunkID == M_SUBMESH_NAME_TABLE_ELEMENT ))
 			{
-				printf("M_SUBMESH_NAME_TABLE_ELEMENT %d bytes\n",long_actual);
+				//	Debug.
+				cout	<<	"		M_SUBMESH_NAME_TABLE_ELEMENT"
+							<<	endl;
 				
 				// Read in the index of the submesh.
@@ -619,7 +622,6 @@
 				// Read in the String and map it to its index.
 				fgets(string,255,f);
-				printf("index %u name %s\n",subMeshIndex,string);
-
-				// If we're not end of file get the next chunk ID
+
+				// If we're not end of file get the next chunk ID.
 				if (!feof(f))
 				{
@@ -629,5 +631,5 @@
 			if (!feof(f))
 			{
-				// Backpedal back to start of chunk
+				// Backpedal back to start of chunk.
 				fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
 			}
@@ -641,8 +643,4 @@
 	bool						nada;
 
-	//	Debug.
-	cout	<<	"Read Mesh"
-				<<	endl;
-	
 	//	Create the VertexBuffer of the mesh.
 	geoMesh->mVertexBuffer	=	new	VertexBuffer();
@@ -675,5 +673,6 @@
 
 					//	Debug.
-					cout	<<	"Geometry"	<<	endl;
+					cout	<<	"		M_GEOMETRY"
+								<<	endl;
 
 					readGeometry(f, geoMesh, option);
@@ -682,5 +681,7 @@
 				case M_SUBMESH:
 
-					cout	<<	"SubMesh"	<<	endl;
+					//	Debug.
+					cout	<<	"		M_SUBMESH"
+								<<	endl;
 
 					if (option == GEOMESH_BUILD)
@@ -696,51 +697,60 @@
 				case M_MESH_SKELETON_LINK:
 
-					cout	<<	"M_MESH_SKELETON_LINK  "
-						<<	long_actual
-						<<	" bytes\n";
+					//	Debug.
+					cout	<<	"		M_MESH_SKELETON_LINK  "
+								<<	endl;
+								
+
+					readSkeletonLink(f, geoMesh, option);
+
+					break;
+
+				case M_MESH_BONE_ASSIGNMENT:
+
+					//	Debug.
+					//cout	<<	"		M_MESH_BONE_ASSIGNMENT  "
+					//			<<	endl;
+
+					//OSCAR
+					readMeshBoneAssignment(f, geoMesh, option);
+
+					break;
+
+				case M_MESH_LOD:
+
+					//	Debug.
+					cout	<<	"		M_MESH_LOD"
+								<<	endl;
+					
+					readMeshLodInfo(f, geoMesh);
+					break;
+
+				case M_MESH_BOUNDS:
+
+					//	Debug.
+					cout	<<	"		M_MESH_BOUNDS "
+								<<	endl;
+
+					//jumpChunk(f);
+					readMeshBounds(f, geoMesh, option);
+					break;
+
+				case M_SUBMESH_NAME_TABLE:
+
+					//	Debug.
+					cout	<<	"		M_SUBMESH_NAME_TABLE "
+								<<	endl;
+
+					readSubMeshNameTable(f,	geoMesh);
+					break;
+
+				case M_EDGE_LISTS:
+
+					//	Debug.
+					cout	<<	"		M_EDGE_LISTS "
+								<<	endl;
 
 					jumpChunk(f);
 					break;
-
-				case M_MESH_BONE_ASSIGNMENT:
-
-					cout	<<	"M_MESH_BONE_ASSIGNMENT  "
-						<<	long_actual
-						<<	" bytes\n";
-
-					break;
-
-				case M_MESH_LOD:
-
-					cout	<<	"M_MESH_LOD\n";
-					readMeshLodInfo(f, geoMesh);
-					break;
-
-				case M_MESH_BOUNDS:
-
-					cout	<<	"M_MESH_BOUNDS "
-						<<	long_actual
-						<<	" bytes\n";
-
-					jumpChunk(f);
-					break;
-
-				case M_SUBMESH_NAME_TABLE:
-
-					cout	<<	"M_SUBMESH_NAME_TABLE "
-						<<	long_actual
-						<<	" bytes\n";
-
-					readSubMeshNameTable(f,	geoMesh);
-					break;
-
-				case M_EDGE_LISTS:
-
-					cout	<<	"M_EDGE_LISTS "
-						<<	long_actual
-						<<	" bytes\n";
-
-					jumpChunk(f);
-					break;
 			}
 
@@ -756,5 +766,8 @@
 			// Backpedal back to start of chunk
 			fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
-			printf("Malo\n");
+
+			//	Debug.
+			cout	<<	"Error: Reading failure."
+						<<	endl;
 		}
 	}
@@ -974,5 +987,4 @@
 	char						version[255];
 	char						kk;
-	FILE						*salida;
 	FILE						*pFile;
 	SubMesh					*geosubmesh;
@@ -981,6 +993,11 @@
 	currentSubMesh	=	-1;
 	
-	std::cout	<<	"Load a new Mesh"
-						<<	std::endl;
+	//	Debug.
+	cout	<<	"---------------------------------"
+				<<	endl
+				<<	"\t LOAD MESH"
+				<<	endl
+				<<	"---------------------------------"
+				<<	endl;
 
 	//	Initialize the return value.
@@ -992,5 +1009,10 @@
   if (!pFile)
   {
-		printf("No he encontrado el fichero\n");
+		//	Debug.
+		cout	<<	"Error: File "
+					<<	nameFileMesh
+					<<	" not found."
+					<<	endl;
+		
 		exit(0);
   }
@@ -1004,5 +1026,6 @@
 		if (uno != M_HEADER)
 		{
-			cout	<<	"no se ha encontrado el header"
+			//	Debug.
+			cout	<<	"Error: Header not found."
 						<<	endl;
 		}
@@ -1015,17 +1038,10 @@
 		if (strcmp(version,"[MeshSerializer_v1.30]\n"))
 		{
-			cout	<<
-						"No se puede trabajar con versiones de"
-						<<
-						" .mesh diferentes de la 1.3"
-						<<
-						endl;
-		}
-
-		salida	=	fopen(nom_salida,"w");
-
-		fprintf(salida,"# Empiezo el fichero:");
-
-		fclose(salida);
+			//	Debug.
+			cout	<<	"Error: Wrong mesh version."
+						<<	endl
+						<<	"Only version 1.3 or older allowed."
+						<<	endl;
+		}
 
 		while(!feof(pFile))
@@ -1044,22 +1060,7 @@
 		if (option == SUBMESH_COUNT)
 		{		
-			cout	<<	"---------------"
-						<<	endl;
-
-			cout	<<	"SubMesh Count: "
-						<<	geoMesh->mSubMeshCount
-						<<	endl;
-
 			geoMesh->mSubMesh	= new SubMesh[geoMesh->mSubMeshCount];
 		}
 							
-		if (feof(pFile))
-		{
-			cout	<<	"------->Hemos llegado al final del fichero"
-						<<	endl;
-		}
-
-		//cout	<<	"Press enter to exit\n";
-
 		//	Move the curso to the begining of the file.
 		fseek(pFile,0,SEEK_SET);
@@ -1087,5 +1088,130 @@
 	}
 	
+	//	Sets coods between -1 and 1.
+	normalizeModel(geoMesh);
+
 	return	geoMesh;
+}
+
+//	Sets coords between -1 and 1.
+void	GeoMeshLoader::normalizeModel(Mesh	*geoMesh)
+{
+	unsigned	int	i;
+	float					maxx, minx, maxy, miny, maxz, minz;
+	float					cx, cy, cz, w, h, d, max;
+	float					scale;
+	VertexBuffer	*vertex_buffer;
+
+	//	Gets vertex buffer.
+	vertex_buffer	=	geoMesh->mSubMesh[0].mVertexBuffer;
+	
+	//	Get the max/mins.
+	maxx = minx = vertex_buffer->mPosition[0].x;
+	maxy = miny = vertex_buffer->mPosition[0].y;
+	maxz = minz = vertex_buffer->mPosition[0].z;
+	
+	//	For each submesh.
+	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
+	{
+		//	Gets the actual submesh.
+		vertex_buffer	=	geoMesh->mSubMesh[submesh].mVertexBuffer;
+
+		//	For each index of the strip.
+		for (int i = 0; i < vertex_buffer->mVertexCount; i++)
+		{
+			if (maxx < vertex_buffer->mPosition[i].x)
+			{
+				maxx = vertex_buffer->mPosition[i].x;
+			}
+
+			if (minx > vertex_buffer->mPosition[i].x)
+			{
+				minx = vertex_buffer->mPosition[i].x;
+			}
+
+			if (maxy < vertex_buffer->mPosition[i].y)
+			{
+				maxy = vertex_buffer->mPosition[i].y;
+			}
+
+			if (miny > vertex_buffer->mPosition[i].y)
+			{
+				miny = vertex_buffer->mPosition[i].y;
+			}
+
+			if (maxz < vertex_buffer->mPosition[i].z)
+			{
+				maxz = vertex_buffer->mPosition[i].z;
+			}
+
+			if (minz > vertex_buffer->mPosition[i].z)
+			{
+				minz = vertex_buffer->mPosition[i].z;
+			}
+		}
+
+		//	If is a shared vertex Buffer.
+		if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer)
+		{
+			break;
+		}
+	}
+	
+	//	Calculate model width, height, and depth.
+	w = fabs(maxx) + fabs(minx);
+	h = fabs(maxy) + fabs(miny);
+	d = fabs(maxz) + fabs(minz);
+
+	//	Calculate center of the model.
+	cx = (maxx + minx) / 2.0;
+	cy = (maxy + miny) / 2.0;
+	cz = (maxz + minz) / 2.0;
+
+
+	//	Calculate max dimension.
+	if (w > h)
+	{
+		max	=	w;
+	}
+	else
+	{
+		max	=	h;
+	}
+
+	if (d > max)
+	{
+		max	=	d;
+	}
+	
+	//	Calculate unitizing scale factor.
+	scale = 1.0 / max;
+
+	geoMesh->mMeshBounds.scaleFactor		=	scale;
+
+	//	Translate around center then scale.
+	//	For each submesh.
+	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
+	{
+		//	Gets the actual submesh.
+		vertex_buffer	=	geoMesh->mSubMesh[submesh].mVertexBuffer;
+
+		//	For each index of the strip.
+		for (int i = 0; i < vertex_buffer->mVertexCount; i++)
+		{
+			vertex_buffer->mPosition[i].x -= cx;
+			vertex_buffer->mPosition[i].y -= cy;
+			vertex_buffer->mPosition[i].z -= cz;
+			vertex_buffer->mPosition[i].x *= scale;
+			vertex_buffer->mPosition[i].y *= scale;
+			vertex_buffer->mPosition[i].z *= scale;
+		}
+
+		//	If is a shared vertex Buffer.
+		if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer)
+		{
+			break;
+		}
+	}
+
 }
 
@@ -1099,5 +1225,4 @@
 GeoMeshLoader::GeoMeshLoader()
 {
-	nom_salida	=	"salida22.obj";
 	geoMesh			=	NULL;
 	mFileSize		=	0;
@@ -1110,2 +1235,70 @@
 }
 
+//OSCAR
+void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, SubMesh* geoSubMesh,int option)
+{
+	if (option == GEOMESH_BUILD)
+	{
+		VertexBoneAssignment assign;
+
+		// unsigned int vertexIndex;
+		fread(&(assign.vertexIndex),sizeof(unsigned int),1,f);
+		// unsigned short boneIndex;
+		fread(&(assign.boneIndex),sizeof(unsigned short),1,f);
+		// float weight
+		fread(&(assign.weight),sizeof(float),1,f);
+
+		geoSubMesh->mBones.push_back(assign);
+	}
+}
+
+//OSCAR
+void GeoMeshLoader::readMeshBoneAssignment(FILE* f, Mesh* geoMesh,int option)
+{
+	if (option == GEOMESH_BUILD)
+	{
+		VertexBoneAssignment assign;
+
+		// unsigned int vertexIndex;
+		fread(&(assign.vertexIndex),sizeof(unsigned int),1,f);
+		// unsigned short boneIndex;
+		fread(&(assign.boneIndex),sizeof(unsigned short),1,f);
+		// float weight
+		fread(&(assign.weight),sizeof(float),1,f);
+
+
+		geoMesh->mBones.push_back(assign);
+	}
+}
+
+//OSCAR
+void GeoMeshLoader::readSkeletonLink(FILE* f, Mesh* geoMesh,int option)
+{
+	if (option == GEOMESH_BUILD)
+	{
+		fgets(geoMesh->mSkeletonName,255,f);
+		
+		geoMesh->hasSkeleton	=	true;
+
+		//	Debug.
+		cout	<<	"Skeleton Name: "
+					<<	geoMesh->mSkeletonName
+					<<	endl;
+	}
+}
+
+//	Read bounding box settings.
+void	GeoMeshLoader::readMeshBounds(FILE	*f, Mesh	*geoMesh,	int	option)
+{
+	if (option == GEOMESH_BUILD)
+	{
+		fread(&(geoMesh->mMeshBounds.minX),sizeof(float),1,f);
+		fread(&(geoMesh->mMeshBounds.minY),sizeof(float),1,f);
+		fread(&(geoMesh->mMeshBounds.minZ),sizeof(float),1,f);
+		fread(&(geoMesh->mMeshBounds.maxX),sizeof(float),1,f);
+		fread(&(geoMesh->mMeshBounds.maxY),sizeof(float),1,f);
+		fread(&(geoMesh->mMeshBounds.maxZ),sizeof(float),1,f);
+		fread(&(geoMesh->mMeshBounds.radius),sizeof(float),1,f);
+	}
+}
+
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 895)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 980)
@@ -63,5 +63,5 @@
 	{
 		//	Create a mesh saver with mesh bounds.
-		mesh_saver	=	new	GeoMeshSaver(mMeshBounds);
+		mesh_saver	=	new	GeoMeshSaver();
 
 		//	Save the file mesh.
@@ -99,5 +99,5 @@
 		if (fcho->value())
 		{
-			mesh_saver	=	new	GeoMeshSaver(mMeshBounds);
+			mesh_saver	=	new	GeoMeshSaver();
 			mesh_saver->save(mGeoMesh,filename_name(fcho->value()));
 			delete	mesh_saver;
@@ -953,4 +953,7 @@
 					//	Simplify the mesh object.
 					simplifyEdgeCollapse();
+					
+					delete	mMeshSimplifier;
+					geoMeshView->restoreContext();
 				}
 				break;
@@ -1043,4 +1046,7 @@
 					//	Create the qslim simplification sequence.
 					createQslimSequence();
+					
+					delete	mMeshSimplifier;
+					geoMeshView->restoreContext();
 				}
 
@@ -1053,5 +1059,5 @@
 
 				//	Set the leaves submesh.
-				geoMeshView->setLeavesSubmesh(idMeshLeaves);
+				geoMeshView->setLeavesSubMesh(idMeshLeaves);
 
 				//	Refresh mesh info.
@@ -1193,5 +1199,5 @@
 						geoMeshView->setMesh(mGeoMesh);
 
-						mesh_saver	=	new	GeoMeshSaver(mMeshBounds);
+						mesh_saver	=	new	GeoMeshSaver();
 						file_name[strlen(file_name) - 4]	=	'\0';
 						mesh_saver->save(mGeoMesh, strcat(file_name,".mesh"));
@@ -1354,6 +1360,6 @@
 	mGeometryBased->set();
 
-	mImageBased->set_visible();
-	mImageBased->activate();
+	mViewPointDriven->set_visible();
+	mViewPointDriven->activate();
 
 	/*
@@ -1401,6 +1407,6 @@
 	mGeometryBased->deactivate();
 
-	mImageBased->hide();
-	mImageBased->deactivate();
+	mViewPointDriven->hide();
+	mViewPointDriven->deactivate();
 
 	/*
@@ -1443,6 +1449,6 @@
 	mGeometryBased->set();
 
-	mImageBased->set_visible();
-	mImageBased->activate();
+	mViewPointDriven->set_visible();
+	mViewPointDriven->activate();
 
 	/*
@@ -1486,6 +1492,6 @@
 	mGeometryBased->deactivate();
 
-	mImageBased->hide();
-	mImageBased->deactivate();
+	mViewPointDriven->hide();
+	mViewPointDriven->deactivate();
 
 	/*
@@ -1662,7 +1668,7 @@
 			char *cadena=new char[12];
 
-			if (geoMeshView->getLeavesSubmesh() >= 0)
+			if (geoMeshView->getLeavesSubMesh() >= 0)
 			{
-				if (geoMeshView->getLeavesSubmesh() == i)
+				if (geoMeshView->getLeavesSubMesh() == i)
 				{
 					strcpy(type,"(Leaves)");
@@ -1693,7 +1699,14 @@
 			}
 
-			char *cadena2=new char[30];
-			sprintf(cadena2, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount);
-			fltk::Item *numberIndex = new fltk::Item(cadena2);
+			//	Adds material name.
+			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];
+			
+			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)
 			{
@@ -1884,5 +1897,5 @@
 	}
 	
-	geoMeshView->setColorSubmeshi(meshNumber);
+	geoMeshView->setSubMeshSelected(meshNumber);
 	geoMeshView->redraw();
 	
@@ -1897,11 +1910,24 @@
 	Real	percent;
 
-	simplificacionState	=	QSLIM;
-
-	mMeshSimplifier = new GeometryBasedSimplifier(mGeoMesh,	progress_function);
+	//-----------------
+	geoMeshView->saveContext();
+
+	//	Gets simplify option.
+	if (mGeometryBased->value())
+	{
+		simplificationState	=	QSLIM;
+		mMeshSimplifier 		= new GeometryBasedSimplifier(mGeoMesh,
+																											progress_function);
+	}
+	else
+	{
+		simplificationState	=	VIEWPOINTDRIVEN;
+		mMeshSimplifier 		= new ViewPointDrivenSimplifier(mGeoMesh,
+																												progress_function);
+	}
 
 	mMeshSimplifier->setMeshLeaves(idMeshLeaves);
 
-	if (mPercent->value() == true)
+	if (mPercent->value())
 	{
 		// Simplificación por porcentaje
@@ -1910,4 +1936,5 @@
 			percent	= mMeshReduction->fvalue();
 			percent	=	percent	/ 100.0;
+			
 
 			// Simplifica el geomesh -> Parámetro es un factor LOD [0,1].
@@ -1928,4 +1955,5 @@
 			//	Visualize mesh.
 			geoMeshView->setMesh(mGeoMesh);
+
 		}
 		else
@@ -1970,5 +1998,5 @@
 	//	Initialize	error flag.
 	error	=	false;
-	
+
 	//	Check submeshes for triangles strips.
 	for (int i = 0; i < mGeoMesh->mSubMeshCount; i++)
@@ -1980,5 +2008,5 @@
 		}
 	}
-				
+
 	//	if the mesh is stripified.
 	if (error)
@@ -1988,6 +2016,6 @@
 	//	if the mesh is in triangle list.
 	else
-	{			
-		simplificacionState	=	HOJAS;
+	{
+		simplificationState	=	HOJAS;
 		
 		mTreeSimplifier	=	new TreeSimplifier(mGeoMesh, progress_function);
@@ -2308,7 +2336,4 @@
 		geoMeshView->setMesh(mGeoMesh);
 
-		//	Get the mesh bounds.
-		mMeshBounds	=	geoMeshView->getBoundingBox();
-
 		//	Hide right panel.
 		hideRightPanel();
@@ -2400,10 +2425,10 @@
 			{
 				fltk::Group* o;
-				o = MainView = new fltk::Group(0, 0, 600, 500);
+				o = MainView = new fltk::Group(0, 0, 500, 530);
 				o->begin();
 
 				{
 					fltk::InvisibleBox* o;
-					o = cframe = new fltk::InvisibleBox(0, 0, 600, 500);
+					o = cframe = new fltk::InvisibleBox(0, 0, 500, 530);
 					o->box(fltk::FLAT_BOX);
 					o->color((fltk::Color)0xffffff00);
@@ -2413,5 +2438,5 @@
 				{
 					GeoMeshView* o;
-					o = geoMeshView = new GeoMeshView(	0,0,600,500,0,this);
+					o = geoMeshView = new GeoMeshView(	0,0,500,530,0,this);
 				}
 
@@ -2424,5 +2449,5 @@
 			{
 				fltk::Group* o;
-				o = MainView = new fltk::Group(600, 0, 200, 500);
+				o = MainView = new fltk::Group(500, 0, 300, 530);
 				o->begin();
 
@@ -2509,5 +2534,5 @@
 					{
 						mGeometryBased = new fltk::RadioButton(0, 8, 25, 25, "Geometry based");
-						mImageBased = new fltk::RadioButton(0, 23, 25, 25, "Image based");
+						mViewPointDriven = new fltk::RadioButton(0, 23, 25, 25, "Viewpoint driven");
 					}
 					o->end();
@@ -2517,5 +2542,5 @@
 
 				{
-					mProcessTitle		= new fltk::Widget(0, 0, 200, 25, "");
+					mProcessTitle		= new fltk::Widget(0, 0, 300, 25, "");
 					fltk::Widget* o	=	mProcessTitle;
 					o->set_vertical();
@@ -2582,5 +2607,5 @@
 
 				{
-					fltk::Browser* o = mMeshInfo = new fltk::Browser(0, 20, 200, 380);
+					fltk::Browser* o = mMeshInfo = new fltk::Browser(0, 20, 300, 380);
 					o->set_vertical();
 					o->callback((fltk::Callback*)cb_mMeshInfo);
@@ -2618,8 +2643,8 @@
 				}
 
-				//{
-				//	fltk::Item* o = menuMeshExportOBJ = new fltk::Item("Export to OBJ");
-				//	o->callback((fltk::Callback*)cb_menuMeshExportOBJ);
-				//}
+				{
+					fltk::Item* o = menuMeshExportOBJ = new fltk::Item("Export to OBJ");
+					o->callback((fltk::Callback*)cb_menuMeshExportOBJ);
+				}
 
 				//{
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 895)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 980)
@@ -200,7 +200,7 @@
 //	Set the color to the submesh sumbmeshIndex
 //---------------------------------------------------------------------------
-void	GeoMeshView::setColorSubmeshi(int submeshIndex)
-{
-	colorsubmeshi	=	submeshIndex;
+void	GeoMeshView::setSubMeshSelected(int submeshIndex)
+{
+	mSubMeshSelected	=	submeshIndex;
 }
 
@@ -208,7 +208,7 @@
 //	Sets the leaves submesh index.
 //---------------------------------------------------------------------------
-void	GeoMeshView::setLeavesSubmesh(int submeshIndex)
-{
-	leavesSubmesh	=	submeshIndex;
+void	GeoMeshView::setLeavesSubMesh(int submeshIndex)
+{
+	leavesSubMesh	=	submeshIndex;
 }
 
@@ -216,7 +216,7 @@
 //	Gets the leaves submesh index.
 //---------------------------------------------------------------------------
-int	GeoMeshView::getLeavesSubmesh()
-{
-	return	leavesSubmesh;
+int	GeoMeshView::getLeavesSubMesh()
+{
+	return	leavesSubMesh;
 }
 
@@ -277,4 +277,5 @@
 }
 
+/*
 //---------------------------------------------------------------------------
 //	Get the bounding box of the object.
@@ -386,4 +387,5 @@
 	return	bounds;
 }
+*/
 
 //---------------------------------------------------------------------------
@@ -446,7 +448,8 @@
 	GLfloat color_blanco[]	=	{1.0f,1.0f,1.0f,1.0f};
 
-	this->geoMesh	=	geomesh;
-	colorsubmeshi	=	-1;
-	leavesSubmesh	=	-1;
+	this->geoMesh			=	geomesh;
+	mSubMeshSelected	=	-1;
+	leavesSubMesh			=	-1;
+	mScaleFactor			=	geomesh->mMeshBounds.scaleFactor;
 	
 	//	Refresh vertices to the vertex array.
@@ -577,5 +580,5 @@
 //	Repaint the Mesh.
 //---------------------------------------------------------------------------
-void GeoMeshView::drawGeoMesh(int selectedMesh)
+void GeoMeshView::drawGeoMesh(bool	paintWire)
 {
 	SubMesh	*geosubmesh;
@@ -601,5 +604,5 @@
 				if (geosubmesh->mType	==	GEO_TRIANGLE_LIST)
 				{
-					if (selectedMesh == submesh)
+					if (mSubMeshSelected == submesh)
 					{
 						submesh_selected	= true;
@@ -611,5 +614,5 @@
 					
 					//	Draw the actual submesh in triangle list.
-					drawTriangleList(submesh,submesh_selected);
+					drawTriangleList(submesh,submesh_selected,paintWire);
 				}
 				else
@@ -618,19 +621,6 @@
 					drawTriangleStrip(submesh);
 				}
-			}		
-		}
-		/*
-		//	Choose the render operation.
-		else if (geoMesh->mType == GEO_TRIANGLE_LIST)
-		{
-			//	Paint vertices.
-			drawTriangleList(selectedMesh);
-		}
-		else
-		{
-			//	Paint vertices.
-			drawTriangleStrip();
-		}
-		*/
+			}
+		}
 	}
 }//	End drawGeoMesh.
@@ -743,5 +733,6 @@
 //---------------------------------------------------------------------------
 void GeoMeshView::drawTriangleList(	int			submesh,
-																		bool 		selectedSubMesh)
+																		bool 		selectedSubMesh,
+																		bool		paintWire)
 {
 	SubMesh	*geosubmesh;
@@ -761,36 +752,39 @@
 	geosubmesh	=	&geoMesh->mSubMesh[submesh];
 	
-	//	If a mesh is selected.
-	if (selectedSubMesh)
-	{
-		glColor3d(1.0,0.0,0.0);
-		GLfloat red[]	=	{1.0f,0.0f,0.0f,1.0f};
-		glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,red);
-	}
-	//	If is a tree.
-	else if (leavesSubmesh >= 0)
-	{
-		glColor3d(1.0, 0.5, 0.5);
-		GLfloat brown[]	=	{1.0f,0.5f,0.5f,1.0f};
-		glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,brown);
-
-		//	For each index of the strip.
-		if (submesh == leavesSubmesh)
-		{
-			glColor3d(0.0,1.0,0.0);
-			GLfloat green[]	=	{0.0f,1.0f,0.0f,1.0f};
-			glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green);
-		}
-	}
-	//	If is NOT a tree.
-	else
-	{
-		//	Set white color to the object.
-		glColor3d(1.0, 1.0, 1.0);
-		GLfloat white[]	=	{1.0f,1.0f,1.0f,1.0f};
-		glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,white);
-	}
-
-
+	//	If wire is not selected.
+	if (!paintWire)
+	{
+		//	If a mesh is selected.
+		if (selectedSubMesh)
+		{
+			glColor3d(1.0,0.0,0.0);
+			GLfloat red[]	=	{1.0f,0.0f,0.0f,1.0f};
+			glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,red);
+		}
+		//	If is a tree.
+		else if (leavesSubMesh >= 0)
+		{
+			glColor3d(1.0, 0.5, 0.5);
+			GLfloat brown[]	=	{1.0f,0.5f,0.5f,1.0f};
+			glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,brown);
+
+			//	For each index of the strip.
+			if (submesh == leavesSubMesh)
+			{
+				glColor3d(0.0,1.0,0.0);
+				GLfloat green[]	=	{0.0f,1.0f,0.0f,1.0f};
+				glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green);
+			}
+		}
+		//	If is NOT a tree.
+		else
+		{
+			//	Set white color to the object.
+			glColor3d(1.0, 1.0, 1.0);
+			GLfloat white[]	=	{1.0f,1.0f,1.0f,1.0f};
+			glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,white);
+		}
+	}
+	
 	//	Enable arrays.
 	glEnableClientState(GL_VERTEX_ARRAY);
@@ -1056,5 +1050,5 @@
 	//	Frustrum.
 	glViewport(0,0,w(),h());
-	gluPerspective(60,1,0.1,1000);
+	gluPerspective(60,(float)w()/(float)h(),0.1,1000);
 
 	glMatrixMode(GL_MODELVIEW);
@@ -1082,10 +1076,10 @@
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	gluLookAt(0,0,mScaleFactor*2+size, 0,0,0, 0,1,0);
+	gluLookAt(0,0,2/*mScaleFactor*/ + size * 0.25, 0,0,0, 0,1,0);
 
 	glTranslatef(xshift,yshift,0);
 	glRotatef(hAng,0,1,0);
 	glRotatef(vAng,1,0,0);
-	glTranslatef(-xMed,-yMed,-zMed);
+	//glTranslatef(-xMed,-yMed,-zMed);
 
 	//	Set white color to the object.
@@ -1094,4 +1088,6 @@
 	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco);
 
+	glClearColor(0,0,0,0);
+	
 	if (mCW)
 	{
@@ -1117,5 +1113,5 @@
 		glDisable(GL_LIGHTING);
 		glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
-		drawGeoMesh(colorsubmeshi);
+		drawGeoMesh(false);
 	}
 	else
@@ -1130,5 +1126,5 @@
 		glColor3d(0.0, 0.0, 1.0);
 		glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
-		drawGeoMesh(-1);
+		drawGeoMesh(true);
 	}
 	else
@@ -1139,5 +1135,5 @@
 			glEnable(GL_LIGHTING);
 			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-			drawGeoMesh(colorsubmeshi);
+			drawGeoMesh(false);
 		}
 	}
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshSaver.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshSaver.cpp	(revision 891)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshSaver.cpp	(revision 980)
@@ -23,30 +23,4 @@
 GeoMeshSaver::GeoMeshSaver()
 {
-	mMaterialName				=	"";
-	mSkeletallyAnimated	=	false;
-
-	//	Initializa the mesh bounds.
-	mMeshBounds.minx			=	0.0;
-	mMeshBounds.miny			=	0.0;
-	mMeshBounds.minz			=	0.0;
-	mMeshBounds.maxx			=	0.0;
-	mMeshBounds.maxy			=	0.0;
-	mMeshBounds.maxz			=	0.0;
-	mMeshBounds.radius		=	0.0;
-}
-
-GeoMeshSaver::GeoMeshSaver(GeometryBounds bounds)
-{
-	mMaterialName				=	"";
-	mSkeletallyAnimated	=	false;
-
-	//	Initializa the mesh bounds.
-	mMeshBounds.minx			=	bounds.minx;
-	mMeshBounds.miny			=	bounds.miny;
-	mMeshBounds.minz			=	bounds.minz;
-	mMeshBounds.maxx			=	bounds.maxx;
-	mMeshBounds.maxy			=	bounds.maxy;
-	mMeshBounds.maxz			=	bounds.maxz;
-	mMeshBounds.radius		=	bounds.radius;
 }
 
@@ -56,4 +30,5 @@
 GeoMeshSaver::~GeoMeshSaver()
 {
+	delete	mGeoMesh;
 }
 
@@ -63,11 +38,28 @@
 	int			size;
 	String	name(fileNameMesh);
-	
+
+	mGeoMesh	=	new Mesh();
+
+	//	Set the mesh.
+	*mGeoMesh	=	*geoMesh;
+
+	//	Debug.
+	cout	<<	endl
+				<<	endl
+				<<	"-----------------------------------"
+				<<	endl
+				<<	"\t SAVE MESH"
+				<<	endl
+				<<	"-----------------------------------"
+				<<	endl
+				<<	endl;
+
+	//	Unnormalize geometry model.
+	unnormalizeModel(mGeoMesh);
+
 	//	Open the file.
 	mSerializer	=	new	Serializer(	name,
 																Serializer::WRITE);
 
-	//	Set the mesh.
-	mGeoMesh	=	geoMesh;
 
 	//	Write the file header.
@@ -75,10 +67,6 @@
 
 	//	Write the mesh data.
-	writeMesh(geoMesh);
-
-	//	Debug.
-	cout	<<	"Write mesh finish"
-				<<	endl;
-	
+	writeMesh(mGeoMesh);
+
 	size	=	mSerializer->GetSize();
 	
@@ -97,25 +85,17 @@
 void	GeoMeshSaver::writeMesh(Mesh	*geoMesh)
 {
-	//	Debug.
-	cout	<<	"Write the chunk header"
-				<<	endl;
-	
 	// Header
 	writeChunkHeader(M_MESH, calcMeshSize(geoMesh));
 
+	//	Debug.
+	cout	<<	"		M_MESH"
+				<<	endl;
+
 	//	Write the skeletally animated flag.
-	writeBools(mSkeletallyAnimated,1);
-	
-	cout	<<	"1 - VertexCount: "
-				<<	geoMesh->mVertexBuffer->mVertexCount
-				<<	endl;
-
+	writeBools(geoMesh->hasSkeleton,1);
+	
 	//	Write shared geometry.
 	if (geoMesh->mVertexBuffer->mVertexCount > 0)
 	{
-		//	Debug.
-		cout	<<	"Write the shared vertex buffer"
-					<<	endl;
-		
 		writeGeometry(geoMesh->mVertexBuffer);
 	}
@@ -124,40 +104,30 @@
 	for (int i = 0;	i < geoMesh->mSubMeshCount;	i++)
 	{
-		//	Debug.
-		cout	<<	"Write the submesh "
-					<<	i
-					<<	endl;
-		
 		writeSubMesh(&geoMesh->mSubMesh[i]);
 	}
 
+	//OSCAR
+	// Write skeleton info if required
+	if (geoMesh->hasSkeleton)
+	{
+		// Write skeleton link
+		writeSkeletonLink(geoMesh->mSkeletonName);
+
+		// Write bone assignments
+		if (!geoMesh->mBones.empty())
+		{
+
+			for (int i=0; i< geoMesh->mBones.size(); i++)
+			{
+				writeMeshBoneAssignment(geoMesh->mBones[i]);
+			}
+
+		}
+	}
+
 	//	Write the mesh bounds.
-	writeMeshBounds(mMeshBounds);
-	
+	writeMeshBounds(geoMesh);
+
 	/*
-	// Write skeleton info if required
-	if (pMesh->hasSkeleton())
-	{
-	LogManager::getSingleton().logMessage("Exporting skeleton link...");
-	// Write skeleton link
-	writeSkeletonLink(pMesh->getSkeletonName());
-	LogManager::getSingleton().logMessage("Skeleton link exported.");
-
-	// Write bone assignments
-	if (!pMesh->mBoneAssignments.empty())
-	{
-	LogManager::getSingleton().logMessage("Exporting shared geometry bone assignments...");
-
-	Mesh::VertexBoneAssignmentList::const_iterator vi;
-	for (vi = pMesh->mBoneAssignments.begin(); 
-	vi != pMesh->mBoneAssignments.end(); ++vi)
-	{
-	writeMeshBoneAssignment(vi->second);
-	}
-
-	LogManager::getSingleton().logMessage("Shared geometry bone assignments exported.");
-	}
-	}
-
 	// Write LOD data if any
 	if (pMesh->getNumLodLevels() > 1)
@@ -186,5 +156,5 @@
 	}
 	*/
-}
+}//	End write mesh.
 
 //	Write a submesh.
@@ -193,27 +163,17 @@
 	bool						idx32bit;
 	unsigned	long	indexCount;
-	String					materialName;
 	Index						*index;
 	Index						*indexBegin;
 	Index						*indexEnd;
 	
-	//	Debug.
-	cout	<<	"Write the submesh chunk header"
-				<<	endl;
-	
 	// Header.
 	writeChunkHeader(M_SUBMESH, calcSubMeshSize(geoSubMesh));
 
 	//	Debug.
-	cout	<<	"Write the material name"
+	cout	<<	"		M_SUBMESH"
 				<<	endl;
 
 	// Material Name.
-	materialName	=	getMaterialName();
-	writeString(materialName);
-
-	//	Debug.
-	cout	<<	"Write the shared vertex buffer flag: "
-				<<	endl;
+	mSerializer->WriteData(geoSubMesh->mMaterialName);
 
 	// bool useSharedVertices
@@ -228,4 +188,5 @@
 	}
 	
+	//	Write index count.
 	writeInts(indexCount, 1);
 
@@ -234,15 +195,7 @@
 	writeBools(idx32bit, 1);
 
-	//	Debug.
-	cout	<<	"Write the mIndex array"
-				<<	endl;
-
 	//	If the submesh is in triangle strips.
 	if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS)
 	{
-		//	Debug.
-		cout	<<	"Write triangle strips"
-					<<	endl;
-		
 		//	For each one of the strips.
 		for (int strip = 0; strip < geoSubMesh->mStripCount; strip++)
@@ -300,36 +253,18 @@
 	if (!geoSubMesh->mSharedVertexBuffer)
 	{
-		//	Debug.
-		cout	<<	"Write the geometry of the submesh"
-					<<	endl;
-
 		writeGeometry(geoSubMesh->mVertexBuffer);
 	}
-
-	//	Debug.
-	cout	<<	"mIndex array written"
-				<<	endl;
 
 	// Operation type
 	writeSubMeshOperation(geoSubMesh);
 
-	//TODO:Bones.
-	/*
 	// Bone assignments
-	if (!s->mBoneAssignments.empty())
-	{
-		LogManager::getSingleton().logMessage("Exporting dedicated geometry bone assignments...");
-
-		SubMesh::VertexBoneAssignmentList::const_iterator vi;
-
-		for (vi = s->mBoneAssignments.begin(); 
-				vi != s->mBoneAssignments.end(); ++vi)
+	if (!geoSubMesh->mBones.empty())
+	{
+		for (int i = 0; i < geoSubMesh->mBones.size(); i++)
 		{
-			writeSubMeshBoneAssignment(vi->second);
+			writeSubMeshBoneAssignment(geoSubMesh->mBones[i]);
 		}
-
-		LogManager::getSingleton().logMessage("Dedicated geometry bone assignments exported.");
-	}
-	*/
+	}
 }
 
@@ -340,8 +275,4 @@
 	unsigned	long	size;
 
-	//	Debug.
-	cout	<<	"Write submesh operation"
-				<<	endl;
-	
 	size	=	CHUNK_OVERHEAD_SIZE	+	sizeof(unsigned	short);
 	
@@ -349,4 +280,8 @@
 	writeChunkHeader(M_SUBMESH_OPERATION, size);
 
+	//	Debug.
+	cout	<<	"		M_SUBMESH_OPERATION"
+				<<	endl;
+
 	//	If the mesh is in triangle strips.
 	if (geoSubMesh->mType	==	GEO_TRIANGLE_STRIPS)
@@ -361,8 +296,4 @@
 	
 	writeShorts(opType, 1);
-
-	//	Debug.
-	cout	<<	"Submesh operation Written"
-				<<	endl;
 }
 
@@ -385,4 +316,8 @@
 	writeChunkHeader(M_GEOMETRY, size);
 
+	//	Debug.
+	cout	<<	"		M_GEOMETRY"
+				<<	endl;
+
 	writeInts(vertexBuffer->mVertexCount,1);
 
@@ -398,4 +333,8 @@
 	writeChunkHeader(	M_GEOMETRY_VERTEX_DECLARATION,size);
 
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_DECLARATION"
+				<<	endl;
+
 	//	Obtain the size of the vertex element chunk.
 	size	=	CHUNK_OVERHEAD_SIZE	+	(sizeof(unsigned short)	*	5);
@@ -405,4 +344,8 @@
 	writeChunkHeader(	M_GEOMETRY_VERTEX_ELEMENT,size);
 
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_ELEMENT"
+				<<	endl;
+
 	element	=	0;
 	writeShorts(element,1);
@@ -424,4 +367,8 @@
 	writeChunkHeader(	M_GEOMETRY_VERTEX_ELEMENT,size);
 	
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_ELEMENT"
+				<<	endl;
+
 	element	=	1;
 	writeShorts(element,1);
@@ -443,4 +390,8 @@
 	writeChunkHeader(M_GEOMETRY_VERTEX_ELEMENT,size);
 	
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_ELEMENT"
+				<<	endl;
+
 	element	=	2;
 	writeShorts(element,1);
@@ -463,4 +414,8 @@
 	//	Write the vertex buffer header for positions.
 	writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER,	size);
+
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_BUFFER"
+				<<	endl;
 
 	element	=	0;
@@ -478,4 +433,8 @@
 	writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER_DATA,	size);
 
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_BUFFER_DATA"
+				<<	endl;
+
 	//	Write all the positions coords.
 	mSerializer->WriteArray(vertexBuffer->mPosition,
@@ -487,4 +446,8 @@
 	//	Write the vertex buffer header.
 	writeChunkHeader(	M_GEOMETRY_VERTEX_BUFFER,	size);
+
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_BUFFER"
+				<<	endl;
 
 	element	=	1;
@@ -502,4 +465,8 @@
 	writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER_DATA,	size);
 
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_BUFFER_DATA"
+				<<	endl;
+
 	//	Write all the normals coords.
 	mSerializer->WriteArray(vertexBuffer->mNormal,
@@ -511,4 +478,8 @@
 	//	Write the vertex buffer header for textures.
 	writeChunkHeader(M_GEOMETRY_VERTEX_BUFFER,	size);
+
+	//	Debug.
+	cout	<<	"		M_GEOMETRY_VERTEX_BUFFER"
+				<<	endl;
 
 	element	=	2;
@@ -527,17 +498,14 @@
 
 	//	Debug.
-	cout	<<	"-7-"	<<	endl;
+	cout	<<	"		M_GEOMETRY_VERTEX_BUFFER_DATA"
+				<<	endl;
 
 	//	Write all the texture coords.
 	mSerializer->WriteArray(vertexBuffer->mTexCoords,
 													vertexBuffer->mVertexCount);
-
-	//	Debug.
-	cout	<<	"-8-"	<<	endl;
-
-}
-
-//	TODO: Write Mesh Bounds.
-void	GeoMeshSaver::writeMeshBounds(GeometryBounds bounds)
+}
+
+//	Write Mesh Bounds.
+void	GeoMeshSaver::writeMeshBounds(Mesh	*geoMesh)
 {
 	size_t	size;
@@ -549,11 +517,15 @@
 	writeChunkHeader(M_MESH_BOUNDS,	size);
 
-	writeFloats(bounds.minx,1);
-	writeFloats(bounds.miny,1);
-	writeFloats(bounds.minz,1);
-	writeFloats(bounds.maxx,1);
-	writeFloats(bounds.maxy,1);
-	writeFloats(bounds.maxz,1);
-	writeFloats(bounds.radius,1);
+	//	Debug.
+	cout	<<	"		M_MESH_BOUNDS"
+				<<	endl;
+
+	writeFloats(geoMesh->mMeshBounds.minX,1);
+	writeFloats(geoMesh->mMeshBounds.minY,1);
+	writeFloats(geoMesh->mMeshBounds.minZ,1);
+	writeFloats(geoMesh->mMeshBounds.maxX,1);
+	writeFloats(geoMesh->mMeshBounds.maxY,1);
+	writeFloats(geoMesh->mMeshBounds.maxZ,1);
+	writeFloats(geoMesh->mMeshBounds.radius,1);
 }
 
@@ -563,23 +535,10 @@
 	size_t size = CHUNK_OVERHEAD_SIZE;
 
-	//	Debug.
-	cout	<<	"Calc the size of the mesh"
-				<<	endl;
-	
 	// Num shared vertices
 	size += sizeof(uint32);
 
-	//	Debug.
-	cout	<<	"VertexCount: "
-				<<	geoMesh->mVertexBuffer->mVertexCount
-				<<	endl;
-
 	// Geometry
 	if (geoMesh->mVertexBuffer->mVertexCount > 0)
 	{
-		//	Debug.
-		cout	<<	"Calc the size of the shared vertex buffer"
-					<<	endl;
-		
 		size += calcGeometrySize(geoMesh->mVertexBuffer);
 	}
@@ -588,9 +547,4 @@
 	for (unsigned short i = 0; i < geoMesh->mSubMeshCount; ++i)
 	{
-		//	Debug.
-		cout	<<	"Calc the size of the submesh "
-					<<	i
-					<<	endl;
-
 		size += calcSubMeshSize(&geoMesh->mSubMesh[i]);
 	}
@@ -601,11 +555,9 @@
 						(sizeof(float)	*	7);
 
-	/*
 	// Skeleton link
-	if (geoMesh->hasSkeleton())
-	{
-		size += calcSkeletonLinkSize(geoMesh->getSkeletonName());
-	}
-	*/
+	if (geoMesh->hasSkeleton)
+	{
+		size +=	calcSkeletonLinkSize(geoMesh);
+	}
 
 	/*
@@ -629,5 +581,5 @@
 
 	// Material name
-	size += getMaterialName().length() + 1;
+	size += strlen(geoSubMesh->mMaterialName);
 
 	// bool useSharedVertices
@@ -682,8 +634,22 @@
 }
 
+//	Calculate the skeleton link size in bytes.
+size_t	GeoMeshSaver::calcSkeletonLinkSize(const Mesh	*geoMesh)
+{
+	size_t	size	=		CHUNK_OVERHEAD_SIZE;
+	size 					+=	strlen(geoMesh->mSkeletonName);
+
+	//	Debug.
+	cout	<<	"Length Skeleton Link: "
+				<<	strlen(geoMesh->mSkeletonName)
+				<<	endl;
+
+	return	size;
+}
+
 //	Write the file header.
 void GeoMeshSaver::writeFileHeader(void)
 {
-	String	mesh_version("[MeshSerializer_v1.30]");
+	String	mesh_version("[MeshSerializer_v1.30]\n");
 	
 	writeShorts(M_HEADER, 1);
@@ -735,26 +701,96 @@
 }
 
-//	Sets the material of the mesh.
-void	GeoMeshSaver::setMaterialName(String	materialName)
-{
-	mMaterialName	=	materialName;
-}
-
-//	Gets the material of the mesh.
-String	GeoMeshSaver::getMaterialName()
-{
-	return	mMaterialName;
-}
-
-//	Set Mesh Bounds.
-void	GeoMeshSaver::setMeshBounds(GeometryBounds	bounds)
-{
-	mMeshBounds.minx		=	bounds.minx;
-	mMeshBounds.miny		=	bounds.miny;
-	mMeshBounds.minz		=	bounds.minz;
-	mMeshBounds.maxx		=	bounds.maxx;
-	mMeshBounds.maxy		=	bounds.maxy;
-	mMeshBounds.maxz		=	bounds.maxz;
-	mMeshBounds.radius	=	bounds.radius;
-}
-
+void GeoMeshSaver::writeSkeletonLink(const String& skelName)
+{	
+	writeChunkHeader(M_MESH_SKELETON_LINK, calcSkeletonLinkSize(mGeoMesh));
+
+	//	Debug.
+	cout	<<	"		M_MESH_SKELETON_LINK"
+				<<	endl;
+
+    writeString(skelName);
+}
+
+void GeoMeshSaver::writeMeshBoneAssignment(const VertexBoneAssignment& assign)
+{
+	size_t size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned int) + sizeof(unsigned short)+ sizeof(float);
+
+	writeChunkHeader(M_MESH_BONE_ASSIGNMENT, size);
+
+	// unsigned int vertexIndex;
+	writeInts(assign.vertexIndex, 1);
+	// unsigned short boneIndex;
+	writeShorts(assign.boneIndex, 1);
+	// float weight;
+	writeFloats(assign.weight, 1);
+}
+
+void GeoMeshSaver::writeSubMeshBoneAssignment(const VertexBoneAssignment& assign)
+{
+	size_t size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned int) + sizeof(unsigned short)+ sizeof(float);
+
+	writeChunkHeader(M_SUBMESH_BONE_ASSIGNMENT, size);
+
+	// unsigned int vertexIndex;
+	writeInts(assign.vertexIndex, 1);
+	// unsigned short boneIndex;
+	writeShorts(assign.boneIndex, 1);
+	// float weight;
+	writeFloats(assign.weight, 1);
+}
+
+//	unnormalize geometry model.
+void	GeoMeshSaver::unnormalizeModel(Mesh	*geoMesh)
+{
+	float	maxx;
+	float	maxy;
+	float	maxz;
+	float	minx;
+	float	miny;
+	float	minz;
+	float	cx;
+	float	cy;
+	float	cz;
+	float	scale;
+	
+	VertexBuffer	*vertex_buffer;
+
+	maxx	=	geoMesh->mMeshBounds.maxX;
+	maxy	=	geoMesh->mMeshBounds.maxY;
+	maxz	=	geoMesh->mMeshBounds.maxZ;
+	minx	=	geoMesh->mMeshBounds.minX;
+	miny	=	geoMesh->mMeshBounds.minY;
+	minz	=	geoMesh->mMeshBounds.minZ;
+	scale	=	geoMesh->mMeshBounds.scaleFactor;
+	
+	//	Calculate center of the model.
+	cx = (maxx + minx) / 2.0;
+	cy = (maxy + miny) / 2.0;
+	cz = (maxz + minz) / 2.0;
+
+	//	Translate around center then scale.
+	//	For each submesh.
+	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
+	{
+		//	Gets the actual submesh.
+		vertex_buffer	=	geoMesh->mSubMesh[submesh].mVertexBuffer;
+
+		//	For each index of the strip.
+		for (int i = 0; i < vertex_buffer->mVertexCount; i++)
+		{
+			vertex_buffer->mPosition[i].x /= scale;
+			vertex_buffer->mPosition[i].y /= scale;
+			vertex_buffer->mPosition[i].z /= scale;
+			vertex_buffer->mPosition[i].x += cx;
+			vertex_buffer->mPosition[i].y += cy;
+			vertex_buffer->mPosition[i].z += cz;
+		}
+
+		//	If is a shared vertex Buffer.
+		if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer)
+		{
+			break;
+		}
+	}
+}
+
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoTool.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoTool.cpp	(revision 774)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoTool.cpp	(revision 980)
@@ -1,2 +1,7 @@
+#include "GL/glew.h"
+#ifdef _WIN32
+#include "GL/wglew.h"
+#endif
+
 #include "GeoMeshViewUI.h"
 
