vrshoot
diff libs/assimp/assimp/types.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/assimp/types.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,500 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2012, assimp team 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the following 1.15 +conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 +--------------------------------------------------------------------------- 1.43 +*/ 1.44 + 1.45 +/** @file types.h 1.46 + * Basic data types and primitives, such as vectors or colors. 1.47 + */ 1.48 +#ifndef AI_TYPES_H_INC 1.49 +#define AI_TYPES_H_INC 1.50 + 1.51 +// Some runtime headers 1.52 +#include <sys/types.h> 1.53 +#include <memory.h> 1.54 +#include <math.h> 1.55 +#include <stddef.h> 1.56 +#include <limits.h> 1.57 + 1.58 +// Our compile configuration 1.59 +#include "defs.h" 1.60 + 1.61 +// Some types moved to separate header due to size of operators 1.62 +#include "vector3.h" 1.63 +#include "vector2.h" 1.64 +#include "color4.h" 1.65 +#include "matrix3x3.h" 1.66 +#include "matrix4x4.h" 1.67 +#include "quaternion.h" 1.68 + 1.69 +#ifdef __cplusplus 1.70 +#include <new> // for std::nothrow_t 1.71 +#include <string> // for aiString::Set(const std::string&) 1.72 + 1.73 +namespace Assimp { 1.74 + //! @cond never 1.75 +namespace Intern { 1.76 + // -------------------------------------------------------------------- 1.77 + /** @brief Internal helper class to utilize our internal new/delete 1.78 + * routines for allocating object of this and derived classes. 1.79 + * 1.80 + * By doing this you can safely share class objects between Assimp 1.81 + * and the application - it works even over DLL boundaries. A good 1.82 + * example is the #IOSystem where the application allocates its custom 1.83 + * #IOSystem, then calls #Importer::SetIOSystem(). When the Importer 1.84 + * destructs, Assimp calls operator delete on the stored #IOSystem. 1.85 + * If it lies on a different heap than Assimp is working with, 1.86 + * the application is determined to crash. 1.87 + */ 1.88 + // -------------------------------------------------------------------- 1.89 +#ifndef SWIG 1.90 + struct ASSIMP_API AllocateFromAssimpHeap { 1.91 + // http://www.gotw.ca/publications/mill15.htm 1.92 + 1.93 + // new/delete overload 1.94 + void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */; 1.95 + void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw(); 1.96 + void operator delete ( void* data); 1.97 + 1.98 + // array new/delete overload 1.99 + void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */; 1.100 + void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw(); 1.101 + void operator delete[] ( void* data); 1.102 + 1.103 + }; // struct AllocateFromAssimpHeap 1.104 +#endif 1.105 +} // namespace Intern 1.106 + //! @endcond 1.107 +} // namespace Assimp 1.108 + 1.109 +extern "C" { 1.110 +#endif 1.111 + 1.112 +/** Maximum dimension for strings, ASSIMP strings are zero terminated. */ 1.113 +#ifdef __cplusplus 1.114 +const size_t MAXLEN = 1024; 1.115 +#else 1.116 +# define MAXLEN 1024 1.117 +#endif 1.118 + 1.119 +#include "./Compiler/pushpack1.h" 1.120 + 1.121 +// ---------------------------------------------------------------------------------- 1.122 +/** Represents a plane in a three-dimensional, euclidean space 1.123 +*/ 1.124 +struct aiPlane 1.125 +{ 1.126 +#ifdef __cplusplus 1.127 + aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {} 1.128 + aiPlane (float _a, float _b, float _c, float _d) 1.129 + : a(_a), b(_b), c(_c), d(_d) {} 1.130 + 1.131 + aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {} 1.132 + 1.133 +#endif // !__cplusplus 1.134 + 1.135 + //! Plane equation 1.136 + float a,b,c,d; 1.137 +} PACK_STRUCT; // !struct aiPlane 1.138 + 1.139 +// ---------------------------------------------------------------------------------- 1.140 +/** Represents a ray 1.141 +*/ 1.142 +struct aiRay 1.143 +{ 1.144 +#ifdef __cplusplus 1.145 + aiRay () {} 1.146 + aiRay (const aiVector3D& _pos, const aiVector3D& _dir) 1.147 + : pos(_pos), dir(_dir) {} 1.148 + 1.149 + aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {} 1.150 + 1.151 +#endif // !__cplusplus 1.152 + 1.153 + //! Position and direction of the ray 1.154 + C_STRUCT aiVector3D pos, dir; 1.155 +} PACK_STRUCT; // !struct aiRay 1.156 + 1.157 +// ---------------------------------------------------------------------------------- 1.158 +/** Represents a color in Red-Green-Blue space. 1.159 +*/ 1.160 +struct aiColor3D 1.161 +{ 1.162 +#ifdef __cplusplus 1.163 + aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {} 1.164 + aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {} 1.165 + aiColor3D (float _r) : r(_r), g(_r), b(_r) {} 1.166 + aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {} 1.167 + 1.168 + /** Component-wise comparison */ 1.169 + // TODO: add epsilon? 1.170 + bool operator == (const aiColor3D& other) const 1.171 + {return r == other.r && g == other.g && b == other.b;} 1.172 + 1.173 + /** Component-wise inverse comparison */ 1.174 + // TODO: add epsilon? 1.175 + bool operator != (const aiColor3D& other) const 1.176 + {return r != other.r || g != other.g || b != other.b;} 1.177 + 1.178 + /** Component-wise addition */ 1.179 + aiColor3D operator+(const aiColor3D& c) const { 1.180 + return aiColor3D(r+c.r,g+c.g,b+c.b); 1.181 + } 1.182 + 1.183 + /** Component-wise subtraction */ 1.184 + aiColor3D operator-(const aiColor3D& c) const { 1.185 + return aiColor3D(r-c.r,g-c.g,b-c.b); 1.186 + } 1.187 + 1.188 + /** Component-wise multiplication */ 1.189 + aiColor3D operator*(const aiColor3D& c) const { 1.190 + return aiColor3D(r*c.r,g*c.g,b*c.b); 1.191 + } 1.192 + 1.193 + /** Multiply with a scalar */ 1.194 + aiColor3D operator*(float f) const { 1.195 + return aiColor3D(r*f,g*f,b*f); 1.196 + } 1.197 + 1.198 + /** Access a specific color component */ 1.199 + float operator[](unsigned int i) const { 1.200 + return *(&r + i); 1.201 + } 1.202 + 1.203 + /** Access a specific color component */ 1.204 + float& operator[](unsigned int i) { 1.205 + return *(&r + i); 1.206 + } 1.207 + 1.208 + /** Check whether a color is black */ 1.209 + bool IsBlack() const { 1.210 + static const float epsilon = 10e-3f; 1.211 + return fabs( r ) < epsilon && fabs( g ) < epsilon && fabs( b ) < epsilon; 1.212 + } 1.213 + 1.214 +#endif // !__cplusplus 1.215 + 1.216 + //! Red, green and blue color values 1.217 + float r, g, b; 1.218 +} PACK_STRUCT; // !struct aiColor3D 1.219 +#include "./Compiler/poppack1.h" 1.220 + 1.221 +// ---------------------------------------------------------------------------------- 1.222 +/** Represents an UTF-8 string, zero byte terminated. 1.223 + * 1.224 + * The character set of an aiString is explicitly defined to be UTF-8. This Unicode 1.225 + * transformation was chosen in the belief that most strings in 3d files are limited 1.226 + * to ASCII, thus the character set needed to be strictly ASCII compatible. 1.227 + * 1.228 + * Most text file loaders provide proper Unicode input file handling, special unicode 1.229 + * characters are correctly transcoded to UTF8 and are kept throughout the libraries' 1.230 + * import pipeline. 1.231 + * 1.232 + * For most applications, it will be absolutely sufficient to interpret the 1.233 + * aiString as ASCII data and work with it as one would work with a plain char*. 1.234 + * Windows users in need of proper support for i.e asian characters can use the 1.235 + * #MultiByteToWideChar(), #WideCharToMultiByte() WinAPI functionality to convert the 1.236 + * UTF-8 strings to their working character set (i.e. MBCS, WideChar). 1.237 + * 1.238 + * We use this representation instead of std::string to be C-compatible. The 1.239 + * (binary) length of such a string is limited to MAXLEN characters (including the 1.240 + * the terminating zero). 1.241 +*/ 1.242 +struct aiString 1.243 +{ 1.244 +#ifdef __cplusplus 1.245 + /** Default constructor, the string is set to have zero length */ 1.246 + aiString() : 1.247 + length(0) 1.248 + { 1.249 + data[0] = '\0'; 1.250 + 1.251 +#ifdef _DEBUG 1.252 + // Debug build: overwrite the string on its full length with ESC (27) 1.253 + memset(data+1,27,MAXLEN-1); 1.254 +#endif 1.255 + } 1.256 + 1.257 + /** Copy constructor */ 1.258 + aiString(const aiString& rOther) : 1.259 + length(rOther.length) 1.260 + { 1.261 + // Crop the string to the maximum length 1.262 + length = length>=MAXLEN?MAXLEN-1:length; 1.263 + memcpy( data, rOther.data, length); 1.264 + data[length] = '\0'; 1.265 + } 1.266 + 1.267 + /** Constructor from std::string */ 1.268 + explicit aiString(const std::string& pString) : 1.269 + length(pString.length()) 1.270 + { 1.271 + length = length>=MAXLEN?MAXLEN-1:length; 1.272 + memcpy( data, pString.c_str(), length); 1.273 + data[length] = '\0'; 1.274 + } 1.275 + 1.276 + /** Copy a std::string to the aiString */ 1.277 + void Set( const std::string& pString) { 1.278 + if( pString.length() > MAXLEN - 1) { 1.279 + return; 1.280 + } 1.281 + length = pString.length(); 1.282 + memcpy( data, pString.c_str(), length); 1.283 + data[length] = 0; 1.284 + } 1.285 + 1.286 + /** Copy a const char* to the aiString */ 1.287 + void Set( const char* sz) { 1.288 + const size_t len = ::strlen(sz); 1.289 + if( len > MAXLEN - 1) { 1.290 + return; 1.291 + } 1.292 + length = len; 1.293 + memcpy( data, sz, len); 1.294 + data[len] = 0; 1.295 + } 1.296 + 1.297 + /** Assign a const char* to the string */ 1.298 + aiString& operator = (const char* sz) { 1.299 + Set(sz); 1.300 + return *this; 1.301 + } 1.302 + 1.303 + /** Assign a cstd::string to the string */ 1.304 + aiString& operator = ( const std::string& pString) { 1.305 + Set(pString); 1.306 + return *this; 1.307 + } 1.308 + 1.309 + /** Comparison operator */ 1.310 + bool operator==(const aiString& other) const { 1.311 + return (length == other.length && 0 == memcmp(data,other.data,length)); 1.312 + } 1.313 + 1.314 + /** Inverse comparison operator */ 1.315 + bool operator!=(const aiString& other) const { 1.316 + return (length != other.length || 0 != memcmp(data,other.data,length)); 1.317 + } 1.318 + 1.319 + /** Append a string to the string */ 1.320 + void Append (const char* app) { 1.321 + const size_t len = ::strlen(app); 1.322 + if (!len) { 1.323 + return; 1.324 + } 1.325 + if (length + len >= MAXLEN) { 1.326 + return; 1.327 + } 1.328 + 1.329 + memcpy(&data[length],app,len+1); 1.330 + length += len; 1.331 + } 1.332 + 1.333 + /** Clear the string - reset its length to zero */ 1.334 + void Clear () { 1.335 + length = 0; 1.336 + data[0] = '\0'; 1.337 + 1.338 +#ifdef _DEBUG 1.339 + // Debug build: overwrite the string on its full length with ESC (27) 1.340 + memset(data+1,27,MAXLEN-1); 1.341 +#endif 1.342 + } 1.343 + 1.344 + /** Returns a pointer to the underlying zero-terminated array of characters */ 1.345 + const char* C_Str() const { 1.346 + return data; 1.347 + } 1.348 + 1.349 +#endif // !__cplusplus 1.350 + 1.351 + /** Binary length of the string excluding the terminal 0. This is NOT the 1.352 + * logical length of strings containing UTF-8 multibyte sequences! It's 1.353 + * the number of bytes from the beginning of the string to its end.*/ 1.354 + size_t length; 1.355 + 1.356 + /** String buffer. Size limit is MAXLEN */ 1.357 + char data[MAXLEN]; 1.358 +} ; // !struct aiString 1.359 + 1.360 + 1.361 +// ---------------------------------------------------------------------------------- 1.362 +/** Standard return type for some library functions. 1.363 + * Rarely used, and if, mostly in the C API. 1.364 + */ 1.365 +enum aiReturn 1.366 +{ 1.367 + /** Indicates that a function was successful */ 1.368 + aiReturn_SUCCESS = 0x0, 1.369 + 1.370 + /** Indicates that a function failed */ 1.371 + aiReturn_FAILURE = -0x1, 1.372 + 1.373 + /** Indicates that not enough memory was available 1.374 + * to perform the requested operation 1.375 + */ 1.376 + aiReturn_OUTOFMEMORY = -0x3, 1.377 + 1.378 + /** @cond never 1.379 + * Force 32-bit size enum 1.380 + */ 1.381 + _AI_ENFORCE_ENUM_SIZE = 0x7fffffff 1.382 +}; // !enum aiReturn 1.383 + 1.384 +// just for backwards compatibility, don't use these constants anymore 1.385 +#define AI_SUCCESS aiReturn_SUCCESS 1.386 +#define AI_FAILURE aiReturn_FAILURE 1.387 +#define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY 1.388 + 1.389 +// ---------------------------------------------------------------------------------- 1.390 +/** Seek origins (for the virtual file system API). 1.391 + * Much cooler than using SEEK_SET, SEEK_CUR or SEEK_END. 1.392 + */ 1.393 +enum aiOrigin 1.394 +{ 1.395 + /** Beginning of the file */ 1.396 + aiOrigin_SET = 0x0, 1.397 + 1.398 + /** Current position of the file pointer */ 1.399 + aiOrigin_CUR = 0x1, 1.400 + 1.401 + /** End of the file, offsets must be negative */ 1.402 + aiOrigin_END = 0x2, 1.403 + 1.404 + /** @cond never 1.405 + * Force 32-bit size enum 1.406 + */ 1.407 + _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff 1.408 +}; // !enum aiOrigin 1.409 + 1.410 +// ---------------------------------------------------------------------------------- 1.411 +/** @brief Enumerates predefined log streaming destinations. 1.412 + * Logging to these streams can be enabled with a single call to 1.413 + * #LogStream::createDefaultStream or #aiAttachPredefinedLogStream(), 1.414 + * respectively. 1.415 + */ 1.416 +enum aiDefaultLogStream 1.417 +{ 1.418 + /** Stream the log to a file */ 1.419 + aiDefaultLogStream_FILE = 0x1, 1.420 + 1.421 + /** Stream the log to std::cout */ 1.422 + aiDefaultLogStream_STDOUT = 0x2, 1.423 + 1.424 + /** Stream the log to std::cerr */ 1.425 + aiDefaultLogStream_STDERR = 0x4, 1.426 + 1.427 + /** MSVC only: Stream the log the the debugger 1.428 + * (this relies on OutputDebugString from the Win32 SDK) 1.429 + */ 1.430 + aiDefaultLogStream_DEBUGGER = 0x8, 1.431 + 1.432 + /** @cond never 1.433 + * Force 32-bit size enum 1.434 + */ 1.435 + _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff 1.436 +}; // !enum aiDefaultLogStream 1.437 + 1.438 +// just for backwards compatibility, don't use these constants anymore 1.439 +#define DLS_FILE aiDefaultLogStream_FILE 1.440 +#define DLS_STDOUT aiDefaultLogStream_STDOUT 1.441 +#define DLS_STDERR aiDefaultLogStream_STDERR 1.442 +#define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER 1.443 + 1.444 +// ---------------------------------------------------------------------------------- 1.445 +/** Stores the memory requirements for different components (e.g. meshes, materials, 1.446 + * animations) of an import. All sizes are in bytes. 1.447 + * @see Importer::GetMemoryRequirements() 1.448 +*/ 1.449 +struct aiMemoryInfo 1.450 +{ 1.451 +#ifdef __cplusplus 1.452 + 1.453 + /** Default constructor */ 1.454 + aiMemoryInfo() 1.455 + : textures (0) 1.456 + , materials (0) 1.457 + , meshes (0) 1.458 + , nodes (0) 1.459 + , animations (0) 1.460 + , cameras (0) 1.461 + , lights (0) 1.462 + , total (0) 1.463 + {} 1.464 + 1.465 +#endif 1.466 + 1.467 + /** Storage allocated for texture data */ 1.468 + unsigned int textures; 1.469 + 1.470 + /** Storage allocated for material data */ 1.471 + unsigned int materials; 1.472 + 1.473 + /** Storage allocated for mesh data */ 1.474 + unsigned int meshes; 1.475 + 1.476 + /** Storage allocated for node data */ 1.477 + unsigned int nodes; 1.478 + 1.479 + /** Storage allocated for animation data */ 1.480 + unsigned int animations; 1.481 + 1.482 + /** Storage allocated for camera data */ 1.483 + unsigned int cameras; 1.484 + 1.485 + /** Storage allocated for light data */ 1.486 + unsigned int lights; 1.487 + 1.488 + /** Total storage allocated for the full import. */ 1.489 + unsigned int total; 1.490 +}; // !struct aiMemoryInfo 1.491 + 1.492 +#ifdef __cplusplus 1.493 +} 1.494 +#endif //! __cplusplus 1.495 + 1.496 +// Include implementation files 1.497 +#include "vector2.inl" 1.498 +#include "vector3.inl" 1.499 +#include "color4.inl" 1.500 +#include "quaternion.inl" 1.501 +#include "matrix3x3.inl" 1.502 +#include "matrix4x4.inl" 1.503 +#endif