Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp	(revision 1071)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp	(revision 1078)
@@ -642,4 +642,8 @@
 //	Read a mesh file.
 //---------------------------------------------------------------------------
+
+#include "GeoLodStripsLibrary.h"
+#include "GeoLodStripsConstructor.h"
+
 void GeoMeshLoader::readMesh(FILE	*f, Mesh	*geoMesh, int option)
 {
@@ -670,8 +674,77 @@
 				 chunkID == M_MESH_BOUNDS ||
 				 chunkID == M_SUBMESH_NAME_TABLE ||
-				 chunkID == M_EDGE_LISTS))
+				 chunkID == M_EDGE_LISTS ||
+				 chunkID == 0xabcd || 
+				 chunkID == 0xdcba))
 		{
 			switch(chunkID)
 			{
+				case 0xabcd:
+					cout << "LODSTRIPS_Chunk" << endl;
+					int				aux,v,c;
+					LODRegisterType	lod_register;
+					LODData			dataaux;
+					int				tam;
+
+					fread(&tam, sizeof(int), 1, f);
+					lodstripsdata.mFileVertices.clear();
+					for (v=0; v<tam; v++)
+					{
+						fread(&aux, sizeof(int), 1, f);
+						lodstripsdata.mFileVertices.push_back(aux);
+					}
+
+					lodstripsdata.mFileChangesLOD.clear();
+					fread(&tam, sizeof(int), 1, f);
+					for (c=0; c<tam; c++)
+					{
+						fread(&dataaux, sizeof(LODData), 1, f);
+						lod_register.strip= dataaux.strip;
+						lod_register.position= dataaux.nP;
+						lod_register.vertexRepetition= dataaux.nL1;
+						lod_register.edgeRepetition= dataaux.nL2;
+						//lod_register.obligatory=false;
+						//lod_register.obligatory= dataaux.obligatory;
+
+						lodstripsdata.mFileChangesLOD.push_back(lod_register);
+					}
+					
+					lodstripsdata.mData.clear();
+					fread(&tam, sizeof(int), 1, f);
+					for (int b=0; b<tam; b++)
+					{
+						fread(&aux, sizeof(int), 1, f);
+						lodstripsdata.mData.push_back(aux);
+					}
+
+					lodstripsdata.p_changes.clear();
+					fread(&tam, sizeof(int), 1, f);
+					for (int p=0; p<tam; p++)
+					{
+						fread(&aux, sizeof(int), 1, f);
+						lodstripsdata.p_changes.push_back(aux);
+					}					
+
+					break;
+
+				case 0xdcba:
+					cout << "LODTREES_Chunk" << endl;
+					int size;
+					fread(&size, sizeof(int), 1, f);
+					treesimpseq.mSteps.clear();
+					for (int i=0; i<size; i++)
+					{
+						Geometry::TreeSimplificationSequence::Step auxstep;
+						fread(&auxstep.mV0,sizeof(int),1,f);
+						fread(&auxstep.mV1,sizeof(int),1,f);
+						fread(&auxstep.mT0,sizeof(int),1,f);
+						fread(&auxstep.mT1,sizeof(int),1,f);
+						fread(auxstep.mNewQuad,sizeof(int),4,f);
+						treesimpseq.mSteps.push_back(auxstep);
+					}
+
+					break;
+
+
 				case M_GEOMETRY:
 
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 1070)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 1078)
@@ -811,5 +811,5 @@
 	if (mGeoMesh != NULL)
 	{
-		fcho	=	new fltk::FileChooser("",
+/*		fcho	=	new fltk::FileChooser("",
 				"*.lod",
 				fltk::FileChooser::CREATE,
@@ -820,14 +820,14 @@
 		//	If a file was selected.
 		if (fcho->value())
-		{
+		{*/
 			//	Build lod strips library.
-			setLodStripsLibrary(string(fcho->value()), mGeoMesh);
+			setLodStripsLibrary(geoMeshLoader->lodstripsdata, mGeoMesh);
 
 			//	Sets the aplication mode.
 			mApplicationState	=	VISUALIZE_LODSTRIPS;
-		}
+	/*	}
 
 		//	Free memory.
-		delete	fcho;
+		delete	fcho;*/
 
 		//	Hide the right panel.
@@ -883,8 +883,8 @@
 
 		//	If an object is loaded.
-		if (mGeoMesh != NULL)
+/*		if (mGeoMesh != NULL)
 		{
 			fcho	=	new fltk::FileChooser("",
-					"*.lod",
+					"*.mesh",
 					fltk::FileChooser::CREATE,
 					"Open Lod file");
@@ -908,16 +908,17 @@
 				if (fcho->value())
 				{
-					std::string leafseqFile(fcho->value());
-
-					setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID);
+					std::string leafseqFile(fcho->value());*/
+
+					//setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID);
+					setLodTreesLibrary(geoMeshLoader->lodstripsdata, geoMeshLoader->treesimpseq, mGeoMesh, leafsSubMeshID);
 
 					//	Sets the aplication mode.
 					mApplicationState	=	VISUALIZE_LODTREES;
-				}
+/*				}
 			}
 
 			//	Free memory.
 			delete	fcho;
-
+*/
 			//	Hide the right panel.
 			hideRightPanel();
@@ -932,5 +933,5 @@
 			//	Repaint the window.
 			mMainWindow->redraw();
-		}
+/*		}*/
 	}
 }
@@ -1243,119 +1244,93 @@
 	{
 		//	Choose between aplication state.
-		switch(mApplicationState)
+		if (mApplicationState==LODSTRIPS_AUTO || mApplicationState==LODTREES_AUTO)
 		{
-			//	Build the LOD file.
-			case	LODTREES_AUTO:
-
-				//	Open file chooser dialog.
-				file_name	=	fltk::file_chooser("Build LOD","*","");
-				
-				if (!file_name)
-				{
-					break;
-				}
-
-				std::cout << "Creando secuencia de simplificacion de hojas...";
-				
-				createLeavesSequence(file_name+std::string(".leafseq"));
-				
-				std::cout << "OK!" << std::endl;
-
-				/*				TreeSimplificationSequence * auxTreeSimpSequence = new TreeSimplificationSequence();
-									auxTreeSimpSequence->Load(Serializer("leavesSimplification.txt",Serializer::READ));
-
-									if (auxTreeSimpSequence && mGeoMesh)
-									{
-									LodTreeConstructor * auxLodTreeConstructor = new LodTreeConstructor(mGeoMesh,auxTreeSimpSequence);
-									delete auxLodTreeConstructor;
-									}
-									else
-									{
-									fltk::alert("There is no leaf simplification sequence.");
-									break;
-									}
-
-
-									delete auxTreeSimpSequence;*/
-
-			case	LODSTRIPS_AUTO:
-
-				//	Builder
-				if (!file_name)
-				{
-					file_name	=	fltk::file_chooser("Build LOD","*","");
-				}
-				
-				//	If a file was selected.
-				if (file_name)
-				{
-					//	Undo the simplification changes.
-					undo();
-
-					//	Stripify the mesh object.
-					stripify();
-
-					//	Reset the build bar.
-					mBuildBar->position(0);
-
-					//	Simplification sequence.
-					oMeshSimpSequence = new MeshSimplificationSequence();
-
-					//	Loads a simplification sequence file.
-					oMeshSimpSequence->Load(Serializer(	"SimplifSequence.txt",
-																							Serializer::READ));
-
-					//	If the simplification sequence and the mesh exist.
-					if (oMeshSimpSequence && mGeoMesh)
+			file_name	=	fltk::file_chooser("Build LOD","*.mesh","");
+			
+			//	If a file was selected.
+			if (file_name)
+			{
+				//	Undo the simplification changes.
+				undo();
+
+				//	Stripify the mesh object.
+				stripify();
+
+				//	Reset the build bar.
+				mBuildBar->position(0);
+
+				//	Simplification sequence.
+				oMeshSimpSequence = new MeshSimplificationSequence();
+
+				//	Loads a simplification sequence file.
+				oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ));
+
+				//	If the simplification sequence and the mesh exist.
+				if (oMeshSimpSequence && mGeoMesh)
+				{
+					oLodStrip		=	new LodStripsConstructor(	mGeoMesh,
+							oMeshSimpSequence,
+							idMeshLeaves,
+							progress_function);
+
+//						oSerializer	= new Serializer(file_name,Serializer::Mode::WRITE);
+
+                    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();
+//					file_name[strlen(file_name) - 4]	=	'\0';
+					
+					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);
+					//	Close file.
+//						delete	oSerializer;				
+				}
+				else
+				{
+					//	Error message.
+					fltk::alert("There is no simplification sequence.");
+				}
+
+				//	Deletes the siplification sequence object.
+				delete	oMeshSimpSequence;
+
+				if (mApplicationState==LODTREES_AUTO)
+				{
+					//	Open file chooser dialog.
+/*					file_name	=	fltk::file_chooser("Build LOD","*","");
+					
+					if (!file_name)
 					{
-						oLodStrip		=	new LodStripsConstructor(	mGeoMesh,
-								oMeshSimpSequence,
-								idMeshLeaves,
-								progress_function);
-
-						oSerializer	=	new Serializer(	strcat(file_name,".lod"),
-																					Serializer::Mode::WRITE);
-
-						oLodStrip->Save(*oSerializer);
-
-						//	Close file.
-						delete	oSerializer;
-
-						//	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();
-						file_name[strlen(file_name) - 4]	=	'\0';
-						
-						mesh_saver->leavesSubMesh=idMeshLeaves;
-						mesh_saver->leavesVB=origSubMeshVB;
-						mesh_saver->numindices=orig_numindices;
-						mesh_saver->indices=orig_indices;
-						mesh_saver->save(mGeoMesh,strcat(file_name,".mesh"));
-						
-						delete	mesh_saver;
-					}
-					else
-					{
-						//	Error message.
-						fltk::alert("There is no simplification sequence.");
-					}
-
-					//	Deletes the siplification sequence object.
-					delete	oMeshSimpSequence;
-				}
-				break;
+						break;
+					}*/
+
+					std::cout << "Creando secuencia de simplificacion de hojas...";
+					
+					createLeavesSequence(file_name);
+					
+					std::cout << "OK!" << std::endl;		
+				}
+			}
 		}
+
 		//	Refresh data aplication.
 		refreshApplicationBar();
@@ -2236,6 +2211,6 @@
 	tree_sequencer	=	mTreeSimplifier->GetSimplificationSequence();
 	
-	tree_sequencer->putMeshName(nombremesh); 
-	tree_sequencer->Save(Serializer(filename,Serializer::WRITE));
+	tree_sequencer->putMeshName(nombremesh); 	
+	tree_sequencer->Save(Serializer(filename,Serializer::APPEND));
 
 	delete	tree_sequencer;
@@ -2392,5 +2367,5 @@
 //	Initialize the lodstripslibrary for visualization.
 //---------------------------------------------------------------------------
-void	GeoMeshViewUI::setLodStripsLibrary(std::string lodfile, Mesh	*geomesh)
+void	GeoMeshViewUI::setLodStripsLibrary(const Geometry::LodStripsLibraryData &loddata, Mesh	*geomesh)
 {
 	//	If there is no lod strips object.
@@ -2401,5 +2376,5 @@
 
 	//	New lod strips object.
-	lodStripsLib	=	new	LodStripsLibrary(lodfile, geomesh);
+	lodStripsLib	=	new	LodStripsLibrary(loddata, geomesh);
 
 	//	Sets the slider range.
@@ -2417,7 +2392,5 @@
 //	Initialize the lodTreelibrary for visualization.
 //---------------------------------------------------------------------------
-//void	GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh	*geomesh)
-void	GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh *geomesh, uint32 ileafSubMesh)
-
+void	GeoMeshViewUI::setLodTreesLibrary(const LodStripsLibraryData &lodstripsdata, const TreeSimplificationSequence &treesimpseq, Mesh *geomesh, uint32 ileafSubMesh)
 {
 	//	If there is no lod strips object.
@@ -2428,13 +2401,8 @@
 
 	//	New lod strips object.
-/*	lodTreeLib	=	new	Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj",
-										"\\\\quake\\home\\\Modelos\\betula_populifolia\\hojas.obj",
-										"\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj");*/
-
-	lodTreeLib = new Geometry::LodTreeLibrary(lodfile,leafseqfile,geomesh,ileafSubMesh);
+
+	lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh,ileafSubMesh);
 
 	//	Sets the slider range.
-//	mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod());
-//	mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod());
 	mLodStripSlider->range(0.0f,1.0f);
 	mLodTreeSlider->range(0.0f,1.0f);
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 1070)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 1078)
@@ -892,4 +892,6 @@
 	current_strip = 0;
 
+	int begin_index = 0;
+
 	//	For each submesh.
 	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
@@ -966,6 +968,10 @@
 		}*/
 
+		int indices_to_render = lodStripsLib->indices_x_submesh[submesh];
+
+
 		glBegin(GL_TRIANGLE_STRIP);
-		for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(); index ++)
+		//for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(); index ++)
+		for (int index = begin_index; index < indices_to_render+begin_index; index ++)
 		{
 			position = lodStripsLib->dataRetrievalInterface->GetIndex(index);
@@ -1001,4 +1007,5 @@
 		}
 		glEnd();
+		begin_index += indices_to_render;
 
 	}
@@ -1026,4 +1033,6 @@
 	// DRAW THE TRUNK AS A LODSTRIP OBJECT
 
+	int begin_index = 0;
+
 	//	For each submesh.
 	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
@@ -1102,6 +1111,9 @@
 
 		}*/
+	
+		int indices_to_render = lodTreeLib->trunk->indices_x_submesh[submesh];
+        		
 		glBegin(GL_TRIANGLE_STRIP);
-		for (int index = 0; index < lodTreeLib->CurrentLOD_Trunk_Indices()->GetNumValidIndices(); index ++)
+		for (int index = begin_index; index < lodTreeLib->trunk->indices_x_submesh[submesh]; index ++)
 		{
 			position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(index);
@@ -1137,4 +1149,5 @@
 		}
 		glEnd();
+		begin_index += indices_to_render;
 
 	}
