Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

268 linhas
7.1 KiB

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