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