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