| 1 | #ifndef __EXPORTER_H__ |
|---|
| 2 | #define __EXPORTER_H__ |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | #include "stdafx.h" |
|---|
| 6 | #include "SemanticLayer.h" |
|---|
| 7 | #include "OgrePrerequisites.h" |
|---|
| 8 | #include "OgreVector2.h" |
|---|
| 9 | #include "OgreVector3.h" |
|---|
| 10 | #include "OgreVector3.h" |
|---|
| 11 | #include "OgreColourValue.h" |
|---|
| 12 | #include "OgreMesh.h" |
|---|
| 13 | |
|---|
| 14 | using namespace Ogre; |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | /* Class for performing a mesh and skeleton export from dotXSI */ |
|---|
| 18 | |
|---|
| 19 | class Exporter { |
|---|
| 20 | public: |
|---|
| 21 | /* Constructor to initialize .XSI scene data */ |
|---|
| 22 | Exporter(CSLModel* Root); |
|---|
| 23 | virtual ~Exporter(); |
|---|
| 24 | /* Function to perform an export to Ogre .mesh. */ |
|---|
| 25 | void exportMesh(std::string fileName, std::string skelName); |
|---|
| 26 | /* Function to perform an export to Ogre .skeleton. */ |
|---|
| 27 | void exportBones(std::string fileName); |
|---|
| 28 | |
|---|
| 29 | protected: |
|---|
| 30 | /* Internal recursive method for exporting a node in the scene */ |
|---|
| 31 | void exportCSLModel(Ogre::Mesh* pMesh, CSLModel* XSIModel); |
|---|
| 32 | /* Export a submesh from the attached information */ |
|---|
| 33 | void exportSubMesh(Ogre::Mesh* pMesh, CSLMesh* XSIMesh); |
|---|
| 34 | /* Recursive routine to traverse bone hierarchy tree */ |
|---|
| 35 | void recurseBones(Skeleton* pSkel, CSLModel* XSIModel); |
|---|
| 36 | /* Exports animation tracks */ |
|---|
| 37 | void exportAnim(Skeleton* pSkel, CSLModel* XSIModel); |
|---|
| 38 | |
|---|
| 39 | /* XSI Scene */ |
|---|
| 40 | CSLModel* SceneRoot; |
|---|
| 41 | int boneCount; |
|---|
| 42 | std::string boneArray[OGRE_MAX_NUM_BONES]; |
|---|
| 43 | bool root; |
|---|
| 44 | |
|---|
| 45 | /* This class represents a unique vertex, identified from a unique combination of components. */ |
|---|
| 46 | |
|---|
| 47 | class UniqueVertex { |
|---|
| 48 | public: |
|---|
| 49 | bool initialized; |
|---|
| 50 | Ogre::Vector3 position; |
|---|
| 51 | Ogre::Vector3 normal; |
|---|
| 52 | Ogre::Vector2 uv[OGRE_MAX_TEXTURE_COORD_SETS]; |
|---|
| 53 | Ogre::RGBA color; |
|---|
| 54 | /* The index of the next component with the same base details, but some variation. */ |
|---|
| 55 | size_t nextIndex; |
|---|
| 56 | UniqueVertex(); |
|---|
| 57 | bool operator==(const UniqueVertex& rhs) const; |
|---|
| 58 | }; |
|---|
| 59 | |
|---|
| 60 | typedef std::vector<UniqueVertex> UniqueVertexList; |
|---|
| 61 | // Unique vertex list |
|---|
| 62 | UniqueVertexList mUniqueVertices; |
|---|
| 63 | // Dynamic index list |
|---|
| 64 | typedef std::vector<size_t> IndexList; |
|---|
| 65 | IndexList mIndices; |
|---|
| 66 | |
|---|
| 67 | /* Function to start processing a polygon mesh. */ |
|---|
| 68 | void startPolygonMesh(size_t origPositionCount, size_t indexCount); |
|---|
| 69 | /* Try to look up an existing vertex with the same information, or create new one. */ |
|---|
| 70 | size_t createOrRetrieveUniqueVertex(size_t originalPositionIndex, const UniqueVertex& vertex); |
|---|
| 71 | /* Templatized method for writing indexes */ |
|---|
| 72 | template <typename T> void writeIndexes(T* buf); |
|---|
| 73 | /* Create and fill a vertex buffer */ |
|---|
| 74 | void createVertexBuffer(VertexData* vd, unsigned short bufIdx); |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | #endif |
|---|