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