aiTypes.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2008, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #ifndef AI_TYPES_H_INC
  35. #define AI_TYPES_H_INC
  36. #include <sys/types.h>
  37. #include <memory.h>
  38. #include "aiDefines.h"
  39. // include math helper classes
  40. #include "aiVector3D.h"
  41. #include "aiVector2D.h"
  42. #include "aiMatrix3x3.h"
  43. #include "aiMatrix4x4.h"
  44. #ifdef __cplusplus
  45. # include <string>
  46. extern "C" {
  47. #endif
  48. /** Maximum dimension for strings, ASSIMP strings are zero terminated */
  49. #ifdef __cplusplus
  50. const size_t MAXLEN = 1024;
  51. #else
  52. # define MAXLEN 1024
  53. #endif
  54. #include "./Compiler/pushpack1.h"
  55. // ---------------------------------------------------------------------------
  56. /** Represents a plane in a three-dimensional, euclidean space
  57. */
  58. struct aiPlane
  59. {
  60. #ifdef __cplusplus
  61. aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
  62. aiPlane (float _a, float _b, float _c, float _d)
  63. : a(_a), b(_b), c(_c), d(_d) {}
  64. aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}
  65. #endif // !__cplusplus
  66. //! Plane equation
  67. float a,b,c,d;
  68. } PACK_STRUCT;
  69. // ---------------------------------------------------------------------------
  70. /** Represents a ray
  71. */
  72. struct aiRay
  73. {
  74. #ifdef __cplusplus
  75. aiRay () {}
  76. aiRay (const aiVector3D& _pos, const aiVector3D& _dir)
  77. : pos(_pos), dir(_dir) {}
  78. aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {}
  79. #endif // !__cplusplus
  80. //! Position and direction of the ray
  81. aiVector3D pos, dir;
  82. } PACK_STRUCT;
  83. // aiVector3D type moved to separate header due to size of operators
  84. // aiQuaternion type moved to separate header due to size of operators
  85. // aiMatrix4x4 type moved to separate header due to size of operators
  86. // ---------------------------------------------------------------------------
  87. /** Represents a color in Red-Green-Blue space.
  88. */
  89. struct aiColor3D
  90. {
  91. #ifdef __cplusplus
  92. aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
  93. aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
  94. aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
  95. bool operator == (const aiColor3D& other) const
  96. {return r == other.r && g == other.g && b == other.b;}
  97. bool operator != (const aiColor3D& other) const
  98. {return r != other.r || g != other.g || b != other.b;}
  99. aiColor3D operator+(const aiColor3D& c) const
  100. {return aiColor3D(r+c.r,g+c.g,b+c.b);}
  101. aiColor3D operator-(const aiColor3D& c) const
  102. {return aiColor3D(r+c.r,g+c.g,b+c.b);}
  103. aiColor3D operator*(const aiColor3D& c) const
  104. {return aiColor3D(r*c.r,g*c.g,b*c.b);}
  105. aiColor3D operator*(float f) const
  106. {return aiColor3D(r*f,g*f,b*f);}
  107. inline float operator[](unsigned int i) const {return *(&r + i);}
  108. inline float& operator[](unsigned int i) {return *(&r + i);}
  109. inline bool IsBlack() const
  110. {
  111. return !r && !g && !b;
  112. }
  113. #endif // !__cplusplus
  114. //! Red, green and blue color values
  115. float r, g, b;
  116. } PACK_STRUCT;
  117. // ---------------------------------------------------------------------------
  118. /** Represents a color in Red-Green-Blue space including an
  119. * alpha component.
  120. */
  121. struct aiColor4D
  122. {
  123. #ifdef __cplusplus
  124. aiColor4D () : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}
  125. aiColor4D (float _r, float _g, float _b, float _a)
  126. : r(_r), g(_g), b(_b), a(_a) {}
  127. aiColor4D (const aiColor4D& o)
  128. : r(o.r), g(o.g), b(o.b), a(o.a) {}
  129. bool operator == (const aiColor4D& other) const
  130. {return r == other.r && g == other.g && b == other.b && a == other.a;}
  131. bool operator != (const aiColor4D& other) const
  132. {return r != other.r || g != other.g || b != other.b || a != other.a;}
  133. inline float operator[](unsigned int i) const {return *(&r + i);}
  134. inline float& operator[](unsigned int i) {return *(&r + i);}
  135. inline bool IsBlack() const
  136. {
  137. // The alpha component doesn't care here. black is black.
  138. return !r && !g && !b;
  139. }
  140. #endif // !__cplusplus
  141. //! Red, green, blue and alpha color values
  142. float r, g, b, a;
  143. } PACK_STRUCT;
  144. #include "./Compiler/poppack1.h"
  145. // ---------------------------------------------------------------------------
  146. /** Represents a string, zero byte terminated
  147. */
  148. struct aiString
  149. {
  150. #ifdef __cplusplus
  151. inline aiString() :
  152. length(0)
  153. {
  154. data[0] = '\0';
  155. }
  156. //! Copy constructor
  157. inline aiString(const aiString& rOther) :
  158. length(rOther.length)
  159. {
  160. ::memcpy( data, rOther.data, rOther.length);
  161. data[length] = '\0';
  162. }
  163. //! Constructor from std::string
  164. inline aiString(const std::string& pString) :
  165. length(pString.length())
  166. {
  167. memcpy( data, pString.c_str(), length);
  168. data[length] = '\0';
  169. }
  170. //! copy a std::string to the aiString
  171. void Set( const std::string& pString)
  172. {
  173. if( pString.length() > MAXLEN - 1)
  174. return;
  175. length = pString.length();
  176. ::memcpy( data, pString.c_str(), length);
  177. data[length] = 0;
  178. }
  179. //! comparison operator
  180. bool operator==(const aiString& other) const
  181. {
  182. return (length == other.length &&
  183. 0 == strcmp(this->data,other.data));
  184. }
  185. //! inverse comparison operator
  186. bool operator!=(const aiString& other) const
  187. {
  188. return (length != other.length ||
  189. 0 != ::strcmp(this->data,other.data));
  190. }
  191. //! Append a string to the string
  192. inline void Append (const char* app)
  193. {
  194. const size_t len = ::strlen(app);
  195. if (!len)return;
  196. if (length + len >= MAXLEN)
  197. return;
  198. ::memcpy(&data[length],app,len+1);
  199. length += len;
  200. }
  201. //! Clear the string
  202. inline void Clear ()
  203. {
  204. length = 0;
  205. data[0] = '\0';
  206. }
  207. #endif // !__cplusplus
  208. //! Length of the string excluding the terminal 0
  209. size_t length;
  210. //! String buffer. Size limit is MAXLEN
  211. char data[MAXLEN];
  212. } ;
  213. // ---------------------------------------------------------------------------
  214. /** Standard return type for all library functions.
  215. *
  216. * To check whether or not a function failed check against
  217. * AI_SUCCESS. The error codes are mainly used by the C-API.
  218. */
  219. enum aiReturn
  220. {
  221. //! Indicates that a function was successful
  222. AI_SUCCESS = 0x0,
  223. //! Indicates that a function failed
  224. AI_FAILURE = -0x1,
  225. //! Indicates that a file was invalid
  226. AI_INVALIDFILE = -0x2,
  227. //! Indicates that not enough memory was available
  228. //! to perform the requested operation
  229. AI_OUTOFMEMORY = -0x3,
  230. //! Indicates that an illegal argument has been
  231. //! passed to a function. This is rarely used,
  232. //! most functions assert in this case.
  233. AI_INVALIDARG = -0x4
  234. };
  235. // ---------------------------------------------------------------------------
  236. /** Stores the memory requirements for different parts (e.g. meshes, materials,
  237. * animations) of an import.
  238. * @see Importer::GetMemoryRequirements()
  239. */
  240. struct aiMemoryInfo
  241. {
  242. #ifdef __cplusplus
  243. //! Default constructor
  244. inline aiMemoryInfo()
  245. : textures (0)
  246. , materials (0)
  247. , meshes (0)
  248. , nodes (0)
  249. , animations (0)
  250. , cameras (0)
  251. , lights (0)
  252. , total (0)
  253. {}
  254. #endif
  255. //! Storage allocated for texture data, in bytes
  256. unsigned int textures;
  257. //! Storage allocated for material data, in bytes
  258. unsigned int materials;
  259. //! Storage allocated for mesh data, in bytes
  260. unsigned int meshes;
  261. //! Storage allocated for node data, in bytes
  262. unsigned int nodes;
  263. //! Storage allocated for animation data, in bytes
  264. unsigned int animations;
  265. //! Storage allocated for camera data, in bytes
  266. unsigned int cameras;
  267. //! Storage allocated for light data, in bytes
  268. unsigned int lights;
  269. //! Storage allocated for the import, in bytes
  270. unsigned int total;
  271. };
  272. #ifdef __cplusplus
  273. }
  274. #endif //! __cplusplus
  275. // Include implementations
  276. #include "aiVector3D.inl"
  277. #include "aiMatrix3x3.inl"
  278. #include "aiMatrix4x4.inl"
  279. #endif //!! include guard