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