Index: trunk/src/formats/obj_loader.cc
===================================================================
--- trunk/src/formats/obj_loader.cc	(revision 238)
+++ trunk/src/formats/obj_loader.cc	(revision 239)
@@ -56,6 +56,6 @@
 	bool read_stream( std::istream& stream );
 	virtual size_t add_face( uint32* vi, uint32* ti, uint32* ni, size_t count ) = 0;
-	virtual size_t raw_size() { return 0; }
-	virtual const uint8* raw_pointer() { return nullptr; }
+	virtual size_t raw_size() const = 0;
+	virtual const uint8* raw_pointer() const = 0;
 	virtual void calculate_tangents() {}
 
@@ -151,138 +151,4 @@
 
 
-struct mesh_obj_reader : public obj_reader
-{
-	mesh_obj_reader( mesh_data_creator* m ) : m_mesh( m ) {}
-	virtual std::size_t add_face( uint32* vi, uint32* ti, uint32* ni, size_t count );
-	virtual void calculate_tangents();
-
-	mesh_data_creator* m_mesh;
-};
-
-size_t mesh_obj_reader::add_face( uint32* vi, uint32* ti, uint32* ni, size_t count )
-{
-	if ( count < 3 )
-	{
-		// TODO : report error?
-		return 0;
-	}
-
-	// TODO : support if normals not present;
-
-	std::vector< vec3 >& vp = m_mesh->get_positions();
-	std::vector< vec3 >& vn = m_mesh->get_normals();
-	std::vector< vec2 >& vt = m_mesh->get_texcoords();
-
-	std::size_t result = 0;
-
-	// Simple triangulation - obj's shouldn't have more than quads anyway
-	for ( size_t i = 2; i < count; ++i )
-	{
-		result++;
-		vp.push_back( v[ vi[ 0 ] ] );   vt.push_back( t[ ti[ 0 ] ] );   vn.push_back( n[ ni[ 0 ] ] );
-		vp.push_back( v[ vi[ i-1 ] ] ); vt.push_back( t[ ti[ i-1 ] ] ); vn.push_back( n[ ni[ i-1 ] ] );
-		vp.push_back( v[ vi[ i ] ] );   vt.push_back( t[ ti[ i ] ] );   vn.push_back( n[ ni[ i ] ] );
-	}
-
-	return result;
-}
-
-// based on http://www.terathon.com/code/tangent.html
-void mesh_obj_reader::calculate_tangents()
-{
-	const std::vector< vec3 >& vp = m_mesh->get_positions();
-	const std::vector< vec2 >& vt = m_mesh->get_texcoords();
-	const std::vector< vec3 >& vn = m_mesh->get_normals();
-	std::vector< vec3 >& tg = m_mesh->get_tangents();
-
-	size_t count  = vp.size();
-	size_t tcount = count / 3;
-
-	std::vector< vec3 > tan1( count );
-	std::vector< vec3 > tan2( count );
-	tg.resize( count );
-
-	for (size_t a = 0; a < tcount; ++a )
-	{
-		size_t i1 = a * 3;
-		size_t i2 = a * 3 + 1;
-		size_t i3 = a * 3 + 2;
-
-		// TODO: simplify
-
-		const vec3& v1 = vp[i1];
-		const vec3& v2 = vp[i2];
-		const vec3& v3 = vp[i3];
-
-		const vec2& w1 = vt[i1];
-		const vec2& w2 = vt[i2];
-		const vec2& w3 = vt[i3];
-
-		vec3 xyz1 = v2 - v1;
-		vec3 xyz2 = v3 - v1;
-		//vec2 st1  = w2 - w1;
-		//vec2 st2  = w3 - w1;
-
-		float s1 = w2.x - w1.x;
-		float t1 = w2.y - w1.y;
-		float s2 = w3.x - w1.x;
-		float t2 = w3.y - w1.y;
-
-		float stst = s1 * t2 - s2 * t1;
-		float r = 0.0f;
-		if (stst > 0.0f || stst < 0.0f) r = 1.0f / stst;
-
-		vec3 sdir = ( t2 * xyz1 - t1 * xyz2 ) * r;
-		vec3 tdir = ( s1 * xyz2 - s2 * xyz1 ) * r;
-
-		// the += below obviously doesn't make sense in this case, but I'll
-		// leave it here for when I move to indices
-		tan1[i1] += sdir;
-		tan1[i2] += sdir;
-		tan1[i3] += sdir;
-
-		// tan2 not needed anymore??
-		tan2[i1] += tdir;
-		tan2[i2] += tdir;
-		tan2[i3] += tdir;
-	}
-
-	for (std::size_t a = 0; a < count; ++a )
-	{
-		const vec3& n = vn[a];
-		const vec3& t = tan1[a];
-		if ( ! (t.x == 0.0f && t.y == 0.0f && t.z == 0.0f) )
-			tg[a] = vec3( glm::normalize(t - n * glm::dot( n, t )) ); 
-			//tg[a][3] =    (glm::dot(glm::cross(n, t), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
-	}
-
-}
-
-nv::obj_loader::obj_loader( bool tangents )
-	: m_mesh( nullptr ), m_tangents( tangents )
-{
-
-}
-
-nv::obj_loader::~obj_loader()
-{
-	delete m_mesh;
-}
-
-bool nv::obj_loader::load( stream& source )
-{
-	if ( m_mesh != nullptr ) delete m_mesh;
-	mesh_data_creator creator;
-	mesh_obj_reader reader( &creator );
-	std_stream sstream( &source );
-	reader.read_stream( sstream );
-	m_size = reader.size;
-	if ( m_tangents )
-	{
-		reader.calculate_tangents();
-	}
-	m_mesh = creator.release();
-	return true;
-}
 
 struct mesh_data_reader_vt : public obj_reader
@@ -305,6 +171,6 @@
 	}
 	std::vector< obj_vertex_vt > m_data;
-	virtual size_t raw_size() { return m_data.size() * sizeof( obj_vertex_vt ); }
-	virtual const uint8* raw_pointer() { return (const uint8*)m_data.data(); }
+	virtual size_t raw_size() const { return m_data.size() * sizeof( obj_vertex_vt ); }
+	virtual const uint8* raw_pointer() const { return (const uint8*)m_data.data(); }
 };
 
@@ -328,6 +194,6 @@
 	}
 	std::vector< obj_vertex_vtn > m_data;
-	virtual size_t raw_size() { return m_data.size() * sizeof( obj_vertex_vtn ); }
-	virtual const uint8* raw_pointer() { return (const uint8*)m_data.data(); }
+	virtual size_t raw_size() const { return m_data.size() * sizeof( obj_vertex_vtn ); }
+	virtual const uint8* raw_pointer() const { return (const uint8*)m_data.data(); }
 };
 
@@ -351,6 +217,6 @@
 	}
 	std::vector< obj_vertex_vtnt > m_data;
-	virtual size_t raw_size() { return m_data.size() * sizeof( obj_vertex_vtnt ); }
-	virtual const uint8* raw_pointer() { return (const uint8*)m_data.data(); }
+	virtual size_t raw_size() const { return m_data.size() * sizeof( obj_vertex_vtnt ); }
+	virtual const uint8* raw_pointer() const { return (const uint8*)m_data.data(); }
 
 	// based on http://www.terathon.com/code/tangent.html
@@ -423,5 +289,5 @@
 };
 
-nv::wavefront_loader::wavefront_loader( bool normals /*= true*/, bool tangents /*= false */ )
+nv::obj_loader::obj_loader( bool normals /*= true*/, bool tangents /*= false */ )
 	: m_normals( normals ), m_tangents( tangents ), m_mesh( nullptr )
 {
@@ -437,5 +303,5 @@
 }
 
-bool nv::wavefront_loader::load( stream& source )
+bool nv::obj_loader::load( stream& source )
 {
 	if ( m_mesh ) delete m_mesh;
@@ -462,4 +328,5 @@
 	mesh_raw_channel* channel = new mesh_raw_channel();
 	nv::uint8* data = nullptr;
+
 	if ( reader->raw_size() > 0 ) 
 	{
@@ -479,5 +346,5 @@
 }
 
-mesh_data* nv::wavefront_loader::release_mesh_data()
+mesh_data* nv::obj_loader::release_mesh_data()
 {
 	mesh_data* result = m_mesh;
@@ -486,5 +353,5 @@
 }
 
-nv::wavefront_loader::~wavefront_loader()
+nv::obj_loader::~obj_loader()
 {
 	if ( m_mesh ) delete m_mesh;
