Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjManualMeshLoader.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjManualMeshLoader.h	(revision 2111)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjManualMeshLoader.h	(revision 2123)
@@ -2,22 +2,21 @@
 #define __ObjManualMeshLoader_H__
 
+#include "Ogre.h"
 
-#include "Ogre.h"
-#include "ObjMeshData.h"
-
+namespace  GtpVisibilityPreprocessor {
+class BvhLeaf;
+}
 
 class __declspec(dllexport) ObjManualMeshLoader: public Ogre::ManualResourceLoader
 {
-	public:
-		ObjManualMeshLoader();
-		ObjManualMeshLoader(ObjMeshData *mData);
-		~ObjManualMeshLoader(); 
+public:
+	ObjManualMeshLoader(GtpVisibilityPreprocessor::BvhLeaf *obj);
+	~ObjManualMeshLoader(); 
 
-		void loadResource(Ogre::Resource *resource);
+	void loadResource(Ogre::Resource *resource);
 
-		Ogre::AxisAlignedBox *getBoundingBox();
-	private:
-		ObjMeshData *data;
+protected:
 
+	GtpVisibilityPreprocessor::BvhLeaf *mObject;
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2122)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2123)
@@ -7,4 +7,7 @@
 #include "Containers.h"
 
+namespace  GtpVisibilityPreprocessor {
+class Intersectable;
+}
 
 class __declspec(dllexport) ObjReader
@@ -14,8 +17,10 @@
 	~ObjReader();
 
-	bool LoadFile(const string &sceneName, 
-				  const string &visibilitySolution,
+	bool LoadFile(const std::string &sceneName, 
+				  const std::string &visibilitySolution,
 				  Ogre::SceneNode *root);
-	
+	void dummy();
+	Ogre::Entity * dummy2(const std::string &name,
+				GtpVisibilityPreprocessor::Intersectable *object);
 	Ogre::Entity *CreateEntity(const std::string &name,
 							   GtpVisibilityPreprocessor::Intersectable *object);
@@ -25,4 +30,5 @@
 
 	Ogre::SceneManager *mSceneManager;
+	GtpVisibilityPreprocessor::ObjectContainer mPvsObjects;
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2122)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2123)
@@ -20,21 +20,21 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include;..\..\..\Preprocessing\src"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib"
-				OutputFile="$(OutDir)/ObjReader.dll"
-				LinkIncremental="1"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib Preprocessor.lib xerces-c_2.lib zdll.lib zziplibd.lib"
+				OutputFile="$(OutDir)/ObjReader.dll"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
@@ -73,5 +73,5 @@
 				Name="VCCLCompilerTool"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include;..\..\..\Preprocessing\src"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE1;USE_VERBOSE_PVS"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE"
 				RuntimeLibrary="2"
 				UsePrecompiledHeader="0"
@@ -339,14 +339,20 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
+				RelativePath=".\ObjManualMeshLoader.cpp">
+			</File>
+			<File
 				RelativePath="..\src\ObjReader.cpp">
 			</File>
-			<Filter
-				Name="Header Files"
-				Filter="h;hpp;hxx;hm;inl;inc;xsd"
-				UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
-				<File
-					RelativePath="..\include\ObjReader.h">
-				</File>
-			</Filter>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath="..\include\ObjManualMeshLoader.h">
+			</File>
+			<File
+				RelativePath="..\include\ObjReader.h">
+			</File>
 		</Filter>
 	</Files>
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjManualMeshLoader.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjManualMeshLoader.cpp	(revision 2111)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjManualMeshLoader.cpp	(revision 2123)
@@ -1,13 +1,12 @@
 #include "ObjManualMeshLoader.h"
-#include "ObjReader.h"
+#include "Triangle3.h"
+#include "IntersectableWrapper.h"
+#include "BvHierarchy.h"
+#include "OgreLogManager.h"
 
-ObjManualMeshLoader::ObjManualMeshLoader()
-{
-	data = NULL;
-}
+#define USE_HBL_DISCARD 1
 
-
-ObjManualMeshLoader::ObjManualMeshLoader(ObjMeshData *mData):
-data(mData)
+ObjManualMeshLoader::ObjManualMeshLoader(GtpVisibilityPreprocessor::BvhLeaf *obj):
+mObject(obj)
 {
 }
@@ -16,15 +15,4 @@
 ObjManualMeshLoader::~ObjManualMeshLoader()
 {
-	if (data != NULL)
-	{
-		data->collapse();
-		delete data;
-	}
-}
-
-
-Ogre::AxisAlignedBox *ObjManualMeshLoader::getBoundingBox()
-{
-	return data->boundingBox;
 }
 
@@ -33,89 +21,109 @@
 {
 	using namespace Ogre;
-	Mesh *pMesh = (Mesh *) resource;
 
+	Mesh *mesh = (Mesh *) resource;
+	SubMesh* submesh = mesh->createSubMesh();
 
-	Vector3 translation = data->boundingBox->getCenter();
+	const int triCount = (int)mObject->mObjects.size();
+	const int vertexCount = triCount * 3;
 
-	bool nOk = ((data->normals != NULL) && (data->ncnt > 0));
-	bool tOk = ((data->texCoords != NULL) && (data->tcnt > 0));
-	
-	pMesh->sharedVertexData = new VertexData(); 
+	// We must create the vertex data, indicating how many vertices there will be
+	submesh->useSharedVertices = false;
+	submesh->vertexData = new VertexData();
+	submesh->vertexData->vertexStart = 0;
+	submesh->vertexData->vertexCount = vertexCount;
 
-	VertexDeclaration* vertexDecl = pMesh->sharedVertexData->vertexDeclaration; 
+	static const unsigned short source = 0;
+	size_t offset = 0;
 
-	size_t currOffset = 0; 
-	vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_POSITION); 
-	currOffset += VertexElement::getTypeSize(VET_FLOAT3); 
-	if (nOk)
+	// We must now declare what the vertex data contains
+	VertexDeclaration* declaration = submesh->vertexData->vertexDeclaration;
+
+	offset += declaration->addElement(source, offset, VET_FLOAT3, VES_POSITION).getSize();
+	offset += declaration->addElement(source, offset, VET_FLOAT3, VES_NORMAL).getSize();
+	//offset += declaration->addElement(source, offset, VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize();
+
+	HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton().
+		createVertexBuffer(declaration->getVertexSize(source),
+						   submesh->vertexData->vertexCount,
+						   HardwareBuffer::HBU_STATIC_WRITE_ONLY);
+
+    // we get access to the buffer to fill it.  During so we record the bounding box.
+	AxisAlignedBox aabox;
+
+	submesh->vertexData->vertexBufferBinding->setBinding(source, vbuffer);
+#if USE_HBL_DISCARD
+	float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD));
+#else
+	float* vdata = static_cast<float *>(vbuffer->lock(HardwareBuffer::HBL_NORMAL));
+#endif
+
+	GtpVisibilityPreprocessor::ObjectContainer::
+		const_iterator oit, oit_end = mObject->mObjects.end();
+
+	for (oit = mObject->mObjects.begin(); oit != oit_end; ++ oit)
 	{
-		vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL); 
-		currOffset += VertexElement::getTypeSize(VET_FLOAT3); 
-	}
-    if (tOk)
-	{
-		vertexDecl->addElement(0, currOffset, VET_FLOAT2, VES_TEXTURE_COORDINATES); 
-		currOffset += VertexElement::getTypeSize(VET_FLOAT2); 
-	}
+		GtpVisibilityPreprocessor::TriangleIntersectable *tObj = 
+			static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit);
+		
+		const GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem();
+		const GtpVisibilityPreprocessor::Vector3 n = tri.GetNormal();
 
-	pMesh->sharedVertexData->vertexCount = data->vcnt/3; 
-	HardwareVertexBufferSharedPtr vbuf = 
-		HardwareBufferManager::getSingleton(). 
-		createVertexBuffer(vertexDecl->getVertexSize(0), pMesh->sharedVertexData->vertexCount, 
-			HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); 
+		for (int i = 0; i < 3; ++ i)
+		{
+			Vector3 vtx(tri.mVertices[i].x, tri.mVertices[i].y, tri.mVertices[i].z);
+		
+			*(vdata ++) = vtx.x;
+			*(vdata ++) = vtx.y;
+			*(vdata ++) = vtx.z;
 
-	VertexBufferBinding* binding = pMesh->sharedVertexData->vertexBufferBinding; 
-	binding->setBinding(0, vbuf); 
+			*(vdata ++) = n.x;
+			*(vdata ++) = n.y;
+			*(vdata ++) = n.z;
 
-	Real* pVertices = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); 
-
-	int offset = 0, size = 3;
-	if (nOk) size += 3;
-	if (tOk) size += 2;
-	for (int i=0; i<data->vcnt/3; i++) 
-	{
-		pVertices[i*size]   = data->vertices[i*3]   - translation.x;
-		pVertices[i*size+1] = data->vertices[i*3+1] - translation.y;
-		pVertices[i*size+2] = data->vertices[i*3+2] - translation.z;
-
-		offset = 3;
-		if (nOk)
-		{
-			pVertices[i*size+offset] = data->normals[i*3];	 offset++;
-			pVertices[i*size+offset] = data->normals[i*3+1]; offset++;
-			pVertices[i*size+offset] = data->normals[i*3+2]; offset++;
-		}
-		if (tOk)
-		{
-			pVertices[i*size+offset] = data->texCoords[i*2];   offset++;
-			pVertices[i*size+offset] = -data->texCoords[i*2+1]; offset++;
+			aabox.merge(vtx);
 		}
 	}
 
-	vbuf->unlock(); 
+	vbuffer->unlock();
+
+#if 0
+	RenderOperation rop;
+	submesh->_getRenderOperation(rop);
+	rop.useIndexes = false;
+#endif
+	//////
+	//-- Creates the index data
+    
+	const int indexCount = vertexCount;
+	submesh->indexData->indexStart = 0;
+	submesh->operationType = RenderOperation::OT_TRIANGLE_LIST;
+
+	// we use an index for every vertex
+	submesh->indexData->indexCount = indexCount;
+	submesh->indexData->indexBuffer =
+	    HardwareBufferManager::getSingleton().
+			createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
+							  submesh->indexData->indexCount,
+							  HardwareBuffer::HBU_STATIC_WRITE_ONLY);
+
+#if USE_HBL_DISCARD
+	uint16* idata = static_cast<uint16 *>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
+#else
+	uint16* idata = static_cast<uint16 *>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_NORMAL));
+#endif
+	for (int j = 0; j < indexCount; ++ j)
+    {
+		idata[j] = j;
+    }
+    
+	submesh->indexData->indexBuffer->unlock();
+	submesh->setMaterialName("BaseWhite"); 
+
+	// indicate the bounding box
+	mesh->_setBounds(aabox); 
+	mesh->_setBoundingSphereRadius((aabox.getMaximum() - aabox.getMinimum()).length() / 2.0); 
+}
 
 
-	SubMesh *pSub = pMesh->createSubMesh(); 
-	pSub->operationType = RenderOperation::OT_TRIANGLE_LIST; //;data->roType;
-	pSub->useSharedVertices = true; 
 
-	pSub->indexData->indexCount = data->icnt; 
-	pSub->indexData->indexBuffer = HardwareBufferManager::getSingleton(). 
-		createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 
-			pSub->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); 
-
-	HardwareIndexBufferSharedPtr ibuf = pSub->indexData->indexBuffer; 
-	unsigned short* pIndices = static_cast<unsigned short*>(ibuf->lock(HardwareBuffer::HBL_DISCARD)); 
-
-	for (i = 0; i < data->icnt; i++) pIndices[i] = data->indices[i];
-	
-	ibuf->unlock(); 
-		
-	AxisAlignedBox bb(data->boundingBox->getMinimum() - translation, data->boundingBox->getMaximum() - translation);
-	//AxisAlignedBox bb(data->boundingBox->getMinimum(), data->boundingBox->getMaximum());
-	pMesh->_setBounds(bb); 
-	Real radius = data->boundingBox->getMinimum().length();
-	if (data->boundingBox->getMaximum().length() > radius) radius = data->boundingBox->getMaximum().length();
-	pMesh->_setBoundingSphereRadius(radius); 
-
-}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2122)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2123)
@@ -8,4 +8,5 @@
 #include "PreprocessorFactory.h"
 #include "OgreLogManager.h"
+#include "ObjManualMeshLoader.h"
 
 
@@ -17,5 +18,7 @@
 
 ObjReader::~ObjReader()
-{}
+{
+	CLEAR_CONTAINER(mPvsObjects);
+}
 
 
@@ -31,7 +34,6 @@
 	// hack
 	preprocessor->mLoadMeshes = false;
-	GtpVisibilityPreprocessor::ObjectContainer pvsObjects;
 
-	Ogre::LogManager::getSingleton().logMessage("loading obj scene!!");
+	Ogre::LogManager::getSingleton().logMessage("loading obj scene");
 
 	if (preprocessor->LoadScene(sceneName))
@@ -39,5 +41,5 @@
 		Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects");
 		// form objects from the scene triangles
-		if (!preprocessor->LoadObjects(visibilitySolution, pvsObjects, preprocessor->mObjects))
+		if (!preprocessor->LoadObjects(visibilitySolution, mPvsObjects, preprocessor->mObjects))
 		{
 			Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded");
@@ -52,17 +54,25 @@
 
 	std::stringstream d; 
-	d << "successfully loaded " << pvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects";
+	d << "successfully loaded " << mPvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects";
 
 	Ogre::LogManager::getSingleton().logMessage(d.str());
 
-	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = pvsObjects.end();
+	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end();
 
 	int i = 0;
-	for (oit = pvsObjects.begin(); oit != oit_end; ++ oit, ++ i)
+	for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit, ++ i)
 	{
-		Ogre::LogManager::getSingleton().logMessage("r");
+		if (i % 5000 == 4999)
+		{
+			d << i << " objects created" << endl;
+		}
+	
 		const Ogre::String entname = "Object" + Ogre::StringConverter::toString(i);
 
-		Ogre::ManualObject *ent = CreateEntity(entname, *oit);
+#if 0
+		Ogre::ManualObject *ent = CreateManualObject(entname, *oit);
+#else
+		Ogre::Entity *ent = CreateEntity(entname, *oit);
+#endif
 
 		const Ogre::String nodeName = entname + "Node";
@@ -70,6 +80,6 @@
 		node->attachObject(ent);
 
-		if (i > 100)
-			break;
+		// problems for too many objects (= vbo)?
+		//if (i > 30000)break;
 	}
 
@@ -89,14 +99,19 @@
 	std::string entityName = name + "Entity";
 
-GtpVisibilityPreprocessor::BvhLeaf *bvhObj = 
+	GtpVisibilityPreprocessor::BvhLeaf *bvhObj = 
 		static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object);
+
 	const int vertexCount = (int)bvhObj->mObjects.size() * 3;
 
 	ManualObject* manual = mSceneManager->createManualObject(entityName);
-	manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
+	manual->begin("BaseWhite", RenderOperation::OT_TRIANGLE_LIST);
 	
+	const float red = GtpVisibilityPreprocessor::Random(1.0f);
+	const float green = GtpVisibilityPreprocessor::Random(1.0f);
+	const float blue = GtpVisibilityPreprocessor::Random(1.0f);
+
 	// create vertices
-	
-	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end();
+	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, 
+		oit_end = bvhObj->mObjects.end();
 	
 	for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit)
@@ -110,13 +125,19 @@
 		{
 			const GtpVisibilityPreprocessor::Vector3 vtx = tri.mVertices[i];
+			const GtpVisibilityPreprocessor::Vector3 n = tri.GetNormal();
+
 			manual->position(vtx.x, vtx.y, vtx.z);
-			manual->colour(1.0f, 0.0f, 0.0f);
+			manual->normal(n.x, n.y, n.z);
+			//manual->colour(red, green, blue);
 		}
 	}
 
+	if (0)
 	for (int i = 0; i < vertexCount; ++ i)
 	{
 		manual->index(i);
 	}
+
+	manual->end();
 
 	return manual;
@@ -137,108 +158,13 @@
 	std::string entityName = name + "Entity";
 
-	MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "Custom");
-	SubMesh* submesh = mesh->createSubMesh();
+	ObjManualMeshLoader *loader = new ObjManualMeshLoader(bvhObj);
 
-	const int vertexCount = (int)bvhObj->mObjects.size() * 3;
-
-	// We must create the vertex data, indicating how many vertices there will be
-	submesh->useSharedVertices = false;
-	submesh->vertexData = new VertexData();
-	submesh->vertexData->vertexStart = 0;
-	submesh->vertexData->vertexCount = vertexCount;
-
-	std::stringstream d; d << "objects: " << bvhObj->mObjects.size() << " vtx: " << submesh->vertexData->vertexCount << endl;
-	Ogre::LogManager::getSingleton().logMessage(d.str());
-
-	static const unsigned short source = 0;
-	size_t offset = 0;
-
-	VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
-
-	offset += declaration->addElement(source, offset, VET_FLOAT3, VES_POSITION).getSize();
-	//offset += declaration->addElement(source, offset, VET_FLOAT3,VES_NORMAL).getSize();
-	//offset += declaration->addElement(source, offset, VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize();
-
-
-	int numVertices = 0;
-
-	HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton().
-		createVertexBuffer(declaration->getVertexSize(source),
-						   submesh->vertexData->vertexCount,
-						   HardwareBuffer::HBU_STATIC_WRITE_ONLY);
-
-    // No we get access to the buffer to fill it.  During so we record the bounding box.
-	AxisAlignedBox aabox;
-
-	float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD));
-
-	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end();
-
-	for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit)
-	{
-		GtpVisibilityPreprocessor::TriangleIntersectable *tObj = 
-			static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit);
-		
-		GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem();
-
-		for (int i = 0; i < 3; ++ i)
-		{
-			Vector3 vtx = Vector3(tri.mVertices[i]);
-
-			*vdata ++ = vtx.x;
-			*vdata ++ = vtx.y;
-			*vdata ++ = vtx.z;
-
-			//std::stringstream d; d << vtx;
-			//Ogre::LogManager::getSingleton().logMessage(d.str());
-			aabox.merge(vtx);
-		}
-	}
-	//Ogre::LogManager::getSingleton().logMessage("***");
-	vbuffer->unlock();
-	
-	/*Ogre::RenderOperation rop;
-	submesh->_getRenderOperation(rop);
-	rop.useIndexes = false;
-*/
-	//////
-	//-- Creates the index data
-
-    submesh->vertexData->vertexBufferBinding->setBinding(source, vbuffer);
-
-	submesh->indexData->indexStart = 0;
-	// we use an index for every vertex
-	submesh->indexData->indexCount = vertexCount;
-	submesh->indexData->indexBuffer =
-	    HardwareBufferManager::getSingleton().
-			createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
-							  submesh->indexData->indexCount,
-							  HardwareBuffer::HBU_STATIC_WRITE_ONLY);
-	submesh->operationType = RenderOperation::OT_LINE_STRIP;
-	//uint16* idata = static_cast<uint16*>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
-    unsigned short* idata = static_cast<unsigned short*>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
-
-	for (int j = 0; j < vertexCount; ++ j)
-    {
-		*idata = j;
-		++ idata;
-    }
-    
-	submesh->indexData->indexBuffer->unlock();
-
-	submesh->setMaterialName("BaseWhiteNoLighting"); 
-
-	// We must indicate the bounding box
-	mesh->_setBounds(aabox); 
-	mesh->_setBoundingSphereRadius((aabox.getMaximum() - aabox.getMinimum()).length() / 2.0); 
-	mesh->load();
-	mesh->touch();
+	Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup", loader).getPointer(); 
+	pMesh->load(); 
 
 	// Create an entity with the mesh
 	entity = mSceneManager->createEntity(entityName, meshName);
 
-	//entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);
+	return entity;
+}
 
-	return entity;
-#endif
-}
