Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef OBJ2SMS_H
- #define OBJ2SMS_H
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <rapidxml/rapidxml.hpp>
- #include <rapidxml/rapidxml_print.hpp>
- #include "SheqMath.h"
- using SheqTech::Vector2;
- using SheqTech::Vector3;
- using SheqTech::Vector4;
- enum MaterialFlags
- {
- BE_MF_HAS_DIFFUSE_MAP = 0x00000001,
- BE_MF_HAS_SPECULAR_MAP = 0x0000002,
- BE_MF_HAS_NORMAL_MAP = 0x00000004,
- BE_MF_HAS_AMBIENT_MAP = 0x00000008,
- BE_MF_HAS_ALPHA_MAP = 0x00000010
- };
- struct CacheEntry
- {
- unsigned int index;
- CacheEntry* next;
- };
- struct OBJMaterial
- {
- OBJMaterial(): name("Default"),
- illumModel(2),
- ambientFactor(Vector3(0.2f, 0.2f, 0.2f)),
- diffuseFactor(Vector3(0.3f, 0.3f, 0.3f)),
- specularFactor(Vector3(0.2f, 0.2f, 0.2f)),
- emissiveFactor(Vector3(0.0f, 0.0f, 0.0f)),
- shininess(0.0f),
- transparency(0.0f),
- hasDiffuseMap(false),
- hasSpecularMap(false),
- hasNormalMap(false),
- hasAlphaMap(false),
- hasAmbientMap(false)
- {}
- std::string name;
- int illumModel;
- Vector3 ambientFactor;
- Vector3 diffuseFactor;
- Vector3 specularFactor;
- Vector3 emissiveFactor;
- float shininess;
- float transparency;
- std::string ambientMap;
- std::string diffuseMap;
- std::string specularMap;
- std::string normalMap;
- std::string alphaMap;
- bool hasDiffuseMap;
- bool hasSpecularMap;
- bool hasNormalMap;
- bool hasAlphaMap;
- bool hasAmbientMap;
- };
- struct OBJVertex
- {
- Vector3 position;
- Vector4 tangent;
- Vector3 bitangent;
- Vector3 normal;
- Vector2 texCoord;
- };
- struct OBJFace
- {
- unsigned int position;
- unsigned int texCoord;
- unsigned int normal;
- };
- struct SMSMaterial
- {
- char name[128];
- int flags;
- Vector3 ambientFactor;
- Vector3 diffuseFactor;
- Vector3 specularFactor;
- Vector3 emissiveFactor;
- float shininess;
- float transparency;
- char ambientMap[128];
- char diffuseMap[128];
- char specularMap[128];
- char normalMap[128];
- char alphaMap[128];
- };
- struct SMSVertex
- {
- Vector3 position;
- Vector4 tangent;
- Vector3 normal;
- Vector2 texCoord;
- };
- struct Submesh
- {
- SMSMaterial* material;
- std::vector<OBJVertex> vertexData;
- std::vector<unsigned short> indexData;
- std::vector<CacheEntry*> vertexCache;
- };
- class OBJ2SMS
- {
- public:
- OBJ2SMS();
- ~OBJ2SMS();
- bool load(std::string filename);
- bool writeSMS(std::string filename);
- void writeMaterials();
- private:
- void loadMTL(std::string filename);
- void getDirectory(std::string filename);
- unsigned int addVertex(unsigned int subsetNumber, unsigned int hash, OBJVertex* vertex);
- void generateTangents();
- void deleteCache();
- private:
- std::string m_directoryPath;
- std::vector<Vector3> m_vertexList;
- std::vector<Vector2> m_texCoordList;
- std::vector<Vector3> m_normalList;
- std::vector<OBJMaterial> m_materialLibrary;
- Submesh* m_submeshes;
- unsigned int m_submeshCount;
- };
- #endif // OBJ2SMS_H
Advertisement
Add Comment
Please, Sign In to add comment