LWSLoader.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, 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 "AssetLib/LWO/LWOFileData.h"
  39. #include <assimp/BaseImporter.h>
  40. #include <assimp/SceneCombiner.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. public:
  55. Element() {}
  56. // first: name, second: rest
  57. std::string tokens[2];
  58. std::list<Element> children;
  59. //! Recursive parsing function
  60. void Parse(const char *&buffer);
  61. };
  62. #define AI_LWS_MASK (0xffffffff >> 4u)
  63. // ---------------------------------------------------------------------------
  64. /** Represents a LWS scenegraph element
  65. */
  66. struct NodeDesc {
  67. NodeDesc() :
  68. type(),
  69. id(),
  70. number(0),
  71. parent(0),
  72. name(""),
  73. isPivotSet(false),
  74. lightColor(1.f, 1.f, 1.f),
  75. lightIntensity(1.f),
  76. lightType(0),
  77. lightFalloffType(0),
  78. lightConeAngle(45.f),
  79. lightEdgeAngle(),
  80. parent_resolved(nullptr) {}
  81. enum {
  82. OBJECT = 1,
  83. LIGHT = 2,
  84. CAMERA = 3,
  85. BONE = 4
  86. } type; // type of node
  87. // if object: path
  88. std::string path;
  89. unsigned int id;
  90. // number of object
  91. unsigned int number;
  92. // index of parent index
  93. unsigned int parent;
  94. // lights & cameras & dummies: name
  95. const char *name;
  96. // animation channels
  97. std::list<LWO::Envelope> channels;
  98. // position of pivot point
  99. aiVector3D pivotPos;
  100. bool isPivotSet;
  101. // color of light source
  102. aiColor3D lightColor;
  103. // intensity of light source
  104. float lightIntensity;
  105. // type of light source
  106. unsigned int lightType;
  107. // falloff type of light source
  108. unsigned int lightFalloffType;
  109. // cone angle of (spot) light source
  110. float lightConeAngle;
  111. // soft cone angle of (spot) light source
  112. float lightEdgeAngle;
  113. // list of resolved children
  114. std::list<NodeDesc *> children;
  115. // resolved parent node
  116. NodeDesc *parent_resolved;
  117. // for std::find()
  118. bool operator==(unsigned int num) const {
  119. if (!num)
  120. return false;
  121. unsigned int _type = num >> 28u;
  122. return _type == static_cast<unsigned int>(type) && (num & AI_LWS_MASK) == number;
  123. }
  124. };
  125. } // end namespace LWS
  126. // ---------------------------------------------------------------------------
  127. /** LWS (LightWave Scene Format) importer class.
  128. *
  129. * This class does heavily depend on the LWO importer class. LWS files
  130. * contain mainly descriptions how LWO objects are composed together
  131. * in a scene.
  132. */
  133. class LWSImporter : public BaseImporter {
  134. public:
  135. LWSImporter();
  136. ~LWSImporter();
  137. // -------------------------------------------------------------------
  138. // Check whether we can read a specific file
  139. bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
  140. bool checkSig) const;
  141. protected:
  142. // -------------------------------------------------------------------
  143. // Get list of supported extensions
  144. const aiImporterDesc *GetInfo() const;
  145. // -------------------------------------------------------------------
  146. // Import file into given scene data structure
  147. void InternReadFile(const std::string &pFile, aiScene *pScene,
  148. IOSystem *pIOHandler);
  149. // -------------------------------------------------------------------
  150. // Setup import properties
  151. void SetupProperties(const Importer *pImp);
  152. private:
  153. // -------------------------------------------------------------------
  154. // Read an envelope description
  155. void ReadEnvelope(const LWS::Element &dad, LWO::Envelope &out);
  156. // -------------------------------------------------------------------
  157. // Read an envelope description for the older LW file format
  158. void ReadEnvelope_Old(std::list<LWS::Element>::const_iterator &it,
  159. const std::list<LWS::Element>::const_iterator &end,
  160. LWS::NodeDesc &nodes,
  161. unsigned int version);
  162. // -------------------------------------------------------------------
  163. // Setup a nice name for a node
  164. void SetupNodeName(aiNode *nd, LWS::NodeDesc &src);
  165. // -------------------------------------------------------------------
  166. // Recursively build the scenegraph
  167. void BuildGraph(aiNode *nd,
  168. LWS::NodeDesc &src,
  169. std::vector<AttachmentInfo> &attach,
  170. BatchLoader &batch,
  171. aiCamera **&camOut,
  172. aiLight **&lightOut,
  173. std::vector<aiNodeAnim *> &animOut);
  174. // -------------------------------------------------------------------
  175. // Try several dirs until we find the right location of a LWS file.
  176. std::string FindLWOFile(const std::string &in);
  177. private:
  178. bool configSpeedFlag;
  179. IOSystem *io;
  180. double first, last, fps;
  181. bool noSkeletonMesh;
  182. };
  183. } // end of namespace Assimp
  184. #endif // AI_LWSIMPORTER_H_INC