IRRShared.h 3.6 KB

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