2009-09-05 12:04:32 +00:00
# include "BaseImporter.h"
# include <vector>
2009-09-28 16:53:33 +00:00
# include "OgreXmlHelper.h"
2009-09-05 12:04:32 +00:00
# include "irrXMLWrapper.h"
namespace Assimp
{
namespace Ogre
{
//Forward declarations:
2009-09-28 16:53:33 +00:00
struct SubMesh ;
2009-09-05 12:04:32 +00:00
struct Face ;
2009-09-13 18:26:54 +00:00
struct Weight ;
struct Bone ;
struct Animation ;
struct Track ;
struct Keyframe ;
2009-09-05 12:04:32 +00:00
///The Main Ogre Importer Class
class OgreImporter : public BaseImporter
{
public :
virtual bool CanRead ( const std : : string & pFile , IOSystem * pIOHandler , bool checkSig ) const ;
virtual void InternReadFile ( const std : : string & pFile , aiScene * pScene , IOSystem * pIOHandler ) ;
virtual void GetExtensionList ( std : : string & append ) ;
virtual void SetupProperties ( const Importer * pImp ) ;
private :
///Helper Functions to read parts of the XML File
2009-09-28 16:53:33 +00:00
void ReadSubMesh ( SubMesh & theSubMesh , XmlReader * Reader ) ; //the submesh reference is the result value
void LoadSkeleton ( std : : string FileName , std : : vector < Bone > & Bones , std : : vector < Animation > & Animations ) ; ///< writes the results in Bones and Animations, Filename is not const, because its call-by-value and the function will change it!
void CreateAssimpSubMesh ( const SubMesh & theSubMesh , const std : : vector < Bone > & Bones ) ;
void CreateAssimpSkeleton ( const std : : vector < Bone > & Bones , const std : : vector < Animation > & Animations ) ;
aiMaterial * LoadMaterial ( const std : : string MaterialName ) ;
///Recursivly creates a filled aiNode from a given root bone
aiNode * CreateAiNodeFromBone ( int BoneId , const std : : vector < Bone > & Bones , aiNode * ParentNode ) ;
2009-09-05 12:04:32 +00:00
//Now we don't have to give theses parameters to all functions
std : : string m_CurrentFilename ;
std : : string m_MaterialLibFilename ;
IOSystem * m_CurrentIOHandler ;
aiScene * m_CurrentScene ;
} ;
2009-09-28 16:53:33 +00:00
///A submesh from Ogre
struct SubMesh
{
std : : string Name ;
std : : string MaterialName ;
std : : vector < Face > FaceList ;
std : : vector < aiVector3D > Positions ; bool HasPositions ;
std : : vector < aiVector3D > Normals ; bool HasNormals ;
std : : vector < aiVector3D > Uvs ; unsigned int NumUvs ; //nearly always 2d, but assimp has always 3d texcoords
std : : vector < std : : vector < Weight > > Weights ; //a list of bones for each vertex
int MaterialIndex ; ///< The Index in the Assimp Materialarray from the material witch is attached to this submesh
unsigned int BonesUsed ; //the highest index of a bone from a bone weight, this is needed to create the assimp bone structur (converting from Vertex-Bones to Bone-Vertices)
SubMesh ( ) : HasPositions ( false ) , HasNormals ( false ) , NumUvs ( 0 ) , MaterialIndex ( - 1 ) , BonesUsed ( 0 ) { } //initialize everything
} ;
2009-09-05 12:04:32 +00:00
///For the moment just triangles, no other polygon types!
struct Face
{
unsigned int VertexIndices [ 3 ] ;
} ;
2009-09-28 16:53:33 +00:00
struct BoneAssignment
2009-09-13 18:26:54 +00:00
{
2009-09-28 16:53:33 +00:00
unsigned int BoneId ; //this is, what we get from ogre
std : : string BoneName ; //this is, what we need for assimp
2009-09-13 18:26:54 +00:00
} ;
2009-09-28 16:53:33 +00:00
///for a vertex->bone structur
struct Weight
2009-09-05 12:04:32 +00:00
{
2009-09-28 16:53:33 +00:00
unsigned int BoneId ;
float Value ;
2009-09-05 12:04:32 +00:00
} ;
2009-09-13 18:26:54 +00:00
2009-09-28 16:53:33 +00:00
/// Helper Class to describe an ogre-bone for the skeleton:
2009-09-13 18:26:54 +00:00
/** All Id's are signed ints, because than we have -1 as a simple INVALID_ID Value (we start from 0 so 0 is a valid bone ID!*/
struct Bone
{
int Id ;
int ParentId ;
std : : string Name ;
aiVector3D Position ;
float RotationAngle ;
aiVector3D RotationAxis ;
std : : vector < int > Children ;
2009-09-28 16:53:33 +00:00
aiMatrix4x4 WorldToBoneSpace ;
2009-09-13 18:26:54 +00:00
///ctor
Bone ( ) : Id ( - 1 ) , ParentId ( - 1 ) , RotationAngle ( 0.0f ) { }
///this operator is needed to sort the bones after Id's
2009-09-21 17:41:57 +00:00
bool operator < ( const Bone & rval ) const
2009-09-13 18:26:54 +00:00
{ return Id < rval . Id ; }
///this operator is needed to find a bone by its name in a vector<Bone>
2009-09-21 17:41:57 +00:00
bool operator = = ( const std : : string & rval ) const
2009-09-13 18:26:54 +00:00
{ return Name = = rval ; }
2009-09-28 16:53:33 +00:00
void CalculateWorldToBoneSpaceMatrix ( std : : vector < Bone > & Bones ) ;
2009-09-13 18:26:54 +00:00
} ;
///Describes an Ogre Animation
struct Animation
{
std : : string Name ;
float Length ;
2009-09-17 19:05:46 +00:00
std : : vector < Track > Tracks ;
2009-09-13 18:26:54 +00:00
} ;
///a track (keyframes for one bone) from an animation
struct Track
{
2009-09-17 19:05:46 +00:00
std : : string BoneName ;
std : : vector < Keyframe > Keyframes ;
2009-09-13 18:26:54 +00:00
} ;
/// keyframe (bone transformation) from a track from a animation
struct Keyframe
{
2009-09-17 19:05:46 +00:00
float Time ;
aiVector3D Position ;
aiQuaternion Rotation ;
aiVector3D Scaling ;
2009-09-13 18:26:54 +00:00
} ;
2009-09-05 12:04:32 +00:00
} //namespace Ogre
} //namespace Assimp