ACLoader.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 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 <assimp/BaseImporter.h>
  40. #include <assimp/types.h>
  41. struct aiNode;
  42. struct aiMesh;
  43. struct aiMaterial;
  44. struct aiLight;
  45. namespace Assimp {
  46. // ---------------------------------------------------------------------------
  47. /** AC3D (*.ac) importer class
  48. */
  49. class AC3DImporter : public BaseImporter {
  50. public:
  51. AC3DImporter();
  52. ~AC3DImporter() override = default;
  53. // Represents an AC3D material
  54. struct Material {
  55. Material() :
  56. rgb(0.6f, 0.6f, 0.6f),
  57. spec(1.f, 1.f, 1.f),
  58. shin(0.f),
  59. trans(0.f) {}
  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. Surface() :
  78. mat(0),
  79. flags(0) {}
  80. unsigned int mat, flags;
  81. using SurfaceEntry = std::pair<unsigned int, aiVector2D>;
  82. std::vector<SurfaceEntry> entries;
  83. // Type is low nibble of flags
  84. enum Type : uint8_t {
  85. Polygon = 0x0,
  86. ClosedLine = 0x1,
  87. OpenLine = 0x2,
  88. TriangleStrip = 0x4, // ACC extension (TORCS and Speed Dreams)
  89. Mask = 0xf,
  90. };
  91. inline uint8_t GetType() const { return (flags & Mask); }
  92. };
  93. // Represents an AC3D object
  94. struct Object {
  95. Object() :
  96. type(World),
  97. name(),
  98. children(),
  99. texRepeat(1.f, 1.f),
  100. texOffset(0.0f, 0.0f),
  101. rotation(),
  102. translation(),
  103. vertices(),
  104. surfaces(),
  105. numRefs(0),
  106. subDiv(0),
  107. crease() {}
  108. // Type description
  109. enum Type {
  110. World = 0x0,
  111. Poly = 0x1,
  112. Group = 0x2,
  113. Light = 0x4
  114. } type;
  115. // name of the object
  116. std::string name;
  117. // object children
  118. std::vector<Object> children;
  119. // texture to be assigned to all surfaces of the object
  120. // the .acc format supports up to 4 textures
  121. std::vector<std::string> textures;
  122. // texture repat factors (scaling for all coordinates)
  123. aiVector2D texRepeat, texOffset;
  124. // rotation matrix
  125. aiMatrix3x3 rotation;
  126. // translation vector
  127. aiVector3D translation;
  128. // vertices
  129. std::vector<aiVector3D> vertices;
  130. // surfaces
  131. std::vector<Surface> surfaces;
  132. // number of indices (= num verts in verbose format)
  133. unsigned int numRefs;
  134. // number of subdivisions to be performed on the
  135. // imported data
  136. unsigned int subDiv;
  137. // max angle limit for smoothing
  138. float crease;
  139. };
  140. public:
  141. // -------------------------------------------------------------------
  142. /** Returns whether the class can handle the format of the given file.
  143. * See BaseImporter::CanRead() for details.
  144. */
  145. bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
  146. bool checkSig) const override;
  147. protected:
  148. // -------------------------------------------------------------------
  149. /** Return importer meta information.
  150. * See #BaseImporter::GetInfo for the details */
  151. const aiImporterDesc *GetInfo() const override;
  152. // -------------------------------------------------------------------
  153. /** Imports the given file into the given scene structure.
  154. * See BaseImporter::InternReadFile() for details*/
  155. void InternReadFile(const std::string &pFile, aiScene *pScene,
  156. IOSystem *pIOHandler) override;
  157. // -------------------------------------------------------------------
  158. /** Called prior to ReadFile().
  159. * The function is a request to the importer to update its configuration
  160. * basing on the Importer's configuration property list.*/
  161. void SetupProperties(const Importer *pImp) override;
  162. private:
  163. // -------------------------------------------------------------------
  164. /** Get the next line from the file.
  165. * @return false if the end of the file was reached*/
  166. bool GetNextLine();
  167. // -------------------------------------------------------------------
  168. /** Load the object section. This method is called recursively to
  169. * load subobjects, the method returns after a 'kids 0' was
  170. * encountered.
  171. * @objects List of output objects*/
  172. bool 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. aiNode *ConvertObjectSection(Object &object,
  181. std::vector<aiMesh *> &meshes,
  182. std::vector<aiMaterial *> &outMaterials,
  183. const std::vector<Material> &materials,
  184. aiNode *parent = nullptr);
  185. // -------------------------------------------------------------------
  186. /** Convert a material
  187. * @param object Current object
  188. * @param matSrc Source material description
  189. * @param matDest Destination material to be filled */
  190. void ConvertMaterial(const Object &object,
  191. const Material &matSrc,
  192. aiMaterial &matDest);
  193. private:
  194. // points to the next data line
  195. aiBuffer mBuffer;
  196. // Configuration option: if enabled, up to two meshes
  197. // are generated per material: those faces who have
  198. // their bf cull flags set are separated.
  199. bool configSplitBFCull;
  200. // Configuration switch: subdivision surfaces are only
  201. // evaluated if the value is true.
  202. bool configEvalSubdivision;
  203. // counts how many objects we have in the tree.
  204. // basing on this information we can find a
  205. // good estimate how many meshes we'll have in the final scene.
  206. unsigned int mNumMeshes;
  207. // current list of light sources
  208. std::vector<aiLight *> *mLights;
  209. // name counters
  210. unsigned int mLightsCounter, mGroupsCounter, mPolysCounter, mWorldsCounter;
  211. };
  212. } // end of namespace Assimp
  213. #endif // AI_AC3DIMPORTER_H_INC