LWSLoader.h 6.8 KB

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