Index: GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/dwarf.material
===================================================================
--- GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/dwarf.material	(revision 1092)
+++ GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/dwarf.material	(revision 1783)
@@ -6,6 +6,5 @@
 		pass
 		{
-			ambient 0.2 0.2 0.2 1
-			diffuse 0.8 0.8 0.8 1
+			ambient 1.0 1.0 1.0 1
 
 			cull_hardware none
@@ -26,6 +25,5 @@
 		pass
 		{
-			ambient 0.2 0.2 0.2 1
-			diffuse 0.8 0.8 0.8 1
+			ambient 1.0 1.0 1.0 1
 
 			cull_hardware none
@@ -46,6 +44,5 @@
 		pass
 		{
-			ambient 0.2 0.2 0.2 1
-			diffuse 0.8 0.8 0.8 1
+			ambient 1.0 1.0 1.0 1
 
 			cull_hardware none
@@ -59,2 +56,21 @@
 	}
 }
+
+material Material3
+{
+	technique
+	{
+		pass
+		{
+			ambient 1.0 1.0 1.0 1
+
+			cull_hardware none
+			cull_software none
+
+			texture_unit
+			{
+				texture axe.jpg
+			}
+		}
+	}
+}
Index: GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/Example.material
===================================================================
--- GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/Example.material	(revision 1561)
+++ GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/Example.material	(revision 1783)
@@ -44,7 +44,5 @@
 		pass
 		{
-			ambient 0.8 0.8 0.8
-			cull_hardware true
-
+			ambient 1.0 1.0 1.0
 			texture_unit
 			{
@@ -165,4 +163,5 @@
 			lighting off
 			depth_write off
+			fog_override true
 
 			texture_unit
@@ -703,4 +702,58 @@
 	}
 }
+
+material Demos/TerrainMixed
+{
+   technique
+   {
+     pass
+     {
+       // lighting on
+       // Base Pass
+       ambient 0.6 0.6 0.6
+       diffuse 0.6 0.6 0.6
+       texture_unit
+       {
+         // Base Texture
+         texture grass_1024.jpg
+	   scale 0.5 0.5
+       }
+       texture_unit
+      {
+         texture grass.png
+         colour_op_ex modulate_x2 src_current src_texture
+         scale 0.01 0.01
+      }         
+     }    
+    
+     pass
+     {
+       // Rock pass
+       ambient 0.6 0.6 0.6
+       diffuse 0.6 0.6 0.6
+       scene_blend alpha_blend
+       depth_func equal
+       texture_unit
+       {
+         // Alpha Map for rock
+         texture terrain_splat3.tga
+         tex_address_mode mirror
+         alpha_op_ex source1 src_texture src_texture
+         colour_op_ex source1 src_current src_current
+	   scale 0.5 0.5
+       }
+
+       texture_unit
+       {
+         // Rock Splatting texture
+         texture destina.jpg
+         tex_address_mode mirror
+         alpha_op_ex source1 src_current src_current
+         colour_op_ex source2 src_current src_texture
+         scale 0.01 0.01
+       }
+     }
+  }
+} 
 
 vertex_program Examples/GrassWaverVp cg
@@ -787,5 +840,5 @@
 }
 
-material Examples/ML11/leaf
+material Examples/ML11/leaf_orig
 {
     technique
@@ -806,4 +859,78 @@
 }
 
+material Examples/ML11/leaf
+{
+    technique
+    {
+        pass
+        {
+		alpha_rejection greater 150 
+	      cull_hardware none
+            texture_unit
+            {
+		    filtering linear linear linear
+                texture ml11lef.dds
+            }
+        }
+    }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// Bump map vertex program, support for this is required
+
+vertex_program Lodtree/BumpMapVP cg
+{
+	source LodTree_BumpMapping.cg
+	entry_point main_vp
+	profiles vs_1_1 arbvp1
+}
+
+// Bump map fragment program, support for this is optional
+fragment_program Lodtree/BumpMapFP cg
+{
+	source LodTree_BumpMapping.cg
+	entry_point main_fp
+	profiles ps_2_0 arbfp1 fp20
+}
+
+
+// Single light material, less passes (one pass on a 4-unit card)
+//material Demos/ML06/Leaf
+//{
+//	// Preferred technique, uses vertex and fragment programs
+//	// to support a single coloured light
+//	technique
+//	{
+//		pass
+//		{
+//			// base colours, not needed for rendering, but as information
+//			// to lighting pass categorisation routine
+//			ambient 0.7 0.7 0.7 
+//			// Vertex program reference
+//			vertex_program_ref Lodtree/BumpMapVP
+//			{
+//				param_named_auto lightPosition light_position_object_space 0
+//				param_named_auto worldViewProj worldviewproj_matrix
+//			}
+//
+//			// Fragment program
+//			fragment_program_ref Lodtree/BumpMapFP
+//			{
+//				param_named_auto lightDiffuse light_diffuse_colour 0 
+//			}
+//			
+//			// Decal
+//			texture_unit
+//			{
+//				texture ml06lef.dds
+//			}
+//		}
+//	}
+//
+//}
+
+
 material Examples/ML11/trunk
 {
@@ -821,4 +948,105 @@
 }
 
+material Demos/ML06/Leaf
+{
+    technique
+    {
+        pass
+        {
+		ambient 1 1 1
+		alpha_rejection greater 150 
+	      cull_hardware none
+		cull_software none
+            texture_unit
+            {
+		    filtering linear linear linear
+                texture ml06lef.dds
+            }
+        }
+    }
+}
+
+
+material Demos/ML06/Trunk
+{
+	technique
+	{
+		pass
+		{
+			cull_hardware clockwise
+			texture_unit
+			{
+				texture ML15brk.tif
+			}
+		}
+	}
+}
+
+material Demos/ML15/Trunk
+{
+	technique
+	{
+		pass
+		{
+			cull_hardware clockwise
+			texture_unit
+			{
+				texture ML15brk.tif
+			}
+		}
+	}
+}
+
+material Demos/ML15/Leaf
+{
+    technique
+    {
+        pass
+        {
+		alpha_rejection greater 150 
+	      cull_hardware none
+		ambient 1 1 1
+            texture_unit
+            {
+		    filtering linear linear linear
+                texture ml15lef.dds
+            }
+        }
+    }
+}
+
+material Demos/ML13/Trunk
+{
+	technique
+	{
+		pass
+		{
+			cull_hardware clockwise
+			texture_unit
+			{
+				texture ML13brk.tif
+			}
+		}
+	}
+}
+
+material Demos/ML13/Leaf
+{
+    technique
+    {
+        pass
+        {
+		alpha_rejection greater 150 
+	      cull_hardware none
+		ambient 1 1 1
+            texture_unit
+            {
+		    filtering linear linear linear
+                texture ml13lef.dds
+            }
+        }
+    }
+}
+
 material Examples/Rockwall
 {
Index: GTP/trunk/App/Demos/Geom/OgreStuff/bin/release/terrain.cfg
===================================================================
--- GTP/trunk/App/Demos/Geom/OgreStuff/bin/release/terrain.cfg	(revision 1092)
+++ GTP/trunk/App/Demos/Geom/OgreStuff/bin/release/terrain.cfg	(revision 1783)
@@ -1,10 +1,10 @@
 # The main world texture (if you wish the terrain manager to create a material for you)
-WorldTexture=terrain_texture.jpg
+WorldTexture=grass_1024.jpg
 
 # The detail texture (if you wish the terrain manager to create a material for you)
-DetailTexture=terrain_detail.jpg
+DetailTexture=grass.png
 
 #number of times the detail texture will tile in a terrain tile
-DetailTile=3
+DetailTile=8
 
 # Heightmap source
@@ -12,5 +12,5 @@
 
 # Heightmap-source specific settings
-Heightmap.image=terrain.png
+Heightmap.image=noise2.jpg
 
 # If you use RAW, fill in the below too
@@ -23,8 +23,8 @@
 
 # How large is a page of tiles (in vertices)? Must be (2^n)+1
-PageSize=513
+PageSize=33
 
 # How large is each tile? Must be (2^n)+1 and be smaller than PageSize
-TileSize=65
+TileSize=17
 
 # The maximum error allowed when determining which LOD to use
@@ -35,5 +35,5 @@
 PageWorldZ=1500
 # Maximum height of the terrain 
-MaxHeight=100
+MaxHeight=120
 
 # Upper LOD limit
@@ -69,5 +69,5 @@
 
 # The name of the material you will define to shade the terrain
-CustomMaterialName=TestTerrainMaterial
+CustomMaterialName=Demos/TerrainMixed
 
 
Index: GTP/trunk/App/Demos/Geom/OgreStuff/bin/debug/terrain.cfg
===================================================================
--- GTP/trunk/App/Demos/Geom/OgreStuff/bin/debug/terrain.cfg	(revision 1092)
+++ GTP/trunk/App/Demos/Geom/OgreStuff/bin/debug/terrain.cfg	(revision 1783)
@@ -1,10 +1,10 @@
 # The main world texture (if you wish the terrain manager to create a material for you)
-WorldTexture=terrain_texture.jpg
+WorldTexture=grass_1024.jpg
 
 # The detail texture (if you wish the terrain manager to create a material for you)
-DetailTexture=terrain_detail.jpg
+DetailTexture=grass.png
 
 #number of times the detail texture will tile in a terrain tile
-DetailTile=3
+DetailTile=8
 
 # Heightmap source
@@ -12,5 +12,5 @@
 
 # Heightmap-source specific settings
-Heightmap.image=terrain.png
+Heightmap.image=noise2.jpg
 
 # If you use RAW, fill in the below too
@@ -23,8 +23,8 @@
 
 # How large is a page of tiles (in vertices)? Must be (2^n)+1
-PageSize=513
+PageSize=33
 
 # How large is each tile? Must be (2^n)+1 and be smaller than PageSize
-TileSize=65
+TileSize=17
 
 # The maximum error allowed when determining which LOD to use
@@ -35,5 +35,5 @@
 PageWorldZ=1500
 # Maximum height of the terrain 
-MaxHeight=100
+MaxHeight=120
 
 # Upper LOD limit
@@ -69,3 +69,5 @@
 
 # The name of the material you will define to shade the terrain
-CustomMaterialName=TestTerrainMaterial
+CustomMaterialName=Demos/TerrainMixed
+
+
Index: GTP/trunk/App/Demos/Geom/Demo_LodTrees/build/Release/terrain.cfg
===================================================================
--- GTP/trunk/App/Demos/Geom/Demo_LodTrees/build/Release/terrain.cfg	(revision 1540)
+++ GTP/trunk/App/Demos/Geom/Demo_LodTrees/build/Release/terrain.cfg	(revision 1783)
@@ -1,10 +1,10 @@
 # The main world texture (if you wish the terrain manager to create a material for you)
-WorldTexture=terrain_texture.jpg
+WorldTexture=grass_1024.jpg
 
 # The detail texture (if you wish the terrain manager to create a material for you)
-DetailTexture=terrain_detail.jpg
+DetailTexture=grass.png
 
 #number of times the detail texture will tile in a terrain tile
-DetailTile=3
+DetailTile=8
 
 # Heightmap source
@@ -12,5 +12,5 @@
 
 # Heightmap-source specific settings
-Heightmap.image=terrain.png
+Heightmap.image=noise2.jpg
 
 # If you use RAW, fill in the below too
@@ -23,8 +23,8 @@
 
 # How large is a page of tiles (in vertices)? Must be (2^n)+1
-PageSize=513
+PageSize=33
 
 # How large is each tile? Must be (2^n)+1 and be smaller than PageSize
-TileSize=65
+TileSize=17
 
 # The maximum error allowed when determining which LOD to use
@@ -35,5 +35,5 @@
 PageWorldZ=1500
 # Maximum height of the terrain 
-MaxHeight=100
+MaxHeight=120
 
 # Upper LOD limit
@@ -69,5 +69,5 @@
 
 # The name of the material you will define to shade the terrain
-CustomMaterialName=TestTerrainMaterial
+CustomMaterialName=Demos/TerrainMixed
 
 
Index: GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp	(revision 1561)
+++ GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp	(revision 1783)
@@ -18,19 +18,12 @@
 
 // Distance values
-#define dist_min 300
-#define dist_max 900
-
-// Model name
-#define model_name "arbol"
-
+#define dist_min 40
+#define dist_max 800
 
 //Global variables
-Entity* entity;
-Geometry::LodTreeLibrary* myTrees;
-Ogre::Mesh *ogreMesh=NULL;
 Geometry::GeoMeshLoader *meshloader=NULL;
 bool force_maxLODfactor = false;
-
-Ogre::Vector3 forest_center;
+const int num_tree_types=10;
+Vector3 *centers=NULL;
 
 ColourValue color=ColourValue::Red;
@@ -44,14 +37,15 @@
 
 char HelpString[]="(F1) Help\n"
-			"This demo shows an example of the LodTree model in action. The trees in the scene\n"
-			"are associated to a LodTree object that manage their level of detail of both the\n"
-			"trunk and the leaves. The level of detail of the objects depend on the distance to\n"
-			"the camera. When the camera goes away from them, the level of detail decreases, and\n"
-			"when the camera gets closer to them the level of detail increases to restore the\n"
-			"original geometry of the model.\n"
-			"The current level of detail can be seen in real-time in the top-left corner of the screen.\n"
-			"The level of detail begins to decrease at a certain distance of the forest, and stops\n"
+			"This demo shows an example of the LodTree model in action. The scene is composed of\n"
+			"several tree groups which are associated to a LodTree object that manage the level\n"
+			"of detail of both their trunk and leaves. The level of detail of the objects depends\n"
+			"on the distance to the camera. When the camera goes away from them, the level of detail\n"
+			"decreases, and when the camera gets closer to them increases to restore the original\n"
+			"geometry of the model.\n"
+			"The level of detail begins to decrease at a certain distance of each group, and stops\n"
 			"decreasing when the objects reach the their minimum LOD. This 'lodding' distance is\n"
-			"customizable from the source code of the demo.";
+			"customizable from the source code of the demo.\n"
+			"The user can compare the differences in performance disabling the LOD management while\n" 
+			"maintaining pressed F2.";
 
 char NoHelpString[]="(F1) Help\n";
@@ -62,11 +56,19 @@
 {
 	int manage;
+	Ogre::RaySceneQuery * raySceneQuery;
+	float *lodfactorBefore; // one lodfactor per LOD object type
+	Geometry::LodTreeLibrary **lod_tree_types;
 
 public:
 
-    LodTreeFrameListener(RenderWindow* win, Camera* cam)
+	LodTreeFrameListener(RenderWindow* win, Camera* cam,RaySceneQuery *rsq,Geometry::LodTreeLibrary **lod_trees)
         : ExampleFrameListener(win, cam, false, false)
     {
 		manage=1;
+		raySceneQuery=rsq;
+		lodfactorBefore=new float[num_tree_types];
+		for (int i=0; i<num_tree_types; i++)
+			lodfactorBefore[i]=-1;
+		lod_tree_types=lod_trees;
 	}
 
@@ -74,9 +76,9 @@
     {
 		Vector3 dist; 
-		int distance=0,inc2=0,d;
+		int inc2=0,d;
 		unsigned int nlod,diflods;
 
 		// Move upto 80 units/second
-		Real MoveFactor = 180.0 * evt.timeSinceLastFrame;
+		Real MoveFactor = 120.0 * evt.timeSinceLastFrame;
 
 		// Copy the current state of the input devices
@@ -103,28 +105,31 @@
 
 		//LOD selection
-		int difdist = dist_max - dist_min;
-	
-		int i=0;
-
-		dist = forest_center - mCamera->getPosition(); 
-		distance =dist.length();
-
-		float lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min);
-		lodfactor = 1.0f - lodfactor;
-
-		if (lodfactor<0.0f)
-			lodfactor=0.0f;
-		if (lodfactor>1.0f)
-			lodfactor=1.0f;
-
-		if (force_maxLODfactor)
-			lodfactor=1.0f;
-
-		static float lodfactorBefore = -1.0f;
-		if (fabsf(lodfactorBefore-lodfactor)>0.1f)
-		{
-			myTrees->GoToLod(lodfactor);
-//			DumpDataToOgreBuffers(ogreMesh,myTrees);
-			lodfactorBefore=lodfactor;
+		for (int i=0; i<num_tree_types; i++)
+		{	
+			dist = centers[i] - mCamera->getPosition(); 
+			int distance = dist.length();
+
+			float lodfactor = 0.0f;
+			if (distance < dist_min)
+				lodfactor = 1.0f;
+			else if (distance > dist_max)
+				lodfactor = 0.0f;
+			else
+			{
+                lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min);
+				lodfactor = 1.0f - lodfactor;
+			}
+
+			assert(lodfactor>=0.0f);
+			assert(lodfactor<=1.0f);
+
+			if (force_maxLODfactor)
+				lodfactor=1.0f;
+
+			if (fabsf(lodfactorBefore[i]-lodfactor)>0.1f)
+			{
+				lod_tree_types[i]->GoToLod(lodfactor);
+				lodfactorBefore[i]=lodfactor;
+			}
 		}
 
@@ -148,5 +153,4 @@
 			mTranslateVector.x = mMoveScale;
 
-		// Instead of moving the ship left and right, rotate it using yaw()
 		if(mInputDevice->isKeyDown(Ogre::KC_LEFT))
 		  mCamera->yaw(mRotScale);
@@ -173,8 +177,5 @@
 
 		if(mInputDevice->isKeyDown(Ogre::KC_ESCAPE))
-		{
-			//delete myTrees;
 		    return false;
-		}
 
         if( mInputDevice->getMouseButton( 1 ) )
@@ -189,19 +190,15 @@
         }
 
-
-		char cadena[256];
-
-				
-		sprintf(cadena,"Distance: %d",distance);
-		
-		mInfo->setCaption(cadena);
-
-		sprintf(cadena,"LOD factor: %f",lodfactor);
-
-		mInfo2->setCaption(cadena);
-
 		mCamera->yaw(mRotX);
         mCamera->pitch(mRotY);
         mCamera->moveRelative(mTranslateVector);
+
+		// make the camera walk onto the ground
+		Ogre::Ray ray(mCamera->getPosition()+Ogre::Vector3(0.0f,200.0f,0.0f), Ogre::Vector3::NEGATIVE_UNIT_Y);
+		raySceneQuery->setRay(ray);
+		RaySceneQueryResult &rayRes = raySceneQuery->execute();
+		RaySceneQueryResult::iterator itr = rayRes.begin();
+		if (itr != rayRes.end() && itr->worldFragment)
+			mCamera->setPosition(itr->worldFragment->singleIntersection+Ogre::Vector3(0.0f,15.0f,0.0f));
 
 		return true;
@@ -230,5 +227,5 @@
 	}
 	virtual void SetIndex(unsigned int i, unsigned int index){
-		pIdx[i] = index; //lodStripsLib->dataRetrievalInterface->GetIndex(k+offset);
+		pIdx[i] = index;
 	}
 	virtual void End(){
@@ -244,9 +241,20 @@
 protected:
 public:
-    LodTreeApplication(){}
+    LodTreeApplication(){ 
+		raySceneQuery=NULL; 
+		centers=new Vector3[num_tree_types]; // one center per object 
+	}
     ~LodTreeApplication(){}
+
+	Ogre::RaySceneQuery * raySceneQuery;
+	Geometry::LodTreeLibrary **lod_tree_types;
 
 protected:
     
+    void chooseSceneManager(void)
+    {
+        // Get the SceneManager, in this case a generic one
+		mSceneMgr = mRoot->getSceneManager(Ogre::ST_EXTERIOR_CLOSE);
+    }
 
 
@@ -254,32 +262,21 @@
     void createScene(void)
     {
-//		mat = new MaterialPtr[1];
-		
         theCam = mCamera;
-		theCam->setPosition(0,20,dist_min-40);
+		theCam->setPosition(500,100,dist_min+600);
         // Set ambient light
         mSceneMgr->setAmbientLight(ColourValue(0.4, 0.4, 0.4));
 		theCam->setNearClipDistance(0.1f);
 
+		mSceneMgr->setFog( FOG_EXP, Ogre::ColourValue(0.4f,0.5f,0.6f), 0.001 );
+
         // Create a directional light
 		Light* l = mSceneMgr->createLight("MainLight");
 		l->setType(Light::LT_DIRECTIONAL);
-        l->setDirection(0.0,-1.0,0.0);
+        l->setDirection(0.1,-1.0,-0.2);
         
-        // Define a floor plane mesh
-		Plane plane( Vector3::UNIT_Y, 0 );
-
-		MeshManager::getSingleton().createPlane("ground",
-			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
-			1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
-
-		Entity* suelo = mSceneMgr->createEntity( "GroundEntity", "ground" );
-		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(suelo);
-		
-
-		suelo->setMaterialName("Examples/GrassFloor");
-		suelo->setCastShadows(false);       
-
-        
+		// terrain
+		mSceneMgr->setWorldGeometry( "terrain.cfg" );
+
+       
         mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
 
@@ -287,58 +284,35 @@
         SceneNode* myRootNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
 
-		std::string model_file=model_name;
-		model_file.append(".mesh");
-
-		//Models
-        entity = mSceneMgr->createEntity(model_name, "../../../OgreStuff/media/GT/ML11.mesh");
-
-		ogreMesh = entity->getMesh().getPointer();
-
-		// load LOD info from the object
-		meshloader=new Geometry::GeoMeshLoader;
-		Geometry::Mesh *themesh = meshloader->load("../../../OgreStuff/media/GT/ML11.mesh");
-
-		if (!meshloader->GetLodStripsData())
-            OGRE_EXCEPT(1, "The loaded mesh does not contain LOD info for the trunk","LOD Demo");
-		if (!meshloader->GetTreeSimpSeq())
-            OGRE_EXCEPT(1, "The loaded mesh does not contain LOD info for the foliage","LOD Demo");
-
-		myTrees = new Geometry::LodTreeLibrary(	meshloader->GetLodStripsData(),
-												meshloader->GetTreeSimpSeq(),
-												themesh,
-												new CustomIndexData(ogreMesh));
-
-		entity->setNormaliseNormals(true);
-
-		for (int submesh=0; submesh < ogreMesh->getNumSubMeshes(); submesh++)
-		{
-			bool istrunk = myTrees->GetLeavesSubMesh()!=submesh;
-			if (istrunk)
-				entity->getSubEntity(submesh)->setMaterialName("Examples/ML11/trunk");
-			else
-				entity->getSubEntity(submesh)->setMaterialName("Examples/ML11/leaf");
-		}
-
-		forest_center=Ogre::Vector3(150.0f,0.0f,0.0f);
-		for (int i=1; i<5; i++) // 20
-			for (int j=1; j<5; j++) // 20
-			{
-				char newTreeName[16]="";
-				sprintf(newTreeName,"arbol_%d_%d",i,j);
-				Ogre::SceneNode * auxnode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
-				Ogre::Entity *auxent = entity->clone(newTreeName);
-				auxnode->attachObject( auxent );
-				auxnode->scale(4.0f,4.0f,4.0f);
-				auxnode->rotate(Ogre::Vector3(0,0,1),Ogre::Degree(rand()%360));
-				auxnode->rotate(Ogre::Vector3(1,0,0),Ogre::Radian(-3.14159f*0.5f),Ogre::Node::TS_WORLD);
-				float randomsepx = (float)((rand()%38)-19);
-				float randomsepy = (float)((rand()%32)-12);
-				auxnode->translate(i*80.0f+randomsepx,0.0f,-j*80.0f-randomsepx);
-				auxent->setNormaliseNormals(true);
-			}
-
-		if (!meshloader->GetLodStripsData() || !meshloader->GetTreeSimpSeq())
-            OGRE_EXCEPT(1, "The loaded mesh does not contain any LOD info","LOD Demo");
-
+		// initialize the rayscene queryer
+		raySceneQuery = mSceneMgr->createRayQuery(Ray());
+
+		// the blacksmith
+		Vector3 BS_center=Ogre::Vector3(780.0f,200.0f,650.0f);
+		Ogre::Ray ray(BS_center, Ogre::Vector3::NEGATIVE_UNIT_Y);
+		raySceneQuery->setRay(ray);
+		RaySceneQueryResult &rayRes = raySceneQuery->execute();
+		RaySceneQueryResult::iterator itr = rayRes.begin();
+		if (itr != rayRes.end() && itr->worldFragment)
+			BS_center=itr->worldFragment->singleIntersection-Ogre::Vector3(0.0f,1.0f,0.0f);
+
+		Ogre::Entity *entBS = mSceneMgr->createEntity("blacksmith","../../../OgreStuff/media/models/blacksmith.mesh");
+		Ogre::SceneNode * nodeBS = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+		nodeBS->attachObject(entBS);
+		nodeBS->translate(BS_center);
+		nodeBS->scale(0.1f,0.1f,0.1f);
+
+		lod_tree_types = new Geometry::LodTreeLibrary*[num_tree_types];
+
+		// trees
+		lod_tree_types[0] = CreateLODTrees("../../../OgreStuff/media/GT/ML06a_01.mesh",5,780,630,200,200,centers[0], 4.0f);
+		lod_tree_types[1] = CreateLODTrees("../../../OgreStuff/media/GT/ML13a_02.mesh",4,150,150,200,200,centers[1], 2.0f);
+		lod_tree_types[2] = CreateLODTrees("../../../OgreStuff/media/GT/ML15a_03.mesh",10,300,400,200,200,centers[2], 6.0f);
+		lod_tree_types[3] = CreateLODTrees("../../../OgreStuff/media/GT/ML06a_01.mesh",5,330,900,500,500,centers[3], 3.0f);
+		lod_tree_types[4] = CreateLODTrees("../../../OgreStuff/media/GT/ML13a_02.mesh",5,1100,900,300,300,centers[4], 2.0f);
+		lod_tree_types[5] = CreateLODTrees("../../../OgreStuff/media/GT/ML15a_03.mesh",10,1100,300,200,200,centers[5], 6.0f);
+		lod_tree_types[6] = CreateLODTrees("../../../OgreStuff/media/GT/ML06a_01.mesh",7,900,500,300,300,centers[6], 2.0f);
+		lod_tree_types[7] = CreateLODTrees("../../../OgreStuff/media/GT/ML13a_02.mesh",5,500,950,200,200,centers[7], 3.0f);
+		lod_tree_types[8] = CreateLODTrees("../../../OgreStuff/media/GT/ML15a_03.mesh",9,600,400,200,200,centers[8], 6.0f);
+		lod_tree_types[9] = CreateLODTrees("../../../OgreStuff/media/GT/ML06a_01.mesh",7,950,1100,200,200,centers[9], 2.5f);
 
         // show overlay
@@ -350,12 +324,94 @@
 	    pOver->show();
 
+		mInfo->setCaption("Maintain F2 to disable LOD");
+
     }
+
+    void destroyScene(void)
+	{
+		if (raySceneQuery)
+			delete raySceneQuery;
+		delete[] lod_tree_types;
+	}
 
     void createFrameListener(void)
     {
-        mFrameListener= new LodTreeFrameListener(mWindow, mCamera);
+        mFrameListener= new LodTreeFrameListener(mWindow, mCamera, raySceneQuery, lod_tree_types);
         mFrameListener->showDebugOverlay(true);
         mRoot->addFrameListener(mFrameListener);
     }
+
+	Geometry::LodTreeLibrary *CreateLODTrees(const char *filename, int numObjs, float cx, float cz, float w, float h, Vector3 &outcenter, float scale)
+	{
+		static int iname = 0;
+		char newMeshName[16]="";
+		sprintf(newMeshName,"tree_%d",iname);
+
+
+		// load LOD info from the object
+		meshloader=new Geometry::GeoMeshLoader;
+		Geometry::Mesh *themesh = meshloader->load((char*)filename);
+
+		if (!meshloader->GetLodStripsData())
+            OGRE_EXCEPT(1, "The loaded mesh does not contain LOD info for the trunk","LOD Demo");
+		if (!meshloader->GetTreeSimpSeq())
+            OGRE_EXCEPT(1, "The loaded mesh does not contain LOD info for the foliage","LOD Demo");
+
+		Ogre::Entity *entity = mSceneMgr->createEntity(newMeshName,filename);		
+		if (!entity->getMesh().unique())
+		{
+			static int iclone = 0;
+			char newCloneMesh[16]="";
+			sprintf(newCloneMesh,"clonetree_%d",iclone++);
+			entity->getMesh() = entity->getMesh()->clone(newCloneMesh);
+		}
+		Ogre::Mesh *ogreMesh = entity->getMesh().getPointer();
+		entity->setNormaliseNormals(true);
+
+		Geometry::LodTreeLibrary *mytree = new Geometry::LodTreeLibrary(
+												meshloader->GetLodStripsData(),
+												meshloader->GetTreeSimpSeq(),
+												themesh,
+												new CustomIndexData(ogreMesh) );
+
+		outcenter=Vector3::ZERO;
+
+		for (int i=0; i<numObjs; i++)
+		{
+			char newTreeName[16]="";
+			sprintf(newTreeName,"arbol_%d_%d",iname,i);
+			Ogre::SceneNode * auxnode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+			Ogre::Entity *auxent = entity->clone(newTreeName);
+			auxnode->attachObject( auxent );
+
+			float kx = (rand()%100)/100.0f;
+			float kz = (rand()%100)/100.0f;
+
+			Ogre::Vector3 treepos(kx*(cx-w*0.5f) + (1.0f-kx)*(cx+w*0.5f), 200.0f, 
+								  kz*(cz-h*0.5f) + (1.0f-kz)*(cz+h*0.5f));
+
+			Ogre::Ray ray(treepos,Ogre::Vector3::NEGATIVE_UNIT_Y);
+			raySceneQuery->setRay(ray);
+			RaySceneQueryResult &rayRes = raySceneQuery->execute();
+			RaySceneQueryResult::iterator itr = rayRes.begin();
+		 	if (itr != rayRes.end() && itr->worldFragment)
+				treepos = itr->worldFragment->singleIntersection;
+
+			auxnode->translate(treepos);
+			auxnode->scale(scale,scale,scale);
+			auxnode->rotate(Ogre::Vector3(0,1,0),Ogre::Degree(rand()%360));
+			auxent->setNormaliseNormals(true);
+			outcenter+=treepos;
+		}
+		outcenter/=numObjs;
+		iname++;
+
+		return mytree;
+	}
+
+	float Rand(float minN, float maxN)
+	{
+		return (((rand()%1000)/1000.0f)*(maxN-minN))+minN;
+	}
 
 };
Index: GTP/trunk/App/Demos/Geom/Demo_LodTrees/README.txt
===================================================================
--- GTP/trunk/App/Demos/Geom/Demo_LodTrees/README.txt	(revision 1540)
+++ GTP/trunk/App/Demos/Geom/Demo_LodTrees/README.txt	(revision 1783)
@@ -2,12 +2,15 @@
 --------
 
-This demo shows an example of the LodTree model in action. The trees in the scene
-are associated to a LodTree object that manage their level of detail of both the 
-trunk and the leaves. The level of detail of the objects depend on the distance to 
-the camera. When the camera goes away from them, the level of detail decreases, and 
-when the camera gets closer to them the level of detail increases to restore the 
-original geometry of the model.
+This demo shows an example of the LodTree model in action. The scene is composed of 
+several tree groups which are associated to a LodTree object that manage the level 
+of detail of both their trunk and leaves. The level of detail of the objects depends
+on the distance to the camera. When the camera goes away from them, the level of detail 
+decreases, and when the camera gets closer to them increases to restore the original 
+geometry of the model.
 
-The level of detail begins to decrease at a certain distance of the forest, and stops
+The level of detail begins to decrease at a certain distance of each group, and stops
 decreasing when the objects reach the their minimum LOD. This 'lodding' distance is
 customizable from the source code of the demo.
+
+The user can compare the differences in performance disabling the LOD management while 
+maintaining pressed F2.
