rev |
line source |
nuclear@0
|
1 #include "BaseImporter.h"
|
nuclear@0
|
2
|
nuclear@0
|
3 #include <vector>
|
nuclear@0
|
4
|
nuclear@0
|
5 #include "OgreXmlHelper.hpp"
|
nuclear@0
|
6 #include "irrXMLWrapper.h"
|
nuclear@0
|
7
|
nuclear@0
|
8 /// Ogre Importer TODO
|
nuclear@0
|
9 /* - Read Vertex Colors
|
nuclear@0
|
10 - Read multiple TexCoords
|
nuclear@0
|
11 */
|
nuclear@0
|
12
|
nuclear@0
|
13
|
nuclear@0
|
14
|
nuclear@0
|
15 namespace Assimp
|
nuclear@0
|
16 {
|
nuclear@0
|
17 namespace Ogre
|
nuclear@0
|
18 {
|
nuclear@0
|
19
|
nuclear@0
|
20
|
nuclear@0
|
21 //Forward declarations:
|
nuclear@0
|
22 struct Face;
|
nuclear@0
|
23 struct Weight;
|
nuclear@0
|
24 struct Bone;
|
nuclear@0
|
25 struct Animation;
|
nuclear@0
|
26 struct Track;
|
nuclear@0
|
27 struct Keyframe;
|
nuclear@0
|
28
|
nuclear@0
|
29 ///A submesh from Ogre
|
nuclear@0
|
30 struct SubMesh
|
nuclear@0
|
31 {
|
nuclear@0
|
32 bool SharedData;
|
nuclear@0
|
33
|
nuclear@0
|
34 std::string Name;
|
nuclear@0
|
35 std::string MaterialName;
|
nuclear@0
|
36 std::vector<Face> FaceList;
|
nuclear@0
|
37
|
nuclear@0
|
38 std::vector<aiVector3D> Positions; bool HasPositions;
|
nuclear@0
|
39 std::vector<aiVector3D> Normals; bool HasNormals;
|
nuclear@0
|
40 std::vector<aiVector3D> Tangents; bool HasTangents;
|
nuclear@0
|
41 std::vector<std::vector<aiVector3D> > Uvs;//arbitrary number of texcoords, they are nearly always 2d, but assimp has always 3d texcoords, n vectors(outer) with texcoords for each vertex(inner)
|
nuclear@0
|
42
|
nuclear@0
|
43 std::vector< std::vector<Weight> > Weights;//a list(inner) of bones for each vertex(outer)
|
nuclear@0
|
44 int MaterialIndex;///< The Index in the Assimp Materialarray from the material witch is attached to this submesh
|
nuclear@0
|
45 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)
|
nuclear@0
|
46
|
nuclear@0
|
47 SubMesh(): SharedData(false), HasPositions(false), HasNormals(false), HasTangents(false),
|
nuclear@0
|
48 MaterialIndex(-1), BonesUsed(0) {}//initialize everything
|
nuclear@0
|
49 };
|
nuclear@0
|
50
|
nuclear@0
|
51
|
nuclear@0
|
52 ///The Main Ogre Importer Class
|
nuclear@0
|
53 class OgreImporter : public BaseImporter
|
nuclear@0
|
54 {
|
nuclear@0
|
55 public:
|
nuclear@0
|
56 virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
nuclear@0
|
57 virtual void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
nuclear@0
|
58 virtual const aiImporterDesc* GetInfo () const;
|
nuclear@0
|
59 virtual void SetupProperties(const Importer* pImp);
|
nuclear@0
|
60 private:
|
nuclear@0
|
61
|
nuclear@0
|
62
|
nuclear@0
|
63 //-------------------------------- OgreMesh.cpp -------------------------------
|
nuclear@0
|
64 /// Helper Functions to read parts of the XML File
|
nuclear@0
|
65 void ReadSubMesh(SubMesh& theSubMesh, XmlReader* Reader);//the submesh reference is the result value
|
nuclear@0
|
66
|
nuclear@0
|
67 /// Reads a single Vertexbuffer and writes its data in the Submesh
|
nuclear@0
|
68 static void ReadVertexBuffer(SubMesh &theSubMesh, XmlReader *Reader, unsigned int NumVertices);
|
nuclear@0
|
69
|
nuclear@0
|
70 /// Reads bone weights are stores them into the given submesh
|
nuclear@0
|
71 static void ReadBoneWeights(SubMesh &theSubMesh, XmlReader *Reader);
|
nuclear@0
|
72
|
nuclear@0
|
73 /// After Loading a SubMehs some work needs to be done (make all Vertexes unique, normalize weights)
|
nuclear@0
|
74 static void ProcessSubMesh(SubMesh &theSubMesh, SubMesh &theSharedGeometry);
|
nuclear@0
|
75
|
nuclear@0
|
76 /// Uses the bone data to convert a SubMesh into a aiMesh which will be created and returned
|
nuclear@0
|
77 aiMesh* CreateAssimpSubMesh(const SubMesh &theSubMesh, const std::vector<Bone>& Bones) const;
|
nuclear@0
|
78
|
nuclear@0
|
79
|
nuclear@0
|
80 //-------------------------------- OgreSkeleton.cpp -------------------------------
|
nuclear@0
|
81 /// Writes the results in Bones and Animations, Filename is not const, because its call-by-value and the function will change it!
|
nuclear@0
|
82 void LoadSkeleton(std::string FileName, std::vector<Bone> &Bones, std::vector<Animation> &Animations) const;
|
nuclear@0
|
83
|
nuclear@0
|
84 /// Converts the animations in aiAnimations and puts them into the scene
|
nuclear@0
|
85 void PutAnimationsInScene(const std::vector<Bone> &Bones, const std::vector<Animation> &Animations);
|
nuclear@0
|
86
|
nuclear@0
|
87 /// Creates the aiskeleton in current scene
|
nuclear@0
|
88 void CreateAssimpSkeleton(const std::vector<Bone> &Bones, const std::vector<Animation> &Animations);
|
nuclear@0
|
89
|
nuclear@0
|
90 /// Recursivly creates a filled aiNode from a given root bone
|
nuclear@0
|
91 static aiNode* CreateAiNodeFromBone(int BoneId, const std::vector<Bone> &Bones, aiNode* ParentNode);
|
nuclear@0
|
92
|
nuclear@0
|
93
|
nuclear@0
|
94 //-------------------------------- OgreMaterial.cpp -------------------------------
|
nuclear@0
|
95 aiMaterial* LoadMaterial(const std::string MaterialName) const;
|
nuclear@0
|
96 void ReadTechnique(std::stringstream &ss, aiMaterial* NewMaterial) const;
|
nuclear@0
|
97
|
nuclear@0
|
98
|
nuclear@0
|
99
|
nuclear@0
|
100
|
nuclear@0
|
101 //Now we don't have to give theses parameters to all functions
|
nuclear@0
|
102 std::string m_CurrentFilename;
|
nuclear@0
|
103 std::string m_MaterialLibFilename;
|
nuclear@0
|
104 bool m_TextureTypeFromFilename;
|
nuclear@0
|
105 IOSystem* m_CurrentIOHandler;
|
nuclear@0
|
106 aiScene *m_CurrentScene;
|
nuclear@0
|
107 SubMesh m_SharedGeometry;///< we will just use the vertexbuffers of the submesh
|
nuclear@0
|
108 };
|
nuclear@0
|
109
|
nuclear@0
|
110 ///For the moment just triangles, no other polygon types!
|
nuclear@0
|
111 struct Face
|
nuclear@0
|
112 {
|
nuclear@0
|
113 unsigned int VertexIndices[3];
|
nuclear@0
|
114 };
|
nuclear@0
|
115
|
nuclear@0
|
116 struct BoneAssignment
|
nuclear@0
|
117 {
|
nuclear@0
|
118 unsigned int BoneId;//this is, what we get from ogre
|
nuclear@0
|
119 std::string BoneName;//this is, what we need for assimp
|
nuclear@0
|
120 };
|
nuclear@0
|
121
|
nuclear@0
|
122 ///for a vertex->bone structur
|
nuclear@0
|
123 struct Weight
|
nuclear@0
|
124 {
|
nuclear@0
|
125 unsigned int BoneId;
|
nuclear@0
|
126 float Value;
|
nuclear@0
|
127 };
|
nuclear@0
|
128
|
nuclear@0
|
129
|
nuclear@0
|
130 /// Helper Class to describe an ogre-bone for the skeleton:
|
nuclear@0
|
131 /** 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!*/
|
nuclear@0
|
132 struct Bone
|
nuclear@0
|
133 {
|
nuclear@0
|
134 int Id;
|
nuclear@0
|
135 int ParentId;
|
nuclear@0
|
136 std::string Name;
|
nuclear@0
|
137 aiVector3D Position;
|
nuclear@0
|
138 float RotationAngle;
|
nuclear@0
|
139 aiVector3D RotationAxis;
|
nuclear@0
|
140 std::vector<int> Children;
|
nuclear@0
|
141 aiMatrix4x4 BoneToWorldSpace;
|
nuclear@0
|
142
|
nuclear@0
|
143 ///ctor
|
nuclear@0
|
144 Bone(): Id(-1), ParentId(-1), RotationAngle(0.0f) {}
|
nuclear@0
|
145 ///this operator is needed to sort the bones after Id's
|
nuclear@0
|
146 bool operator<(const Bone& rval) const
|
nuclear@0
|
147 {return Id<rval.Id; }
|
nuclear@0
|
148 ///this operator is needed to find a bone by its name in a vector<Bone>
|
nuclear@0
|
149 bool operator==(const std::string& rval) const
|
nuclear@0
|
150 {return Name==rval; }
|
nuclear@0
|
151 bool operator==(const aiString& rval) const
|
nuclear@0
|
152 {return Name==std::string(rval.data); }
|
nuclear@0
|
153
|
nuclear@0
|
154 // implemented in OgreSkeleton.cpp
|
nuclear@0
|
155 void CalculateBoneToWorldSpaceMatrix(std::vector<Bone>& Bones);
|
nuclear@0
|
156 };
|
nuclear@0
|
157
|
nuclear@0
|
158
|
nuclear@0
|
159
|
nuclear@0
|
160 ///Describes an Ogre Animation
|
nuclear@0
|
161 struct Animation
|
nuclear@0
|
162 {
|
nuclear@0
|
163 std::string Name;
|
nuclear@0
|
164 float Length;
|
nuclear@0
|
165 std::vector<Track> Tracks;
|
nuclear@0
|
166 };
|
nuclear@0
|
167
|
nuclear@0
|
168 ///a track (keyframes for one bone) from an animation
|
nuclear@0
|
169 struct Track
|
nuclear@0
|
170 {
|
nuclear@0
|
171 std::string BoneName;
|
nuclear@0
|
172 std::vector<Keyframe> Keyframes;
|
nuclear@0
|
173 };
|
nuclear@0
|
174
|
nuclear@0
|
175 /// keyframe (bone transformation) from a track from a animation
|
nuclear@0
|
176 struct Keyframe
|
nuclear@0
|
177 {
|
nuclear@0
|
178 float Time;
|
nuclear@0
|
179 aiVector3D Position;
|
nuclear@0
|
180 aiQuaternion Rotation;
|
nuclear@0
|
181 aiVector3D Scaling;
|
nuclear@0
|
182 };
|
nuclear@0
|
183
|
nuclear@0
|
184 }//namespace Ogre
|
nuclear@0
|
185 }//namespace Assimp
|