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