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