Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCSampleConfigFile.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCSampleConfigFile.h	(revision 731)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCSampleConfigFile.h	(revision 745)
@@ -52,5 +52,7 @@
 	Ogre::String getEntityClustersMeshPrefixName();
 
-	Ogre::String getEntityClustersMaterialPrefixName();
+	Ogre::String getEntityClustersMergedMaterialPrefixName();
+
+	Ogre::String getEntityClustersSplittedMaterialPrefixName();
 
 	bool getBillboardCloudMergedBillboards();
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCManager.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCManager.h	(revision 731)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCManager.h	(revision 745)
@@ -21,9 +21,9 @@
     ~LBBCManager();
 
-	void runSampleConfigFile();
-
 	void loadSampleConfigFile(Ogre::String sampleConfigFile);
 
 	SampleConfigFile* getSampleConfigFile();
+
+	void initialize();
 
 	void setSampleConfigFile(SampleConfigFile *sampleConfigFile);
@@ -57,5 +57,16 @@
 	void saveBillboardCloudXML();
 
+	void saveBillboardCloudMergedXML();
+
+	void saveBillboardCloudGroupedXML();
+
 	Leaves* getLeaves();
+
+	void loadBillboardCloudXML();
+
+	void loadBillboardCloudGroupedXML();
+
+	void loadBillboardCloudMergedXML();
+
 
   protected:
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCKMeansClusterSerializer.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCKMeansClusterSerializer.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCKMeansClusterSerializer.h	(revision 745)
@@ -15,6 +15,7 @@
     virtual ~KMeansClusterSerializer();
 
-	virtual void writeBillboardCloud(TiXmlDocument *document);
+	virtual void writeBillboardCloud(TiXmlDocument *document, bool groupedBillboards);
 
+	virtual void readBillboardCloud(TiXmlDocument *document, bool groupedBillboards);
 };
 
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCKdTreeClusterSerializer.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCKdTreeClusterSerializer.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCKdTreeClusterSerializer.h	(revision 745)
@@ -12,5 +12,7 @@
     virtual ~KdTreeClusterSerializer();
 
-    void writeBillboardCloud(TiXmlDocument *document);
+    virtual void writeBillboardCloud(TiXmlDocument *document, bool groupedBillboards);
+
+	virtual void readBillboardCloud(TiXmlDocument *document, bool groupedBillboards);
 
 };
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBC.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBC.h	(revision 731)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBC.h	(revision 745)
@@ -10,3 +10,4 @@
 #include <LBBCClusterViewMode.h>
 #include <LBBCEntityTextureAtlasViewMode.h>
+#include <LBBCBillboardCloudTextureViewMode.h>
 #endif
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCEntityTextureAtlasViewMode.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCEntityTextureAtlasViewMode.h	(revision 731)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCEntityTextureAtlasViewMode.h	(revision 745)
@@ -40,6 +40,4 @@
 		virtual ~EntityTextureAtlasViewMode();		
 
-		void setTextureAtlasFolder(Ogre::String textureAtlasFolder);
-
 		unsigned int nextPowerOf2(unsigned int nPlanes);
 
@@ -58,4 +56,6 @@
 		void setTextureAtlasName(Ogre::String textureAtlasName);
 
+		void setTextureAtlasFolder(Ogre::String textureAtlasFolder);
+
 		void setTextureAtlasSize(unsigned int size);
 };
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardKMeansClusterData.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardKMeansClusterData.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardKMeansClusterData.h	(revision 745)
@@ -14,7 +14,7 @@
     virtual ~BillboardKMeansClusterData();
 
-	virtual void readBillboardClusterData(TiXmlNode *parentNode);
+	virtual void readBillboardClusterData(TiXmlNode *parentNode, int iBillboardGroup);
 
-	virtual void writeBillboardClusterData(TiXmlNode *parentNode);
+	virtual void writeBillboardClusterData(TiXmlNode *parentNode, int iBillboardGroup);
 
 	virtual void generateBillboardBoundingQuad();
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudTextureViewMode.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudTextureViewMode.h	(revision 745)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudTextureViewMode.h	(revision 745)
@@ -0,0 +1,151 @@
+#ifndef _LBBCBILLBOARDCLOUDTEXTUREVIEWMODE_H
+#define _LBBCBILLBOARDCLOUDTEXTUREVIEWMODE_H
+
+#include <LBBCPrerequisites.h>
+#include <LBBCManager.h>
+#include <IMG.h>
+#include <OBAOgreFrameListenerMode.h>
+
+namespace LBBC {
+
+class _BBCExport ClusterTextureListener : public Ogre::RenderTargetListener
+{
+protected:
+	IMG::TextureAtlasPtr mTextureAtlas;
+
+	IMG::TexturePtr mTexture;
+
+	unsigned int mNumTextures;
+
+	unsigned int mCurrentTexture;
+
+	unsigned int mSubEntityVisible;
+
+	Ogre::Entity *mEntity;
+
+public:
+	
+	void setEntity(Ogre::Entity *entity)
+	{
+		mEntity = entity;
+	}
+
+	void setSubEntityVisible(unsigned int iSubEntity)
+	{
+		mSubEntityVisible = iSubEntity;
+	}
+
+	void setTexture(IMG::TexturePtr texture)
+	{
+		mTexture = texture;
+	}
+
+	void setTextureAtlas(IMG::TextureAtlasPtr textureAtlas)
+	{
+		mTextureAtlas = textureAtlas;
+	}
+
+	void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
+    {
+		if (mCurrentTexture < mNumTextures)
+		{
+			//calculateProjectionMatrix(unsigned int iSubEntity, Ogre::Camera *cam);
+			//initializeShaderParameters(unsigned int iSubEntity);
+			mTexture->getRectangle2D()->setVisible(false);
+			mTextureAtlas->getRectangle2D()->setVisible(false);
+		}
+    }
+
+	void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
+    {   
+
+    }
+
+	void setNumTextures(unsigned int numTextures)
+	{
+		mNumTextures = numTextures;
+		mCurrentTexture = 0;
+	}
+
+
+};
+
+class _BBCExport TextureAtlasListener : public Ogre::RenderTargetListener
+{
+public:
+	void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
+    {
+		//configureTexture( unsigned int iSubEntity );
+    }
+
+	void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
+    {
+		
+    }
+};
+
+class _BBCExport BillboardCloudTextureViewMode : public OBA::OgreFrameListenerMode 
+{
+	protected:
+		unsigned int mFrame;
+
+		Ogre::SceneNode *mClusterizedEntitiesMergedSceneNode;
+		
+		Ogre::Entity *mClusterizedEntities;
+
+		ClusterTextureListener mClusterTextureListener;
+
+		TextureAtlasListener mTextureAtlasListener;
+
+		IMG::TexturePtr mClusterTexture;
+
+		IMG::TextureAtlasPtr mTextureAtlas;
+
+		unsigned int mNumTextures;
+
+		unsigned int mCurrentTexture;
+
+		unsigned int mTextureAtlasSize;
+
+		unsigned int mTextureSize;
+
+		Ogre::PixelFormat mTexturePixelFormat;
+
+		Ogre::String mEntityName;
+
+		unsigned int mBitRange;
+
+		Ogre::PixelFormat mSrcPixelFormat;
+
+		Ogre::PixelFormat mDestPixelFormat;
+
+		Ogre::String mTextureAtlasName;
+
+		Ogre::String mTextureAtlasFolder;
+
+	public:
+		BillboardCloudTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);
+
+		virtual ~BillboardCloudTextureViewMode();		
+
+		virtual bool frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader);
+
+		virtual void createScene();
+
+		virtual void destroyScene();
+		
+		void setTextureAtlasSize(unsigned int size);
+
+		void setTextureSize(unsigned int size);
+
+		void setEntityName(Ogre::String entityName);
+
+		void setTextureAtlasName(Ogre::String textureAtlasName);
+
+		void setTextureAtlasFolder(Ogre::String textureAtlasFolder);
+
+		void setTextureAtlasBitRange(unsigned int bitRange);
+};
+
+}
+#endif
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardClusterData.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardClusterData.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardClusterData.h	(revision 745)
@@ -39,9 +39,11 @@
 	void setEntityCluster(EntityClusterPtr value);
 
-	virtual void readBillboardClusterData(TiXmlNode *parentNode);
+	virtual void readBillboardClusterData(TiXmlNode *parentNode, int iBillboardGroup);
 
-	virtual void writeBillboardClusterData(TiXmlNode *parentNode);
+	virtual void writeBillboardClusterData(TiXmlNode *parentNode, int iBillboardGroup);
 
 	virtual void generateBillboardBoundingQuad();
+
+	unsigned int getNumUVMapGroups();
 
 	Ogre::Vector3 getQuadTopLeftCorner();
@@ -53,4 +55,12 @@
 	Ogre::Vector3 getQuadBottomRightCorner();
 
+	void setQuadTopLeftCorner(Ogre::Vector3 topLeft);
+
+	void setQuadTopRightCorner(Ogre::Vector3 topRight);
+
+	void setQuadBottomLeftCorner(Ogre::Vector3 bottomLeft);
+
+	void setQuadBottomRightCorner(Ogre::Vector3 bottomRight);
+
 	Ogre::Vector3 getAxisX();
 
@@ -59,4 +69,21 @@
 	Ogre::Vector3 getAxisZ();
 
+	void setAxisX(Ogre::Vector3 axisX);
+
+	void setAxisY(Ogre::Vector3 axisY);
+
+	void setAxisZ(Ogre::Vector3 axisZ);
+
+	Ogre::Vector2 getBillboardUVMapMin(unsigned int iBillboardGroup);
+
+	void addBillboardUVMapMin(Ogre::Vector2 min);
+
+	void removeBillboardUVMapMin(unsigned int iBillboardGroup);
+
+	Ogre::Vector2 getBillboardUVMapMax(unsigned int iBillboardGroup);
+
+	void addBillboardUVMapMax(Ogre::Vector2 max);
+
+	void removeBillboardUVMapMax(unsigned int iBillboardGroup);
 
 
@@ -80,4 +107,8 @@
 
 	Ogre::Vector3 mNormal;
+
+	std::vector<Ogre::Vector2> mGroupedBillboardUVMapMinList;
+
+	std::vector<Ogre::Vector2> mGroupedBillboardUVMapMaxList;
 
 	float mD;
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboard.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboard.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboard.h	(revision 745)
@@ -31,5 +31,4 @@
   protected:
     unsigned int mBillboardHandle;
-
 
   public:
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardCloudUVMapper.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardCloudUVMapper.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardCloudUVMapper.h	(revision 745)
@@ -46,5 +46,5 @@
     void generateTextureAtlasTextureCoords(bool mergeBillboards, bool groupedBillboards = false, unsigned int numberGroups = 1);
 
-	void addTextureAtlasTextureCoords(bool mergeBillboards, bool groupedBillboards, unsigned int numGeneratedBillboardClouds, unsigned int iBillboardGroup);
+	void addTextureAtlasTextureCoords(bool mergeBillboards, bool groupedBillboards, unsigned int numGeneratedBillboardClouds, unsigned int iBillboardGroup, unsigned int iBillboard);
 
     void setBillboardCloud(BillboardCloud *billboardCloud);
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardGroup.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardGroup.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardGroup.h	(revision 745)
@@ -5,13 +5,4 @@
 
 namespace BBC {
-
-typedef struct
-{
-	unsigned int billboardHandle;
-	unsigned int width;
-	unsigned int height;
-	Ogre::Vector2 min;
-	Ogre::Vector2 max; 
-} BillboardGroupedInfo;
 
 // Forward declarations
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardCloudSerializer.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardCloudSerializer.h	(revision 721)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCBillboardCloudSerializer.h	(revision 745)
@@ -30,5 +30,7 @@
 	BillboardCloud * getBillboardCloud();
 
-	virtual void writeBillboardCloud(TiXmlDocument *document);
+	virtual void writeBillboardCloud(TiXmlDocument *document, bool groupedBillboards);
+
+	virtual void readBillboardCloud(TiXmlDocument *document, bool groupedBillboards);
 
 };
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBC.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBC.h	(revision 700)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBC.h	(revision 745)
@@ -11,4 +11,6 @@
 #include <BBCBillboard.h>
 #include <BBCBillboardCloud.h>
+#include <BBCBillboardGroup.h>
+#include <BBCBillboardClusterData.h>
 #include <BBCBillboardCloudGenerator.h>
 #include <BBCEntityDistributionGenerator.h>
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGTexture.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGTexture.h	(revision 731)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGTexture.h	(revision 745)
@@ -44,8 +44,16 @@
 	 bool mCalculatedAvgColour;
 
+	 Ogre::Camera *mCamera;
+
+	 Ogre::PixelFormat mPixelFormat;
+
   public:
      Texture();
 
      virtual ~Texture();
+
+	 void setRenderTargetListener(Ogre::RenderTargetListener *renderTargetListener);
+
+	 virtual void create(Ogre::String fileName, unsigned int width, unsigned int height, Ogre::PixelFormat pixelFormat, Ogre::Camera *camera);
 
 	 Ogre::ColourValue getAvgColour();
@@ -61,5 +69,5 @@
 	 virtual void save(Ogre::String folderName, Ogre::String filename);
 
-	 void rotate(Ogre::Real rRotation);
+	 virtual void update();
 
 	 void setCorners(Ogre::Real left, Ogre::Real top, Ogre::Real right, Ogre::Real bottom);
@@ -89,4 +97,8 @@
 	 void bind(Ogre::String textureName);
 
+	 void setCamera(Ogre::Camera *camera);
+
+	 void setFormat(Ogre::PixelFormat pixelFormat);
+
 };
 
Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGTextureAtlas.h
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGTextureAtlas.h	(revision 731)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/IMG/IMGTextureAtlas.h	(revision 745)
@@ -25,9 +25,13 @@
 
   protected:
+	 enum CurrentTextureAtlas 
+	 {
+	     TEXTURE_ATLAS_PING,
+         TEXTURE_ATLAS_PONG
+     };
+
      Ogre::String mTextureAtlasName;
 
-	 Ogre::TexturePtr mTextureAtlas;
-
-	 Ogre::Camera *mCamera;
+	 Ogre::Texture *mTextureAtlasPong;
 	
 	 Ogre::SceneNode *mTextureAtlasSceneNode;
@@ -35,5 +39,7 @@
      std::vector<TexturePtr> mTextureList;
 
-	 Ogre::PixelFormat mPixelFormat;
+	 unsigned int mCurrentTextureAtlas;
+
+	 bool mFirstUpdate;
 
   public:
@@ -43,13 +49,11 @@
     virtual ~TextureAtlas();
 
-	unsigned int getReference();
-
-	void setFormat(Ogre::PixelFormat pixelFormat);
+	void debug();
 
 	void create(Ogre::String fileName, unsigned int width, unsigned int height, Ogre::PixelFormat pixelFormat, Ogre::Camera *camera);
 
-	void setCamera(Ogre::Camera *camera);
+	void update();
 
-	void update();
+	unsigned int getReference();
 
 	void setTextureAtlasSceneNode(Ogre::SceneNode *textureAtlasSceneNode);
