1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41
42/** @file LWSLoader.h
43 * @brief Declaration of the LightWave scene importer class.
44 */
45#ifndef AI_LWSLOADER_H_INCLUDED
46#define AI_LWSLOADER_H_INCLUDED
47
48#include "LWOFileData.h"
49#include <assimp/SceneCombiner.h>
50#include "BaseImporter.h"
51
52struct aiImporterDesc;
53
54namespace Assimp {
55 class BatchLoader;
56 class Importer;
57 class IOSystem;
58
59 namespace LWS {
60
61// ---------------------------------------------------------------------------
62/** Represents an element in a LWS file.
63 *
64 * This can either be a single data line - <name> <value> or a data
65 * group - { name <data_line0> ... n }
66 */
67class Element
68{
69public:
70 Element()
71 {}
72
73 // first: name, second: rest
74 std::string tokens[2];
75 std::list<Element> children;
76
77 //! Recursive parsing function
78 void Parse (const char*& buffer);
79};
80
81#define AI_LWS_MASK (0xffffffff >> 4u)
82
83// ---------------------------------------------------------------------------
84/** Represents a LWS scenegraph element
85 */
86struct NodeDesc
87{
88 NodeDesc()
89 : type()
90 , id()
91 , number (0)
92 , parent (0)
93 , name ("")
94 , isPivotSet (false)
95 , lightColor (1.f,1.f,1.f)
96 , lightIntensity (1.f)
97 , lightType (0)
98 , lightFalloffType (0)
99 , lightConeAngle (45.f)
100 , lightEdgeAngle()
101 , parent_resolved (NULL)
102 {}
103
104 enum {
105
106 OBJECT = 1,
107 LIGHT = 2,
108 CAMERA = 3,
109 BONE = 4
110 } type; // type of node
111
112 // if object: path
113 std::string path;
114 unsigned int id;
115
116 // number of object
117 unsigned int number;
118
119 // index of parent index
120 unsigned int parent;
121
122 // lights & cameras & dummies: name
123 const char* name;
124
125 // animation channels
126 std::list< LWO::Envelope > channels;
127
128 // position of pivot point
129 aiVector3D pivotPos;
130 bool isPivotSet;
131
132
133
134 // color of light source
135 aiColor3D lightColor;
136
137 // intensity of light source
138 float lightIntensity;
139
140 // type of light source
141 unsigned int lightType;
142
143 // falloff type of light source
144 unsigned int lightFalloffType;
145
146 // cone angle of (spot) light source
147 float lightConeAngle;
148
149 // soft cone angle of (spot) light source
150 float lightEdgeAngle;
151
152
153
154 // list of resolved children
155 std::list< NodeDesc* > children;
156
157 // resolved parent node
158 NodeDesc* parent_resolved;
159
160
161 // for std::find()
162 bool operator == (unsigned int num) const {
163 if (!num)
164 return false;
165 unsigned int _type = num >> 28u;
166
167 return _type == static_cast<unsigned int>(type) && (num & AI_LWS_MASK) == number;
168 }
169};
170
171} // end namespace LWS
172
173// ---------------------------------------------------------------------------
174/** LWS (LightWave Scene Format) importer class.
175 *
176 * This class does heavily depend on the LWO importer class. LWS files
177 * contain mainly descriptions how LWO objects are composed together
178 * in a scene.
179*/
180class LWSImporter : public BaseImporter
181{
182public:
183 LWSImporter();
184 ~LWSImporter();
185
186
187public:
188
189 // -------------------------------------------------------------------
190 // Check whether we can read a specific file
191 bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
192 bool checkSig) const;
193
194protected:
195
196 // -------------------------------------------------------------------
197 // Get list of supported extensions
198 const aiImporterDesc* GetInfo () const;
199
200 // -------------------------------------------------------------------
201 // Import file into given scene data structure
202 void InternReadFile( const std::string& pFile, aiScene* pScene,
203 IOSystem* pIOHandler);
204
205 // -------------------------------------------------------------------
206 // Setup import properties
207 void SetupProperties(const Importer* pImp);
208
209private:
210
211
212 // -------------------------------------------------------------------
213 // Read an envelope description
214 void ReadEnvelope(const LWS::Element& dad, LWO::Envelope& out );
215
216 // -------------------------------------------------------------------
217 // Read an envelope description for the older LW file format
218 void ReadEnvelope_Old(std::list< LWS::Element >::const_iterator& it,
219 const std::list< LWS::Element >::const_iterator& end,
220 LWS::NodeDesc& nodes,
221 unsigned int version);
222
223 // -------------------------------------------------------------------
224 // Setup a nice name for a node
225 void SetupNodeName(aiNode* nd, LWS::NodeDesc& src);
226
227 // -------------------------------------------------------------------
228 // Recursively build the scenegraph
229 void BuildGraph(aiNode* nd,
230 LWS::NodeDesc& src,
231 std::vector<AttachmentInfo>& attach,
232 BatchLoader& batch,
233 aiCamera**& camOut,
234 aiLight**& lightOut,
235 std::vector<aiNodeAnim*>& animOut);
236
237 // -------------------------------------------------------------------
238 // Try several dirs until we find the right location of a LWS file.
239 std::string FindLWOFile(const std::string& in);
240
241private:
242
243 bool configSpeedFlag;
244 IOSystem* io;
245
246 double first,last,fps;
247
248 bool noSkeletonMesh;
249};
250
251} // end of namespace Assimp
252
253#endif // AI_LWSIMPORTER_H_INC
254