1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2019, 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  LWSLoader.h
44  *  @brief Declaration of the LightWave scene importer class.
45  */
46 #ifndef AI_LWSLOADER_H_INCLUDED
47 #define AI_LWSLOADER_H_INCLUDED
48 
49 #include "LWO/LWOFileData.h"
50 
51 #include <assimp/SceneCombiner.h>
52 #include <assimp/BaseImporter.h>
53 
54 struct aiImporterDesc;
55 
56 namespace Assimp    {
57     class BatchLoader;
58     class Importer;
59     class IOSystem;
60 
61     namespace LWS   {
62 
63 // ---------------------------------------------------------------------------
64 /** Represents an element in a LWS file.
65  *
66  *  This can either be a single data line - <name> <value> or a data
67  *  group - { name <data_line0> ... n }
68  */
69 class Element
70 {
71 public:
Element()72     Element()
73     {}
74 
75     // first: name, second: rest
76     std::string tokens[2];
77     std::list<Element> children;
78 
79     //! Recursive parsing function
80     void Parse (const char*& buffer);
81 };
82 
83 #define AI_LWS_MASK (0xffffffff >> 4u)
84 
85 // ---------------------------------------------------------------------------
86 /** Represents a LWS scenegraph element
87  */
88 struct NodeDesc
89 {
NodeDescNodeDesc90     NodeDesc()
91         :   type()
92         ,   id()
93         ,   number  (0)
94         ,   parent  (0)
95         ,   name    ("")
96         ,   isPivotSet (false)
97         ,   lightColor (1.f,1.f,1.f)
98         ,   lightIntensity (1.f)
99         ,   lightType (0)
100         ,   lightFalloffType (0)
101         ,   lightConeAngle (45.f)
102         ,   lightEdgeAngle()
103         ,   parent_resolved (NULL)
104     {}
105 
106     enum {
107 
108         OBJECT = 1,
109         LIGHT  = 2,
110         CAMERA = 3,
111         BONE   = 4
112     } type; // type of node
113 
114     // if object: path
115     std::string path;
116     unsigned int id;
117 
118     // number of object
119     unsigned int number;
120 
121     // index of parent index
122     unsigned int parent;
123 
124     // lights & cameras & dummies: name
125     const char* name;
126 
127     // animation channels
128     std::list< LWO::Envelope > channels;
129 
130     // position of pivot point
131     aiVector3D pivotPos;
132     bool isPivotSet;
133 
134 
135 
136     // color of light source
137     aiColor3D lightColor;
138 
139     // intensity of light source
140     float lightIntensity;
141 
142     // type of light source
143     unsigned int lightType;
144 
145     // falloff type of light source
146     unsigned int lightFalloffType;
147 
148     // cone angle of (spot) light source
149     float lightConeAngle;
150 
151     // soft cone angle of (spot) light source
152     float lightEdgeAngle;
153 
154 
155 
156     // list of resolved children
157     std::list< NodeDesc* > children;
158 
159     // resolved parent node
160     NodeDesc* parent_resolved;
161 
162 
163     // for std::find()
164     bool operator == (unsigned int num)  const {
165         if (!num)
166             return false;
167         unsigned int _type = num >> 28u;
168 
169         return _type == static_cast<unsigned int>(type) && (num & AI_LWS_MASK) == number;
170     }
171 };
172 
173 } // end namespace LWS
174 
175 // ---------------------------------------------------------------------------
176 /** LWS (LightWave Scene Format) importer class.
177  *
178  *  This class does heavily depend on the LWO importer class. LWS files
179  *  contain mainly descriptions how LWO objects are composed together
180  *  in a scene.
181 */
182 class LWSImporter : public BaseImporter
183 {
184 public:
185     LWSImporter();
186     ~LWSImporter();
187 
188 
189 public:
190 
191     // -------------------------------------------------------------------
192     // Check whether we can read a specific file
193     bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
194         bool checkSig) const;
195 
196 protected:
197 
198     // -------------------------------------------------------------------
199     // Get list of supported extensions
200     const aiImporterDesc* GetInfo () const;
201 
202     // -------------------------------------------------------------------
203     // Import file into given scene data structure
204     void InternReadFile( const std::string& pFile, aiScene* pScene,
205         IOSystem* pIOHandler);
206 
207     // -------------------------------------------------------------------
208     // Setup import properties
209     void SetupProperties(const Importer* pImp);
210 
211 private:
212 
213 
214     // -------------------------------------------------------------------
215     // Read an envelope description
216     void ReadEnvelope(const LWS::Element& dad, LWO::Envelope& out );
217 
218     // -------------------------------------------------------------------
219     // Read an envelope description for the older LW file format
220     void ReadEnvelope_Old(std::list< LWS::Element >::const_iterator& it,
221         const std::list< LWS::Element >::const_iterator& end,
222         LWS::NodeDesc& nodes,
223         unsigned int version);
224 
225     // -------------------------------------------------------------------
226     // Setup a nice name for a node
227     void SetupNodeName(aiNode* nd, LWS::NodeDesc& src);
228 
229     // -------------------------------------------------------------------
230     // Recursively build the scenegraph
231     void BuildGraph(aiNode* nd,
232         LWS::NodeDesc& src,
233         std::vector<AttachmentInfo>& attach,
234         BatchLoader& batch,
235         aiCamera**& camOut,
236         aiLight**& lightOut,
237         std::vector<aiNodeAnim*>& animOut);
238 
239     // -------------------------------------------------------------------
240     // Try several dirs until we find the right location of a LWS file.
241     std::string FindLWOFile(const std::string& in);
242 
243 private:
244 
245     bool configSpeedFlag;
246     IOSystem* io;
247 
248     double first,last,fps;
249 
250     bool noSkeletonMesh;
251 };
252 
253 } // end of namespace Assimp
254 
255 #endif // AI_LWSIMPORTER_H_INC
256