nuclear@0: /* nuclear@0: --------------------------------------------------------------------------- nuclear@0: Open Asset Import Library (assimp) nuclear@0: --------------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2018, assimp team nuclear@0: nuclear@0: nuclear@0: nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the following nuclear@0: conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: --------------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file types.h nuclear@0: * Basic data types and primitives, such as vectors or colors. nuclear@0: */ nuclear@0: #pragma once nuclear@0: #ifndef AI_TYPES_H_INC nuclear@0: #define AI_TYPES_H_INC nuclear@0: nuclear@0: // Some runtime headers nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: // Our compile configuration nuclear@0: #include "defs.h" nuclear@0: nuclear@0: // Some types moved to separate header due to size of operators nuclear@0: #include "vector3.h" nuclear@0: #include "vector2.h" nuclear@0: #include "color4.h" nuclear@0: #include "matrix3x3.h" nuclear@0: #include "matrix4x4.h" nuclear@0: #include "quaternion.h" nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: #include nuclear@0: #include // for std::nothrow_t nuclear@0: #include // for aiString::Set(const std::string&) nuclear@0: nuclear@0: namespace Assimp { nuclear@0: //! @cond never nuclear@0: namespace Intern { nuclear@0: // -------------------------------------------------------------------- nuclear@0: /** @brief Internal helper class to utilize our internal new/delete nuclear@0: * routines for allocating object of this and derived classes. nuclear@0: * nuclear@0: * By doing this you can safely share class objects between Assimp nuclear@0: * and the application - it works even over DLL boundaries. A good nuclear@0: * example is the #IOSystem where the application allocates its custom nuclear@0: * #IOSystem, then calls #Importer::SetIOSystem(). When the Importer nuclear@0: * destructs, Assimp calls operator delete on the stored #IOSystem. nuclear@0: * If it lies on a different heap than Assimp is working with, nuclear@0: * the application is determined to crash. nuclear@0: */ nuclear@0: // -------------------------------------------------------------------- nuclear@0: #ifndef SWIG nuclear@0: struct ASSIMP_API AllocateFromAssimpHeap { nuclear@0: // http://www.gotw.ca/publications/mill15.htm nuclear@0: nuclear@0: // new/delete overload nuclear@0: void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */; nuclear@0: void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw(); nuclear@0: void operator delete ( void* data); nuclear@0: nuclear@0: // array new/delete overload nuclear@0: void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */; nuclear@0: void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw(); nuclear@0: void operator delete[] ( void* data); nuclear@0: nuclear@0: }; // struct AllocateFromAssimpHeap nuclear@0: #endif nuclear@0: } // namespace Intern nuclear@0: //! @endcond nuclear@0: } // namespace Assimp nuclear@0: nuclear@0: extern "C" { nuclear@0: #endif nuclear@0: nuclear@0: /** Maximum dimension for strings, ASSIMP strings are zero terminated. */ nuclear@0: #ifdef __cplusplus nuclear@0: static const size_t MAXLEN = 1024; nuclear@0: #else nuclear@0: # define MAXLEN 1024 nuclear@0: #endif nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Represents a plane in a three-dimensional, euclidean space nuclear@0: */ nuclear@0: struct aiPlane { nuclear@0: #ifdef __cplusplus nuclear@0: aiPlane () AI_NO_EXCEPT : a(0.f), b(0.f), c(0.f), d(0.f) {} nuclear@0: aiPlane (ai_real _a, ai_real _b, ai_real _c, ai_real _d) nuclear@0: : a(_a), b(_b), c(_c), d(_d) {} nuclear@0: nuclear@0: aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {} nuclear@0: nuclear@0: #endif // !__cplusplus nuclear@0: nuclear@0: //! Plane equation nuclear@0: ai_real a,b,c,d; nuclear@0: }; // !struct aiPlane nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Represents a ray nuclear@0: */ nuclear@0: struct aiRay { nuclear@0: #ifdef __cplusplus nuclear@0: aiRay () AI_NO_EXCEPT {} nuclear@0: aiRay (const aiVector3D& _pos, const aiVector3D& _dir) nuclear@0: : pos(_pos), dir(_dir) {} nuclear@0: nuclear@0: aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {} nuclear@0: nuclear@0: #endif // !__cplusplus nuclear@0: nuclear@0: //! Position and direction of the ray nuclear@0: C_STRUCT aiVector3D pos, dir; nuclear@0: }; // !struct aiRay nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Represents a color in Red-Green-Blue space. nuclear@0: */ nuclear@0: struct aiColor3D nuclear@0: { nuclear@0: #ifdef __cplusplus nuclear@0: aiColor3D () AI_NO_EXCEPT : r(0.0f), g(0.0f), b(0.0f) {} nuclear@0: aiColor3D (ai_real _r, ai_real _g, ai_real _b) : r(_r), g(_g), b(_b) {} nuclear@0: explicit aiColor3D (ai_real _r) : r(_r), g(_r), b(_r) {} nuclear@0: aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {} nuclear@0: nuclear@0: /** Component-wise comparison */ nuclear@0: // TODO: add epsilon? nuclear@0: bool operator == (const aiColor3D& other) const nuclear@0: {return r == other.r && g == other.g && b == other.b;} nuclear@0: nuclear@0: /** Component-wise inverse comparison */ nuclear@0: // TODO: add epsilon? nuclear@0: bool operator != (const aiColor3D& other) const nuclear@0: {return r != other.r || g != other.g || b != other.b;} nuclear@0: nuclear@0: /** Component-wise comparison */ nuclear@0: // TODO: add epsilon? nuclear@0: bool operator < (const aiColor3D& other) const { nuclear@0: return r < other.r || ( r == other.r && (g < other.g || (g == other.g && b < other.b ) ) ); nuclear@0: } nuclear@0: nuclear@0: /** Component-wise addition */ nuclear@0: aiColor3D operator+(const aiColor3D& c) const { nuclear@0: return aiColor3D(r+c.r,g+c.g,b+c.b); nuclear@0: } nuclear@0: nuclear@0: /** Component-wise subtraction */ nuclear@0: aiColor3D operator-(const aiColor3D& c) const { nuclear@0: return aiColor3D(r-c.r,g-c.g,b-c.b); nuclear@0: } nuclear@0: nuclear@0: /** Component-wise multiplication */ nuclear@0: aiColor3D operator*(const aiColor3D& c) const { nuclear@0: return aiColor3D(r*c.r,g*c.g,b*c.b); nuclear@0: } nuclear@0: nuclear@0: /** Multiply with a scalar */ nuclear@0: aiColor3D operator*(ai_real f) const { nuclear@0: return aiColor3D(r*f,g*f,b*f); nuclear@0: } nuclear@0: nuclear@0: /** Access a specific color component */ nuclear@0: ai_real operator[](unsigned int i) const { nuclear@0: return *(&r + i); nuclear@0: } nuclear@0: nuclear@0: /** Access a specific color component */ nuclear@0: ai_real& operator[](unsigned int i) { nuclear@0: if ( 0 == i ) { nuclear@0: return r; nuclear@0: } else if ( 1 == i ) { nuclear@0: return g; nuclear@0: } else if ( 2 == i ) { nuclear@0: return b; nuclear@0: } nuclear@0: return r; nuclear@0: } nuclear@0: nuclear@0: /** Check whether a color is black */ nuclear@0: bool IsBlack() const { nuclear@0: static const ai_real epsilon = ai_real(10e-3); nuclear@0: return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon; nuclear@0: } nuclear@0: nuclear@0: #endif // !__cplusplus nuclear@0: nuclear@0: //! Red, green and blue color values nuclear@0: ai_real r, g, b; nuclear@0: }; // !struct aiColor3D nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Represents an UTF-8 string, zero byte terminated. nuclear@0: * nuclear@0: * The character set of an aiString is explicitly defined to be UTF-8. This Unicode nuclear@0: * transformation was chosen in the belief that most strings in 3d files are limited nuclear@0: * to ASCII, thus the character set needed to be strictly ASCII compatible. nuclear@0: * nuclear@0: * Most text file loaders provide proper Unicode input file handling, special unicode nuclear@0: * characters are correctly transcoded to UTF8 and are kept throughout the libraries' nuclear@0: * import pipeline. nuclear@0: * nuclear@0: * For most applications, it will be absolutely sufficient to interpret the nuclear@0: * aiString as ASCII data and work with it as one would work with a plain char*. nuclear@0: * Windows users in need of proper support for i.e asian characters can use the nuclear@0: * MultiByteToWideChar(), WideCharToMultiByte() WinAPI functionality to convert the nuclear@0: * UTF-8 strings to their working character set (i.e. MBCS, WideChar). nuclear@0: * nuclear@0: * We use this representation instead of std::string to be C-compatible. The nuclear@0: * (binary) length of such a string is limited to MAXLEN characters (including the nuclear@0: * the terminating zero). nuclear@0: */ nuclear@0: struct aiString nuclear@0: { nuclear@0: #ifdef __cplusplus nuclear@0: /** Default constructor, the string is set to have zero length */ nuclear@0: aiString() AI_NO_EXCEPT nuclear@0: : length( 0 ) { nuclear@0: data[0] = '\0'; nuclear@0: nuclear@0: #ifdef ASSIMP_BUILD_DEBUG nuclear@0: // Debug build: overwrite the string on its full length with ESC (27) nuclear@0: memset(data+1,27,MAXLEN-1); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: /** Copy constructor */ nuclear@0: aiString(const aiString& rOther) : nuclear@0: length(rOther.length) nuclear@0: { nuclear@0: // Crop the string to the maximum length nuclear@0: length = length>=MAXLEN?MAXLEN-1:length; nuclear@0: memcpy( data, rOther.data, length); nuclear@0: data[length] = '\0'; nuclear@0: } nuclear@0: nuclear@0: /** Constructor from std::string */ nuclear@0: explicit aiString(const std::string& pString) : nuclear@0: length(pString.length()) nuclear@0: { nuclear@0: length = length>=MAXLEN?MAXLEN-1:length; nuclear@0: memcpy( data, pString.c_str(), length); nuclear@0: data[length] = '\0'; nuclear@0: } nuclear@0: nuclear@0: /** Copy a std::string to the aiString */ nuclear@0: void Set( const std::string& pString) { nuclear@0: if( pString.length() > MAXLEN - 1) { nuclear@0: return; nuclear@0: } nuclear@0: length = pString.length(); nuclear@0: memcpy( data, pString.c_str(), length); nuclear@0: data[length] = 0; nuclear@0: } nuclear@0: nuclear@0: /** Copy a const char* to the aiString */ nuclear@0: void Set( const char* sz) { nuclear@0: const size_t len = ::strlen(sz); nuclear@0: if( len > MAXLEN - 1) { nuclear@0: return; nuclear@0: } nuclear@0: length = len; nuclear@0: memcpy( data, sz, len); nuclear@0: data[len] = 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /** Assignment operator */ nuclear@0: aiString& operator = (const aiString &rOther) { nuclear@0: if (this == &rOther) { nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: length = rOther.length;; nuclear@0: memcpy( data, rOther.data, length); nuclear@0: data[length] = '\0'; nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /** Assign a const char* to the string */ nuclear@0: aiString& operator = (const char* sz) { nuclear@0: Set(sz); nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: /** Assign a cstd::string to the string */ nuclear@0: aiString& operator = ( const std::string& pString) { nuclear@0: Set(pString); nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: /** Comparison operator */ nuclear@0: bool operator==(const aiString& other) const { nuclear@0: return (length == other.length && 0 == memcmp(data,other.data,length)); nuclear@0: } nuclear@0: nuclear@0: /** Inverse comparison operator */ nuclear@0: bool operator!=(const aiString& other) const { nuclear@0: return (length != other.length || 0 != memcmp(data,other.data,length)); nuclear@0: } nuclear@0: nuclear@0: /** Append a string to the string */ nuclear@0: void Append (const char* app) { nuclear@0: const size_t len = ::strlen(app); nuclear@0: if (!len) { nuclear@0: return; nuclear@0: } nuclear@0: if (length + len >= MAXLEN) { nuclear@0: return; nuclear@0: } nuclear@0: nuclear@0: memcpy(&data[length],app,len+1); nuclear@0: length += len; nuclear@0: } nuclear@0: nuclear@0: /** Clear the string - reset its length to zero */ nuclear@0: void Clear () { nuclear@0: length = 0; nuclear@0: data[0] = '\0'; nuclear@0: nuclear@0: #ifdef ASSIMP_BUILD_DEBUG nuclear@0: // Debug build: overwrite the string on its full length with ESC (27) nuclear@0: memset(data+1,27,MAXLEN-1); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: /** Returns a pointer to the underlying zero-terminated array of characters */ nuclear@0: const char* C_Str() const { nuclear@0: return data; nuclear@0: } nuclear@0: nuclear@0: #endif // !__cplusplus nuclear@0: nuclear@0: /** Binary length of the string excluding the terminal 0. This is NOT the nuclear@0: * logical length of strings containing UTF-8 multi-byte sequences! It's nuclear@0: * the number of bytes from the beginning of the string to its end.*/ nuclear@0: size_t length; nuclear@0: nuclear@0: /** String buffer. Size limit is MAXLEN */ nuclear@0: char data[MAXLEN]; nuclear@0: } ; // !struct aiString nuclear@0: nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Standard return type for some library functions. nuclear@0: * Rarely used, and if, mostly in the C API. nuclear@0: */ nuclear@0: typedef enum aiReturn nuclear@0: { nuclear@0: /** Indicates that a function was successful */ nuclear@0: aiReturn_SUCCESS = 0x0, nuclear@0: nuclear@0: /** Indicates that a function failed */ nuclear@0: aiReturn_FAILURE = -0x1, nuclear@0: nuclear@0: /** Indicates that not enough memory was available nuclear@0: * to perform the requested operation nuclear@0: */ nuclear@0: aiReturn_OUTOFMEMORY = -0x3, nuclear@0: nuclear@0: /** @cond never nuclear@0: * Force 32-bit size enum nuclear@0: */ nuclear@0: _AI_ENFORCE_ENUM_SIZE = 0x7fffffff nuclear@0: nuclear@0: /// @endcond nuclear@0: } aiReturn; // !enum aiReturn nuclear@0: nuclear@0: // just for backwards compatibility, don't use these constants anymore nuclear@0: #define AI_SUCCESS aiReturn_SUCCESS nuclear@0: #define AI_FAILURE aiReturn_FAILURE nuclear@0: #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Seek origins (for the virtual file system API). nuclear@0: * Much cooler than using SEEK_SET, SEEK_CUR or SEEK_END. nuclear@0: */ nuclear@0: enum aiOrigin nuclear@0: { nuclear@0: /** Beginning of the file */ nuclear@0: aiOrigin_SET = 0x0, nuclear@0: nuclear@0: /** Current position of the file pointer */ nuclear@0: aiOrigin_CUR = 0x1, nuclear@0: nuclear@0: /** End of the file, offsets must be negative */ nuclear@0: aiOrigin_END = 0x2, nuclear@0: nuclear@0: /** @cond never nuclear@0: * Force 32-bit size enum nuclear@0: */ nuclear@0: _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff nuclear@0: nuclear@0: /// @endcond nuclear@0: }; // !enum aiOrigin nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** @brief Enumerates predefined log streaming destinations. nuclear@0: * Logging to these streams can be enabled with a single call to nuclear@0: * #LogStream::createDefaultStream. nuclear@0: */ nuclear@0: enum aiDefaultLogStream nuclear@0: { nuclear@0: /** Stream the log to a file */ nuclear@0: aiDefaultLogStream_FILE = 0x1, nuclear@0: nuclear@0: /** Stream the log to std::cout */ nuclear@0: aiDefaultLogStream_STDOUT = 0x2, nuclear@0: nuclear@0: /** Stream the log to std::cerr */ nuclear@0: aiDefaultLogStream_STDERR = 0x4, nuclear@0: nuclear@0: /** MSVC only: Stream the log the the debugger nuclear@0: * (this relies on OutputDebugString from the Win32 SDK) nuclear@0: */ nuclear@0: aiDefaultLogStream_DEBUGGER = 0x8, nuclear@0: nuclear@0: /** @cond never nuclear@0: * Force 32-bit size enum nuclear@0: */ nuclear@0: _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff nuclear@0: /// @endcond nuclear@0: }; // !enum aiDefaultLogStream nuclear@0: nuclear@0: // just for backwards compatibility, don't use these constants anymore nuclear@0: #define DLS_FILE aiDefaultLogStream_FILE nuclear@0: #define DLS_STDOUT aiDefaultLogStream_STDOUT nuclear@0: #define DLS_STDERR aiDefaultLogStream_STDERR nuclear@0: #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER nuclear@0: nuclear@0: // ---------------------------------------------------------------------------------- nuclear@0: /** Stores the memory requirements for different components (e.g. meshes, materials, nuclear@0: * animations) of an import. All sizes are in bytes. nuclear@0: * @see Importer::GetMemoryRequirements() nuclear@0: */ nuclear@0: struct aiMemoryInfo nuclear@0: { nuclear@0: #ifdef __cplusplus nuclear@0: nuclear@0: /** Default constructor */ nuclear@0: aiMemoryInfo() AI_NO_EXCEPT nuclear@0: : textures (0) nuclear@0: , materials (0) nuclear@0: , meshes (0) nuclear@0: , nodes (0) nuclear@0: , animations (0) nuclear@0: , cameras (0) nuclear@0: , lights (0) nuclear@0: , total (0) nuclear@0: {} nuclear@0: nuclear@0: #endif nuclear@0: nuclear@0: /** Storage allocated for texture data */ nuclear@0: unsigned int textures; nuclear@0: nuclear@0: /** Storage allocated for material data */ nuclear@0: unsigned int materials; nuclear@0: nuclear@0: /** Storage allocated for mesh data */ nuclear@0: unsigned int meshes; nuclear@0: nuclear@0: /** Storage allocated for node data */ nuclear@0: unsigned int nodes; nuclear@0: nuclear@0: /** Storage allocated for animation data */ nuclear@0: unsigned int animations; nuclear@0: nuclear@0: /** Storage allocated for camera data */ nuclear@0: unsigned int cameras; nuclear@0: nuclear@0: /** Storage allocated for light data */ nuclear@0: unsigned int lights; nuclear@0: nuclear@0: /** Total storage allocated for the full import. */ nuclear@0: unsigned int total; nuclear@0: }; // !struct aiMemoryInfo nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: } nuclear@0: #endif //! __cplusplus nuclear@0: nuclear@0: // Include implementation files nuclear@0: #include "vector2.inl" nuclear@0: #include "vector3.inl" nuclear@0: #include "color4.inl" nuclear@0: #include "quaternion.inl" nuclear@0: #include "matrix3x3.inl" nuclear@0: #include "matrix4x4.inl" nuclear@0: nuclear@0: #endif // AI_TYPES_H_INC