IRRShared.h 3.9 KB

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