Index: trunk/src/formats/md5_loader.cc
===================================================================
--- trunk/src/formats/md5_loader.cc	(revision 257)
+++ trunk/src/formats/md5_loader.cc	(revision 258)
@@ -10,4 +10,5 @@
 #include "nv/logging.hh"
 #include "nv/io/std_stream.hh"
+#include "nv/profiler.hh"
 #include <cstring>
 
@@ -211,4 +212,22 @@
 		vtc.tangent  = glm::vec3(0);
 
+		std::sort( mdata->m_weights.begin() + vdata.start_weight, mdata->m_weights.begin() + vdata.start_weight + vdata.weight_count, [](const md5_weight& a, const md5_weight& b) -> bool { return a.bias > b.bias; } );
+
+		if ( vdata.weight_count > 4 )
+		{
+			float sum = 0.0f;
+			for ( size_t j = 0; j < 4; ++j )
+			{
+				sum += mdata->m_weights[vdata.start_weight + j].bias;
+			}
+			float ratio = 1.0f / sum;
+			for ( size_t j = 0; j < 4; ++j )
+			{
+				mdata->m_weights[vdata.start_weight + j].bias = 
+					ratio * mdata->m_weights[vdata.start_weight + j].bias;
+			}
+			vdata.weight_count = 4;
+		}
+
 		for ( size_t j = 0; j < vdata.weight_count; ++j )
 		{
@@ -517,4 +536,7 @@
 void nv::md5_mesh_instance::apply( const std::vector< transform >& skeleton )
 {
+	NV_PROFILE("md5::apply");
+	char* fill_ptr = (char*)&(m_pntdata[0]);
+	std::fill( fill_ptr, fill_ptr + m_size * ( sizeof( md5_vtx_pnt ) ), 0 );
 	for ( unsigned int i = 0; i < m_size; ++i )
 	{
@@ -522,8 +544,4 @@
 		md5_vtx_pnt& result = m_pntdata[i];
 
-		result.position = glm::vec3(0);
-		result.normal   = glm::vec3(0);
-		result.tangent  = glm::vec3(0);
-
 		for ( size_t j = 0; j < vert.weight_count; ++j )
 		{
