ACLoader.h 6.8 KB

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