LWSLoader.h 6.6 KB

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