LWSLoader.h 7.0 KB

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