2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2016-01-01 20:07:24 +00:00
|
|
|
Copyright (c) 2006-2016, assimp team
|
2015-05-19 03:48:29 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
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.
|
|
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Md3FileData.h
|
|
|
|
*
|
|
|
|
* @brief Defines helper data structures for importing MD3 files.
|
|
|
|
* http://linux.ucla.edu/~phaethon/q3/formats/md3format.html
|
|
|
|
*/
|
|
|
|
#ifndef AI_MD3FILEHELPER_H_INC
|
|
|
|
#define AI_MD3FILEHELPER_H_INC
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/types.h>
|
|
|
|
#include <assimp/mesh.h>
|
|
|
|
#include <assimp/anim.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/Compiler/pushpack1.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace MD3 {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// to make it easier for us, we test the magic word against both "endianesses"
|
2015-05-19 03:57:13 +00:00
|
|
|
#define AI_MD3_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP3")
|
|
|
|
#define AI_MD3_MAGIC_NUMBER_LE AI_MAKE_MAGIC("3PDI")
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// common limitations
|
2015-05-19 03:57:13 +00:00
|
|
|
#define AI_MD3_VERSION 15
|
|
|
|
#define AI_MD3_MAXQPATH 64
|
|
|
|
#define AI_MD3_MAXFRAME 16
|
|
|
|
#define AI_MD3_MAX_FRAMES 1024
|
|
|
|
#define AI_MD3_MAX_TAGS 16
|
|
|
|
#define AI_MD3_MAX_SURFACES 32
|
|
|
|
#define AI_MD3_MAX_SHADERS 256
|
|
|
|
#define AI_MD3_MAX_VERTS 4096
|
|
|
|
#define AI_MD3_MAX_TRIANGLES 8192
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// master scale factor for all vertices in a MD3 model
|
2015-05-19 03:57:13 +00:00
|
|
|
#define AI_MD3_XYZ_SCALE (1.0f/64.0f)
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the MD3 main header
|
|
|
|
*/
|
|
|
|
struct Header
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! magic number
|
|
|
|
uint32_t IDENT;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! file format version
|
|
|
|
uint32_t VERSION;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! original name in .pak archive
|
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! unknown
|
|
|
|
int32_t FLAGS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of frames in the file
|
|
|
|
uint32_t NUM_FRAMES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of tags in the file
|
|
|
|
uint32_t NUM_TAGS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of surfaces in the file
|
|
|
|
uint32_t NUM_SURFACES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of skins in the file
|
|
|
|
uint32_t NUM_SKINS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset of the first frame
|
|
|
|
uint32_t OFS_FRAMES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset of the first tag
|
|
|
|
uint32_t OFS_TAGS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset of the first surface
|
|
|
|
uint32_t OFS_SURFACES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! end of file
|
|
|
|
uint32_t OFS_EOF;
|
2015-05-19 03:48:29 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the frame header
|
|
|
|
*/
|
|
|
|
struct Frame
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! minimum bounds
|
|
|
|
aiVector3D min;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! maximum bounds
|
|
|
|
aiVector3D max;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! local origin for this frame
|
|
|
|
aiVector3D origin;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! radius of bounding sphere
|
2016-07-15 05:38:29 +00:00
|
|
|
ai_real radius;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! name of frame
|
|
|
|
char name[ AI_MD3_MAXFRAME ];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the tag header
|
|
|
|
*/
|
|
|
|
struct Tag
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! name of the tag
|
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Local tag origin and orientation
|
|
|
|
aiVector3D origin;
|
2016-07-15 05:38:29 +00:00
|
|
|
ai_real orientation[3][3];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the surface header
|
|
|
|
*/
|
|
|
|
struct Surface
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! magic number
|
|
|
|
int32_t IDENT;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! original name of the surface
|
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! unknown
|
|
|
|
int32_t FLAGS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of frames in the surface
|
|
|
|
uint32_t NUM_FRAMES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of shaders in the surface
|
|
|
|
uint32_t NUM_SHADER;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of vertices in the surface
|
|
|
|
uint32_t NUM_VERTICES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! number of triangles in the surface
|
|
|
|
uint32_t NUM_TRIANGLES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset to the triangle data
|
|
|
|
uint32_t OFS_TRIANGLES;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset to the shader data
|
|
|
|
uint32_t OFS_SHADERS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset to the texture coordinate data
|
|
|
|
uint32_t OFS_ST;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset to the vertex/normal data
|
|
|
|
uint32_t OFS_XYZNORMAL;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! offset to the end of the Surface object
|
|
|
|
int32_t OFS_END;
|
2015-05-19 03:48:29 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for a shader defined in there
|
|
|
|
*/
|
|
|
|
struct Shader
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! filename of the shader
|
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! index of the shader
|
|
|
|
uint32_t SHADER_INDEX;
|
2015-05-19 03:48:29 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for a triangle
|
|
|
|
*/
|
|
|
|
struct Triangle
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! triangle indices
|
|
|
|
uint32_t INDEXES[3];
|
2015-05-19 03:48:29 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for an UV coord
|
|
|
|
*/
|
|
|
|
struct TexCoord
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! UV coordinates
|
2016-07-15 05:38:29 +00:00
|
|
|
ai_real U,V;
|
2015-05-19 03:48:29 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for a vertex
|
|
|
|
*/
|
|
|
|
struct Vertex
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
//! X/Y/Z coordinates
|
|
|
|
int16_t X,Y,Z;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! encoded normal vector
|
|
|
|
uint16_t NORMAL;
|
2015-05-19 03:48:29 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
#include "./../include/assimp/Compiler/poppack1.h"
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
/** @brief Unpack a Q3 16 bit vector to its full float3 representation
|
2015-05-19 03:48:29 +00:00
|
|
|
*
|
2015-05-19 03:57:13 +00:00
|
|
|
* @param p_iNormal Input normal vector in latitude/longitude form
|
|
|
|
* @param p_afOut Pointer to an array of three floats to receive the result
|
2015-05-19 03:48:29 +00:00
|
|
|
*
|
2015-05-19 03:57:13 +00:00
|
|
|
* @note This has been taken from q3 source (misc_model.c)
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
2016-07-15 05:38:29 +00:00
|
|
|
inline void LatLngNormalToVec3(uint16_t p_iNormal, ai_real* p_afOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2016-07-15 05:38:29 +00:00
|
|
|
ai_real lat = (ai_real)(( p_iNormal >> 8u ) & 0xff);
|
|
|
|
ai_real lng = (ai_real)(( p_iNormal & 0xff ));
|
|
|
|
lat *= 3.141926/128.0;
|
|
|
|
lng *= 3.141926/128.0;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
p_afOut[0] = std::cos(lat) * std::sin(lng);
|
|
|
|
p_afOut[1] = std::sin(lat) * std::sin(lng);
|
|
|
|
p_afOut[2] = std::cos(lng);
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
/** @brief Pack a Q3 normal into 16bit latitute/longitude representation
|
|
|
|
* @param p_vIn Input vector
|
|
|
|
* @param p_iOut Output normal
|
2015-05-19 03:48:29 +00:00
|
|
|
*
|
2015-05-19 03:57:13 +00:00
|
|
|
* @note This has been taken from q3 source (mathlib.c)
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
2015-05-19 03:52:10 +00:00
|
|
|
inline void Vec3NormalToLatLng( const aiVector3D& p_vIn, uint16_t& p_iOut )
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
// check for singularities
|
|
|
|
if ( 0.0f == p_vIn[0] && 0.0f == p_vIn[1] )
|
|
|
|
{
|
|
|
|
if ( p_vIn[2] > 0.0f )
|
|
|
|
{
|
|
|
|
((unsigned char*)&p_iOut)[0] = 0;
|
|
|
|
((unsigned char*)&p_iOut)[1] = 0; // lat = 0, long = 0
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((unsigned char*)&p_iOut)[0] = 128;
|
|
|
|
((unsigned char*)&p_iOut)[1] = 0; // lat = 0, long = 128
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int a, b;
|
|
|
|
|
2016-10-15 09:05:57 +00:00
|
|
|
a = int(57.2957795f * ( std::atan2( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f ));
|
2015-05-19 03:57:13 +00:00
|
|
|
a &= 0xff;
|
|
|
|
|
2016-10-15 09:05:57 +00:00
|
|
|
b = int(57.2957795f * ( std::acos( p_vIn[2] ) ) * ( 255.0f / 360.0f ));
|
2015-05-19 03:57:13 +00:00
|
|
|
b &= 0xff;
|
|
|
|
|
|
|
|
((unsigned char*)&p_iOut)[0] = b; // longitude
|
2016-04-03 00:38:00 +00:00
|
|
|
((unsigned char*)&p_iOut)[1] = a; // latitude
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !! AI_MD3FILEHELPER_H_INC
|