summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/include/assimp/types.h
blob: 592d5c64d9b45e13cac8bae92e3552c7fa97c173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------

Copyright (c) 2006-2016, assimp team

All rights reserved.

Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.

* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.

* Neither the name of the assimp team, nor the names of its
  contributors may be used to endorse or promote products
  derived from this software without specific prior
  written permission of the assimp team.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/

/** @file types.h
 *  Basic data types and primitives, such as vectors or colors.
 */
#ifndef AI_TYPES_H_INC
#define AI_TYPES_H_INC

// Some runtime headers
#include <sys/types.h>
#include <math.h>
#include <stddef.h>
#include <string.h>
#include <limits.h>

// Our compile configuration
#include "defs.h"

// Some types moved to separate header due to size of operators
#include "vector3.h"
#include "vector2.h"
#include "color4.h"
#include "matrix3x3.h"
#include "matrix4x4.h"
#include "quaternion.h"

#ifdef __cplusplus
#include <cstring>
#include <new>      // for std::nothrow_t
#include <string>   // for aiString::Set(const std::string&)

namespace Assimp    {
    //! @cond never
namespace Intern        {
    // --------------------------------------------------------------------
    /** @brief Internal helper class to utilize our internal new/delete
     *    routines for allocating object of this and derived classes.
     *
     * By doing this you can safely share class objects between Assimp
     * and the application - it works even over DLL boundaries. A good
     * example is the #IOSystem where the application allocates its custom
     * #IOSystem, then calls #Importer::SetIOSystem(). When the Importer
     * destructs, Assimp calls operator delete on the stored #IOSystem.
     * If it lies on a different heap than Assimp is working with,
     * the application is determined to crash.
     */
    // --------------------------------------------------------------------
#ifndef SWIG
    struct ASSIMP_API AllocateFromAssimpHeap    {
        // http://www.gotw.ca/publications/mill15.htm

        // new/delete overload
        void *operator new    ( size_t num_bytes) /* throw( std::bad_alloc ) */;
        void *operator new    ( size_t num_bytes, const std::nothrow_t& ) throw();
        void  operator delete ( void* data);

        // array new/delete overload
        void *operator new[]    ( size_t num_bytes) /* throw( std::bad_alloc ) */;
        void *operator new[]    ( size_t num_bytes, const std::nothrow_t& )  throw();
        void  operator delete[] ( void* data);

    }; // struct AllocateFromAssimpHeap
#endif
} // namespace Intern
    //! @endcond
} // namespace Assimp

extern "C" {
#endif

/** Maximum dimension for strings, ASSIMP strings are zero terminated. */
#ifdef __cplusplus
const size_t MAXLEN = 1024;
#else
#   define MAXLEN 1024
#endif

#include "./Compiler/pushpack1.h"

// ----------------------------------------------------------------------------------
/** Represents a plane in a three-dimensional, euclidean space
*/
struct aiPlane
{
#ifdef __cplusplus
    aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
    aiPlane (float _a, float _b, float _c, float _d)
        : a(_a), b(_b), c(_c), d(_d) {}

    aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}

#endif // !__cplusplus

    //! Plane equation
    float a,b,c,d;
} PACK_STRUCT; // !struct aiPlane

// ----------------------------------------------------------------------------------
/** Represents a ray
*/
struct aiRay
{
#ifdef __cplusplus
    aiRay () {}
    aiRay (const aiVector3D& _pos, const aiVector3D& _dir)
        : pos(_pos), dir(_dir) {}

    aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {}

#endif // !__cplusplus

    //! Position and direction of the ray
    C_STRUCT aiVector3D pos, dir;
} PACK_STRUCT; // !struct aiRay

// ----------------------------------------------------------------------------------
/** Represents a color in Red-Green-Blue space.
*/
struct aiColor3D
{
#ifdef __cplusplus
    aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
    aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
    explicit aiColor3D (float _r) : r(_r), g(_r), b(_r) {}
    aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}

    /** Component-wise comparison */
    // TODO: add epsilon?
    bool operator == (const aiColor3D& other) const
        {return r == other.r && g == other.g && b == other.b;}

    /** Component-wise inverse comparison */
    // TODO: add epsilon?
    bool operator != (const aiColor3D& other) const
        {return r != other.r || g != other.g || b != other.b;}

    /** Component-wise comparison */
    // TODO: add epsilon?
    bool operator < (const aiColor3D& other) const {
        return r < other.r || (
            r == other.r && (g < other.g ||
                (g == other.g && b < other.b)
            )
        );
    }

    /** Component-wise addition */
    aiColor3D operator+(const aiColor3D& c) const {
        return aiColor3D(r+c.r,g+c.g,b+c.b);
    }

    /** Component-wise subtraction */
    aiColor3D operator-(const aiColor3D& c) const {
        return aiColor3D(r-c.r,g-c.g,b-c.b);
    }

    /** Component-wise multiplication */
    aiColor3D operator*(const aiColor3D& c) const {
        return aiColor3D(r*c.r,g*c.g,b*c.b);
    }

    /** Multiply with a scalar */
    aiColor3D operator*(float f) const {
        return aiColor3D(r*f,g*f,b*f);
    }

    /** Access a specific color component */
    float operator[](unsigned int i) const {
        return *(&r + i);
    }

    /** Access a specific color component */
    float& operator[](unsigned int i) {
        return *(&r + i);
    }

    /** Check whether a color is black */
    bool IsBlack() const {
        static const float epsilon = 10e-3f;
        return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
    }

#endif // !__cplusplus

    //! Red, green and blue color values
    float r, g, b;
} PACK_STRUCT;  // !struct aiColor3D
#include "./Compiler/poppack1.h"

// ----------------------------------------------------------------------------------
/** Represents an UTF-8 string, zero byte terminated.
 *
 *  The character set of an aiString is explicitly defined to be UTF-8. This Unicode
 *  transformation was chosen in the belief that most strings in 3d files are limited
 *  to ASCII, thus the character set needed to be strictly ASCII compatible.
 *
 *  Most text file loaders provide proper Unicode input file handling, special unicode
 *  characters are correctly transcoded to UTF8 and are kept throughout the libraries'
 *  import pipeline.
 *
 *  For most applications, it will be absolutely sufficient to interpret the
 *  aiString as ASCII data and work with it as one would work with a plain char*.
 *  Windows users in need of proper support for i.e asian characters can use the
 *  MultiByteToWideChar(), WideCharToMultiByte() WinAPI functionality to convert the
 *  UTF-8 strings to their working character set (i.e. MBCS, WideChar).
 *
 *  We use this representation instead of std::string to be C-compatible. The
 *  (binary) length of such a string is limited to MAXLEN characters (including the
 *  the terminating zero).
*/
struct aiString
{
#ifdef __cplusplus
    /** Default constructor, the string is set to have zero length */
    aiString() :
        length(0)
    {
        data[0] = '\0';

#ifdef ASSIMP_BUILD_DEBUG
        // Debug build: overwrite the string on its full length with ESC (27)
        memset(data+1,27,MAXLEN-1);
#endif
    }

    /** Copy constructor */
    aiString(const aiString& rOther) :
        length(rOther.length)
    {
        // Crop the string to the maximum length
        length = length>=MAXLEN?MAXLEN-1:length;
        memcpy( data, rOther.data, length);
        data[length] = '\0';
    }

    /** Constructor from std::string */
    explicit aiString(const std::string& pString) :
        length(pString.length())
    {
        length = length>=MAXLEN?MAXLEN-1:length;
        memcpy( data, pString.c_str(), length);
        data[length] = '\0';
    }

    /** Copy a std::string to the aiString */
    void Set( const std::string& pString) {
        if( pString.length() > MAXLEN - 1) {
            return;
        }
        length = pString.length();
        memcpy( data, pString.c_str(), length);
        data[length] = 0;
    }

    /** Copy a const char* to the aiString */
    void Set( const char* sz) {
        const size_t len = ::strlen(sz);
        if( len > MAXLEN - 1) {
            return;
        }
        length = len;
        memcpy( data, sz, len);
        data[len] = 0;
    }

    /** Assign a const char* to the string */
    aiString& operator = (const char* sz) {
        Set(sz);
        return *this;
    }

    /** Assign a cstd::string to the string */
    aiString& operator = ( const std::string& pString) {
        Set(pString);
        return *this;
    }

    /** Comparison operator */
    bool operator==(const aiString& other) const {
        return  (length == other.length && 0 == memcmp(data,other.data,length));
    }

    /** Inverse comparison operator */
    bool operator!=(const aiString& other) const {
        return  (length != other.length || 0 != memcmp(data,other.data,length));
    }

    /** Append a string to the string */
    void Append (const char* app)   {
        const size_t len = ::strlen(app);
        if (!len) {
            return;
        }
        if (length + len >= MAXLEN) {
            return;
        }

        memcpy(&data[length],app,len+1);
        length += len;
    }

    /** Clear the string - reset its length to zero */
    void Clear ()   {
        length  = 0;
        data[0] = '\0';

#ifdef ASSIMP_BUILD_DEBUG
        // Debug build: overwrite the string on its full length with ESC (27)
        memset(data+1,27,MAXLEN-1);
#endif
    }

    /** Returns a pointer to the underlying zero-terminated array of characters */
    const char* C_Str() const {
        return data;
    }

#endif // !__cplusplus

    /** Binary length of the string excluding the terminal 0. This is NOT the
     *  logical length of strings containing UTF-8 multibyte sequences! It's
     *  the number of bytes from the beginning of the string to its end.*/
    size_t length;

    /** String buffer. Size limit is MAXLEN */
    char data[MAXLEN];
} ;  // !struct aiString


// ----------------------------------------------------------------------------------
/** Standard return type for some library functions.
 * Rarely used, and if, mostly in the C API.
 */
typedef enum aiReturn
{
    /** Indicates that a function was successful */
    aiReturn_SUCCESS = 0x0,

    /** Indicates that a function failed */
    aiReturn_FAILURE = -0x1,

    /** Indicates that not enough memory was available
     * to perform the requested operation
     */
    aiReturn_OUTOFMEMORY = -0x3,

    /** @cond never
     *  Force 32-bit size enum
     */
    _AI_ENFORCE_ENUM_SIZE = 0x7fffffff

    /// @endcond
} aiReturn;  // !enum aiReturn

// just for backwards compatibility, don't use these constants anymore
#define AI_SUCCESS     aiReturn_SUCCESS
#define AI_FAILURE     aiReturn_FAILURE
#define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY

// ----------------------------------------------------------------------------------
/** Seek origins (for the virtual file system API).
 *  Much cooler than using SEEK_SET, SEEK_CUR or SEEK_END.
 */
enum aiOrigin
{
    /** Beginning of the file */
    aiOrigin_SET = 0x0,

    /** Current position of the file pointer */
    aiOrigin_CUR = 0x1,

    /** End of the file, offsets must be negative */
    aiOrigin_END = 0x2,

    /**  @cond never
     *   Force 32-bit size enum
     */
    _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff

    /// @endcond
}; // !enum aiOrigin

// ----------------------------------------------------------------------------------
/** @brief Enumerates predefined log streaming destinations.
 *  Logging to these streams can be enabled with a single call to
 *   #LogStream::createDefaultStream.
 */
enum aiDefaultLogStream
{
    /** Stream the log to a file */
    aiDefaultLogStream_FILE = 0x1,

    /** Stream the log to std::cout */
    aiDefaultLogStream_STDOUT = 0x2,

    /** Stream the log to std::cerr */
    aiDefaultLogStream_STDERR = 0x4,

    /** MSVC only: Stream the log the the debugger
     * (this relies on OutputDebugString from the Win32 SDK)
     */
    aiDefaultLogStream_DEBUGGER = 0x8,

    /** @cond never
     *  Force 32-bit size enum
     */
    _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff
    /// @endcond
}; // !enum aiDefaultLogStream

// just for backwards compatibility, don't use these constants anymore
#define DLS_FILE     aiDefaultLogStream_FILE
#define DLS_STDOUT   aiDefaultLogStream_STDOUT
#define DLS_STDERR   aiDefaultLogStream_STDERR
#define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER

// ----------------------------------------------------------------------------------
/** Stores the memory requirements for different components (e.g. meshes, materials,
 *  animations) of an import. All sizes are in bytes.
 *  @see Importer::GetMemoryRequirements()
*/
struct aiMemoryInfo
{
#ifdef __cplusplus

    /** Default constructor */
    aiMemoryInfo()
        : textures   (0)
        , materials  (0)
        , meshes     (0)
        , nodes      (0)
        , animations (0)
        , cameras    (0)
        , lights     (0)
        , total      (0)
    {}

#endif

    /** Storage allocated for texture data */
    unsigned int textures;

    /** Storage allocated for material data  */
    unsigned int materials;

    /** Storage allocated for mesh data */
    unsigned int meshes;

    /** Storage allocated for node data */
    unsigned int nodes;

    /** Storage allocated for animation data */
    unsigned int animations;

    /** Storage allocated for camera data */
    unsigned int cameras;

    /** Storage allocated for light data */
    unsigned int lights;

    /** Total storage allocated for the full import. */
    unsigned int total;
}; // !struct aiMemoryInfo

#ifdef __cplusplus
}
#endif //!  __cplusplus

// Include implementation files
#include "vector2.inl"
#include "vector3.inl"
#include "color4.inl"
#include "quaternion.inl"
#include "matrix3x3.inl"
#include "matrix4x4.inl"
#endif