aiTypes.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. /** @file aiTypes.h
  35. * Basic data types and primitives, such as vectors or colors.
  36. */
  37. #ifndef AI_TYPES_H_INC
  38. #define AI_TYPES_H_INC
  39. // Some runtime headers
  40. #include <sys/types.h>
  41. #include <memory.h>
  42. #include <math.h>
  43. #include <stddef.h>
  44. // Our compile configuration
  45. #include "aiDefines.h"
  46. // Some types moved to separate header due to size of operators
  47. #include "aiVector3D.h"
  48. #include "aiVector2D.h"
  49. #include "aiColor4D.h"
  50. #include "aiMatrix3x3.h"
  51. #include "aiMatrix4x4.h"
  52. #include "aiQuaternion.h"
  53. #ifdef __cplusplus
  54. # include <string> // for aiString::Set(const std::string&)
  55. namespace Assimp {
  56. //! @cond never
  57. namespace Intern {
  58. // --------------------------------------------------------------------
  59. /** @brief Internal helper class to utilize our internal new/delete
  60. * routines for allocating object of this and derived classes.
  61. *
  62. * By doing this you can safely share class objects between Assimp
  63. * and the application - it works even over DLL boundaries. A good
  64. * example is the #IOSystem where the application allocates its custom
  65. * #IOSystem, then calls #Importer::SetIOSystem(). When the Importer
  66. * destructs, Assimp calls operator delete on the stored #IOSystem.
  67. * If it lies on a different heap than Assimp is working with,
  68. * the application is determined to crash.
  69. */
  70. // --------------------------------------------------------------------
  71. struct ASSIMP_API AllocateFromAssimpHeap {
  72. // new/delete overload
  73. void *operator new ( size_t num_bytes);
  74. void operator delete ( void* data);
  75. // array new/delete overload
  76. void *operator new[] ( size_t num_bytes);
  77. void operator delete[] ( void* data);
  78. }; // struct AllocateFromAssimpHeap
  79. } // namespace Intern
  80. //! @endcond
  81. } // namespace Assimp
  82. extern "C" {
  83. #endif
  84. /** Maximum dimension for strings, ASSIMP strings are zero terminated. */
  85. #ifdef __cplusplus
  86. const size_t MAXLEN = 1024;
  87. #else
  88. # define MAXLEN 1024
  89. #endif
  90. #include "./Compiler/pushpack1.h"
  91. // ----------------------------------------------------------------------------------
  92. /** Represents a plane in a three-dimensional, euclidean space
  93. */
  94. struct aiPlane
  95. {
  96. #ifdef __cplusplus
  97. aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
  98. aiPlane (float _a, float _b, float _c, float _d)
  99. : a(_a), b(_b), c(_c), d(_d) {}
  100. aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}
  101. #endif // !__cplusplus
  102. //! Plane equation
  103. float a,b,c,d;
  104. } PACK_STRUCT; // !struct aiPlane
  105. // ----------------------------------------------------------------------------------
  106. /** Represents a ray
  107. */
  108. struct aiRay
  109. {
  110. #ifdef __cplusplus
  111. aiRay () {}
  112. aiRay (const aiVector3D& _pos, const aiVector3D& _dir)
  113. : pos(_pos), dir(_dir) {}
  114. aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {}
  115. #endif // !__cplusplus
  116. //! Position and direction of the ray
  117. C_STRUCT aiVector3D pos, dir;
  118. } PACK_STRUCT; // !struct aiRay
  119. // ----------------------------------------------------------------------------------
  120. /** Represents a color in Red-Green-Blue space.
  121. */
  122. struct aiColor3D
  123. {
  124. #ifdef __cplusplus
  125. aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
  126. aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
  127. aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
  128. /** Component-wise comparison */
  129. // TODO: add epsilon?
  130. bool operator == (const aiColor3D& other) const
  131. {return r == other.r && g == other.g && b == other.b;}
  132. /** Component-wise inverse comparison */
  133. // TODO: add epsilon?
  134. bool operator != (const aiColor3D& other) const
  135. {return r != other.r || g != other.g || b != other.b;}
  136. /** Component-wise addition */
  137. aiColor3D operator+(const aiColor3D& c) const {
  138. return aiColor3D(r+c.r,g+c.g,b+c.b);
  139. }
  140. /** Component-wise subtraction */
  141. aiColor3D operator-(const aiColor3D& c) const {
  142. return aiColor3D(r+c.r,g+c.g,b+c.b);
  143. }
  144. /** Component-wise multiplication */
  145. aiColor3D operator*(const aiColor3D& c) const {
  146. return aiColor3D(r*c.r,g*c.g,b*c.b);
  147. }
  148. /** Multiply with a scalar */
  149. aiColor3D operator*(float f) const {
  150. return aiColor3D(r*f,g*f,b*f);
  151. }
  152. /** Access a specific color component */
  153. float operator[](unsigned int i) const {
  154. return *(&r + i);
  155. }
  156. /** Access a specific color component */
  157. float& operator[](unsigned int i) {
  158. return *(&r + i);
  159. }
  160. /** Check whether a color is black */
  161. bool IsBlack() const {
  162. static const float epsilon = 10e-3f;
  163. return fabs( r ) < epsilon && fabs( g ) < epsilon && fabs( b ) < epsilon;
  164. }
  165. #endif // !__cplusplus
  166. //! Red, green and blue color values
  167. float r, g, b;
  168. } PACK_STRUCT; // !struct aiColor3D
  169. #include "./Compiler/poppack1.h"
  170. // ----------------------------------------------------------------------------------
  171. /** Represents an UTF-8 string, zero byte terminated.
  172. *
  173. * The character set of an aiString is explicitly defined to be UTF-8. This Unicode
  174. * transformation was chosen in the belief that most strings in 3d files are limited
  175. * to the ASCII characters, thus the character set needed to be ASCII compatible.
  176. *
  177. * Most text file loaders provide proper Unicode input file handling, special unicode
  178. * characters are correctly transcoded to UTF8 and are kept throughout the libraries'
  179. * import pipeline.
  180. *
  181. * For most applications, it will be absolutely sufficient to interpret the
  182. * aiString as ASCII data and work with it as one would work with a plain char*.
  183. * Windows users in need of proper support for i.e asian characters can use the
  184. * #MultiByteToWideChar(), #WideCharToMultiByte() WinAPI functionality to convert the
  185. * UTF-8 strings to their working character set (i.e. MBCS, WideChar).
  186. *
  187. * We use this representation instead of std::string to be C-compatible. The
  188. * (binary) length of such a string is limited to MAXLEN characters (excluding the 0).
  189. */
  190. struct aiString
  191. {
  192. #ifdef __cplusplus
  193. /** Default constructor, the string is set to have zero length */
  194. aiString() :
  195. length(0)
  196. {
  197. data[0] = '\0';
  198. #ifdef _DEBUG
  199. // Debug build: overwrite the string on its full length with ESC (27)
  200. memset(data+1,27,MAXLEN-1);
  201. #endif
  202. }
  203. /** Copy constructor */
  204. aiString(const aiString& rOther) :
  205. length(rOther.length)
  206. {
  207. memcpy( data, rOther.data, rOther.length);
  208. data[length] = '\0';
  209. }
  210. /** Constructor from std::string */
  211. aiString(const std::string& pString) :
  212. length(pString.length())
  213. {
  214. memcpy( data, pString.c_str(), length);
  215. data[length] = '\0';
  216. }
  217. /** Copy a std::string to the aiString */
  218. void Set( const std::string& pString) {
  219. if( pString.length() > MAXLEN - 1) {
  220. return;
  221. }
  222. length = pString.length();
  223. ::memcpy( data, pString.c_str(), length);
  224. data[length] = 0;
  225. }
  226. /** Copy a const char* to the aiString */
  227. void Set( const char* sz) {
  228. const size_t len = ::strlen(sz);
  229. if( len > MAXLEN - 1) {
  230. return;
  231. }
  232. length = len;
  233. ::memcpy( data, sz, len);
  234. data[len] = 0;
  235. }
  236. /** Assign a const char* to the string */
  237. aiString& operator = (const char* sz) {
  238. Set(sz);
  239. return *this;
  240. }
  241. /** Assign a cstd::string to the string */
  242. aiString& operator = ( const std::string& pString) {
  243. Set(pString);
  244. return *this;
  245. }
  246. /** Comparison operator */
  247. bool operator==(const aiString& other) const {
  248. return (length == other.length && 0 == strcmp(this->data,other.data));
  249. }
  250. /** Inverse comparison operator */
  251. bool operator!=(const aiString& other) const {
  252. return (length != other.length || 0 != ::strcmp(this->data,other.data));
  253. }
  254. /** Append a string to the string */
  255. void Append (const char* app) {
  256. const size_t len = ::strlen(app);
  257. if (!len) {
  258. return;
  259. }
  260. if (length + len >= MAXLEN) {
  261. return;
  262. }
  263. memcpy(&data[length],app,len+1);
  264. length += len;
  265. }
  266. /** Clear the string - reset its length to zero */
  267. void Clear () {
  268. length = 0;
  269. data[0] = '\0';
  270. #ifdef _DEBUG
  271. // Debug build: overwrite the string on its full length with ESC (27)
  272. memset(data+1,27,MAXLEN-1);
  273. #endif
  274. }
  275. #endif // !__cplusplus
  276. /** Binary length of the string excluding the terminal 0. This is NOT the
  277. * logical length of strings containing UTF-8 multibyte sequences! It's
  278. * the number of bytes from the beginning of the string to its end.*/
  279. size_t length;
  280. /** String buffer. Size limit is MAXLEN */
  281. char data[MAXLEN];
  282. } ; // !struct aiString
  283. // ----------------------------------------------------------------------------------
  284. /** Standard return type for some library functions.
  285. * Rarely used, and if, mostly in the C API.
  286. */
  287. enum aiReturn
  288. {
  289. /** Indicates that a function was successful */
  290. aiReturn_SUCCESS = 0x0,
  291. /** Indicates that a function failed */
  292. aiReturn_FAILURE = -0x1,
  293. /** Indicates that not enough memory was available
  294. * to perform the requested operation
  295. */
  296. aiReturn_OUTOFMEMORY = -0x3,
  297. /** @cond never
  298. * Force 32-bit size enum
  299. */
  300. _AI_ENFORCE_ENUM_SIZE = 0x7fffffff
  301. }; // !enum aiReturn
  302. // just for backwards compatibility, don't use these constants anymore
  303. #define AI_SUCCESS aiReturn_SUCCESS
  304. #define AI_FAILURE aiReturn_FAILURE
  305. #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY
  306. // ----------------------------------------------------------------------------------
  307. /** Seek origins (for the virtual file system API).
  308. * Much cooler than using SEEK_SET, SEEK_CUR or SEEK_END.
  309. */
  310. enum aiOrigin
  311. {
  312. /** Beginning of the file */
  313. aiOrigin_SET = 0x0,
  314. /** Current position of the file pointer */
  315. aiOrigin_CUR = 0x1,
  316. /** End of the file, offsets must be negative */
  317. aiOrigin_END = 0x2,
  318. /** @cond never
  319. * Force 32-bit size enum
  320. */
  321. _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff
  322. }; // !enum aiOrigin
  323. // ----------------------------------------------------------------------------------
  324. /** @brief Enumerates predefined log streaming destinations.
  325. * Logging to these streams can be enabled with a single call to
  326. * #LogStream::createDefaultStream or #aiAttachPredefinedLogStream(),
  327. * respectively.
  328. */
  329. enum aiDefaultLogStream
  330. {
  331. /** Stream the log to a file */
  332. aiDefaultLogStream_FILE = 0x1,
  333. /** Stream the log to std::cout */
  334. aiDefaultLogStream_STDOUT = 0x2,
  335. /** Stream the log to std::cerr */
  336. aiDefaultLogStream_STDERR = 0x4,
  337. /** MSVC only: Stream the log the the debugger
  338. * (this relies on OutputDebugString from the Win32 SDK)
  339. */
  340. aiDefaultLogStream_DEBUGGER = 0x8,
  341. /** @cond never
  342. * Force 32-bit size enum
  343. */
  344. _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff
  345. }; // !enum aiDefaultLogStream
  346. // just for backwards compatibility, don't use these constants anymore
  347. #define DLS_FILE aiDefaultLogStream_FILE
  348. #define DLS_STDOUT aiDefaultLogStream_STDOUT
  349. #define DLS_STDERR aiDefaultLogStream_STDERR
  350. #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER
  351. // ----------------------------------------------------------------------------------
  352. /** Stores the memory requirements for different components (e.g. meshes, materials,
  353. * animations) of an import. All sizes are in bytes.
  354. * @see Importer::GetMemoryRequirements()
  355. */
  356. struct aiMemoryInfo
  357. {
  358. #ifdef __cplusplus
  359. /** Default constructor */
  360. aiMemoryInfo()
  361. : textures (0)
  362. , materials (0)
  363. , meshes (0)
  364. , nodes (0)
  365. , animations (0)
  366. , cameras (0)
  367. , lights (0)
  368. , total (0)
  369. {}
  370. #endif
  371. /** Storage allocated for texture data */
  372. unsigned int textures;
  373. /** Storage allocated for material data */
  374. unsigned int materials;
  375. /** Storage allocated for mesh data */
  376. unsigned int meshes;
  377. /** Storage allocated for node data */
  378. unsigned int nodes;
  379. /** Storage allocated for animation data */
  380. unsigned int animations;
  381. /** Storage allocated for camera data */
  382. unsigned int cameras;
  383. /** Storage allocated for light data */
  384. unsigned int lights;
  385. /** Total storage allocated for the full import. */
  386. unsigned int total;
  387. }; // !struct aiMemoryInfo
  388. #ifdef __cplusplus
  389. }
  390. #endif //! __cplusplus
  391. // Include implementations
  392. #include "aiVector3D.inl"
  393. #include "aiColor4D.inl"
  394. #include "aiMatrix3x3.inl"
  395. #include "aiMatrix4x4.inl"
  396. #endif