ACLoader.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, 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 ACLoader.h
  34. * @brief Declaration of the .ac importer class.
  35. */
  36. #ifndef AI_AC3DLOADER_H_INCLUDED
  37. #define AI_AC3DLOADER_H_INCLUDED
  38. #include <vector>
  39. #include "BaseImporter.h"
  40. #include "../include/aiTypes.h"
  41. namespace Assimp {
  42. // ---------------------------------------------------------------------------
  43. /** AC3D (*.ac) importer class
  44. */
  45. class AC3DImporter : public BaseImporter
  46. {
  47. friend class Importer;
  48. protected:
  49. /** Constructor to be privately used by Importer */
  50. AC3DImporter();
  51. /** Destructor, private as well */
  52. ~AC3DImporter();
  53. // Represents an AC3D material
  54. struct Material
  55. {
  56. Material()
  57. : rgb (0.6f,0.6f,0.6f)
  58. , spec (1.f,1.f,1.f)
  59. , shin (0.f)
  60. , trans (0.f)
  61. {}
  62. // base color of the material
  63. aiColor3D rgb;
  64. // ambient color of the material
  65. aiColor3D amb;
  66. // emissive color of the material
  67. aiColor3D emis;
  68. // specular color of the material
  69. aiColor3D spec;
  70. // shininess exponent
  71. float shin;
  72. // transparency. 0 == opaque
  73. float trans;
  74. // name of the material. optional.
  75. std::string name;
  76. };
  77. // Represents an AC3D surface
  78. struct Surface
  79. {
  80. Surface()
  81. : mat (0)
  82. , flags (0)
  83. {}
  84. unsigned int mat,flags;
  85. typedef std::pair<unsigned int, aiVector2D > SurfaceEntry;
  86. std::vector< SurfaceEntry > entries;
  87. };
  88. // Represents an AC3D object
  89. struct Object
  90. {
  91. Object()
  92. : type (World)
  93. , name( "" )
  94. , children()
  95. , texture( "" )
  96. , texRepeat( 1.f, 1.f )
  97. , texOffset( 0.0f, 0.0f )
  98. , rotation()
  99. , translation()
  100. , vertices()
  101. , surfaces()
  102. , numRefs (0)
  103. , subDiv (0)
  104. {}
  105. // Type description
  106. enum Type
  107. {
  108. World = 0x0,
  109. Poly = 0x1,
  110. Group = 0x2,
  111. Light = 0x4
  112. } type;
  113. // name of the object
  114. std::string name;
  115. // object children
  116. std::vector<Object> children;
  117. // texture to be assigned to all surfaces of the object
  118. std::string texture;
  119. // texture repat factors (scaling for all coordinates)
  120. aiVector2D texRepeat, texOffset;
  121. // rotation matrix
  122. aiMatrix3x3 rotation;
  123. // translation vector
  124. aiVector3D translation;
  125. // vertices
  126. std::vector<aiVector3D> vertices;
  127. // surfaces
  128. std::vector<Surface> surfaces;
  129. // number of indices (= num verts in verbose format)
  130. unsigned int numRefs;
  131. // number of subdivisions to be performed on the
  132. // imported data
  133. unsigned int subDiv;
  134. };
  135. public:
  136. // -------------------------------------------------------------------
  137. /** Returns whether the class can handle the format of the given file.
  138. * See BaseImporter::CanRead() for details.
  139. */
  140. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  141. bool checkSig) const;
  142. protected:
  143. // -------------------------------------------------------------------
  144. /** Called by Importer::GetExtensionList() for each loaded importer.
  145. * See BaseImporter::GetExtensionList() for details
  146. */
  147. void GetExtensionList(std::string& append);
  148. // -------------------------------------------------------------------
  149. /** Imports the given file into the given scene structure.
  150. * See BaseImporter::InternReadFile() for details
  151. */
  152. void InternReadFile( const std::string& pFile, aiScene* pScene,
  153. IOSystem* pIOHandler);
  154. // -------------------------------------------------------------------
  155. /** Called prior to ReadFile().
  156. * The function is a request to the importer to update its configuration
  157. * basing on the Importer's configuration property list.
  158. */
  159. void SetupProperties(const Importer* pImp);
  160. private:
  161. // -------------------------------------------------------------------
  162. /** Get the next line from the file.
  163. * @return false if the end of the file was reached
  164. */
  165. bool GetNextLine();
  166. // -------------------------------------------------------------------
  167. /** Load the object section. This method is called recursively to
  168. * load subobjects, the method returns after a 'kids 0' was
  169. * encountered.
  170. * @objects List of output objects
  171. */
  172. void LoadObjectSection(std::vector<Object>& objects);
  173. // -------------------------------------------------------------------
  174. /** Convert all objects into meshes and nodes.
  175. * @param object Current object to work on
  176. * @param meshes Pointer to the list of output meshes
  177. * @param outMaterials List of output materials
  178. * @param materials Material list
  179. * @param Scenegraph node for the object
  180. */
  181. aiNode* ConvertObjectSection(Object& object,
  182. std::vector<aiMesh*>& meshes,
  183. std::vector<MaterialHelper*>& outMaterials,
  184. const std::vector<Material>& materials,
  185. aiNode* parent = NULL);
  186. // -------------------------------------------------------------------
  187. /** Convert a material
  188. * @param object Current object
  189. * @param matSrc Source material description
  190. * @param matDest Destination material to be filled
  191. */
  192. void ConvertMaterial(const Object& object,
  193. const Material& matSrc,
  194. MaterialHelper& matDest);
  195. private:
  196. // points to the next data line
  197. const char* buffer;
  198. // Configuration option: if enabled, up to two meshes
  199. // are generated per material: those faces who have
  200. // their bf cull flags set are separated.
  201. bool configSplitBFCull;
  202. // counts how many objects we have in the tree.
  203. // basing on this information we can find a
  204. // good estimate how many meshes we'll have in the final scene.
  205. unsigned int mNumMeshes;
  206. // current list of light sources
  207. std::vector<aiLight*>* mLights;
  208. // name counters
  209. unsigned int lights, groups, polys, worlds;
  210. };
  211. } // end of namespace Assimp
  212. #endif // AI_AC3DIMPORTER_H_INC