1 /* 2 --------------------------------------------------------------------------- 3 Open Asset Import Library (assimp) 4 --------------------------------------------------------------------------- 5 6 Copyright (c) 2006-2019, assimp team 7 8 9 10 All rights reserved. 11 12 Redistribution and use of this software in source and binary forms, 13 with or without modification, are permitted provided that the following 14 conditions are met: 15 16 * Redistributions of source code must retain the above 17 copyright notice, this list of conditions and the 18 following disclaimer. 19 20 * Redistributions in binary form must reproduce the above 21 copyright notice, this list of conditions and the 22 following disclaimer in the documentation and/or other 23 materials provided with the distribution. 24 25 * Neither the name of the assimp team, nor the names of its 26 contributors may be used to endorse or promote products 27 derived from this software without specific prior 28 written permission of the assimp team. 29 30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 --------------------------------------------------------------------------- 42 */ 43 44 /** @file types.h 45 * Basic data types and primitives, such as vectors or colors. 46 */ 47 #pragma once 48 #ifndef AI_TYPES_H_INC 49 #define AI_TYPES_H_INC 50 51 #ifdef __GNUC__ 52 # pragma GCC system_header 53 #endif 54 55 // Some runtime headers 56 #include <sys/types.h> 57 #include <stddef.h> 58 #include <string.h> 59 #include <limits.h> 60 #include <stdint.h> 61 62 // Our compile configuration 63 #include <assimp/defs.h> 64 65 // Some types moved to separate header due to size of operators 66 #include <assimp/vector3.h> 67 #include <assimp/vector2.h> 68 #include <assimp/color4.h> 69 #include <assimp/matrix3x3.h> 70 #include <assimp/matrix4x4.h> 71 #include <assimp/quaternion.h> 72 73 typedef int32_t ai_int32; 74 typedef uint32_t ai_uint32 ; 75 76 #ifdef __cplusplus 77 #include <cstring> 78 //#include <new> // for std::nothrow_t 79 #include <string> // for aiString::Set(const std::string&) 80 81 //namespace Assimp { 82 //! @cond never 83 //namespace Intern { 84 // -------------------------------------------------------------------- 85 /** @brief Internal helper class to utilize our internal new/delete 86 * routines for allocating object of this and derived classes. 87 * 88 * By doing this you can safely share class objects between Assimp 89 * and the application - it works even over DLL boundaries. A good 90 * example is the #IOSystem where the application allocates its custom 91 * #IOSystem, then calls #Importer::SetIOSystem(). When the Importer 92 * destructs, Assimp calls operator delete on the stored #IOSystem. 93 * If it lies on a different heap than Assimp is working with, 94 * the application is determined to crash. 95 */ 96 // -------------------------------------------------------------------- 97 #ifndef SWIG 98 // struct ASSIMP_API AllocateFromAssimpHeap { 99 // http://www.gotw.ca/publications/mill15.htm 100 101 // new/delete overload 102 // void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */; 103 // void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw(); 104 // void operator delete ( void* data); 105 106 // array new/delete overload 107 // void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */; 108 // void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw(); 109 // void operator delete[] ( void* data); 110 111 // }; // struct AllocateFromAssimpHeap 112 #endif 113 //} // namespace Intern 114 //! @endcond 115 //} namespace Assimp 116 117 extern "C" { 118 #endif 119 120 /** Maximum dimension for strings, ASSIMP strings are zero terminated. */ 121 #ifdef __cplusplus 122 static const size_t MAXLEN = 1024; 123 #else 124 # define MAXLEN 1024 125 #endif 126 127 // ---------------------------------------------------------------------------------- 128 /** Represents a plane in a three-dimensional, euclidean space 129 */ 130 struct aiPlane { 131 #ifdef __cplusplus aiPlaneaiPlane132 aiPlane () AI_NO_EXCEPT : a(0.f), b(0.f), c(0.f), d(0.f) {} aiPlaneaiPlane133 aiPlane (ai_real _a, ai_real _b, ai_real _c, ai_real _d) 134 : a(_a), b(_b), c(_c), d(_d) {} 135 aiPlaneaiPlane136 aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {} 137 138 #endif // !__cplusplus 139 140 //! Plane equation 141 ai_real a,b,c,d; 142 }; // !struct aiPlane 143 144 // ---------------------------------------------------------------------------------- 145 /** Represents a ray 146 */ 147 struct aiRay { 148 #ifdef __cplusplus aiRayaiRay149 aiRay () AI_NO_EXCEPT {} aiRayaiRay150 aiRay (const aiVector3D& _pos, const aiVector3D& _dir) 151 : pos(_pos), dir(_dir) {} 152 aiRayaiRay153 aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {} 154 155 #endif // !__cplusplus 156 157 //! Position and direction of the ray 158 C_STRUCT aiVector3D pos, dir; 159 }; // !struct aiRay 160 161 // ---------------------------------------------------------------------------------- 162 /** Represents a color in Red-Green-Blue space. 163 */ 164 struct aiColor3D 165 { 166 #ifdef __cplusplus aiColor3DaiColor3D167 aiColor3D () AI_NO_EXCEPT : r(0.0f), g(0.0f), b(0.0f) {} aiColor3DaiColor3D168 aiColor3D (ai_real _r, ai_real _g, ai_real _b) : r(_r), g(_g), b(_b) {} aiColor3DaiColor3D169 explicit aiColor3D (ai_real _r) : r(_r), g(_r), b(_r) {} aiColor3DaiColor3D170 aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {} 171 172 aiColor3D &operator=(const aiColor3D &o) { 173 r = o.r; 174 g = o.g; 175 b = o.b; 176 return *this; 177 } 178 179 /** Component-wise comparison */ 180 // TODO: add epsilon? 181 bool operator == (const aiColor3D& other) const 182 {return r == other.r && g == other.g && b == other.b;} 183 184 /** Component-wise inverse comparison */ 185 // TODO: add epsilon? 186 bool operator != (const aiColor3D& other) const 187 {return r != other.r || g != other.g || b != other.b;} 188 189 /** Component-wise comparison */ 190 // TODO: add epsilon? 191 bool operator < (const aiColor3D& other) const { 192 return r < other.r || ( r == other.r && (g < other.g || (g == other.g && b < other.b ) ) ); 193 } 194 195 /** Component-wise addition */ 196 aiColor3D operator+(const aiColor3D& c) const { 197 return aiColor3D(r+c.r,g+c.g,b+c.b); 198 } 199 200 /** Component-wise subtraction */ 201 aiColor3D operator-(const aiColor3D& c) const { 202 return aiColor3D(r-c.r,g-c.g,b-c.b); 203 } 204 205 /** Component-wise multiplication */ 206 aiColor3D operator*(const aiColor3D& c) const { 207 return aiColor3D(r*c.r,g*c.g,b*c.b); 208 } 209 210 /** Multiply with a scalar */ 211 aiColor3D operator*(ai_real f) const { 212 return aiColor3D(r*f,g*f,b*f); 213 } 214 215 /** Access a specific color component */ 216 ai_real operator[](unsigned int i) const { 217 return *(&r + i); 218 } 219 220 /** Access a specific color component */ 221 ai_real& operator[](unsigned int i) { 222 if ( 0 == i ) { 223 return r; 224 } else if ( 1 == i ) { 225 return g; 226 } else if ( 2 == i ) { 227 return b; 228 } 229 return r; 230 } 231 232 /** Check whether a color is black */ IsBlackaiColor3D233 bool IsBlack() const { 234 static const ai_real epsilon = ai_real(10e-3); 235 return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon; 236 } 237 238 #endif // !__cplusplus 239 240 //! Red, green and blue color values 241 ai_real r, g, b; 242 }; // !struct aiColor3D 243 244 // ---------------------------------------------------------------------------------- 245 /** Represents an UTF-8 string, zero byte terminated. 246 * 247 * The character set of an aiString is explicitly defined to be UTF-8. This Unicode 248 * transformation was chosen in the belief that most strings in 3d files are limited 249 * to ASCII, thus the character set needed to be strictly ASCII compatible. 250 * 251 * Most text file loaders provide proper Unicode input file handling, special unicode 252 * characters are correctly transcoded to UTF8 and are kept throughout the libraries' 253 * import pipeline. 254 * 255 * For most applications, it will be absolutely sufficient to interpret the 256 * aiString as ASCII data and work with it as one would work with a plain char*. 257 * Windows users in need of proper support for i.e asian characters can use the 258 * MultiByteToWideChar(), WideCharToMultiByte() WinAPI functionality to convert the 259 * UTF-8 strings to their working character set (i.e. MBCS, WideChar). 260 * 261 * We use this representation instead of std::string to be C-compatible. The 262 * (binary) length of such a string is limited to MAXLEN characters (including the 263 * the terminating zero). 264 */ 265 struct aiString 266 { 267 #ifdef __cplusplus 268 /** Default constructor, the string is set to have zero length */ aiStringaiString269 aiString() AI_NO_EXCEPT 270 : length( 0 ) { 271 data[0] = '\0'; 272 273 #ifdef ASSIMP_BUILD_DEBUG 274 // Debug build: overwrite the string on its full length with ESC (27) 275 memset(data+1,27,MAXLEN-1); 276 #endif 277 } 278 279 /** Copy constructor */ aiStringaiString280 aiString(const aiString& rOther) 281 : length(rOther.length) 282 { 283 // Crop the string to the maximum length 284 length = length>=MAXLEN?MAXLEN-1:length; 285 memcpy( data, rOther.data, length); 286 data[length] = '\0'; 287 } 288 289 /** Constructor from std::string */ aiStringaiString290 explicit aiString(const std::string& pString) : 291 length( (ai_uint32) pString.length()) 292 { 293 length = length>=MAXLEN?MAXLEN-1:length; 294 memcpy( data, pString.c_str(), length); 295 data[length] = '\0'; 296 } 297 298 /** Copy a std::string to the aiString */ SetaiString299 void Set( const std::string& pString) { 300 if( pString.length() > MAXLEN - 1) { 301 return; 302 } 303 length = (ai_uint32)pString.length(); 304 memcpy( data, pString.c_str(), length); 305 data[length] = 0; 306 } 307 308 /** Copy a const char* to the aiString */ SetaiString309 void Set( const char* sz) { 310 const ai_int32 len = (ai_uint32) ::strlen(sz); 311 if( len > (ai_int32)MAXLEN - 1) { 312 return; 313 } 314 length = len; 315 memcpy( data, sz, len); 316 data[len] = 0; 317 } 318 319 320 /** Assignment operator */ 321 aiString& operator = (const aiString &rOther) { 322 if (this == &rOther) { 323 return *this; 324 } 325 326 length = rOther.length;; 327 memcpy( data, rOther.data, length); 328 data[length] = '\0'; 329 return *this; 330 } 331 332 333 /** Assign a const char* to the string */ 334 aiString& operator = (const char* sz) { 335 Set(sz); 336 return *this; 337 } 338 339 /** Assign a cstd::string to the string */ 340 aiString& operator = ( const std::string& pString) { 341 Set(pString); 342 return *this; 343 } 344 345 /** Comparison operator */ 346 bool operator==(const aiString& other) const { 347 return (length == other.length && 0 == memcmp(data,other.data,length)); 348 } 349 350 /** Inverse comparison operator */ 351 bool operator!=(const aiString& other) const { 352 return (length != other.length || 0 != memcmp(data,other.data,length)); 353 } 354 355 /** Append a string to the string */ AppendaiString356 void Append (const char* app) { 357 const ai_uint32 len = (ai_uint32) ::strlen(app); 358 if (!len) { 359 return; 360 } 361 if (length + len >= MAXLEN) { 362 return; 363 } 364 365 memcpy(&data[length],app,len+1); 366 length += len; 367 } 368 369 /** Clear the string - reset its length to zero */ ClearaiString370 void Clear () { 371 length = 0; 372 data[0] = '\0'; 373 374 #ifdef ASSIMP_BUILD_DEBUG 375 // Debug build: overwrite the string on its full length with ESC (27) 376 memset(data+1,27,MAXLEN-1); 377 #endif 378 } 379 380 /** Returns a pointer to the underlying zero-terminated array of characters */ C_StraiString381 const char* C_Str() const { 382 return data; 383 } 384 385 #endif // !__cplusplus 386 387 /** Binary length of the string excluding the terminal 0. This is NOT the 388 * logical length of strings containing UTF-8 multi-byte sequences! It's 389 * the number of bytes from the beginning of the string to its end.*/ 390 ai_uint32 length; 391 392 /** String buffer. Size limit is MAXLEN */ 393 char data[MAXLEN]; 394 } ; // !struct aiString 395 396 397 // ---------------------------------------------------------------------------------- 398 /** Standard return type for some library functions. 399 * Rarely used, and if, mostly in the C API. 400 */ 401 typedef enum aiReturn 402 { 403 /** Indicates that a function was successful */ 404 aiReturn_SUCCESS = 0x0, 405 406 /** Indicates that a function failed */ 407 aiReturn_FAILURE = -0x1, 408 409 /** Indicates that not enough memory was available 410 * to perform the requested operation 411 */ 412 aiReturn_OUTOFMEMORY = -0x3, 413 414 /** @cond never 415 * Force 32-bit size enum 416 */ 417 _AI_ENFORCE_ENUM_SIZE = 0x7fffffff 418 419 /// @endcond 420 } aiReturn; // !enum aiReturn 421 422 // just for backwards compatibility, don't use these constants anymore 423 #define AI_SUCCESS aiReturn_SUCCESS 424 #define AI_FAILURE aiReturn_FAILURE 425 #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY 426 427 // ---------------------------------------------------------------------------------- 428 /** Seek origins (for the virtual file system API). 429 * Much cooler than using SEEK_SET, SEEK_CUR or SEEK_END. 430 */ 431 enum aiOrigin 432 { 433 /** Beginning of the file */ 434 aiOrigin_SET = 0x0, 435 436 /** Current position of the file pointer */ 437 aiOrigin_CUR = 0x1, 438 439 /** End of the file, offsets must be negative */ 440 aiOrigin_END = 0x2, 441 442 /** @cond never 443 * Force 32-bit size enum 444 */ 445 _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff 446 447 /// @endcond 448 }; // !enum aiOrigin 449 450 // ---------------------------------------------------------------------------------- 451 /** @brief Enumerates predefined log streaming destinations. 452 * Logging to these streams can be enabled with a single call to 453 * #LogStream::createDefaultStream. 454 */ 455 enum aiDefaultLogStream 456 { 457 /** Stream the log to a file */ 458 aiDefaultLogStream_FILE = 0x1, 459 460 /** Stream the log to std::cout */ 461 aiDefaultLogStream_STDOUT = 0x2, 462 463 /** Stream the log to std::cerr */ 464 aiDefaultLogStream_STDERR = 0x4, 465 466 /** MSVC only: Stream the log the the debugger 467 * (this relies on OutputDebugString from the Win32 SDK) 468 */ 469 aiDefaultLogStream_DEBUGGER = 0x8, 470 471 /** @cond never 472 * Force 32-bit size enum 473 */ 474 _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff 475 /// @endcond 476 }; // !enum aiDefaultLogStream 477 478 // just for backwards compatibility, don't use these constants anymore 479 #define DLS_FILE aiDefaultLogStream_FILE 480 #define DLS_STDOUT aiDefaultLogStream_STDOUT 481 #define DLS_STDERR aiDefaultLogStream_STDERR 482 #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER 483 484 // ---------------------------------------------------------------------------------- 485 /** Stores the memory requirements for different components (e.g. meshes, materials, 486 * animations) of an import. All sizes are in bytes. 487 * @see Importer::GetMemoryRequirements() 488 */ 489 struct aiMemoryInfo 490 { 491 #ifdef __cplusplus 492 493 /** Default constructor */ aiMemoryInfoaiMemoryInfo494 aiMemoryInfo() AI_NO_EXCEPT 495 : textures (0) 496 , materials (0) 497 , meshes (0) 498 , nodes (0) 499 , animations (0) 500 , cameras (0) 501 , lights (0) 502 , total (0) 503 {} 504 505 #endif 506 507 /** Storage allocated for texture data */ 508 unsigned int textures; 509 510 /** Storage allocated for material data */ 511 unsigned int materials; 512 513 /** Storage allocated for mesh data */ 514 unsigned int meshes; 515 516 /** Storage allocated for node data */ 517 unsigned int nodes; 518 519 /** Storage allocated for animation data */ 520 unsigned int animations; 521 522 /** Storage allocated for camera data */ 523 unsigned int cameras; 524 525 /** Storage allocated for light data */ 526 unsigned int lights; 527 528 /** Total storage allocated for the full import. */ 529 unsigned int total; 530 }; // !struct aiMemoryInfo 531 532 #ifdef __cplusplus 533 } 534 #endif //! __cplusplus 535 536 // Include implementation files 537 #include "vector2.inl" 538 #include "vector3.inl" 539 #include "color4.inl" 540 #include "quaternion.inl" 541 #include "matrix3x3.inl" 542 #include "matrix4x4.inl" 543 544 #endif // AI_TYPES_H_INC 545