Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp	(revision 3245)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp	(revision 3246)
@@ -13,4 +13,7 @@
 
 #define VIEWCELLS_VERSION 1.0f
+
+static const float sScale = 0.05f;
+
 
 namespace CHCDemoEngine
@@ -75,10 +78,13 @@
 	}
 
+	AxisAlignedBox3 box;
 	// get the bounding box
 	// exchange x and y coordinates and recompute box
-	fread(&mBox, sizeof(AxisAlignedBox3), 1, fr);
+	fread(&box, sizeof(AxisAlignedBox3), 1, fr);
 
-	Vector3 v1(mBox.Min().x, -mBox.Min().z, mBox.Min().y);
-	Vector3 v2(mBox.Max().x, -mBox.Max().z, mBox.Max().y);
+	box.Scale(sScale);
+
+	Vector3 v1(box.Min().x, -box.Min().z, box.Min().y);
+	Vector3 v2(box.Max().x, -box.Max().z, box.Max().y);
 	
 	mBox.Initialize();
@@ -119,4 +125,7 @@
 			float mypos;
 			fread(&mypos, sizeof(float), 1, fr);
+
+			mypos *= sScale;
+
 			// changed coordinate system must be considered also here
 			if (node->mAxis == 1) 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3232)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3246)
@@ -6,7 +6,7 @@
 //-- ssao + gi parameters
 
-#define NUM_SAMPLES 8
+//#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
-//#define NUM_SAMPLES 24
+#define NUM_SAMPLES 24
 //#define NUM_SAMPLES 48
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3232)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3246)
@@ -115,5 +115,5 @@
 	float4 ao =  tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-#if 0 // use half size
+#if 1 // use half resolution
 
 	// the following has to be done for half resolution ssao:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3193)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3246)
@@ -108,6 +108,7 @@
 	Vector3 position = camera->GetPosition();
 
-	const float scaleFactor = 80.0f;
-	//const float scaleFactor = 5.0f;
+	// scale the sky dome so no intersection with the scene is visible
+	//const float scaleFactor = 80.0f;
+	const float scaleFactor = 200.0f;
 
 	position.z -= 3.0f * scaleFactor;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 3245)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 3246)
@@ -175,5 +175,5 @@
 	{
 		vcTechnique.Render(mRenderState);
-		Visualization::RenderBoxForViz(mViewCell->GetBox());
+		RenderBoxForViz(mViewCell->GetBox());
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3245)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3246)
@@ -113,5 +113,5 @@
 /// max depth where candidates for tighter bounds are searched
 int maxDepthForTestingChildren = 3;
-
+/// use full resolution for ssao or half
 bool ssaoUseFullResolution = false;
 
@@ -140,8 +140,8 @@
 
 ViewCellsTree *viewCellsTree = NULL;
+ViewCell *viewCell = NULL;
 
 static int globalVisibleId = 0;
 
-ViewCell *viewCell = NULL;
 
 
@@ -255,4 +255,7 @@
 bool useLenseFlare = true;
 
+bool usePvs = false;
+
+
 PerfTimer frameTimer, algTimer;
 /// the performance graph window
@@ -263,7 +266,9 @@
 static Matrix4x4 invTrafo = IdentityMatrix();
 
+float mouseMotion = 0.2f;
+
 
 //////////////
-//-- algorithm parameters
+//-- chc++ algorithm parameters
 
 /// the pixel threshold where a node is still considered invisible 
@@ -356,5 +361,9 @@
 SceneQuery *GetOrCreateSceneQuery();
 
-void RenderPvs();
+void LoadPvs();
+
+void LoadVisibilitySolution();
+
+void RenderViewCell();
 
 
@@ -419,4 +428,5 @@
 		env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion);
 		env.GetFloatParam(string("keyRotation"), keyRotation);
+		env.GetFloatParam(string("mouseMotion"), mouseMotion);
 		env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor);
 		env.GetFloatParam(string("turbitity"), turbitity);
@@ -443,4 +453,6 @@
 		env.GetStringParam(string("filename"), filename);
 		env.GetStringParam(string("visibilitySolution"), visibilitySolution);
+
+		env.GetBoolParam(string("usePvs"), usePvs);
 
 		//env.GetStringParam(string("modelPath"), model_path);
@@ -474,4 +486,5 @@
 		cout << "stats filename: " << statsFilename << endl;
 		cout << "filename: " << filename << endl;
+		cout << "use PVS: " << usePvs << endl;
 		cout << "visibilitySolution: " << visibilitySolution << endl;
 		
@@ -558,5 +571,5 @@
 
 	//LoadModel("fisch.dem", dynamicObjects);
-	LoadModel("hbuddha.dem", dynamicObjects);
+	//LoadModel("hbuddha.dem", dynamicObjects);
 
 	//LoadModel("venusm.dem", dynamicObjects);
@@ -568,4 +581,5 @@
 	resourceManager->mUseSpecialColors = false;
 
+	/*
 	buddha = dynamicObjects.back();
 	
@@ -594,5 +608,5 @@
 		dynamicObjects.push_back(ent);
 	}
-
+	*/
 
 /*	int cityEntities = LoadModel("vienna_full_hp.dem", dynamicObjects);
@@ -619,15 +633,4 @@
 	/// set the depth of the bvh depending on the triangles per leaf node
 	bvh->SetVirtualLeaves(trianglesPerVirtualLeaf);
-
-	///////////
-	//-- load the visibility solution
-
-	const string vis_filename = 
-		string(model_path + visibilitySolution + ".vis");
-
-	VisibilitySolutionLoader visLoader;
-
-	viewCellsTree = visLoader.Load(vis_filename, bvh);
-
 
 	// set far plane based on scene extent
@@ -753,5 +756,5 @@
 void InitGLstate() 
 {
-	glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
+	glClearColor(0.4f, 0.4f, 0.4f, 1e20f);
 	
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -1063,36 +1066,38 @@
 void MainLoop() 
 {	
-	Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix();
-	Vector3 buddhaPos = motionPath->GetCurrentPosition();
-	Matrix4x4 trafo = TranslationMatrix(buddhaPos);
-	
-	buddha->GetTransform()->SetMatrix(trafo);
-
-#if TODO
-	/*for (int i = 0; i < 10; ++ i)
-	{
-		SceneEntity *ent = dynamicObjects[i];
-		Vector3 newPos = ent->GetWorldCenter();
-
-		if (GetOrCreateSceneQuery()->CalcIntersection(newPos))
+	if (buddha)
+	{
+		Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix();
+		Vector3 buddhaPos = motionPath->GetCurrentPosition();
+		Matrix4x4 trafo = TranslationMatrix(buddhaPos);
+
+		buddha->GetTransform()->SetMatrix(trafo);
+
+#if TODO // drop objects on ground floor
+		for (int i = 0; i < 10; ++ i)
 		{
-			Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter());
-			ent->GetTransform()->SetMatrix(mat);
+			SceneEntity *ent = dynamicObjects[i];
+			Vector3 newPos = ent->GetWorldCenter();
+
+			if (GetOrCreateSceneQuery()->CalcIntersection(newPos))
+			{
+				Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter());
+				ent->GetTransform()->SetMatrix(mat);
+			}
 		}
-	}*/
 #endif
 
 
-	/////////////////////////
-	//-- update animations
-
-	//const float rotAngle = M_PI * 1e-3f;
-	const float rotAngle = 1.0f * M_PI / 180.0f;
-
-	Matrix4x4 rotMatrix = RotationZMatrix(rotAngle);
-	dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix);
-
-	motionPath->Move(0.01f);
-
+		/////////////////////////
+		//-- update animations
+
+		//const float rotAngle = M_PI * 1e-3f;
+		const float rotAngle = 1.0f * M_PI / 180.0f;
+
+		Matrix4x4 rotMatrix = RotationZMatrix(rotAngle);
+		dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix);
+
+		motionPath->Move(0.01f);
+	}
 
 
@@ -1181,4 +1186,10 @@
 	glEnableClientState(GL_VERTEX_ARRAY);
 
+	if (usePvs)
+	{
+		if (!viewCellsTree) LoadVisibilitySolution();
+		LoadPvs();	
+	}
+
 	// render with the specified method (forward rendering, forward + depth, deferred)
 	switch (renderMethod)
@@ -1260,6 +1271,4 @@
 	else
 	{
-		RenderPvs();
-
 		// actually render the scene geometry using the specified algorithm
 		traverser->RenderScene();
@@ -1283,4 +1292,5 @@
 	const int sunVisiblePixels = useLenseFlare  &&  useDeferred ? TestSunVisible() : 0;
 
+	
 
 	///////////////
@@ -1574,4 +1584,9 @@
 		// make a snapshot of the current frame
 		makeSnapShot = true;
+		break;
+	case '.':
+		// enable / disable view cells
+		usePvs = !usePvs;
+		if (!usePvs) SceneEntity::SetGlobalVisibleId(-1);
 		break;
 	default:
@@ -1829,5 +1844,5 @@
 	camera->Pitch(eyeXAngle);
 
-	pos += horView * (yMotionBegin - y) * 0.2f;
+	pos += horView * (yMotionBegin - y) * mouseMotion;
 	
 	camera->SetPosition(pos);
@@ -1897,6 +1912,6 @@
 	rVec = rot * rVec;
 	
-	pos -= rVec * (x - horizontalMotionBegin) * 0.1f;
-	pos[2] += (verticalMotionBegin - y) * 0.1f;
+	pos -= rVec * (x - horizontalMotionBegin) * mouseMotion;
+	pos[2] += (verticalMotionBegin - y) * mouseMotion;
 
 	camera->SetPosition(pos);
@@ -1960,6 +1975,10 @@
 void DisplayVisualization()
 {
+	// render current view cell
+	if (usePvs) RenderViewCell();
+	
+	visualization->SetViewCell(usePvs ? viewCell : NULL);
 	visualization->SetFrameId(traverser->GetCurrentFrameId());
-	visualization->SetViewCell(viewCell);
+	
 
 	Begin2D();
@@ -2229,5 +2248,5 @@
 			sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d", 
 					useMultiQueries, useTightBounds, useRenderQueue);
-			sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderMethodStr[renderMethod], useAdvancedShading);
+			sprintf(msg[i ++], "render technique: %s, use pvss: %d", renderMethodStr[renderMethod], usePvs);
 			sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf);
 			sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d", 
@@ -2267,5 +2286,5 @@
 			sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d",
 				traversedNodes, frustumCulledNodes, queryCulledNodes);
-			sprintf(msg[i ++], "issued queries: %5d, renderState changes: %5d, render batches: %5d", 
+			sprintf(msg[i ++], "issued queries: %5d, renderstate changes: %5d, render batches: %5d", 
 				issuedQueries, stateChanges, numBatches);
 
@@ -2531,7 +2550,4 @@
 	tech.Init();
 
-	//tech.SetLightingEnabled(false);
-	//tech.SetDepthWriteEnabled(false);
-
 	tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
 	tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
@@ -2542,5 +2558,5 @@
 
 
-void RenderPvs()
+void LoadPvs()
 {
 	viewCell = viewCellsTree->GetViewCell(camera->GetPosition());
@@ -2551,5 +2567,4 @@
 	{
 		SceneEntity *ent = viewCell->mPvs.GetEntry(i);
-		//ent->Render(&renderState);
 		ent->SetVisibleId(globalVisibleId);
 
@@ -2558,5 +2573,23 @@
 
 	SceneEntity::SetGlobalVisibleId(globalVisibleId ++);
-
+}
+
+
+void LoadVisibilitySolution()
+{
+	///////////
+	//-- load the visibility solution
+
+	const string vis_filename = 
+		string(model_path + visibilitySolution + ".vis");
+
+	VisibilitySolutionLoader visLoader;
+
+	viewCellsTree = visLoader.Load(vis_filename, bvh);
+}
+
+
+void RenderViewCell()
+{
 	// render current view cell
 	static Technique vcTechnique = GetVizTechnique();
@@ -2564,7 +2597,3 @@
 	vcTechnique.Render(&renderState);
 	Visualization::RenderBoxForViz(viewCell->GetBox());
-
-	visualization->SetViewCell(viewCell);
-
-	//cout << "pvs: " << vc->mPvs.Size() << " triangles: " << numTriangles << endl;
-}
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3242)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3246)
@@ -73,7 +73,7 @@
 
 // ssao random spherical samples
-//static Sample2 samples2[NUM_SAMPLES];
-#define NUM_PRECOMPUTED_SAMPLES 240
-static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES];
+static Sample2 samples2[NUM_SAMPLES];
+//#define NUM_PRECOMPUTED_SAMPLES 240
+//static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES];
 // pcf samples
 static Sample2 pcfSamples[NUM_PCF_TABS];
@@ -210,5 +210,6 @@
 	case DeferredRenderer::SAMPLING_QUADRATIC:
 		{
-			static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
+			//static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
+			static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);
 			g.Generate((float *)samples2);
 		}
@@ -753,9 +754,8 @@
 		// in the first case, the sample patterns look nicer, but the kernel
 		// needs longer to converge
-		if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES)
-		{
+		//if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES)	{
 			currentPos = 0;
 			GenerateSamples(mSamplingMethod);
-		}
+		//}
 
 		//if (mSortSamples) { SortSamples(); }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj	(revision 3238)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj	(revision 3246)
@@ -154,4 +154,5 @@
 				GenerateDebugInformation="true"
 				SubSystem="1"
+				LargeAddressAware="2"
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3161)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3246)
@@ -122,5 +122,4 @@
 			}
 
-			++ dummy;
 			if (!texcoords.empty())
 			{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3245)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3246)
@@ -7,5 +7,5 @@
 # misc stuff
 
-filename=vienna_full_hp
+#filename=vienna_full_hp
 useLODs=1
 # shadow map size
@@ -16,7 +16,12 @@
 statsFilename=mystats.log
 
+# use potentially viible sets?
+usePvs=0
+
+# if using pvs, this specifies the name of the visibility solutin
 #visibilitySolution=vienna_full-8x3-refu
 visibilitySolution=vienna_full-8x3-pgv
-#visibilitySolution=vienna_full-8x3-spgvu
+
+
 
 ############
@@ -35,8 +40,8 @@
 
 # move speed
-keyForwardMotion=5.0f
-keyRotation=0.5f
+#keyForwardMotion=5.0f
+#keyRotation=0.5f
 #keyForwardMotion=20.0f
-#keyRotation=1.5f
+keyRotation=1.5f
 
 # initial camera position
@@ -50,4 +55,15 @@
 #lightDirection=-0.8f 1.0f -0.7f
 lightDirection=-0.3f 0.2f -0.7f
+
+###########################
+## powerplant options
+
+filename=PowerPlantM
+
+keyForwardMotion=200.0f
+mouseMotion=1.0f;
+visibilitySolution=power-plant-2c-xx-1000b-pgv2
+camPosition=-1320.57 -6306.34 3603
+camDirection=0.292156 0.9556 0.0383878
 
 
@@ -93,5 +109,5 @@
 
 # use full resolution ssao (vs. half resoltion)
-ssaoUseFullResolution=1
+ssaoUseFullResolution=0
 # ssao kernel radius
 #ssaoKernelRadius=8e-1f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h	(revision 3243)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h	(revision 3246)
@@ -120,13 +120,7 @@
 				 VertexArray &normals,
 				 std::vector<TexCoord> &texcoords);
-	
-	bool ReadSimpleObj(const std::string &filename,
-		               VertexArray &vertices,
-					   VertexArray &normals,
-					   std::vector<TexCoord> &texcoords);
 
 	bool ReadBinObj(const std::string &filename,
-                    VertexArray &vertices,
-					float scale);
+                    VertexArray &vertices);
 
 	bool WriteBinObj(const std::string &filename,
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3243)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3246)
@@ -20,6 +20,6 @@
 #define TYPE_LEAF -3
 
-//const int maxVertices = 20000000;
-
+
+static const float sScale = 0.05f;
 
 
@@ -125,5 +125,5 @@
 
 
-			if (!normals.empty())
+			/*if (!normals.empty())
 			{
 				faceNormals.push_back(normals[nIndices[idx1]]);
@@ -144,5 +144,5 @@
 				faceNormals.push_back(n);
 				faceNormals.push_back(n);
-			}
+			}*/
 
 			if (!texCoords.empty())
@@ -196,12 +196,7 @@
 	{
 		// convert to our camera system: change y and z
-		geom->mVertices[i].x =  vertices[i].x;
-		geom->mVertices[i].y = -vertices[i].z;
-		geom->mVertices[i].z =  vertices[i].y;
-	
-		geom->mNormals[i].x =  normals[i].x;
-		geom->mNormals[i].y = -normals[i].z;
-		geom->mNormals[i].z =  normals[i].y;
-
+		geom->mVertices[i] =  vertices[i];
+		geom->mNormals[i] =  normals[i];
+		
 		if (i < geom->mTexcoordCount)
 		{
@@ -249,5 +244,5 @@
 	UpdateBvh(mRoot);
 
-	cout << "bvh: " << mRoot->first << " " << mRoot->last << " bb: " << mRoot->box << endl;
+	cout << "loading bvh, bb: " << mRoot->box << endl;
 
 	cout << "writing scene" << endl;
@@ -277,6 +272,6 @@
 	vector<TexCoord> texCoords;
 
-	if (ReadSimpleObj(filename, vertices, normals, texCoords))
-	//if (ReadObj(filename, vertices, normals, texCoords)) 
+	//if (ReadSimpleObj(filename, vertices, normals, texCoords))
+	if (ReadObj(filename, vertices, normals, texCoords)) 
 	{
 		ConstructBvhObjects(vertices, normals, texCoords);
@@ -297,5 +292,8 @@
 	if ((file = fopen(filename.c_str(), "r")) == NULL) return false;
 	
-	VertexArray tempVertices; 
+	VertexArray tempVertices;
+	//tempVertices.reserve(11000000);
+	//tempVertices.reserve(13000000 * 3);
+
 	VertexArray tempNormals;
 	vector<TexCoord> tempTexcoords;
@@ -307,85 +305,14 @@
 	char str[len];
 
-	while (fgets(str, len, file) != NULL)
-	{
-		if (line % 500000 == 0)
-			cout << line << " " << str << endl;
-
-		++ line;
-
-		switch (str[0])
-		{
-		case 'v': // vertex or normal
-			{
-				float x, y, z;
-
-				//if (tempVertices.size() >= maxVertices * 3) continue;
-
-				switch (str[1]) 
-				{
-				case 'n' :
-					sscanf(str + 2, "%f %f %f", &x, &y, &z);
-					tempNormals.push_back(CHCDemoEngine::Vector3(x, y, z));
-					break;
-				case 't':
-					sscanf(str + 2, "%f %f", &x, &y);
-					tempTexcoords.push_back(pair<float, float>(x, y));
-					break;
-				default:
-					sscanf(str + 1, "%f %f %f", &x, &y, &z);
-					const float scale = 1.0f;
-					//const float scale = 0.1f;
-					tempVertices.push_back(CHCDemoEngine::Vector3(x * scale, y * scale, z * scale));
-					//cout <<"v " << x << " " << y << " "<< z << " ";
-				}
-				break;
-			}
-		case 'f': 
-			{
-				//////////
-				//-- indices in the current line
-
-				//if (tempVertices.size() >= maxVertices * 3) continue;
-				LoadIndices(str, 
-					        tempVertices, tempNormals, tempTexcoords, 
-					        vertices, normals, texcoords);
-
-				break;
-			}  
-			break;
-		default:
-			// throw away line
-			break;
-		}
-	}
-
-	fclose(file);
-
-	return !vertices.empty();
-}
-
-
-bool VisibilitySolutionConverter::ReadSimpleObj(const string &filename,
-												VertexArray &vertices,
-												VertexArray &normals,
-												vector<TexCoord> &texcoords)
-{
 	const string binFilename = ReplaceSuffix(filename, ".obj", ".bn");
 
-	if (!ReadBinObj(binFilename, vertices, 1))
+	if (!ReadBinObj(binFilename, vertices))
 	{
 		cout << "binary dump " << binFilename << " not available, loading ascii obj" << endl;
-
-		FILE *file;
-		if ((file = fopen(filename.c_str(), "r")) == NULL) return false;
-
-		int line = 0;
-		const int len = 10000;
-		char str[len];
 
 		while (fgets(str, len, file) != NULL)
 		{
 			if (line % 500000 == 0)
-				cout << line << " " << str << endl;
+				cout << line << " " << str;
 
 			++ line;
@@ -397,9 +324,38 @@
 					float x, y, z;
 
-					sscanf(str + 1, "%f %f %f", &x, &y, &z);
-					const float scale = 1.0f;
-					vertices.push_back(CHCDemoEngine::Vector3(x * scale, y * scale, z * scale));
+					//if (tempVertices.size() >= maxVertices * 3) continue;
+
+					switch (str[1]) 
+					{
+					case 'n' :
+						sscanf(str + 2, "%f %f %f", &x, &y, &z);
+						tempNormals.push_back(CHCDemoEngine::Vector3(x, -z, y));
+						break;
+					case 't':
+						sscanf(str + 2, "%f %f", &x, &y);
+						tempTexcoords.push_back(pair<float, float>(x, y));
+						break;
+					default:
+						sscanf(str + 1, "%f %f %f", &x, &y, &z);
+						
+						CHCDemoEngine::Vector3 v = CHCDemoEngine::Vector3(x, -z, y) * sScale;
+						tempVertices.push_back(v);
+						//cout <<"v " << x << " " << y << " "<< z << " ";
+					}
 					break;
 				}
+			case 'f': 
+				{
+					//////////
+					//-- indices in the current line
+
+					//if (tempVertices.size() >= maxVertices * 3) continue;
+					LoadIndices(str, 
+						tempVertices, tempNormals, tempTexcoords, 
+						vertices, normals, texcoords);
+
+					break;
+				}  
+				break;
 			default:
 				// throw away line
@@ -408,26 +364,31 @@
 		}
 
-		fclose(file);
-
-		cout << "dumping " << vertices.size() << " to binary " << binFilename << endl;
 		ExportBinObj(binFilename, vertices);
 	}
-
-	for (size_t i = 0; i < vertices.size(); i += 3)
-	{
-		// no face normals? => create normals
-		const CHCDemoEngine::Triangle3 
-			tri(vertices[i], vertices[i + 1], vertices[i + 2]);
-
-		const CHCDemoEngine::Vector3 n = tri.GetNormal();
-
-		normals.push_back(n);
-		normals.push_back(n);
-		normals.push_back(n);
-	}
+	else if (0)
+	{
+		cout << "creating normals" << endl;
+		normals.reserve(vertices.size());
+
+		for (size_t i = 0; i < vertices.size(); i += 3)
+		{
+			// no face normals? => create normals
+			const CHCDemoEngine::Triangle3 
+				tri(vertices[i], vertices[i + 1], vertices[i + 2]);
+
+			const CHCDemoEngine::Vector3 n = tri.GetNormal();
+
+			normals.push_back(n);
+			normals.push_back(n);
+			normals.push_back(n);
+		}
+	}
+
+	cout << "finished creating normals" << endl;
+
+	fclose(file);
 
 	return !vertices.empty();
 }
-
 
 
@@ -554,8 +515,4 @@
 													  const vector<TexCoord> &texCoords)
 {
-	VertexArray _vertices;
-	VertexArray _normals;
-	vector<TexCoord> _texCoords;
-
 	CHCDemoEngine::AxisAlignedBox3 testBox;
 	testBox.Initialize();
@@ -566,5 +523,5 @@
 	}
 
-	cout << "testbox: " << testBox << endl;
+	cout << "geometry bounds: " << testBox << endl;
 
 	mGeometry.reserve(mBvhLeaves.size());
@@ -576,4 +533,14 @@
 		BvhLeaf *node = mBvhLeaves[i];
 
+		VertexArray _vertices;	
+		VertexArray _normals;
+		vector<TexCoord> _texCoords;
+
+		const int size = node->last - node->first + 1;
+
+		_vertices.reserve(size);
+		_normals.reserve(size);
+
+		//cout << "vtx: " << size << endl;
 		for (int j = node->first; j <= node->last; ++ j)
 		{
@@ -583,7 +550,17 @@
 			{
 				_vertices.push_back(vertices[idx + k]);
-				_normals.push_back(normals[idx + k]);
+				//_normals.push_back(normals[idx + k]);
 				//_texCoords.push_back(texCoords[idx + k]);
 			}
+
+			// no face normals? => create normals
+			const CHCDemoEngine::Triangle3 
+				tri(vertices[idx], vertices[idx + 1], vertices[idx + 2]);
+
+			const CHCDemoEngine::Vector3 n = tri.GetNormal();
+
+			_normals.push_back(n);
+			_normals.push_back(n);
+			_normals.push_back(n);
 		}
 
@@ -595,7 +572,7 @@
 		node->last = (int)mGeometry.size() - 1;
 
-		_vertices.clear();
-		_normals.clear();
-		_texCoords.clear();
+		//_vertices.clear();
+		//_normals.clear();
+		//_texCoords.clear();
 	}
 }
@@ -621,4 +598,5 @@
 	// load triangle ids
 	size_t numTriangles = buffer[2];
+	mGlobalTriangleIds.reserve(numTriangles);
 
 	for (size_t i = 0; i < numTriangles; ++i) 
@@ -778,6 +756,6 @@
 
 bool VisibilitySolutionConverter::ReadBinObj(const string &filename,
-											 VertexArray &vertices,
-											 float scale)
+											 VertexArray &vertices
+											 )
 {
 	igzstream inStream(filename.c_str());
@@ -862,6 +840,9 @@
 	stream.write(reinterpret_cast<char *>(&nodeType), sizeof(int));
 
-	CHCDemoEngine::Vector3 bMin = node->box.Min();
-	CHCDemoEngine::Vector3 bMax = node->box.Max();
+	CHCDemoEngine::AxisAlignedBox3 box = node->box;
+	//box.Scale(sScale);
+
+	CHCDemoEngine::Vector3 bMin = box.Min();
+	CHCDemoEngine::Vector3 bMax = box.Max();
 
 	stream.write(reinterpret_cast<char *>(&(node->first)), sizeof(int));
