1 2 3 /** @file IRRShared.h 4 * @brief Shared utilities for the IRR and IRRMESH loaders 5 */ 6 7 #ifndef INCLUDED_AI_IRRSHARED_H 8 #define INCLUDED_AI_IRRSHARED_H 9 10 #include <assimp/BaseImporter.h> 11 #include <assimp/XmlParser.h> 12 #include <cstdint> 13 14 struct aiMaterial; 15 16 namespace Assimp { 17 18 /** @brief Matrix to convert from Assimp to IRR and backwards 19 */ 20 extern const aiMatrix4x4 AI_TO_IRR_MATRIX; 21 22 // Default: 0 = solid, one texture 23 #define AI_IRRMESH_MAT_solid_2layer 0x10000 24 25 // Transparency flags 26 #define AI_IRRMESH_MAT_trans_vertex_alpha 0x1 27 #define AI_IRRMESH_MAT_trans_add 0x2 28 29 // Lightmapping flags 30 #define AI_IRRMESH_MAT_lightmap 0x2 31 #define AI_IRRMESH_MAT_lightmap_m2 (AI_IRRMESH_MAT_lightmap | 0x4) 32 #define AI_IRRMESH_MAT_lightmap_m4 (AI_IRRMESH_MAT_lightmap | 0x8) 33 #define AI_IRRMESH_MAT_lightmap_light (AI_IRRMESH_MAT_lightmap | 0x10) 34 #define AI_IRRMESH_MAT_lightmap_light_m2 (AI_IRRMESH_MAT_lightmap | 0x20) 35 #define AI_IRRMESH_MAT_lightmap_light_m4 (AI_IRRMESH_MAT_lightmap | 0x40) 36 #define AI_IRRMESH_MAT_lightmap_add (AI_IRRMESH_MAT_lightmap | 0x80) 37 38 // Standard NormalMap (or Parallax map, they're treated equally) 39 #define AI_IRRMESH_MAT_normalmap_solid (0x100) 40 41 // Normal map combined with vertex alpha 42 #define AI_IRRMESH_MAT_normalmap_tva \ 43 (AI_IRRMESH_MAT_normalmap_solid | AI_IRRMESH_MAT_trans_vertex_alpha) 44 45 // Normal map combined with additive transparency 46 #define AI_IRRMESH_MAT_normalmap_ta \ 47 (AI_IRRMESH_MAT_normalmap_solid | AI_IRRMESH_MAT_trans_add) 48 49 // Special flag. It indicates a second texture has been found 50 // Its type depends ... either a normal textue or a normal map 51 #define AI_IRRMESH_EXTRA_2ND_TEXTURE 0x100000 52 53 // --------------------------------------------------------------------------- 54 /** Base class for the Irr and IrrMesh importers. 55 * 56 * Declares some irrlight-related xml parsing utilities and provides tools 57 * to load materials from IRR and IRRMESH files. 58 */ 59 class IrrlichtBase { 60 protected: IrrlichtBase()61 IrrlichtBase() : 62 mNode(nullptr) { 63 // empty 64 } 65 ~IrrlichtBase()66 ~IrrlichtBase() { 67 // empty 68 } 69 70 /** @brief Data structure for a simple name-value property 71 */ 72 template <class T> 73 struct Property { 74 std::string name; 75 T value; 76 }; 77 78 typedef Property<uint32_t> HexProperty; 79 typedef Property<std::string> StringProperty; 80 typedef Property<bool> BoolProperty; 81 typedef Property<float> FloatProperty; 82 typedef Property<aiVector3D> VectorProperty; 83 typedef Property<int> IntProperty; 84 85 /// XML reader instance 86 XmlParser mParser; 87 pugi::xml_node *mNode; 88 89 // ------------------------------------------------------------------- 90 /** Parse a material description from the XML 91 * @return The created material 92 * @param matFlags Receives AI_IRRMESH_MAT_XX flags 93 */ 94 aiMaterial *ParseMaterial(unsigned int &matFlags); 95 96 // ------------------------------------------------------------------- 97 /** Read a property of the specified type from the current XML element. 98 * @param out Receives output data 99 */ 100 void ReadHexProperty(HexProperty &out); 101 void ReadStringProperty(StringProperty &out); 102 void ReadBoolProperty(BoolProperty &out); 103 void ReadFloatProperty(FloatProperty &out); 104 void ReadVectorProperty(VectorProperty &out); 105 void ReadIntProperty(IntProperty &out); 106 }; 107 108 // ------------------------------------------------------------------------------------------------ 109 // Unpack a hex color, e.g. 0xdcdedfff ColorFromARGBPacked(uint32_t in,aiColor4D & clr)110inline void ColorFromARGBPacked(uint32_t in, aiColor4D &clr) { 111 clr.a = ((in >> 24) & 0xff) / 255.f; 112 clr.r = ((in >> 16) & 0xff) / 255.f; 113 clr.g = ((in >> 8) & 0xff) / 255.f; 114 clr.b = ((in)&0xff) / 255.f; 115 } 116 117 } // end namespace Assimp 118 119 #endif // !! INCLUDED_AI_IRRSHARED_H 120