/src/assimp/code/AssetLib/NFF/NFFLoader.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2025, 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 | | #pragma once |
46 | | #ifndef AI_NFFLOADER_H_INCLUDED |
47 | | #define AI_NFFLOADER_H_INCLUDED |
48 | | |
49 | | #include <assimp/BaseImporter.h> |
50 | | #include <assimp/material.h> |
51 | | #include <assimp/types.h> |
52 | | #include <vector> |
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 | | public: |
65 | 1.50k | NFFImporter() = default; |
66 | | ~NFFImporter() override = default; |
67 | | |
68 | | // ------------------------------------------------------------------- |
69 | | /** Returns whether the class can handle the format of the given file. |
70 | | * See BaseImporter::CanRead() for details. |
71 | | */ |
72 | | bool CanRead(const std::string &pFile, IOSystem *pIOHandler, |
73 | | bool checkSig) const override; |
74 | | |
75 | | protected: |
76 | | // ------------------------------------------------------------------- |
77 | | /** Return importer meta information. |
78 | | * See #BaseImporter::GetInfo for the details |
79 | | */ |
80 | | const aiImporterDesc *GetInfo() const override; |
81 | | |
82 | | // ------------------------------------------------------------------- |
83 | | /** Imports the given file into the given scene structure. |
84 | | * See BaseImporter::InternReadFile() for details |
85 | | */ |
86 | | void InternReadFile(const std::string &pFile, aiScene *pScene, |
87 | | IOSystem *pIOHandler) override; |
88 | | |
89 | | private: |
90 | | // describes face material properties |
91 | | struct ShadingInfo { |
92 | | ShadingInfo() : |
93 | 132 | color(0.6f, 0.6f, 0.6f), |
94 | 132 | diffuse(1.f, 1.f, 1.f), |
95 | 132 | specular(1.f, 1.f, 1.f), |
96 | 132 | ambient(0.f, 0.f, 0.f), |
97 | 132 | emissive(0.f, 0.f, 0.f), |
98 | 132 | refracti(1.f), |
99 | 132 | twoSided(false), // for NFF2 |
100 | 132 | shaded(true), // for NFF2 |
101 | 132 | opacity(1.f), |
102 | 132 | shininess(0.f), |
103 | 132 | mapping(aiTextureMapping_UV) { |
104 | | // empty |
105 | 132 | } |
106 | | |
107 | | aiColor3D color, diffuse, specular, ambient, emissive; |
108 | | ai_real refracti; |
109 | | std::string texFile; |
110 | | bool twoSided; // For NFF2 |
111 | | bool shaded; |
112 | | ai_real opacity, shininess; |
113 | | std::string name; |
114 | | |
115 | | // texture mapping to be generated for the mesh - uv is the default |
116 | | // it means: use UV if there, nothing otherwise. This property is |
117 | | // used for locked meshes. |
118 | | aiTextureMapping mapping; |
119 | | |
120 | | // shininess is ignored for the moment |
121 | 24 | bool operator == (const ShadingInfo &other) const { |
122 | 24 | return color == other.color && |
123 | 24 | diffuse == other.diffuse && |
124 | 24 | specular == other.specular && |
125 | 24 | ambient == other.ambient && |
126 | 24 | refracti == other.refracti && |
127 | 24 | texFile == other.texFile && |
128 | 24 | twoSided == other.twoSided && |
129 | 24 | shaded == other.shaded; |
130 | | |
131 | | // Some properties from NFF2 aren't compared by this operator. |
132 | | // Comparing MeshInfo::matIndex should do that. |
133 | 24 | } |
134 | | }; |
135 | | |
136 | | // describes a NFF light source |
137 | | struct Light { |
138 | | Light() : |
139 | 703 | intensity(1.f), color(1.f, 1.f, 1.f) {} |
140 | | |
141 | | aiVector3D position; |
142 | | ai_real intensity; |
143 | | aiColor3D color; |
144 | | }; |
145 | | |
146 | | enum PatchType { |
147 | | PatchType_Simple = 0x0, |
148 | | PatchType_Normals = 0x1, |
149 | | PatchType_UVAndNormals = 0x2 |
150 | | }; |
151 | | |
152 | | // describes a NFF mesh |
153 | | struct MeshInfo { |
154 | | MeshInfo(PatchType _pType, bool bL = false) : |
155 | 106 | pType(_pType), bLocked(bL), radius(1.f, 1.f, 1.f), dir(0.f, 1.f, 0.f), matIndex(0) { |
156 | 106 | name[0] = '\0'; // by default meshes are unnamed |
157 | 106 | } |
158 | | |
159 | | ShadingInfo shader; |
160 | | PatchType pType; |
161 | | bool bLocked; |
162 | | |
163 | | // for spheres, cones and cylinders: center point of the object |
164 | | aiVector3D center, radius, dir; |
165 | | static const size_t MaxNameLen = 128; |
166 | | char name[MaxNameLen]; |
167 | | |
168 | | std::vector<aiVector3D> vertices, normals, uvs; |
169 | | std::vector<unsigned int> faces; |
170 | | |
171 | | // for NFF2 |
172 | | std::vector<aiColor4D> colors; |
173 | | unsigned int matIndex; |
174 | | }; |
175 | | |
176 | | // ------------------------------------------------------------------- |
177 | | /** Loads the material table for the NFF2 file format from an |
178 | | * external file. |
179 | | * |
180 | | * @param output Receives the list of output meshes |
181 | | * @param path Path to the file (abs. or rel.) |
182 | | * @param pIOHandler IOSystem to be used to open the file |
183 | | */ |
184 | | void LoadNFF2MaterialTable(std::vector<ShadingInfo> &output, |
185 | | const std::string &path, IOSystem *pIOHandler); |
186 | | }; |
187 | | |
188 | | } // end of namespace Assimp |
189 | | |
190 | | #endif // AI_NFFIMPORTER_H_IN |