1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2017, assimp team |
6 | |
7 | All rights reserved. |
8 | |
9 | Redistribution and use of this software in source and binary forms, |
10 | with or without modification, are permitted provided that the |
11 | following conditions are met: |
12 | |
13 | * Redistributions of source code must retain the above |
14 | copyright notice, this list of conditions and the |
15 | following disclaimer. |
16 | |
17 | * Redistributions in binary form must reproduce the above |
18 | copyright notice, this list of conditions and the |
19 | following disclaimer in the documentation and/or other |
20 | materials provided with the distribution. |
21 | |
22 | * Neither the name of the assimp team, nor the names of its |
23 | contributors may be used to endorse or promote products |
24 | derived from this software without specific prior |
25 | written permission of the assimp team. |
26 | |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | |
39 | ---------------------------------------------------------------------- |
40 | */ |
41 | |
42 | /** @file NFFLoader.h |
43 | * @brief Declaration of the NFF importer class. |
44 | */ |
45 | #ifndef AI_NFFLOADER_H_INCLUDED |
46 | #define AI_NFFLOADER_H_INCLUDED |
47 | |
48 | #include "BaseImporter.h" |
49 | #include <assimp/types.h> |
50 | #include <assimp/material.h> |
51 | #include <vector> |
52 | |
53 | |
54 | namespace Assimp { |
55 | |
56 | // ---------------------------------------------------------------------------------- |
57 | /** NFF (Neutral File Format) Importer class. |
58 | * |
59 | * The class implements both Eric Haynes NFF format and Sense8's NFF (NFF2) format. |
60 | * Both are quite different and the loading code is somewhat dirty at |
61 | * the moment. Sense8 should be moved to a separate loader. |
62 | */ |
63 | class NFFImporter : public BaseImporter |
64 | { |
65 | public: |
66 | NFFImporter(); |
67 | ~NFFImporter(); |
68 | |
69 | |
70 | public: |
71 | |
72 | // ------------------------------------------------------------------- |
73 | /** Returns whether the class can handle the format of the given file. |
74 | * See BaseImporter::CanRead() for details. |
75 | */ |
76 | bool CanRead( const std::string& pFile, IOSystem* pIOHandler, |
77 | bool checkSig) const; |
78 | |
79 | protected: |
80 | |
81 | // ------------------------------------------------------------------- |
82 | /** Return importer meta information. |
83 | * See #BaseImporter::GetInfo for the details |
84 | */ |
85 | const aiImporterDesc* GetInfo () const; |
86 | |
87 | // ------------------------------------------------------------------- |
88 | /** Imports the given file into the given scene structure. |
89 | * See BaseImporter::InternReadFile() for details |
90 | */ |
91 | void InternReadFile( const std::string& pFile, aiScene* pScene, |
92 | IOSystem* pIOHandler); |
93 | |
94 | private: |
95 | |
96 | |
97 | // describes face material properties |
98 | struct ShadingInfo |
99 | { |
100 | ShadingInfo() |
101 | : color (0.6f,0.6f,0.6f) |
102 | , diffuse (1.f,1.f,1.f) |
103 | , specular (1.f,1.f,1.f) |
104 | , ambient (0.f,0.f,0.f) |
105 | , emissive (0.f,0.f,0.f) |
106 | , refracti (1.f) |
107 | , twoSided (false) // for NFF2 |
108 | , shaded (true) // for NFF2 |
109 | , opacity (1.f) |
110 | , shininess (0.f) |
111 | , mapping (aiTextureMapping_UV) |
112 | {} |
113 | |
114 | aiColor3D color,diffuse,specular,ambient,emissive; |
115 | float refracti; |
116 | |
117 | std::string texFile; |
118 | |
119 | // For NFF2 |
120 | bool twoSided; |
121 | bool shaded; |
122 | float opacity, shininess; |
123 | |
124 | std::string name; |
125 | |
126 | // texture mapping to be generated for the mesh - uv is the default |
127 | // it means: use UV if there, nothing otherwise. This property is |
128 | // used for locked meshes. |
129 | aiTextureMapping mapping; |
130 | |
131 | // shininess is ignored for the moment |
132 | bool operator == (const ShadingInfo& other) const |
133 | { |
134 | return color == other.color && |
135 | diffuse == other.diffuse && |
136 | specular == other.specular && |
137 | ambient == other.ambient && |
138 | refracti == other.refracti && |
139 | texFile == other.texFile && |
140 | twoSided == other.twoSided && |
141 | shaded == other.shaded; |
142 | |
143 | // Some properties from NFF2 aren't compared by this operator. |
144 | // Comparing MeshInfo::matIndex should do that. |
145 | } |
146 | }; |
147 | |
148 | // describes a NFF light source |
149 | struct Light |
150 | { |
151 | Light() |
152 | : intensity (1.f) |
153 | , color (1.f,1.f,1.f) |
154 | {} |
155 | |
156 | aiVector3D position; |
157 | float intensity; |
158 | aiColor3D color; |
159 | }; |
160 | |
161 | enum PatchType |
162 | { |
163 | PatchType_Simple = 0x0, |
164 | PatchType_Normals = 0x1, |
165 | PatchType_UVAndNormals = 0x2 |
166 | }; |
167 | |
168 | // describes a NFF mesh |
169 | struct MeshInfo |
170 | { |
171 | MeshInfo(PatchType _pType, bool bL = false) |
172 | : pType (_pType) |
173 | , bLocked (bL) |
174 | , radius (1.f,1.f,1.f) |
175 | , dir (0.f,1.f,0.f) |
176 | , matIndex (0) |
177 | { |
178 | name[0] = '\0'; // by default meshes are unnamed |
179 | } |
180 | |
181 | ShadingInfo shader; |
182 | PatchType pType; |
183 | bool bLocked; |
184 | |
185 | // for spheres, cones and cylinders: center point of the object |
186 | aiVector3D center, radius, dir; |
187 | |
188 | char name[128]; |
189 | |
190 | std::vector<aiVector3D> vertices, normals, uvs; |
191 | std::vector<unsigned int> faces; |
192 | |
193 | // for NFF2 |
194 | std::vector<aiColor4D> colors; |
195 | unsigned int matIndex; |
196 | }; |
197 | |
198 | |
199 | // ------------------------------------------------------------------- |
200 | /** Loads the material table for the NFF2 file format from an |
201 | * external file. |
202 | * |
203 | * @param output Receives the list of output meshes |
204 | * @param path Path to the file (abs. or rel.) |
205 | * @param pIOHandler IOSystem to be used to open the file |
206 | */ |
207 | void LoadNFF2MaterialTable(std::vector<ShadingInfo>& output, |
208 | const std::string& path, IOSystem* pIOHandler); |
209 | |
210 | }; |
211 | |
212 | } // end of namespace Assimp |
213 | |
214 | #endif // AI_NFFIMPORTER_H_IN |
215 | |