Index: trunk/src/formats/assimp_loader.cc
===================================================================
--- trunk/src/formats/assimp_loader.cc	(revision 282)
+++ 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);
+		}
+	}
+
+}
+
