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