IRRShared.h 3.7 KB

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