Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3264)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3265)
@@ -266,6 +266,6 @@
 
 	mVboId = -1;
-	// bound the maximal depth of the dynamic branch
-	mMaxDepthForDynamicBranch = 1;
+	// bounds the maximal depth of the dynamic branch
+	mMaxDepthForDynamicBranch = 10;
 }
 
@@ -1357,7 +1357,9 @@
     while (1)
 	{
-		while (mGeometry[i]->GetWorldCenter()[axis] < position) ++ i;
-		//while ((j > 0) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j;
-		while (position < mGeometry[j]->GetWorldCenter()[axis]) -- j;
+		//while (mGeometry[i]->GetWorldCenter()[axis] < position) ++ i;
+		//while (position < mGeometry[j]->GetWorldCenter()[axis]) -- j;
+
+		while ((i < leaf->mLast) && (mGeometry[i]->GetWorldCenter()[axis] < position)) ++ i;
+		while ((j > leaf->mFirst) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j;
 
 		// sorting finished
@@ -1391,5 +1393,7 @@
 	if (TerminationCriteriaMet(leaf))
 	{
-		//cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl;
+		if (leaf->CountPrimitives() == 0)
+			cout << "error: leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl;
+		
 		return leaf;
 	}
@@ -1409,9 +1413,10 @@
 	pos = leaf->mBox.Center()[axis];
 	
+	//if ((split >= leaf->mLast) || (split < leaf->mFirst))
 	if (split == leaf->mLast)
 	{
 		// no split could be achieved => just halve number of objects
-		split = (leaf->mLast - leaf->mFirst) / 2;
-		cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl;
+		split = (leaf->mLast + leaf->mFirst) / 2;
+		cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << " " << split << endl;
 	}
 
@@ -1436,4 +1441,7 @@
 	front->mDepth = leaf->mDepth + 1;
 
+	if (leaf->mFirst > leaf->mLast)
+		cerr << "erorr!!! " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << " " << split << endl;
+
 	leaf->mLast = split;
 	leaf->mDepth = front->mDepth;
@@ -1455,5 +1463,5 @@
 	const bool criteriaMet = 
 		(leaf->mDepth > mMaxDepthForDynamicBranch) ||
-		(leaf->CountPrimitives() == 1);
+		(leaf->CountPrimitives() <= 1);
 
 	return criteriaMet;
@@ -1501,5 +1509,5 @@
 	-- mNumNodes;
 
-#if 0
+#if 1
 	BvhConstructor bvhConstructor(mGeometry, (int)mStaticGeometrySize, (int)mGeometrySize - 1);
 
@@ -1510,4 +1518,5 @@
 
 #else
+
 	BvhLeaf *l = new BvhLeaf(mRoot);
 	mDynamicRoot = l;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhConstructor.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhConstructor.cpp	(revision 3262)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhConstructor.cpp	(revision 3265)
@@ -40,6 +40,7 @@
 
 int BvhConstructor::SortTriangles(BvhLeaf *leaf, 
-								  int axis, 
-								  float position)
+					   int axis, 
+					   float position
+					   )
 {
 	int i = leaf->mFirst;
@@ -48,7 +49,9 @@
     while (1)
 	{
-		while (mEntities[i]->GetWorldCenter()[axis] < position) ++ i;
-		//while ((j > 0) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j;
-		while (position < mEntities[j]->GetWorldCenter()[axis]) -- j;
+		//while (mEntities[i]->GetWorldCenter()[axis] < position) ++ i;
+		//while (position < mEntities[j]->GetWorldCenter()[axis]) -- j;
+
+		while ((i < leaf->mLast) && (mEntities[i]->GetWorldCenter()[axis] < position)) ++ i;
+		while ((j > leaf->mFirst) && (position < mEntities[j]->GetWorldCenter()[axis])) -- j;
 
 		// sorting finished
@@ -81,5 +84,6 @@
 	if (TerminationCriteriaMet(leaf))
 	{
-		cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl;
+		if (leaf->CountPrimitives() <= 0)
+			cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl;
 		return leaf;
 	}
@@ -101,5 +105,5 @@
 	{
 		// no split could be achieved => just halve number of objects
-		split = (leaf->mLast - leaf->mFirst) / 2;
+		split = (leaf->mLast + leaf->mFirst) / 2;
 		cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl;
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp	(revision 3262)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp	(revision 3265)
@@ -510,27 +510,28 @@
 
 
-	int entityCount = 1;
+	int entityCount = mNumShapes;
 	ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int));
 
 
 	//////////
-	//-- write single scene entity
-
-	// no transformation
-	bool hasTrafo = false;
-	ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool));
-
-	// a dummy lod
-	int numLODs = 1;
-	ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int));
-
-	float dist = 0;
-	ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
-
-	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+	//-- write scene entities
 
 	// all shapes belong to this scene entity
 	for (int i = 0; i < mNumShapes; ++ i)
 	{
+		// no transformation
+		bool hasTrafo = false;
+		ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool));
+
+		// a dummy lod
+		int numLODs = 1;
+		ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int));
+
+		float dist = 0;
+		ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
+
+		int numShapes = 1;
+		ofile.write(reinterpret_cast<char *>(&numShapes), sizeof(int));
+
 		int shapeId = i;
 		ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int));
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp	(revision 3262)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp	(revision 3265)
@@ -32,5 +32,5 @@
 	
 	//const int numFiles = 879;
-	const int numFiles = 300;
+	const int numFiles = 10;
 
 	vector<string> filenames;
