IRRShared.h 3.7 KB

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