vrshoot
diff libs/assimp/NFFLoader.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/NFFLoader.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,212 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file NFFLoader.h 1.45 + * @brief Declaration of the NFF importer class. 1.46 + */ 1.47 +#ifndef AI_NFFLOADER_H_INCLUDED 1.48 +#define AI_NFFLOADER_H_INCLUDED 1.49 + 1.50 +#include "BaseImporter.h" 1.51 +#include <vector> 1.52 + 1.53 +#include "assimp/types.h" 1.54 + 1.55 +namespace Assimp { 1.56 + 1.57 +// ---------------------------------------------------------------------------------- 1.58 +/** NFF (Neutral File Format) Importer class. 1.59 + * 1.60 + * The class implements both Eric Haynes NFF format and Sense8's NFF (NFF2) format. 1.61 + * Both are quite different and the loading code is somewhat dirty at 1.62 + * the moment. Sense8 should be moved to a separate loader. 1.63 +*/ 1.64 +class NFFImporter : public BaseImporter 1.65 +{ 1.66 +public: 1.67 + NFFImporter(); 1.68 + ~NFFImporter(); 1.69 + 1.70 + 1.71 +public: 1.72 + 1.73 + // ------------------------------------------------------------------- 1.74 + /** Returns whether the class can handle the format of the given file. 1.75 + * See BaseImporter::CanRead() for details. 1.76 + */ 1.77 + bool CanRead( const std::string& pFile, IOSystem* pIOHandler, 1.78 + bool checkSig) const; 1.79 + 1.80 +protected: 1.81 + 1.82 + // ------------------------------------------------------------------- 1.83 + /** Return importer meta information. 1.84 + * See #BaseImporter::GetInfo for the details 1.85 + */ 1.86 + const aiImporterDesc* GetInfo () const; 1.87 + 1.88 + // ------------------------------------------------------------------- 1.89 + /** Imports the given file into the given scene structure. 1.90 + * See BaseImporter::InternReadFile() for details 1.91 + */ 1.92 + void InternReadFile( const std::string& pFile, aiScene* pScene, 1.93 + IOSystem* pIOHandler); 1.94 + 1.95 +private: 1.96 + 1.97 + 1.98 + // describes face material properties 1.99 + struct ShadingInfo 1.100 + { 1.101 + ShadingInfo() 1.102 + : color (0.6f,0.6f,0.6f) 1.103 + , diffuse (1.f,1.f,1.f) 1.104 + , specular (1.f,1.f,1.f) 1.105 + , ambient (0.f,0.f,0.f) 1.106 + , emissive (0.f,0.f,0.f) 1.107 + , refracti (1.f) 1.108 + , twoSided (false) // for NFF2 1.109 + , shaded (true) // for NFF2 1.110 + , opacity (1.f) 1.111 + , shininess (0.f) 1.112 + , mapping (aiTextureMapping_UV) 1.113 + {} 1.114 + 1.115 + aiColor3D color,diffuse,specular,ambient,emissive; 1.116 + float refracti; 1.117 + 1.118 + std::string texFile; 1.119 + 1.120 + // For NFF2 1.121 + bool twoSided; 1.122 + bool shaded; 1.123 + float opacity, shininess; 1.124 + 1.125 + std::string name; 1.126 + 1.127 + // texture mapping to be generated for the mesh - uv is the default 1.128 + // it means: use UV if there, nothing otherwise. This property is 1.129 + // used for locked meshes. 1.130 + aiTextureMapping mapping; 1.131 + 1.132 + // shininess is ignored for the moment 1.133 + bool operator == (const ShadingInfo& other) const 1.134 + { 1.135 + return color == other.color && 1.136 + diffuse == other.diffuse && 1.137 + specular == other.specular && 1.138 + ambient == other.ambient && 1.139 + refracti == other.refracti && 1.140 + texFile == other.texFile && 1.141 + twoSided == other.twoSided && 1.142 + shaded == other.shaded; 1.143 + 1.144 + // Some properties from NFF2 aren't compared by this operator. 1.145 + // Comparing MeshInfo::matIndex should do that. 1.146 + } 1.147 + }; 1.148 + 1.149 + // describes a NFF light source 1.150 + struct Light 1.151 + { 1.152 + Light() 1.153 + : intensity (1.f) 1.154 + , color (1.f,1.f,1.f) 1.155 + {} 1.156 + 1.157 + aiVector3D position; 1.158 + float intensity; 1.159 + aiColor3D color; 1.160 + }; 1.161 + 1.162 + enum PatchType 1.163 + { 1.164 + PatchType_Simple = 0x0, 1.165 + PatchType_Normals = 0x1, 1.166 + PatchType_UVAndNormals = 0x2 1.167 + }; 1.168 + 1.169 + // describes a NFF mesh 1.170 + struct MeshInfo 1.171 + { 1.172 + MeshInfo(PatchType _pType, bool bL = false) 1.173 + : pType (_pType) 1.174 + , bLocked (bL) 1.175 + , radius (1.f,1.f,1.f) 1.176 + , dir (0.f,1.f,0.f) 1.177 + , matIndex (0) 1.178 + { 1.179 + name[0] = '\0'; // by default meshes are unnamed 1.180 + } 1.181 + 1.182 + ShadingInfo shader; 1.183 + PatchType pType; 1.184 + bool bLocked; 1.185 + 1.186 + // for spheres, cones and cylinders: center point of the object 1.187 + aiVector3D center, radius, dir; 1.188 + 1.189 + char name[128]; 1.190 + 1.191 + std::vector<aiVector3D> vertices, normals, uvs; 1.192 + std::vector<unsigned int> faces; 1.193 + 1.194 + // for NFF2 1.195 + std::vector<aiColor4D> colors; 1.196 + unsigned int matIndex; 1.197 + }; 1.198 + 1.199 + 1.200 + // ------------------------------------------------------------------- 1.201 + /** Loads the material table for the NFF2 file format from an 1.202 + * external file. 1.203 + * 1.204 + * @param output Receives the list of output meshes 1.205 + * @param path Path to the file (abs. or rel.) 1.206 + * @param pIOHandler IOSystem to be used to open the file 1.207 + */ 1.208 + void LoadNFF2MaterialTable(std::vector<ShadingInfo>& output, 1.209 + const std::string& path, IOSystem* pIOHandler); 1.210 + 1.211 +}; 1.212 + 1.213 +} // end of namespace Assimp 1.214 + 1.215 +#endif // AI_NFFIMPORTER_H_IN