Index: trunk/src/formats/assimp_loader.cc
===================================================================
--- trunk/src/formats/assimp_loader.cc	(revision 283)
+++ trunk/src/formats/assimp_loader.cc	(revision 284)
@@ -15,6 +15,22 @@
 const int MAX_BONES = 64;
 
-nv::assimp_loader::assimp_loader( const string& a_ext, const mat4& a_rotate_transform, float a_scale, uint32 a_assimp_flags /*= 0 */ ) : m_ext( a_ext ), m_rotate_transform( a_rotate_transform ), m_scale( a_scale ), m_assimp_flags( a_assimp_flags ), m_mesh_count(0), m_scene( nullptr )
-{
+nv::assimp_loader::assimp_loader( const string& a_ext, const mat3& a_rotate_transform, float a_scale, uint32 a_assimp_flags /*= 0 */ ) : m_mesh_count(0), m_scene( nullptr )
+{
+	initialize( a_ext, a_rotate_transform, a_scale, a_assimp_flags );
+}
+
+nv::assimp_loader::assimp_loader( const string& a_ext, uint32 a_assimp_flags /*= 0 */ ) : m_mesh_count(0), m_scene( nullptr )
+{
+	initialize( a_ext, mat3(), 1.0f, a_assimp_flags );
+}
+
+
+void nv::assimp_loader::initialize( const string& a_ext, const mat3& a_rotate_transform, float a_scale, uint32 a_assimp_flags )
+{
+	m_ext   = a_ext;
+	m_r33   = a_rotate_transform;
+	m_ri33  = glm::transpose( m_r33 );
+	m_scale = a_scale;
+	m_assimp_flags = a_assimp_flags;
 	if ( m_assimp_flags == 0 )
 	{
@@ -36,24 +52,5 @@
 }
 
-nv::assimp_loader::assimp_loader( const string& a_ext, uint32 a_assimp_flags /*= 0 */ ) : m_ext( a_ext ), m_rotate_transform(), m_scale( 1.0f ), m_assimp_flags( a_assimp_flags ), m_mesh_count(0), m_scene( nullptr )
-{
-	if ( m_assimp_flags == 0 )
-	{
-		m_assimp_flags = ( 
-			aiProcess_CalcTangentSpace				|  
-			aiProcess_GenSmoothNormals				|  
-			aiProcess_JoinIdenticalVertices			|   
-			aiProcess_ImproveCacheLocality			|  
-			aiProcess_LimitBoneWeights				|  
-			aiProcess_RemoveRedundantMaterials      |  
-			aiProcess_SplitLargeMeshes				|  
-			aiProcess_Triangulate					|  
-			aiProcess_GenUVCoords                   |  
-			aiProcess_SortByPType                   |  
-			aiProcess_FindDegenerates               |  
-			aiProcess_FindInvalidData               |  
-			0 );
-	}
-}
+
 bool nv::assimp_loader::load( stream& source )
 {
@@ -86,9 +83,7 @@
 	const aiMesh*  mesh  = scene->mMeshes[ index ];
 
-	mat3 scaled_rotatation = glm::mat3( glm::scale( m_scale, m_scale, m_scale ) * m_rotate_transform );
-	//mat3 scaled_rotatation = glm::mat3( m_rotate_transform );
 	vec3 vertex_offset     = glm::vec3(); 
-	mat3 vertex_transform  = scaled_rotatation;
-	mat3 normal_transform  = glm::mat3( m_rotate_transform );
+	mat3 vertex_transform  = m_scale * m_r33;
+	mat3 normal_transform  = m_r33;
 
 	bool skinned = mesh->mNumBones > 0;
@@ -170,6 +165,6 @@
 	if ( mesh->mNumBones == 0 ) return false;
 
-	mat4 bone_transform    = glm::scale( 1.f/m_scale, 1.f/m_scale, 1.f/m_scale ) *  glm::inverse( glm::mat4(m_rotate_transform) ); 
-	mat4 bone_pre_transform    = glm::scale( m_scale, m_scale, m_scale );
+	mat4 bone_transform     = mat4( ( 1.f/m_scale * m_ri33 ) ); 
+	mat4 bone_pre_transform = mat4( m_scale * m_r33 );
 
 	for (unsigned int m=0; m<mesh->mNumBones; m++)
@@ -291,5 +286,5 @@
 			}
 		}
-		if ( m > 0 )
+		if ( m > 0 && bones.size() > 0 )
 		{
 			mesh_data* mesh = model->meshes[m];
@@ -318,5 +313,5 @@
 	if ( m_scene == nullptr ) return nullptr;
 	const aiScene* scene = (const aiScene*)m_scene;
-	if ( scene->mRootNode == nullptr || scene->mAnimations[0] == nullptr ) return nullptr;
+	if ( scene->mRootNode == nullptr || scene->mAnimations == nullptr || scene->mAnimations[0] == nullptr) return nullptr;
 	assimp_animation* result = new assimp_animation;
 
@@ -370,4 +365,6 @@
 	//       node's without keys
 	a_data.transform = nv::assimp_mat4_cast( node->mTransformation );
+	if (this_id == 0)
+		a_data.transform = mat4();
 	a_data.channel_count = 0;
 
@@ -405,8 +402,8 @@
 		size_t pn = glm::min( node->mNumPositionKeys - 1, n );
 		size_t rn = glm::min( node->mNumRotationKeys - 1, n );
-		nv::vec3 pos = nv::assimp_vec3_cast(node->mPositionKeys[pn].mValue);
-		nv::quat rot = nv::assimp_quat_cast(node->mRotationKeys[rn].mValue);
+		nv::vec3 pos = m_r33 * nv::assimp_vec3_cast(node->mPositionKeys[pn].mValue) * m_scale;
+		nv::quat rot = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[rn].mValue ) ) * m_ri33 );
 		// TODO: only do the calculation when a rotate transform is present!
-		nv::transform ptr( vec3(), glm::quat_cast( m_rotate_transform ) );
+		nv::transform ptr;
 		if ( parent )
 		{
@@ -417,5 +414,6 @@
 			}
 		}
-		nv::transform key( ptr * nv::transform( pos * m_scale, rot ) );
+
+		nv::transform key( ptr * nv::transform( pos, rot ) );
 		channel[n].tform = key;
 	}
@@ -425,5 +423,4 @@
 {
 	data->channel_count = 0;
-	// TODO : support for m_rotate_transform and m_scale! ( should be easy )
 	const aiNodeAnim* node = (const aiNodeAnim*)vnode;
 	if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 )
@@ -443,10 +440,10 @@
 	{
 		pchannel[np].time     = (float)node->mPositionKeys[np].mTime;
-		pchannel[np].position = assimp_vec3_cast(node->mPositionKeys[np].mValue);
+		pchannel[np].position = m_r33 * assimp_vec3_cast(node->mPositionKeys[np].mValue) * m_scale;
 	}
 	for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
 	{
 		rchannel[np].time     = (float)node->mRotationKeys[np].mTime;
-		rchannel[np].rotation = assimp_quat_cast(node->mRotationKeys[np].mValue);
+		rchannel[np].rotation = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[np].mValue ) ) * m_ri33 );
 	}
 	if ( node->mNumScalingKeys > 0 )
@@ -463,5 +460,11 @@
 			}
 		}
-	}
-}
-
+		else 
+		{
+			schannel[0].time  = (float)node->mScalingKeys[0].mTime;
+			schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
+		}
+	}
+
+}
+
Index: trunk/src/formats/nmd_loader.cc
===================================================================
--- trunk/src/formats/nmd_loader.cc	(revision 283)
+++ trunk/src/formats/nmd_loader.cc	(revision 284)
@@ -22,7 +22,7 @@
 		switch ( element_header.type )
 		{
-		case nmd_type::MESH           : load_mesh( source, element_header.children ); break;
-		case nmd_type::ANIMATION      : load_animation( source, element_header.children ); break;
-		case nmd_type::BONE_ARRAY     : load_bones( source, element_header.children ); break;
+		case nmd_type::MESH           : load_mesh( source, element_header ); break;
+		case nmd_type::ANIMATION      : load_animation( source, element_header ); break;
+		case nmd_type::BONE_ARRAY     : load_bones( source, element_header ); break;
 		case nmd_type::STRING_TABLE   : load_strings( source ); break;
 		default: NV_ASSERT( false, "UNKNOWN NMD ELEMENT!" ); break;
@@ -32,8 +32,8 @@
 }
 
-bool nv::nmd_loader::load_mesh( stream& source, uint32 children )
+bool nv::nmd_loader::load_mesh( stream& source, const nmd_element_header& e )
 {
 	mesh_data* mesh = new mesh_data();
-	for ( uint32 s = 0; s < children; ++s )
+	for ( uint32 s = 0; s < e.children; ++s )
 	{
 		nmd_element_header element_header;
@@ -82,11 +82,11 @@
 }
 
-bool nv::nmd_loader::load_bones( stream& source, uint32 children )
+bool nv::nmd_loader::load_bones( stream& source, const nmd_element_header& e )
 {
 	NV_ASSERT( m_bone_data == nullptr, "MULTIPLE BONE ENTRIES!" );
 	m_bone_data = new nmd_bone_data;
-	m_bone_data->bones = new nmd_bone[ children ];
-	m_bone_data->count = (uint16)children;
-	source.read( m_bone_data->bones, sizeof( nmd_bone ), children );
+	m_bone_data->bones = new nmd_bone[ e.children ];
+	m_bone_data->count = (uint16)e.children;
+	source.read( m_bone_data->bones, sizeof( nmd_bone ), e.children );
 	return true;
 }
@@ -114,5 +114,5 @@
 
 
-bool nv::nmd_loader::load_animation( stream& source, uint32 children )
+bool nv::nmd_loader::load_animation( stream& source, const nmd_element_header& e )
 {
 	NV_ASSERT( m_animation == nullptr, "MULTIPLE ANIMATION ENTRIES!" );
@@ -123,11 +123,12 @@
 	m_animation->duration   = header.duration;
 	m_animation->flat       = header.flat;
-	m_animation->node_count = (uint16)children;
-	m_animation->nodes      = new nmd_node[ children ];
-	for ( uint32 i = 0; i < children; ++i )
+	m_animation->node_count = (uint16)e.children;
+	m_animation->nodes      = new nmd_node[ e.children ];
+	for ( uint32 i = 0; i < e.children; ++i )
 	{
 		nmd_element_header element_header;
 		source.read( &element_header, sizeof( element_header ), 1 );
 		NV_ASSERT( element_header.type == nmd_type::ANIMATION_NODE, "ANIMATION_NODE expected!" );
+		m_animation->nodes[i].name          = element_header.name;
 
 		uint16 ch_count = element_header.children;
@@ -135,5 +136,4 @@
 		nmd_animation_node_header node_header;
 		source.read( &node_header, sizeof( node_header ), 1 );
-		m_animation->nodes[i].name          = node_header.name;
 		m_animation->nodes[i].parent_id     = node_header.parent_id;
 		m_animation->nodes[i].transform     = node_header.transform;
