Index: trunk/tests/md5_test/md5_test.cc
===================================================================
--- trunk/tests/md5_test/md5_test.cc	(revision 231)
+++ trunk/tests/md5_test/md5_test.cc	(revision 239)
@@ -18,84 +18,8 @@
 #include <nv/time.hh>
 #include <nv/string.hh>
-#include <nv/interface/mesh.hh>
 #include <nv/gfx/skeletal_mesh.hh>
 #include <glm/gtx/rotate_vector.hpp>
 #include <glm/gtc/matrix_access.hpp>
 #include <glm/gtx/matrix_interpolation.hpp>
-
-class mesh_part
-{
-public:
-	mesh_part( const std::string& path, nv::program* program, nv::window* window )
-		: m_mesh( nullptr ), m_program( program ), m_loader( nullptr ), m_animation( nullptr ), m_window( window )
-	{
-		
-		NV_PROFILE("mesh_construct");
-		{
-			NV_PROFILE("loader->load");
-			nv::c_file_system fs;
-			nv::stream* mesh_file = fs.open( path.c_str() );
-			m_loader = new nv::md5_loader();
-			m_loader->load( *mesh_file );
-			delete mesh_file;
-		}
-
-		{
-			NV_PROFILE("create_mesh");
-			m_mesh = new nv::skeletal_mesh( window->get_context(), m_loader );
-		}
-
-	}
-
-	void load_animation( const std::string& path )
-	{
-		delete m_animation;
-		m_animation = nullptr;
-		NV_PROFILE("load_animation");
-		nv::c_file_system fs;
-		nv::stream* anim_file = fs.open( path.c_str() );
-
-		if ( anim_file != nullptr )
-		{
-			m_animation = new nv::md5_animation();
-			if ( !m_animation->load_animation(*anim_file) )
-			{
-				delete m_animation;
-				m_animation = nullptr;
-			}
-			m_mesh->setup_animation( m_animation );
-			delete anim_file;
-		}
-	}
-
-	void update( nv::uint32 ms )
-	{
-		m_mesh->update( ms );
-	}
-
-	void draw( nv::context* context, nv::render_state& rstate, const glm::mat4& m, const glm::mat4& v, const glm::mat4& p )
-	{
- 		NV_PROFILE( "mesh-draw" );
- 		glm::mat4 mv = v * m;
-		m_program->set_opt_uniform( "nv_m_model", m );
- 		m_program->set_opt_uniform( "nv_m_modelview", mv );
-		m_program->set_opt_uniform( "nv_m_view_inv", glm::inverse( v ) );
- 		m_program->set_opt_uniform( "nv_m_normal", glm::transpose(glm::inverse(glm::mat3(mv))) );
-		m_program->set_uniform( "matrix_mvp", p * mv );
-		context->draw( rstate, m_program, m_mesh );
-	}
-
-	~mesh_part()
-	{
- 		delete m_mesh;
-	}
-
-private:
-	nv::skeletal_mesh* m_mesh;
-	nv::program*       m_program;
-	nv::md5_loader*    m_loader;
-	nv::md5_animation* m_animation;
-	nv::window*        m_window;
-};
 
 class application
@@ -107,4 +31,8 @@
 	~application();
 protected:
+	void load_animation( const std::string& path );
+protected:
+
+
 	nv::device*       m_device;
 	nv::window*       m_window;
@@ -114,7 +42,11 @@
 	nv::clear_state   m_clear_state;
 	nv::render_state  m_render_state;
-
-	mesh_part*   m_mesh;
-	nv::program* m_program;
+	nv::scene_state   m_scene_state;
+
+	nv::skeletal_mesh* m_mesh;
+	nv::program*       m_program;
+	nv::md5_mesh_data* m_mesh_data;
+	nv::md5_animation* m_animation;
+
 };
 
@@ -124,4 +56,5 @@
 	m_device = new nv::gl_device();
 	m_window = m_device->create_window( 800, 600, false );
+	m_animation = nullptr;
 
 	nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::REPEAT );
@@ -152,6 +85,23 @@
 	NV_PROFILE( "app_initialize" );
 	m_program = m_device->create_program( nv::slurp( "md5.vert" ), nv::slurp( "md5.frag" ) );
-	m_mesh    = new mesh_part( "data/qshambler.md5mesh", m_program, m_window );
-	m_mesh->load_animation( "data/idle02.md5anim" );
+
+	nv::md5_loader* loader = nullptr;
+	{
+		NV_PROFILE("loader->load");
+		nv::c_file_system fs;
+		nv::stream* mesh_file = fs.open( "data/qshambler.md5mesh" );
+		loader = new nv::md5_loader();
+		loader->load( *mesh_file );
+		delete mesh_file;
+	}
+
+	{
+		NV_PROFILE("create_mesh");
+		m_mesh_data = (nv::md5_mesh_data*)loader->release_mesh_data();
+		m_mesh = new nv::skeletal_mesh( m_window->get_context(), m_mesh_data );
+		delete loader;
+	}
+
+	load_animation( "data/idle02.md5anim" );
 	return true;
 }
@@ -182,6 +132,4 @@
 		}
 
-		glm::mat4 view;
-		glm::mat4 projection;
 		{
 			NV_PROFILE( "update_sh" );
@@ -190,28 +138,25 @@
 			glm::vec3 eye = glm::rotate( source, (ticks / 20.f), glm::vec3( 0.0,1.0,0.0 ) );
 
-			view       = glm::lookAt(eye + move, glm::vec3(0.0f, 0.0f, 0.0f) + move, glm::vec3(0.0, 1.0, 0.0));
-			projection = glm::perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f);
+			m_scene_state.get_camera().set_lookat(eye + move, glm::vec3(0.0f, 0.0f, 0.0f) + move, glm::vec3(0.0, 1.0, 0.0));
+			m_scene_state.get_camera().set_perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f);
 
 			m_diffuse ->bind( 0 );
 			m_specular->bind( 1 );
 			m_normal  ->bind( 2 );
-			m_program->set_opt_uniform( "nv_m_projection", projection );
-			m_program->set_uniform( "light_position", glm::vec3(180.0, 180.0, 0) );
-			m_program->set_uniform( "light_diffuse",  glm::vec4(0.7,0.7,0.7,1.0) );
-			m_program->set_uniform( "light_specular", glm::vec4(1.0,1.0,1.0,1.0) );
-			m_program->set_uniform( "diffuse", 0 );
-			m_program->set_uniform( "specular", 1 );
-			m_program->set_uniform( "normalmap", 2 );
+			m_program->set_opt_uniform( "light_position", glm::vec3(180.0, 180.0, 0) );
+			m_program->set_opt_uniform( "light_diffuse",  glm::vec4(0.7,0.7,0.7,1.0) );
+			m_program->set_opt_uniform( "light_specular", glm::vec4(1.0,1.0,1.0,1.0) );
 		}
 
 		{
 			NV_PROFILE( "draw" );
-			glm::mat4 model      = 
-				glm::mat4(1.f,0.f,0.f,0.f,
-				          0.f,0.f,1.f,0.f,
-						  0.f,1.f,0.f,0.f,
-						  0.f,0.f,0.f,1.f);
-
-			m_mesh->draw( m_window->get_context(), m_render_state, model, view, projection );
+			m_scene_state.set_model(nv::mat4(
+				1.f,0.f,0.f,0.f,
+				0.f,0.f,1.f,0.f,
+				0.f,1.f,0.f,0.f,
+				0.f,0.f,0.f,1.f
+			) );
+
+			m_window->get_context()->draw( m_render_state, m_scene_state, m_program, m_mesh );
 		}
 
@@ -251,4 +196,26 @@
 }
 
+void application::load_animation( const std::string& path )
+{
+	delete m_animation;
+	m_animation = nullptr;
+	NV_PROFILE("load_animation");
+	nv::c_file_system fs;
+	nv::stream* anim_file = fs.open( path.c_str() );
+
+	if ( anim_file != nullptr )
+	{
+		m_animation = new nv::md5_animation();
+		if ( !m_animation->load_animation(*anim_file) )
+		{
+			delete m_animation;
+			m_animation = nullptr;
+		}
+		m_mesh->setup_animation( m_animation );
+		delete anim_file;
+	}
+}
+
+
 application::~application()
 {
