2008-05-09 17:24:28 +00:00
|
|
|
/*
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-05-09 17:24:28 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-05-09 17:24:28 +00:00
|
|
|
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.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2008-05-09 17:24:28 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2008-05-09 17:24:28 +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
|
|
|
|
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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
/** @file Md3FileData.h
|
|
|
|
*
|
|
|
|
* @brief Defines helper data structures for importing MD3 files.
|
|
|
|
* http://linux.ucla.edu/~phaethon/q3/formats/md3format.html
|
|
|
|
*/
|
2008-05-05 12:36:31 +00:00
|
|
|
#ifndef AI_MD3FILEHELPER_H_INC
|
|
|
|
#define AI_MD3FILEHELPER_H_INC
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
|
|
|
2012-02-03 17:04:06 +00:00
|
|
|
#include "../include/assimp/types.h"
|
|
|
|
#include "../include/assimp/mesh.h"
|
|
|
|
#include "../include/assimp/anim.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2012-02-03 16:25:12 +00:00
|
|
|
#include "./../include/assimp/Compiler/pushpack1.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-08-08 15:18:28 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace MD3 {
|
2008-05-05 12:36:31 +00:00
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
// to make it easier for us, we test the magic word against both "endianesses"
|
|
|
|
#define AI_MD3_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP3")
|
|
|
|
#define AI_MD3_MAGIC_NUMBER_LE AI_MAKE_MAGIC("3PDI")
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// common limitations
|
|
|
|
#define AI_MD3_VERSION 15
|
|
|
|
#define AI_MD3_MAXQPATH 64
|
2009-02-12 16:44:12 +00:00
|
|
|
#define AI_MD3_MAXFRAME 16
|
2008-05-05 12:36:31 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
// master scale factor for all vertices in a MD3 model
|
|
|
|
#define AI_MD3_XYZ_SCALE (1.0f/64.0f)
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the MD3 main header
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Header
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
//! magic number
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t IDENT;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! file format version
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t VERSION;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! original name in .pak archive
|
2009-02-13 22:03:57 +00:00
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! unknown
|
2008-05-05 12:36:31 +00:00
|
|
|
int32_t FLAGS;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of frames in the file
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_FRAMES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of tags in the file
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_TAGS;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of surfaces in the file
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_SURFACES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of skins in the file
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_SKINS;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset of the first frame
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_FRAMES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset of the first tag
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_TAGS;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset of the first surface
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_SURFACES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! end of file
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_EOF;
|
2008-05-05 12:36:31 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the frame header
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Frame
|
|
|
|
{
|
2009-02-12 16:44:12 +00:00
|
|
|
//! minimum bounds
|
|
|
|
aiVector3D min;
|
|
|
|
|
|
|
|
//! maximum bounds
|
|
|
|
aiVector3D max;
|
|
|
|
|
|
|
|
//! local origin for this frame
|
|
|
|
aiVector3D origin;
|
|
|
|
|
|
|
|
//! radius of bounding sphere
|
|
|
|
float radius;
|
|
|
|
|
|
|
|
//! name of frame
|
|
|
|
char name[ AI_MD3_MAXFRAME ];
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the tag header
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Tag
|
|
|
|
{
|
2009-02-12 16:44:12 +00:00
|
|
|
//! name of the tag
|
2009-02-13 22:03:57 +00:00
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2009-02-12 16:44:12 +00:00
|
|
|
|
|
|
|
//! Local tag origin and orientation
|
|
|
|
aiVector3D origin;
|
|
|
|
float orientation[3][3];
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for the surface header
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Surface
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
//! magic number
|
2008-05-05 12:36:31 +00:00
|
|
|
int32_t IDENT;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! original name of the surface
|
2009-02-13 22:03:57 +00:00
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! unknown
|
2008-05-05 12:36:31 +00:00
|
|
|
int32_t FLAGS;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of frames in the surface
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_FRAMES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of shaders in the surface
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_SHADER;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of vertices in the surface
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_VERTICES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! number of triangles in the surface
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t NUM_TRIANGLES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset to the triangle data
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_TRIANGLES;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset to the shader data
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_SHADERS;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset to the texture coordinate data
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_ST;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset to the vertex/normal data
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t OFS_XYZNORMAL;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! offset to the end of the Surface object
|
2008-05-05 12:36:31 +00:00
|
|
|
int32_t OFS_END;
|
|
|
|
} PACK_STRUCT;
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for a shader defined in there
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Shader
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
//! filename of the shader
|
2009-02-13 22:03:57 +00:00
|
|
|
char NAME[ AI_MD3_MAXQPATH ];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! index of the shader
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t SHADER_INDEX;
|
2008-05-05 12:36:31 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for a triangle
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Triangle
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
//! triangle indices
|
2008-06-22 10:09:26 +00:00
|
|
|
uint32_t INDEXES[3];
|
2008-05-05 12:36:31 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for an UV coord
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct TexCoord
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
//! UV coordinates
|
2008-05-05 12:36:31 +00:00
|
|
|
float U,V;
|
|
|
|
} PACK_STRUCT;
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Data structure for a vertex
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
struct Vertex
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
//! X/Y/Z coordinates
|
2008-05-05 12:36:31 +00:00
|
|
|
int16_t X,Y,Z;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
//! encoded normal vector
|
2008-06-22 10:09:26 +00:00
|
|
|
uint16_t NORMAL;
|
2008-05-05 12:36:31 +00:00
|
|
|
} PACK_STRUCT;
|
|
|
|
|
2012-02-03 16:25:12 +00:00
|
|
|
#include "./../include/assimp/Compiler/poppack1.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Unpack a Q3 16 bit vector to its full float3 representation
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
2009-02-13 22:03:57 +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
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
2009-02-13 22:03:57 +00:00
|
|
|
* @note This has been taken from q3 source (misc_model.c)
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-06-22 10:09:26 +00:00
|
|
|
inline void LatLngNormalToVec3(uint16_t p_iNormal, float* p_afOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
float lat = (float)(( p_iNormal >> 8u ) & 0xff);
|
2008-05-05 12:36:31 +00:00
|
|
|
float lng = (float)(( p_iNormal & 0xff ));
|
|
|
|
lat *= 3.141926f/128.0f;
|
|
|
|
lng *= 3.141926f/128.0f;
|
|
|
|
|
2014-09-22 22:42:32 +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);
|
2008-05-05 12:36:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 22:03:57 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** @brief Pack a Q3 normal into 16bit latitute/longitude representation
|
|
|
|
* @param p_vIn Input vector
|
|
|
|
* @param p_iOut Output normal
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
2009-02-13 22:03:57 +00:00
|
|
|
* @note This has been taken from q3 source (mathlib.c)
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
inline void Vec3NormalToLatLng( const aiVector3D& p_vIn, uint16_t& p_iOut )
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
a = int(57.2957795f * ( atan2f( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f ));
|
|
|
|
a &= 0xff;
|
|
|
|
|
|
|
|
b = int(57.2957795f * ( acosf( p_vIn[2] ) ) * ( 255.0f / 360.0f ));
|
|
|
|
b &= 0xff;
|
|
|
|
|
|
|
|
((unsigned char*)&p_iOut)[0] = b; // longitude
|
|
|
|
((unsigned char*)&p_iOut)[1] = a; // lattitude
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-17 15:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
#endif // !! AI_MD3FILEHELPER_H_INC
|
2008-09-12 20:25:11 +00:00
|
|
|
|