IRRShared.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // Urho3D: VS2008 compatibility
  9. #if !defined(_MSC_VER) || (_MSC_VER >= 1600)
  10. #include <stdint.h>
  11. #else
  12. #include "../include/assimp/Compiler/pstdint.h"
  13. #endif
  14. struct aiMaterial;
  15. namespace Assimp {
  16. /** @brief Matrix to convert from Assimp to IRR and backwards
  17. */
  18. extern const aiMatrix4x4 AI_TO_IRR_MATRIX;
  19. // Default: 0 = solid, one texture
  20. #define AI_IRRMESH_MAT_solid_2layer 0x10000
  21. // Transparency flags
  22. #define AI_IRRMESH_MAT_trans_vertex_alpha 0x1
  23. #define AI_IRRMESH_MAT_trans_add 0x2
  24. // Lightmapping flags
  25. #define AI_IRRMESH_MAT_lightmap 0x2
  26. #define AI_IRRMESH_MAT_lightmap_m2 (AI_IRRMESH_MAT_lightmap|0x4)
  27. #define AI_IRRMESH_MAT_lightmap_m4 (AI_IRRMESH_MAT_lightmap|0x8)
  28. #define AI_IRRMESH_MAT_lightmap_light (AI_IRRMESH_MAT_lightmap|0x10)
  29. #define AI_IRRMESH_MAT_lightmap_light_m2 (AI_IRRMESH_MAT_lightmap|0x20)
  30. #define AI_IRRMESH_MAT_lightmap_light_m4 (AI_IRRMESH_MAT_lightmap|0x40)
  31. #define AI_IRRMESH_MAT_lightmap_add (AI_IRRMESH_MAT_lightmap|0x80)
  32. // Standard NormalMap (or Parallax map, they're treated equally)
  33. #define AI_IRRMESH_MAT_normalmap_solid (0x100)
  34. // Normal map combined with vertex alpha
  35. #define AI_IRRMESH_MAT_normalmap_tva \
  36. (AI_IRRMESH_MAT_normalmap_solid | AI_IRRMESH_MAT_trans_vertex_alpha)
  37. // Normal map combined with additive transparency
  38. #define AI_IRRMESH_MAT_normalmap_ta \
  39. (AI_IRRMESH_MAT_normalmap_solid | AI_IRRMESH_MAT_trans_add)
  40. // Special flag. It indicates a second texture has been found
  41. // Its type depends ... either a normal textue or a normal map
  42. #define AI_IRRMESH_EXTRA_2ND_TEXTURE 0x100000
  43. // ---------------------------------------------------------------------------
  44. /** Base class for the Irr and IrrMesh importers.
  45. *
  46. * Declares some irrlight-related xml parsing utilities and provides tools
  47. * to load materials from IRR and IRRMESH files.
  48. */
  49. class IrrlichtBase
  50. {
  51. protected:
  52. /** @brief Data structure for a simple name-value property
  53. */
  54. template <class T>
  55. struct Property
  56. {
  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. */
  68. irr::io::IrrXMLReader* reader;
  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 Recives 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. {
  90. clr.a = ((in >> 24) & 0xff) / 255.f;
  91. clr.r = ((in >> 16) & 0xff) / 255.f;
  92. clr.g = ((in >> 8) & 0xff) / 255.f;
  93. clr.b = ((in ) & 0xff) / 255.f;
  94. }
  95. } // end namespace Assimp
  96. #endif // !! INCLUDED_AI_IRRSHARED_H