Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1173)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1175)
@@ -13,6 +13,6 @@
 #include <OgreKdTreeHierarchyInterface.h>
 #include <OgreSceneManager.h>
+#include <VisibilityManager.h>
 #include "OgreKdTree.h"
-#include "VisibilityManager.h"
 
 #define KDTREE_MAX_DEPTH 20
@@ -22,5 +22,5 @@
 	class KdTreeSceneNode;
 	class WireBoundingBox;
-	typedef std::list < WireBoundingBox * > WBBList;
+	//typedef std::list < WireBoundingBox * > WBBList;
 
 	class KdTreeSceneManager : public SceneManager
@@ -31,8 +31,18 @@
 
 		virtual const String& getTypeName(void) const;
+
 		virtual SceneNode* createSceneNode(void);
 		virtual SceneNode* createSceneNode(const String& name);
+		/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
+		*/
+		Entity* createEntity(const String& entityName, const String& meshName);
 
+		/** Update the KdTree with the node (more or less disabled now)
+		*/
+		virtual void _updateNode(KdTreeSceneNode *node); // TODO: 
+
+		//virtual void _updateSceneGraph(Camera* cam);
 		virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
+		//virtual void _renderVisibleObjects();
 
 		virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
@@ -42,8 +52,44 @@
 		virtual bool getShowBoxes(void) const;
 
-		virtual void _updateNode(KdTreeSceneNode *node); // TODO: 
-
 		virtual bool setOption(const String& strKey, const void* pValue);
 		virtual bool getOption(const String& strKey, void* pDestValue);
+
+		bool getOptionValues(const String & key, StringVector &refValueList);
+		bool getOptionKeys(StringVector &refKeys);
+
+		/** Sets the visibility manager.
+		@param visManager the visibility manager
+		*/
+		void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
+		/** See set.
+		*/
+		GtpVisibility::VisibilityManager *getVisibilityManager();
+
+		/** Returns pointer to visibility manager.
+		*/
+		GtpVisibility::VisibilityManager *GetVisibilityManager();
+
+		/** Returns hierarchy interface.
+		*/
+		KdTreeHierarchyInterface *GetHierarchyInterface();
+
+
+		///** Render a queue group. 
+		//Override so we can handle delayed rendering of transparent objects
+		//*/
+		//void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 
+		//	QueuedRenderableCollection::OrganisationMode om);
+
+		///** Writes out stats into the Ogre log file.
+		//*/
+		//void WriteLog();
+
+		///** Override pass so we can do the z-fail pass. 
+		//*/
+		//const Pass* _setPass(Pass* pass);
+
+		///** Override from SceneManager so we can skip all but first pass for depth pass. 
+		//*/
+		//bool validatePassForRendering(Pass* pass);
 
 		virtual void clearScene()
@@ -64,4 +110,10 @@
 		KdTreeHierarchyInterface *mHierarchyInterface;
 
+		/// consecutive number for sub-entities
+		int mCurrentEntityId;
+
+		/// flag for passes which should not be deleted from queue during first traversal
+		int mLeavePassesInQueue;
+		
 		int mMaxDepth;
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1173)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1175)
@@ -9,7 +9,9 @@
 
 #include <OgreCamera.h>
+#include <OgreSubEntity.h>
 #include "OgreKdTreeSceneManager.h"
 #include "OgreKdTreeSceneNode.h"
 #include "OgreKdTree.h"
+#include "OgreVisibilityOptionsManager.h"
 
 #include <OgreLogManager.h>
@@ -19,5 +21,17 @@
 {
 	KdTreeSceneManager::KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm):
-		SceneManager(name), mKdTree(0), mVisibilityManager(vm)
+		SceneManager(name), 
+		mVisibilityManager(vm), 
+		mKdTree(0), 
+		mMaxDepth(KDTREE_MAX_DEPTH),
+		mShowBoxes(false),
+#ifdef KDTREE_DEBUG
+		mHighlighLevel(0),
+		mShowAllBoxes(false),
+#endif
+		mBuildMethod(KdTree::KDBM_PRIORITYQUEUE),
+		mRenderMethod(KdTree::KDRM_RECURSE),
+		mLeavePassesInQueue(0),
+		mCurrentEntityId(1)
 	{
 		// Replace root node with my node
@@ -26,19 +40,4 @@
 		mSceneRoot = new KdTreeSceneNode(this, "root node");
 		mSceneRoot->_notifyRootNode();
-
-		mMaxDepth = KDTREE_MAX_DEPTH;
-		mShowBoxes = false;
-
-		// kill the old kd-tree if exists 
-		OGRE_DELETE(mKdTree);
-
-		mRenderMethod = KdTree::KDRM_RECURSE;
-
-		//mBuildMethod = KdTree::KDBM_RECURSIVE;
-		mBuildMethod = KdTree::KDBM_PRIORITYQUEUE;
-#ifdef KDTREE_DEBUG
-		mHighlighLevel = 0;
-		mShowAllBoxes = false;
-#endif
 
 		mHierarchyInterface = new KdTreeHierarchyInterface(this, mDestRenderSystem);
@@ -197,5 +196,6 @@
 		}
 
-		return SceneManager::setOption(strKey, pValue);
+		return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
+			.setOption(strKey, pValue) || SceneManager::setOption(strKey, pValue);
 	}
 
@@ -269,5 +269,49 @@
 		}
 
-		return SceneManager::getOption(strKey, pDestValue);
+		return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
+			.getOption(strKey, pDestValue) || SceneManager::getOption(strKey, pDestValue);
+	}
+
+	bool KdTreeSceneManager::getOptionKeys(StringVector &refKeys)
+	{
+		refKeys.push_back("BuildMethod");
+		refKeys.push_back("KI");
+		refKeys.push_back("KT");
+		refKeys.push_back("KdTreeMaxDepth");
+		refKeys.push_back("RebuildKdTree");
+		refKeys.push_back("RenderMethod");
+		refKeys.push_back("ShowKdTree");
+		refKeys.push_back("TreeBox");
+#ifdef KDTREE_DEBUG
+		refKeys.push_back("HighlightLevel");
+		refKeys.push_back("ShowAllBoxes");
+#endif
+		return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
+			.getOptionKeys(refKeys);
+	}
+
+	bool KdTreeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
+	{
+		return SceneManager::getOptionValues(key, refValueList);
+	}
+
+	void KdTreeSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
+	{
+		mVisibilityManager = visManager;
+	}
+
+	GtpVisibility::VisibilityManager * KdTreeSceneManager::getVisibilityManager()
+	{
+		return mVisibilityManager;
+	}
+
+	GtpVisibility::VisibilityManager * KdTreeSceneManager::GetVisibilityManager()
+	{
+		return mVisibilityManager;
+	}
+
+	KdTreeHierarchyInterface * KdTreeSceneManager::GetHierarchyInterface()
+	{
+		return mHierarchyInterface;
 	}
 
@@ -294,4 +338,19 @@
 		mSceneNodes[sn->getName()] = sn;
 		return sn;
+	}
+
+	Entity * KdTreeSceneManager::createEntity(const String& entityName, const String& meshName)
+	{
+		Entity *ent = SceneManager::createEntity(entityName, meshName);
+
+		for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
+		{
+			ent->getSubEntity(i)->setId(mCurrentEntityId);
+		}
+
+		// increase counter of entity id values
+		++ mCurrentEntityId;
+
+		return ent;
 	}
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp	(revision 903)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp	(revision 1175)
@@ -82,4 +82,5 @@
 	refKeys.push_back("NumQueryCulledNodes");
 	refKeys.push_back("NumFrustumCulledNodes");
+	refKeys.push_back("NumQueriesIssued");
 	
 	return true;
