assimp/code/MD4/MD4FileData.h

219 lines
6.0 KiB
C
Raw Normal View History

/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2020, ASSIMP Development Team
All rights reserved.
2015-05-19 03:52:10 +00:00
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 Development Team.
2015-05-19 03:52:10 +00:00
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
2015-05-19 03:52:10 +00:00
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2015-05-19 03:52:10 +00:00
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2015-05-19 03:52:10 +00:00
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 Defines the helper data structures for importing MD4 files */
#ifndef AI_MD4FILEHELPER_H_INC
#define AI_MD4FILEHELPER_H_INC
#include <string>
#include <vector>
#include <sstream>
#include <assimp/types.h>
#include <assimp/mesh.h>
#include <assimp/anim.h>
2015-05-19 03:57:13 +00:00
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack(push,1)
# define PACK_STRUCT
#elif defined( __GNUC__ )
2015-05-19 03:57:13 +00:00
# define PACK_STRUCT __attribute__((packed))
#else
2015-05-19 03:57:13 +00:00
# error Compiler not supported
#endif
namespace Assimp
{
// http://gongo.quakedev.com/md4.html
namespace MD4
{
2015-05-19 03:57:13 +00:00
#define AI_MD4_MAGIC_NUMBER_BE 'IDP4'
#define AI_MD4_MAGIC_NUMBER_LE '4PDI'
// common limitations
2015-05-19 03:57:13 +00:00
#define AI_MD4_VERSION 4
#define AI_MD4_MAXQPATH 64
#define AI_MD4_MAX_FRAMES 2028
#define AI_MD4_MAX_SURFACES 32
#define AI_MD4_MAX_BONES 256
#define AI_MD4_MAX_VERTS 4096
#define AI_MD4_MAX_TRIANGLES 8192
// ---------------------------------------------------------------------------
/** \brief Data structure for the MD4 main header
*/
// ---------------------------------------------------------------------------
struct Header
{
2015-05-19 03:57:13 +00:00
//! magic number
int32_t magic;
2015-05-19 03:57:13 +00:00
//! file format version
int32_t version;
2015-05-19 03:57:13 +00:00
//! original name in .pak archive
unsigned char name[ AI_MD4_MAXQPATH ];
2015-05-19 03:57:13 +00:00
//! number of frames in the file
int32_t NUM_FRAMES;
2015-05-19 03:57:13 +00:00
//! number of bones in the file
int32_t NUM_BONES;
2015-05-19 03:57:13 +00:00
//! number of surfaces in the file
int32_t NUM_SURFACES;
2015-05-19 03:57:13 +00:00
//! offset of the first frame
int32_t OFS_FRAMES;
2015-05-19 03:57:13 +00:00
//! offset of the first bone
int32_t OFS_BONES;
2015-05-19 03:57:13 +00:00
//! offset of the first surface
int32_t OFS_SURFACES;
2015-05-19 03:57:13 +00:00
//! end of file
int32_t OFS_EOF;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Stores the local transformation matrix of a bone
*/
// ---------------------------------------------------------------------------
struct BoneFrame
2015-05-19 03:52:10 +00:00
{
2015-05-19 03:57:13 +00:00
float matrix[3][4];
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Stores the name / parent index / flag of a node
*/
// ---------------------------------------------------------------------------
struct BoneName
2015-05-19 03:52:10 +00:00
{
2015-05-19 03:57:13 +00:00
char name[32] ;
int parent ;
int flags ;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Data structure for a surface in a MD4 file
*/
// ---------------------------------------------------------------------------
struct Surface
2015-05-19 03:52:10 +00:00
{
2015-05-19 03:57:13 +00:00
int32_t ident;
char name[64];
char shader[64];
int32_t shaderIndex;
int32_t lodBias;
int32_t minLod;
int32_t ofsHeader;
int32_t numVerts;
int32_t ofsVerts;
int32_t numTris;
int32_t ofsTris;
int32_t numBoneRefs;
int32_t ofsBoneRefs;
int32_t ofsCollapseMap;
int32_t ofsEnd;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Data structure for a MD4 vertex' weight
*/
// ---------------------------------------------------------------------------
struct Weight
2015-05-19 03:52:10 +00:00
{
2015-05-19 03:57:13 +00:00
int32_t boneIndex;
float boneWeight;
float offset[3];
2015-05-19 03:52:10 +00:00
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Data structure for a vertex in a MD4 file
*/
// ---------------------------------------------------------------------------
struct Vertex
2015-05-19 03:52:10 +00:00
{
2015-05-19 03:57:13 +00:00
float vertex[3];
float normal[3];
float texCoords[2];
int32_t numWeights;
Weight weights[1];
2015-05-19 03:52:10 +00:00
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Data structure for a triangle in a MD4 file
*/
// ---------------------------------------------------------------------------
2015-05-19 03:52:10 +00:00
struct Triangle
{
2015-05-19 03:57:13 +00:00
int32_t indexes[3];
} PACK_STRUCT;
// ---------------------------------------------------------------------------
/** \brief Data structure for a MD4 frame
*/
// ---------------------------------------------------------------------------
struct Frame
2015-05-19 03:52:10 +00:00
{
2015-05-19 03:57:13 +00:00
float bounds[3][2];
float localOrigin[3];
float radius;
BoneFrame bones[1];
2015-05-19 03:52:10 +00:00
} PACK_STRUCT;
// reset packing to the original value
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
2015-05-19 03:57:13 +00:00
# pragma pack( pop )
#endif
#undef PACK_STRUCT
};
};
#endif // !! AI_MD4FILEHELPER_H_INC