vrshoot

diff libs/assimp/MD3FileData.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/MD3FileData.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,315 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +/** @file Md3FileData.h
    1.45 + *
    1.46 + *  @brief Defines helper data structures for importing MD3 files.
    1.47 + *  http://linux.ucla.edu/~phaethon/q3/formats/md3format.html
    1.48 + */
    1.49 +#ifndef AI_MD3FILEHELPER_H_INC
    1.50 +#define AI_MD3FILEHELPER_H_INC
    1.51 +
    1.52 +#include <string>
    1.53 +#include <vector>
    1.54 +#include <sstream>
    1.55 +
    1.56 +#include "assimp/types.h"
    1.57 +#include "assimp/mesh.h"
    1.58 +#include "assimp/anim.h"
    1.59 +
    1.60 +#include "assimp/Compiler/pushpack1.h"
    1.61 +
    1.62 +namespace Assimp	{
    1.63 +namespace MD3	{
    1.64 +
    1.65 +// to make it easier for us, we test the magic word against both "endianesses"
    1.66 +#define AI_MD3_MAGIC_NUMBER_BE	AI_MAKE_MAGIC("IDP3")
    1.67 +#define AI_MD3_MAGIC_NUMBER_LE	AI_MAKE_MAGIC("3PDI")
    1.68 +
    1.69 +// common limitations
    1.70 +#define AI_MD3_VERSION			15
    1.71 +#define AI_MD3_MAXQPATH			64
    1.72 +#define AI_MD3_MAXFRAME			16
    1.73 +#define AI_MD3_MAX_FRAMES		1024
    1.74 +#define AI_MD3_MAX_TAGS			16
    1.75 +#define AI_MD3_MAX_SURFACES		32
    1.76 +#define AI_MD3_MAX_SHADERS		256	
    1.77 +#define AI_MD3_MAX_VERTS		4096	
    1.78 +#define AI_MD3_MAX_TRIANGLES	8192	
    1.79 +
    1.80 +// master scale factor for all vertices in a MD3 model
    1.81 +#define AI_MD3_XYZ_SCALE		(1.0f/64.0f)
    1.82 +
    1.83 +// -------------------------------------------------------------------------------
    1.84 +/** @brief Data structure for the MD3 main header
    1.85 + */
    1.86 +struct Header
    1.87 +{
    1.88 +	//! magic number
    1.89 +	uint32_t IDENT;
    1.90 +
    1.91 +	//! file format version
    1.92 +	uint32_t VERSION;
    1.93 +
    1.94 +	//! original name in .pak archive
    1.95 +	char NAME[ AI_MD3_MAXQPATH ];
    1.96 +
    1.97 +	//! unknown
    1.98 +	int32_t FLAGS;
    1.99 +
   1.100 +	//! number of frames in the file
   1.101 +	uint32_t NUM_FRAMES;
   1.102 +
   1.103 +	//! number of tags in the file
   1.104 +	uint32_t NUM_TAGS;
   1.105 +
   1.106 +	//! number of surfaces in the file
   1.107 +	uint32_t NUM_SURFACES;
   1.108 +
   1.109 +	//! number of skins in the file
   1.110 +	uint32_t NUM_SKINS;
   1.111 +
   1.112 +	//! offset of the first frame
   1.113 +	uint32_t OFS_FRAMES;
   1.114 +
   1.115 +	//! offset of the first tag
   1.116 +	uint32_t OFS_TAGS;
   1.117 +
   1.118 +	//! offset of the first surface
   1.119 +	uint32_t OFS_SURFACES;
   1.120 +
   1.121 +	//! end of file
   1.122 +	uint32_t OFS_EOF;
   1.123 +} PACK_STRUCT;
   1.124 +
   1.125 +
   1.126 +// -------------------------------------------------------------------------------
   1.127 +/** @brief Data structure for the frame header
   1.128 + */
   1.129 +struct Frame
   1.130 +{
   1.131 +	//! minimum bounds
   1.132 +	aiVector3D min;
   1.133 +
   1.134 +	//! maximum bounds
   1.135 +	aiVector3D max;
   1.136 +
   1.137 +	//! local origin for this frame
   1.138 +	aiVector3D origin;
   1.139 +
   1.140 +	//! radius of bounding sphere
   1.141 +	float radius;
   1.142 +
   1.143 +	//! name of frame
   1.144 +	char name[ AI_MD3_MAXFRAME ];
   1.145 +
   1.146 +} PACK_STRUCT;
   1.147 +
   1.148 +
   1.149 +// -------------------------------------------------------------------------------
   1.150 +/** @brief Data structure for the tag header
   1.151 + */
   1.152 +struct Tag
   1.153 +{
   1.154 +	//! name of the tag
   1.155 +	char NAME[ AI_MD3_MAXQPATH ];
   1.156 +
   1.157 +	//! Local tag origin and orientation
   1.158 +	aiVector3D  origin;
   1.159 +	float  orientation[3][3];
   1.160 +
   1.161 +} PACK_STRUCT;
   1.162 +
   1.163 +
   1.164 +// -------------------------------------------------------------------------------
   1.165 +/** @brief Data structure for the surface header
   1.166 + */
   1.167 +struct Surface
   1.168 +{
   1.169 +	//! magic number
   1.170 +	int32_t IDENT;
   1.171 +
   1.172 +	//! original name of the surface
   1.173 +	char NAME[ AI_MD3_MAXQPATH ];
   1.174 +
   1.175 +	//! unknown
   1.176 +	int32_t FLAGS;
   1.177 +
   1.178 +	//! number of frames in the surface
   1.179 +	uint32_t NUM_FRAMES;
   1.180 +
   1.181 +	//! number of shaders in the surface
   1.182 +	uint32_t NUM_SHADER;
   1.183 +
   1.184 +	//! number of vertices in the surface
   1.185 +	uint32_t NUM_VERTICES;
   1.186 +
   1.187 +	//! number of triangles in the surface
   1.188 +	uint32_t NUM_TRIANGLES;
   1.189 +
   1.190 +
   1.191 +	//! offset to the triangle data 
   1.192 +	uint32_t OFS_TRIANGLES;
   1.193 +
   1.194 +	//! offset to the shader data
   1.195 +	uint32_t OFS_SHADERS;
   1.196 +
   1.197 +	//! offset to the texture coordinate data
   1.198 +	uint32_t OFS_ST;
   1.199 +
   1.200 +	//! offset to the vertex/normal data
   1.201 +	uint32_t OFS_XYZNORMAL;
   1.202 +
   1.203 +	//! offset to the end of the Surface object
   1.204 +	int32_t OFS_END;
   1.205 +} PACK_STRUCT;
   1.206 +
   1.207 +// -------------------------------------------------------------------------------
   1.208 +/** @brief Data structure for a shader defined in there
   1.209 + */
   1.210 +struct Shader
   1.211 +{
   1.212 +	//! filename of the shader
   1.213 +	char NAME[ AI_MD3_MAXQPATH ];
   1.214 +
   1.215 +	//! index of the shader
   1.216 +	uint32_t SHADER_INDEX;
   1.217 +} PACK_STRUCT;
   1.218 +
   1.219 +
   1.220 +// -------------------------------------------------------------------------------
   1.221 +/** @brief Data structure for a triangle
   1.222 + */
   1.223 +struct Triangle
   1.224 +{
   1.225 +	//! triangle indices
   1.226 +	uint32_t INDEXES[3];
   1.227 +} PACK_STRUCT;
   1.228 +
   1.229 +
   1.230 +// -------------------------------------------------------------------------------
   1.231 +/** @brief Data structure for an UV coord
   1.232 + */
   1.233 +struct TexCoord
   1.234 +{
   1.235 +	//! UV coordinates
   1.236 +	float U,V;
   1.237 +} PACK_STRUCT;
   1.238 +
   1.239 +
   1.240 +// -------------------------------------------------------------------------------
   1.241 +/** @brief Data structure for a vertex
   1.242 + */
   1.243 +struct Vertex
   1.244 +{
   1.245 +	//! X/Y/Z coordinates
   1.246 +	int16_t X,Y,Z;
   1.247 +
   1.248 +	//! encoded normal vector
   1.249 +	uint16_t  NORMAL;
   1.250 +} PACK_STRUCT;
   1.251 +
   1.252 +#include "assimp/Compiler/poppack1.h"
   1.253 +
   1.254 +// -------------------------------------------------------------------------------
   1.255 +/**	@brief Unpack a Q3 16 bit vector to its full float3 representation
   1.256 + *
   1.257 + *	@param p_iNormal Input normal vector in latitude/longitude form
   1.258 + *	@param p_afOut Pointer to an array of three floats to receive the result
   1.259 + *
   1.260 + *	@note This has been taken from q3 source (misc_model.c)
   1.261 + */
   1.262 +inline void LatLngNormalToVec3(uint16_t p_iNormal, float* p_afOut)
   1.263 +{
   1.264 +	float lat = (float)(( p_iNormal >> 8u ) & 0xff);
   1.265 +	float lng = (float)(( p_iNormal & 0xff ));
   1.266 +	lat *= 3.141926f/128.0f;
   1.267 +	lng *= 3.141926f/128.0f;
   1.268 +
   1.269 +	p_afOut[0] = cosf(lat) * sinf(lng);
   1.270 +	p_afOut[1] = sinf(lat) * sinf(lng);
   1.271 +	p_afOut[2] = cosf(lng);
   1.272 +	return;
   1.273 +}
   1.274 +
   1.275 +
   1.276 +// -------------------------------------------------------------------------------
   1.277 +/**	@brief Pack a Q3 normal into 16bit latitute/longitude representation
   1.278 + *	@param p_vIn Input vector
   1.279 + *	@param p_iOut Output normal
   1.280 + *
   1.281 + *	@note This has been taken from q3 source (mathlib.c)
   1.282 + */
   1.283 +inline void Vec3NormalToLatLng( const aiVector3D& p_vIn, uint16_t& p_iOut ) 
   1.284 +{
   1.285 +	// check for singularities
   1.286 +	if ( 0.0f == p_vIn[0] && 0.0f == p_vIn[1] ) 
   1.287 +	{
   1.288 +		if ( p_vIn[2] > 0.0f ) 
   1.289 +		{
   1.290 +			((unsigned char*)&p_iOut)[0] = 0;
   1.291 +			((unsigned char*)&p_iOut)[1] = 0;		// lat = 0, long = 0
   1.292 +		} 
   1.293 +		else 
   1.294 +		{
   1.295 +			((unsigned char*)&p_iOut)[0] = 128;
   1.296 +			((unsigned char*)&p_iOut)[1] = 0;		// lat = 0, long = 128
   1.297 +		}
   1.298 +	} 
   1.299 +	else 
   1.300 +	{
   1.301 +		int	a, b;
   1.302 +
   1.303 +		a = int(57.2957795f * ( atan2f( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f ));
   1.304 +		a &= 0xff;
   1.305 +
   1.306 +		b = int(57.2957795f * ( acosf( p_vIn[2] ) ) * ( 255.0f / 360.0f ));
   1.307 +		b &= 0xff;
   1.308 +
   1.309 +		((unsigned char*)&p_iOut)[0] = b;	// longitude
   1.310 +		((unsigned char*)&p_iOut)[1] = a;	// lattitude
   1.311 +	}
   1.312 +}
   1.313 +
   1.314 +}
   1.315 +}
   1.316 +
   1.317 +#endif // !! AI_MD3FILEHELPER_H_INC
   1.318 +