IRRShared.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <cstdint>
  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. // empty
  48. }
  49. ~IrrlichtBase() = default;
  50. /** @brief Data structure for a simple name-value property
  51. */
  52. template <class T>
  53. struct Property {
  54. std::string name;
  55. T value;
  56. };
  57. typedef Property<uint32_t> HexProperty;
  58. typedef Property<std::string> StringProperty;
  59. typedef Property<bool> BoolProperty;
  60. typedef Property<float> FloatProperty;
  61. typedef Property<aiVector3D> VectorProperty;
  62. typedef Property<int> IntProperty;
  63. /// XML reader instance
  64. XmlParser mParser;
  65. // -------------------------------------------------------------------
  66. /** Parse a material description from the XML
  67. * @return The created material
  68. * @param matFlags Receives AI_IRRMESH_MAT_XX flags
  69. */
  70. aiMaterial *ParseMaterial(pugi::xml_node &materialNode, unsigned int &matFlags);
  71. // -------------------------------------------------------------------
  72. /** Read a property of the specified type from the current XML element.
  73. * @param out Receives output data
  74. * @param node XML attribute element containing data
  75. */
  76. void ReadHexProperty(HexProperty &out, pugi::xml_node& hexnode);
  77. void ReadStringProperty(StringProperty &out, pugi::xml_node& stringnode);
  78. void ReadBoolProperty(BoolProperty &out, pugi::xml_node& boolnode);
  79. void ReadFloatProperty(FloatProperty &out, pugi::xml_node& floatnode);
  80. void ReadVectorProperty(VectorProperty &out, pugi::xml_node& vectornode);
  81. void ReadIntProperty(IntProperty &out, pugi::xml_node& intnode);
  82. };
  83. // ------------------------------------------------------------------------------------------------
  84. // Unpack a hex color, e.g. 0xdcdedfff
  85. inline void ColorFromARGBPacked(uint32_t in, aiColor4D &clr) {
  86. clr.a = ((in >> 24) & 0xff) / 255.f;
  87. clr.r = ((in >> 16) & 0xff) / 255.f;
  88. clr.g = ((in >> 8) & 0xff) / 255.f;
  89. clr.b = ((in)&0xff) / 255.f;
  90. }
  91. } // end namespace Assimp
  92. #endif // !! INCLUDED_AI_IRRSHARED_H