Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3274)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3358)
@@ -346,5 +346,6 @@
 	int vertexCount;
 	str.read(reinterpret_cast<char *>(&vertexCount), sizeof(int));
-	
+	cout << "vertices: " << vertexCount << endl;
+
 	// end of file reached
 	if (str.eof()) return NULL;
@@ -381,4 +382,8 @@
 		texcoords = NULL;
 	}
+
+	cout << "here3: " << normals[vertexCount-1] << endl;
+	cout << "texCoordCount: " << texCoordCount << endl;
+
 
 	const bool delGeometry = true;
@@ -415,7 +420,7 @@
 	igzstream istr(filename.c_str());
 	
-	if (!istr.is_open())
-		return 0;
-
+	if (!istr.is_open()) return 0;
+
+	cout << "here7" << endl;
 	cout << "loading textures" << endl;
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3353)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3358)
@@ -656,5 +656,7 @@
 	Matrix4x4 transl = TranslationMatrix(positions[0]);
 	
-	LoadModel("hbuddha.dem", dynamicObjects);
+	//LoadModel("hbuddha.dem", dynamicObjects);
+	//LoadModel("horse.dem", dynamicObjects);
+	LoadModel("happy.dem", dynamicObjects);
 	//LoadModel("torus.dem", dynamicObjects);
 	//LoadModel("venusm.dem", dynamicObjects);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.h	(revision 3357)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.h	(revision 3358)
@@ -13,7 +13,17 @@
 typedef std::vector<SimpleVec> VertexArray;
 typedef std::pair<float, float> Texcoord;
-typedef std::vector<SimpleVec> TexcoordArray;
+typedef std::vector<Texcoord> TexcoordArray;
 typedef std::map<std::string, int> TextureTable;
 typedef std::vector<std::string> TextureArray;
+
+
+struct Face
+{
+	std::vector<int> indices;
+};
+
+
+typedef std::vector<Face> FaceArray;
+
 
 
@@ -37,7 +47,8 @@
 protected:
 
-	void LoadShape(const VertexArray &faceVertices,
-		           const VertexArray &faceNormals,
-				   const std::vector<Texcoord> &faceTexcoords
+	void LoadShape(const VertexArray &vertices,
+				   const VertexArray &normals,
+				   const TexcoordArray &texcoords,
+				   const FaceArray &faces
 				   );
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3342)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3358)
@@ -14,8 +14,8 @@
 						const VertexArray &vertices, 
 						const VertexArray &normals, 
-						const vector<pair<float, float> > &texcoords,
+						const TexcoordArray &texcoords,
 						VertexArray &faceVertices,
 						VertexArray &faceNormals,
-						vector<Texcoord> &faceTexcoords
+						TexcoordArray &faceTexcoords
 						)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp	(revision 3342)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp	(revision 3358)
@@ -12,8 +12,8 @@
 						const VertexArray &vertices, 
 						const VertexArray &normals, 
-						const vector<Texcoord> &texcoords,
+						const TexcoordArray &texcoords,
 						VertexArray &faceVertices,
 						VertexArray &faceNormals,
-						vector<Texcoord> &faceTexcoords
+						TexcoordArray &faceTexcoords
 						)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h	(revision 3261)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h	(revision 3358)
@@ -23,5 +23,5 @@
 typedef std::map<std::string, Material *> MaterialTable;
 typedef std::map<std::string, int> TextureTable;
-
+typedef std::vector<Texcoord> TexcoordArray;
 typedef std::vector<std::string> TextureArray;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.h	(revision 3261)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.h	(revision 3358)
@@ -23,5 +23,5 @@
 typedef std::map<std::string, Material *> MaterialTable;
 typedef std::map<std::string, int> TextureTable;
-
+typedef std::vector<Texcoord> TexcoordArray;
 typedef std::vector<std::string> TextureArray;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.cpp	(revision 3357)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.cpp	(revision 3358)
@@ -14,4 +14,6 @@
 VertexArray sVertices;
 VertexArray sNormals;
+FaceArray sFaces;
+
 
 
@@ -23,35 +25,63 @@
 
 
-void PlyConverter::LoadShape(const VertexArray &faceVertices,
-							 const VertexArray &faceNormals,
-							 const vector<Texcoord> &faceTexcoords
+void PlyConverter::LoadShape(const VertexArray &vertices,
+							 const VertexArray &normals,
+							 const TexcoordArray &texcoords,
+							 const FaceArray &faces
 							 )
 {
-	int numElements = (int)faceVertices.size();
 	Geometry *geom = new Geometry();
-/*
-	// convert the triangles to geometry
-	geom->mVertices = new SimpleVec[numElements];
-	geom->mNormals = new SimpleVec[numElements];
-	geom->mTexcoords = new Texcoord[numElements];
-
-	geom->mVertexCount = numElements;
-	geom->mTexcoordCount = (int)faceTexcoords.size();
-
-	cout << "creating new geometry with " << numElements << " vertices" << endl;
-
-	for (int i = 0; i < numElements; ++ i)
-	{
-		geom->mVertices[i] = faceVertices[i]
-		geom->mNormals[i] = faceNormals[i];
-
-		/*if (i < geom->mTexcoordCount)
+	size_t idx = 0;
+
+	for (size_t i = 0; i < faces.size(); ++ i)
+	{
+		if (i % 1000 == 0)
+			cout << "converted " << i << " lines" << endl;
+
+		Face face = faces[i];
+
+		//cout << "size: " << face.indices.size() << endl;
+		for (size_t j = 0; j < face.indices.size(); ++ j)
 		{
-			geom->mTexcoords[i].first = faceTexcoords[i].first;
-			geom->mTexcoords[i].second = faceTexcoords[i].second;
+			geom->mVertices.push_back(vertices[faces[i].indices[j]]);
+
+			/*if (!normals.empty())
+			{
+				for (int j = 0; j < 3; ++ j)
+					faceNormals.push_back(Normalize(normals[nIndices[idx[j]]]));
+			}
+			else
+			{
+				// no face normals? => create normals
+				const SimpleTri tri(vertices[indices[idx[0]]],
+					                vertices[indices[idx[1]]], 
+									vertices[indices[idx[2]]]);
+
+				const SimpleVec n = tri.GetNormal();
+
+				faceNormals.push_back(n);
+				faceNormals.push_back(n);
+				faceNormals.push_back(n);
+			}*/
 		}
-	}
-*/
+
+		//cout << "idx: " << idx << " " << geom->mVertices.size() << endl;
+
+		// no face normals? => create normals
+		const SimpleTri tri(geom->mVertices[idx],
+			                geom->mVertices[idx + 1], 
+							geom->mVertices[idx + 2]);
+
+		const SimpleVec n = tri.GetNormal();
+
+		geom->mNormals.push_back(n);
+		geom->mNormals.push_back(n);
+		geom->mNormals.push_back(n);
+
+		idx += faces[i].indices.size();
+	}
+
 	mGeometry.push_back(geom);
+	mNumShapes = 1;
 }
 
@@ -86,15 +116,16 @@
     ply_get_argument_user_data(argument, NULL, &eol);
 
-	static int mainIndex = 0;
+	static SimpleVec v;
 	static int i = 0;
 
-	static SimpleVec v;
-
-	v[i] = (float)ply_get_argument_value(argument);
+	v[i ++] = (float)ply_get_argument_value(argument);
 	//printf("here3 %g", ply_get_argument_value(argument));
     
-	if (eol) sVertices.push_back(v);
-	i = (i + 1) % 3;
-	//else printf(" ");
+	if (eol)
+	{
+		sVertices.push_back(v);
+		if (sVertices.size() % 10000 == 0) cout << "read in " << sVertices.size() << " vertices" << endl;
+		i = 0;
+	}
     
 	return 1;
@@ -107,16 +138,26 @@
     ply_get_argument_property(argument, NULL, &length, &value_index);
 
+	static Face face;
+	
 	switch (value_index) 
 	{
         case 0:
         case 1: 
-            printf("here4 %g ", ply_get_argument_value(argument));
+            //printf("here4 %g ", ply_get_argument_value(argument));
+			face.indices.push_back((int)ply_get_argument_value(argument));
             break;
         case 2:
-            printf("here5 %g\n", ply_get_argument_value(argument));
+            //printf("here5 %g\n", ply_get_argument_value(argument));
+			face.indices.push_back((int)ply_get_argument_value(argument));
+			sFaces.push_back(face);
+			if (sFaces.size() % 10000 == 0) cout << "read in " << sFaces.size() << " faces" << endl;
+
+			face.indices.clear();
             break;
         default: 
             break;
     }
+
+
     return 1;
 }
@@ -140,10 +181,14 @@
 	ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
 
-    printf("%ld\n%ld\n", nvertices, ntriangles);
-
-    if (!ply_read(ply)) return 1;
+	cout << "vertices: " << nvertices << endl;
+	cout << "triangles: " << ntriangles << endl;
+
+    if (!ply_read(ply)) return false;
     ply_close(ply);
 
-    return 0;
+	TexcoordArray texCoords;
+	LoadShape(sVertices, sNormals, texCoords, sFaces);
+
+    return true;
 }
 
@@ -152,20 +197,25 @@
 void PlyConverter::WriteGeometry(ogzstream &str, Geometry *geom)
 {
-	int vertexCount = (int)geom->mVertices.size();
+	size_t vertexCount = (int)geom->mVertices.size();
 	str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int));
-  
-	SimpleVec hvertices[3];
-	SimpleVec hnormals[3];
-
-	for (int i = 0; i < 3; ++ i)
-	{
-		hvertices[i] = geom->mVertices[i];
-		hnormals[i] = geom->mNormals[i];
-	}
+
+	cout << "writing geometry" << endl;
+
+	//SimpleVec vertices = new SimpleVec[vertexCount];
+	//for (size_t i = 0; i < vertexCount; ++ i) vertices[i] = geom->mVertices[i];
+	//for (size_t i = 0; i < vertexCount; ++ i) vertices[i] = geom->mNormals[i];
+
+	for (size_t i = 0; i < vertexCount; ++ i)
+		str.write(reinterpret_cast<char *>(&geom->mVertices[i]), sizeof(SimpleVec));
+
+	for (size_t i = 0; i < vertexCount; ++ i)
+		str.write(reinterpret_cast<char *>(&geom->mNormals[i]), sizeof(SimpleVec));
+
+	cout << "finished writing geometry" << endl;
+	//if (texCoordCount) str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2);
+
+	cout << "here34 " << geom->mNormals.back() << endl;
 
 	int texCoordCount = 0;
-
-	str.write(reinterpret_cast<char *>(hvertices), sizeof(SimpleVec) * vertexCount);
-	str.write(reinterpret_cast<char *>(hnormals), sizeof(SimpleVec) * vertexCount);
 	str.write(reinterpret_cast<char *>(&texCoordCount), sizeof(int));
 
@@ -177,7 +227,8 @@
 {
 	ogzstream ofile(filename.c_str());
-
 	if (!ofile.is_open()) return false;
 	
+
+	mNumShapes = (int)mGeometry.size();
 
 	/////////
@@ -218,4 +269,22 @@
 	{
 		WriteGeometry(ofile, *it);
+
+
+		///////
+		//-- texture
+
+		int texId = 0;
+		ofile.write(reinterpret_cast<char *>(&texId), sizeof(int));
+
+		bool alphaTestEnabled = false;
+		//bool cullFaceEnabled = false;
+		bool cullFaceEnabled = true;
+
+		ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
+		ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
+
+		// material
+		bool hasMaterial = false;
+		ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
 	}
 
@@ -238,6 +307,6 @@
 	float dist = 0;
 	ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
-
 	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+	
 
 	// all shapes belong to this scene entity
