2008-07-25 07:31:37 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include "q3data.h"
|
|
|
|
|
|
|
|
//=================================================================
|
|
|
|
|
|
|
|
static void OrderSurfaces( void );
|
|
|
|
static void LoadBase( const char *filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
static int LoadModelFile( const char *filename, polyset_t **ppsets, int *pnumpolysets );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_SURFACE_TRIS ( SHADER_MAX_INDEXES / 3 )
|
|
|
|
#define MAX_SURFACE_VERTS SHADER_MAX_VERTEXES
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#define MD3_TYPE_UNKNOWN 0
|
|
|
|
#define MD3_TYPE_BASE3DS 1
|
|
|
|
#define MD3_TYPE_SPRITE 2
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MD3_TYPE_ASE 3
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_ANIM_FRAMES 512
|
|
|
|
#define MAX_ANIM_SURFACES 32
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
polyset_t *frames;
|
|
|
|
int numFrames;
|
|
|
|
} SurfaceAnimation_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
polyset_t *surfaces[MAX_ANIM_SURFACES];
|
|
|
|
int numSurfaces;
|
|
|
|
} ObjectAnimationFrame_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t xyz;
|
|
|
|
vec3_t normal;
|
|
|
|
vec3_t color;
|
|
|
|
float st[2];
|
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
} baseVertex_t;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
typedef struct {
|
2012-03-17 20:01:54 +00:00
|
|
|
baseVertex_t v[3];
|
2007-11-04 03:34:51 +00:00
|
|
|
} baseTriangle_t;
|
|
|
|
|
|
|
|
//================================================================
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
md3Surface_t header;
|
|
|
|
md3Shader_t shaders[MD3_MAX_SHADERS];
|
2007-11-04 03:34:51 +00:00
|
|
|
// all verts (xyz_normal)
|
2012-03-17 20:01:54 +00:00
|
|
|
float *verts[MD3_MAX_FRAMES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
baseTriangle_t baseTriangles[MD3_MAX_TRIANGLES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// the triangles will be sorted so that they form long generalized tristrips
|
2012-03-17 20:01:54 +00:00
|
|
|
int orderedTriangles[MD3_MAX_TRIANGLES][3];
|
|
|
|
int lodTriangles[MD3_MAX_TRIANGLES][3];
|
|
|
|
baseVertex_t baseVertexes[MD3_MAX_VERTS];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
} md3SurfaceData_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int skinwidth, skinheight;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
md3SurfaceData_t surfData[MD3_MAX_SURFACES];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
md3Tag_t tags[MD3_MAX_FRAMES][MD3_MAX_TAGS];
|
|
|
|
md3Frame_t frames[MD3_MAX_FRAMES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
md3Header_t model;
|
|
|
|
float scale_up; // set by $scale
|
|
|
|
vec3_t adjust; // set by $origin
|
|
|
|
vec3_t aseAdjust;
|
|
|
|
int fixedwidth, fixedheight; // set by $skinsize
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int maxSurfaceTris;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int lowerSkipFrameStart, lowerSkipFrameEnd;
|
|
|
|
int maxUpperFrames;
|
|
|
|
int maxHeadFrames;
|
|
|
|
int currentLod;
|
|
|
|
float lodBias;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int type; // MD3_TYPE_BASE, MD3_TYPE_OLDBASE, MD3_TYPE_ASE, or MD3_TYPE_SPRITE
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
} q3data;
|
|
|
|
|
|
|
|
q3data g_data;
|
|
|
|
|
|
|
|
// the command list holds counts, the count * 3 xyz, st, normal indexes
|
|
|
|
// that are valid for every frame
|
2012-03-17 20:01:54 +00:00
|
|
|
char g_cddir[1024];
|
|
|
|
char g_modelname[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//==============================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
ClearModel
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void ClearModel( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
g_data.type = MD3_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
for ( i = 0; i < MD3_MAX_SURFACES; i++ )
|
|
|
|
{
|
|
|
|
memset( &g_data.surfData[i].header, 0, sizeof( g_data.surfData[i].header ) );
|
|
|
|
memset( &g_data.surfData[i].shaders, 0, sizeof( g_data.surfData[i].shaders ) );
|
|
|
|
memset( &g_data.surfData[i].verts, 0, sizeof( g_data.surfData[i].verts ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
memset( g_data.tags, 0, sizeof( g_data.tags ) );
|
|
|
|
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for ( j = 0; j < g_data.surfData[i].header.numShaders; j++ )
|
|
|
|
{
|
|
|
|
memset( &g_data.surfData[i].shaders[j], 0, sizeof( g_data.surfData[i].shaders[j] ) );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( &g_data.model, 0, sizeof( g_data.model ) );
|
|
|
|
memset( g_cddir, 0, sizeof( g_cddir ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
g_modelname[0] = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.scale_up = 1.0;
|
2007-11-04 03:34:51 +00:00
|
|
|
memset( &g_data.model, 0, sizeof( g_data.model ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( vec3_origin, g_data.adjust );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.fixedwidth = g_data.fixedheight = 0;
|
|
|
|
g_skipmodel = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** void WriteModelSurface( FILE *modelouthandle, md3SurfaceData_t *pSurfData )
|
|
|
|
**
|
|
|
|
** This routine assumes that the file position has been adjusted
|
|
|
|
** properly prior to entry to point at the beginning of the surface.
|
|
|
|
**
|
|
|
|
** Since surface header information is completely relative, we can't
|
|
|
|
** just randomly seek to an arbitrary surface location right now. Is
|
|
|
|
** this something we should add?
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
void WriteModelSurface( FILE *modelouthandle, md3SurfaceData_t *pSurfData ){
|
|
|
|
md3Surface_t *pSurf = &pSurfData->header;
|
|
|
|
md3Shader_t *pShader = pSurfData->shaders;
|
|
|
|
baseVertex_t *pBaseVertex = pSurfData->baseVertexes;
|
|
|
|
float **verts = pSurfData->verts;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
short xyznormals[MD3_MAX_VERTS][4];
|
|
|
|
|
|
|
|
float base_st[MD3_MAX_VERTS][2];
|
|
|
|
md3Surface_t surftemp;
|
|
|
|
|
|
|
|
int f, i, j, k;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( pSurf->name, "tag_" ) == pSurf->name ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the header
|
|
|
|
//
|
|
|
|
surftemp = *pSurf;
|
|
|
|
surftemp.ident = LittleLong( MD3_IDENT );
|
|
|
|
surftemp.flags = LittleLong( pSurf->flags );
|
|
|
|
surftemp.numFrames = LittleLong( pSurf->numFrames );
|
|
|
|
surftemp.numShaders = LittleLong( pSurf->numShaders );
|
|
|
|
|
|
|
|
surftemp.ofsShaders = LittleLong( pSurf->ofsShaders );
|
|
|
|
|
|
|
|
surftemp.ofsTriangles = LittleLong( pSurf->ofsTriangles );
|
|
|
|
surftemp.numTriangles = LittleLong( pSurf->numTriangles );
|
|
|
|
|
|
|
|
surftemp.ofsSt = LittleLong( pSurf->ofsSt );
|
|
|
|
surftemp.ofsXyzNormals = LittleLong( pSurf->ofsXyzNormals );
|
|
|
|
surftemp.ofsEnd = LittleLong( pSurf->ofsEnd );
|
|
|
|
|
|
|
|
SafeWrite( modelouthandle, &surftemp, sizeof( surftemp ) );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_verbose ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
printf( "surface '%s'\n", pSurf->name );
|
|
|
|
printf( "...num shaders: %d\n", pSurf->numShaders );
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out shaders
|
|
|
|
//
|
|
|
|
for ( i = 0; i < pSurf->numShaders; i++ )
|
|
|
|
{
|
|
|
|
md3Shader_t shadertemp;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_verbose ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
printf( "......'%s'\n", pShader[i].name );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
shadertemp = pShader[i];
|
|
|
|
shadertemp.shaderIndex = LittleLong( shadertemp.shaderIndex );
|
|
|
|
SafeWrite( modelouthandle, &shadertemp, sizeof( shadertemp ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out the triangles
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < pSurf->numTriangles ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
int ivalue = LittleLong( pSurfData->orderedTriangles[i][j] );
|
|
|
|
pSurfData->orderedTriangles[i][j] = ivalue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SafeWrite( modelouthandle, pSurfData->orderedTriangles, pSurf->numTriangles * sizeof( g_data.surfData[0].orderedTriangles[0] ) );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_verbose ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
printf( "\n...num verts: %d\n", pSurf->numVerts );
|
|
|
|
printf( "...TEX COORDINATES\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out the texture coordinates
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < pSurf->numVerts ; i++ ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
base_st[i][0] = LittleFloat( pBaseVertex[i].st[0] );
|
|
|
|
base_st[i][1] = LittleFloat( pBaseVertex[i].st[1] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_verbose ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
printf( "......%d: %f,%f\n", i, base_st[i][0], base_st[i][1] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, base_st, pSurf->numVerts * sizeof( base_st[0] ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write the xyz_normal
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_verbose ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
printf( "...XYZNORMALS\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( f = 0; f < g_data.model.numFrames; f++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < pSurf->numVerts; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
short value;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0 ; k < 3 ; k++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
value = ( short ) ( verts[f][j * 6 + k] / MD3_XYZ_SCALE );
|
2007-11-04 03:34:51 +00:00
|
|
|
xyznormals[j][k] = LittleShort( value );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
NormalToLatLong( &verts[f][j * 6 + 3], (byte *)&xyznormals[j][3] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
SafeWrite( modelouthandle, xyznormals, pSurf->numVerts * sizeof( short ) * 4 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** void WriteModelFile( FILE *modelouthandle )
|
|
|
|
**
|
|
|
|
** CHUNK SIZE
|
|
|
|
** header sizeof( md3Header_t )
|
|
|
|
** frames sizeof( md3Frame_t ) * numFrames
|
|
|
|
** tags sizeof( md3Tag_t ) * numFrames * numTags
|
|
|
|
** surfaces surfaceSum
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
void WriteModelFile( FILE *modelouthandle ){
|
|
|
|
int f;
|
|
|
|
int i, j;
|
|
|
|
md3Header_t modeltemp;
|
|
|
|
long surfaceSum = 0;
|
|
|
|
int numRealSurfaces = 0;
|
|
|
|
int numFrames = g_data.model.numFrames;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// compute offsets for all surfaces, sum their total size
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( g_data.surfData[i].header.name, "tag_" ) != g_data.surfData[i].header.name ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
md3Surface_t *psurf = &g_data.surfData[i].header;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( psurf->numTriangles == 0 || psurf->numVerts == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// the triangle and vertex split threshold is controlled by a parameter
|
|
|
|
// to $base, a la $base blah.3ds 1900, where "1900" determines the number
|
|
|
|
// of triangles to split on
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( psurf->numVerts > MAX_SURFACE_VERTS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "too many vertices\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
psurf->numFrames = numFrames;
|
|
|
|
|
|
|
|
psurf->ofsShaders = sizeof( md3Surface_t );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( psurf->numTriangles > MAX_SURFACE_TRIS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "too many faces\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
psurf->ofsTriangles = psurf->ofsShaders + psurf->numShaders * sizeof( md3Shader_t );
|
|
|
|
|
|
|
|
psurf->ofsSt = psurf->ofsTriangles + psurf->numTriangles * sizeof( md3Triangle_t );
|
|
|
|
psurf->ofsXyzNormals = psurf->ofsSt + psurf->numVerts * sizeof( md3St_t );
|
|
|
|
psurf->ofsEnd = psurf->ofsXyzNormals + psurf->numFrames * psurf->numVerts * ( sizeof( short ) * 4 );
|
|
|
|
|
|
|
|
surfaceSum += psurf->ofsEnd;
|
|
|
|
|
|
|
|
numRealSurfaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data.model.ident = MD3_IDENT;
|
|
|
|
g_data.model.version = MD3_VERSION;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.model.ofsFrames = sizeof( md3Header_t );
|
|
|
|
g_data.model.ofsTags = g_data.model.ofsFrames + numFrames * sizeof( md3Frame_t );
|
|
|
|
g_data.model.ofsSurfaces = g_data.model.ofsTags + numFrames * g_data.model.numTags * sizeof( md3Tag_t );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.model.ofsEnd = g_data.model.ofsSurfaces + surfaceSum;
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out the model header
|
|
|
|
//
|
|
|
|
modeltemp = g_data.model;
|
|
|
|
modeltemp.ident = LittleLong( modeltemp.ident );
|
|
|
|
modeltemp.version = LittleLong( modeltemp.version );
|
|
|
|
modeltemp.numFrames = LittleLong( modeltemp.numFrames );
|
|
|
|
modeltemp.numTags = LittleLong( modeltemp.numTags );
|
|
|
|
modeltemp.numSurfaces = LittleLong( numRealSurfaces );
|
|
|
|
modeltemp.ofsFrames = LittleLong( modeltemp.ofsFrames );
|
|
|
|
modeltemp.ofsTags = LittleLong( modeltemp.ofsTags );
|
|
|
|
modeltemp.ofsSurfaces = LittleLong( modeltemp.ofsSurfaces );
|
|
|
|
modeltemp.ofsEnd = LittleLong( modeltemp.ofsEnd );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, &modeltemp, sizeof( modeltemp ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the frames
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < numFrames ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
vec3_t tmpVec;
|
|
|
|
float maxRadius = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// compute localOrigin and radius
|
|
|
|
//
|
|
|
|
g_data.frames[i].localOrigin[0] =
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.frames[i].localOrigin[1] =
|
|
|
|
g_data.frames[i].localOrigin[2] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
for ( j = 0; j < 8; j++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
tmpVec[0] = g_data.frames[i].bounds[( j & 1 ) != 0][0];
|
|
|
|
tmpVec[1] = g_data.frames[i].bounds[( j & 2 ) != 0][1];
|
|
|
|
tmpVec[2] = g_data.frames[i].bounds[( j & 4 ) != 0][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( VectorLength( tmpVec ) > maxRadius ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
maxRadius = VectorLength( tmpVec );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_data.frames[i].radius = LittleFloat( maxRadius );
|
|
|
|
|
|
|
|
// swap
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.frames[i].bounds[0][j] = LittleFloat( g_data.frames[i].bounds[0][j] );
|
|
|
|
g_data.frames[i].bounds[1][j] = LittleFloat( g_data.frames[i].bounds[1][j] );
|
|
|
|
g_data.frames[i].localOrigin[j] = LittleFloat( g_data.frames[i].localOrigin[j] );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
fseek( modelouthandle, g_data.model.ofsFrames, SEEK_SET );
|
|
|
|
SafeWrite( modelouthandle, g_data.frames, numFrames * sizeof( g_data.frames[0] ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the tags
|
|
|
|
//
|
|
|
|
fseek( modelouthandle, g_data.model.ofsTags, SEEK_SET );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( f = 0 ; f < g_data.model.numFrames; f++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
int t;
|
|
|
|
|
|
|
|
for ( t = 0; t < g_data.model.numTags; t++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.tags[f][t].origin[0] = LittleFloat( g_data.tags[f][t].origin[0] );
|
|
|
|
g_data.tags[f][t].origin[1] = LittleFloat( g_data.tags[f][t].origin[1] );
|
|
|
|
g_data.tags[f][t].origin[2] = LittleFloat( g_data.tags[f][t].origin[2] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.tags[f][t].axis[0][j] = LittleFloat( g_data.tags[f][t].axis[0][j] );
|
|
|
|
g_data.tags[f][t].axis[1][j] = LittleFloat( g_data.tags[f][t].axis[1][j] );
|
|
|
|
g_data.tags[f][t].axis[2][j] = LittleFloat( g_data.tags[f][t].axis[2][j] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, g_data.tags[f], g_data.model.numTags * sizeof( md3Tag_t ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out the surfaces
|
|
|
|
//
|
|
|
|
fseek( modelouthandle, g_data.model.ofsSurfaces, SEEK_SET );
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
WriteModelSurface( modelouthandle, &g_data.surfData[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
FinishModel
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void FinishModel( int type ){
|
|
|
|
FILE *modelouthandle;
|
|
|
|
FILE *defaultSkinHandle;
|
|
|
|
char name[1024];
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_data.model.numFrames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// build generalized triangle strips
|
|
|
|
//
|
|
|
|
OrderSurfaces();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type == TYPE_PLAYER ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sprintf( name, "%s%s", writedir, g_modelname );
|
|
|
|
*strrchr( name, '.' ) = 0;
|
|
|
|
strcat( name, "_default.skin" );
|
|
|
|
|
|
|
|
defaultSkinHandle = fopen( name, "wt" );
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
fprintf( defaultSkinHandle, "%s,%s\n", g_data.surfData[i].header.name, g_data.surfData[i].shaders[0].name );
|
|
|
|
}
|
|
|
|
fclose( defaultSkinHandle );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( name, "%s%s", writedir, g_modelname );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
// copy the model and its shaders to release directory tree
|
2007-11-04 03:34:51 +00:00
|
|
|
// if doing a release build
|
|
|
|
//
|
|
|
|
if ( g_release ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
int i, j;
|
2007-11-04 03:34:51 +00:00
|
|
|
md3SurfaceData_t *pSurf;
|
|
|
|
|
|
|
|
ReleaseFile( g_modelname );
|
|
|
|
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ ) {
|
|
|
|
pSurf = &g_data.surfData[i];
|
|
|
|
for ( j = 0; j < g_data.model.numSkins; j++ ) {
|
|
|
|
ReleaseShader( pSurf->shaders[j].name );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// write the model output file
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "saving to %s\n", name );
|
|
|
|
CreatePath( name );
|
|
|
|
modelouthandle = SafeOpenWrite( name );
|
|
|
|
|
|
|
|
WriteModelFile( modelouthandle );
|
|
|
|
|
|
|
|
printf( "%4d surfaces\n", g_data.model.numSurfaces );
|
|
|
|
printf( "%4d frames\n", g_data.model.numFrames );
|
|
|
|
printf( "%4d tags\n", g_data.model.numTags );
|
|
|
|
printf( "file size: %d\n", (int)ftell( modelouthandle ) );
|
|
|
|
printf( "---------------------\n" );
|
|
|
|
|
|
|
|
fclose( modelouthandle );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** OrderSurfaces
|
|
|
|
**
|
|
|
|
** Reorders triangles in all the surfaces.
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
static void OrderSurfaces( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int s;
|
|
|
|
extern qboolean g_stripify;
|
|
|
|
|
|
|
|
// go through each surface and find best strip/fans possible
|
|
|
|
for ( s = 0; s < g_data.model.numSurfaces; s++ )
|
|
|
|
{
|
|
|
|
int mesh[MD3_MAX_TRIANGLES][3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf( "stripifying surface %d/%d with %d tris\n", s, g_data.model.numSurfaces, g_data.surfData[s].header.numTriangles );
|
|
|
|
|
|
|
|
for ( i = 0; i < g_data.surfData[s].header.numTriangles; i++ )
|
|
|
|
{
|
|
|
|
mesh[i][0] = g_data.surfData[s].lodTriangles[i][0];
|
|
|
|
mesh[i][1] = g_data.surfData[s].lodTriangles[i][1];
|
|
|
|
mesh[i][2] = g_data.surfData[s].lodTriangles[i][2];
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_stripify ) {
|
|
|
|
OrderMesh( mesh, // input
|
|
|
|
g_data.surfData[s].orderedTriangles, // output
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.surfData[s].header.numTriangles );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy( g_data.surfData[s].orderedTriangles, mesh, sizeof( int ) * 3 * g_data.surfData[s].header.numTriangles );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
BASE FRAME SETUP
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
===============================================================
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
CopyTrianglesToBaseTriangles
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
*/
|
|
|
|
static void CopyTrianglesToBaseTriangles( triangle_t *ptri, int numtri, baseTriangle_t *bTri ){
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
// int width, height, iwidth, iheight, swidth;
|
|
|
|
// float s_scale, t_scale;
|
|
|
|
// float scale;
|
|
|
|
// vec3_t mins, maxs;
|
2012-03-17 20:01:54 +00:00
|
|
|
float *pbasevert;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
//
|
|
|
|
// find bounds of all the verts on the base frame
|
|
|
|
//
|
|
|
|
ClearBounds (mins, maxs);
|
|
|
|
|
|
|
|
for (i=0 ; i<numtri ; i++)
|
|
|
|
for (j=0 ; j<3 ; j++)
|
|
|
|
AddPointToBounds (ptri[i].verts[j], mins, maxs);
|
|
|
|
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
{
|
|
|
|
mins[i] = floor(mins[i]);
|
|
|
|
maxs[i] = ceil(maxs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
width = maxs[0] - mins[0];
|
|
|
|
height = maxs[2] - mins[2];
|
|
|
|
|
|
|
|
if (!g_data.fixedwidth)
|
|
|
|
{ // old style
|
|
|
|
scale = 8;
|
|
|
|
if (width*scale >= 150)
|
|
|
|
scale = 150.0 / width;
|
|
|
|
if (height*scale >= 190)
|
|
|
|
scale = 190.0 / height;
|
|
|
|
|
|
|
|
s_scale = t_scale = scale;
|
|
|
|
|
|
|
|
iwidth = ceil(width*s_scale);
|
|
|
|
iheight = ceil(height*t_scale);
|
|
|
|
|
|
|
|
iwidth += 4;
|
|
|
|
iheight += 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // new style
|
|
|
|
iwidth = g_data.fixedwidth / 2;
|
|
|
|
iheight = g_data.fixedheight;
|
|
|
|
|
|
|
|
s_scale = (float)(iwidth-4) / width;
|
|
|
|
t_scale = (float)(iheight-4) / height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make the width a multiple of 4; some hardware requires this, and it ensures
|
|
|
|
// dword alignment for each scan
|
|
|
|
swidth = iwidth*2;
|
|
|
|
g_data.skinwidth = (swidth + 3) & ~3;
|
|
|
|
g_data.skinheight = iheight;
|
|
|
|
*/
|
|
|
|
|
|
|
|
for ( i = 0; i < numtri ; i++, ptri++, bTri++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
pbasevert = ptri->verts[j];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( ptri->verts[j], bTri->v[j].xyz );
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( ptri->normals[j], bTri->v[j].normal );
|
|
|
|
|
|
|
|
bTri->v[j].st[0] = ptri->texcoords[j][0];
|
|
|
|
bTri->v[j].st[1] = ptri->texcoords[j][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void BuildBaseFrame( const char *filename, ObjectAnimationFrame_t *pOAF ){
|
|
|
|
baseTriangle_t *bTri;
|
|
|
|
baseVertex_t *bVert;
|
2007-11-04 03:34:51 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
// calculate the base triangles
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
CopyTrianglesToBaseTriangles( pOAF->surfaces[i]->triangles,
|
|
|
|
pOAF->surfaces[i]->numtriangles,
|
|
|
|
g_data.surfData[i].baseTriangles );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
strcpy( g_data.surfData[i].header.name, pOAF->surfaces[i]->name );
|
|
|
|
|
|
|
|
g_data.surfData[i].header.numTriangles = pOAF->surfaces[i]->numtriangles;
|
|
|
|
g_data.surfData[i].header.numVerts = 0;
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( filename, gamedir + 1 ) )
|
|
|
|
{
|
|
|
|
strcpy( shaderName, strstr( filename, gamedir + 1 ) + strlen( gamedir ) - 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy( shaderName, filename );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( shaderName, '/' ) )
|
|
|
|
*( strrchr( shaderName, '/' ) + 1 ) = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( shaderName, pOAF->surfaces[i]->materialname );
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( g_data.surfData[i].shaders[g_data.surfData[i].header.numShaders].name, pOAF->surfaces[i]->materialname );
|
|
|
|
|
|
|
|
g_data.surfData[i].header.numShaders++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// compute unique vertices for each polyset
|
|
|
|
//
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
|
|
|
|
for ( t = 0; t < pOAF->surfaces[i]->numtriangles; t++ )
|
|
|
|
{
|
|
|
|
bTri = &g_data.surfData[i].baseTriangles[t];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
|
|
|
|
bVert = &bTri->v[j];
|
|
|
|
|
|
|
|
// get the xyz index
|
|
|
|
for ( k = 0; k < g_data.surfData[i].header.numVerts; k++ )
|
|
|
|
{
|
|
|
|
if ( ( g_data.surfData[i].baseVertexes[k].st[0] == bVert->st[0] ) &&
|
|
|
|
( g_data.surfData[i].baseVertexes[k].st[1] == bVert->st[1] ) &&
|
2012-03-17 20:01:54 +00:00
|
|
|
( VectorCompare( bVert->xyz, g_data.surfData[i].baseVertexes[k].xyz ) ) &&
|
|
|
|
( VectorCompare( bVert->normal, g_data.surfData[i].baseVertexes[k].normal ) ) ) {
|
|
|
|
break; // this vertex is already in the base vertex list
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( k == g_data.surfData[i].header.numVerts ) { // new index
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.surfData[i].baseVertexes[g_data.surfData[i].header.numVerts] = *bVert;
|
|
|
|
g_data.surfData[i].header.numVerts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bVert->index = k;
|
|
|
|
|
|
|
|
g_data.surfData[i].lodTriangles[t][j] = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// find tags
|
|
|
|
//
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( pOAF->surfaces[i]->name, "tag_" ) == pOAF->surfaces[i]->name ) {
|
|
|
|
if ( pOAF->surfaces[i]->numtriangles != 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "tag polysets must consist of only one triangle" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( filename, "_flash.md3" ) && !strcmp( pOAF->surfaces[i]->name, "tag_parent" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
printf( "found tag '%s'\n", pOAF->surfaces[i]->name );
|
|
|
|
g_data.model.numTags++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static int LoadModelFile( const char *filename, polyset_t **psets, int *numpolysets ){
|
|
|
|
int time1;
|
|
|
|
char file1[1024];
|
|
|
|
const char *frameFile;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "---------------------\n" );
|
|
|
|
if ( filename[1] != ':' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
frameFile = filename;
|
|
|
|
sprintf( file1, "%s/%s", g_cddir, frameFile );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy( file1, filename );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
time1 = FileTime( file1 );
|
|
|
|
if ( time1 == -1 ) {
|
|
|
|
Error( "%s doesn't exist", file1 );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// load the base triangles
|
|
|
|
//
|
|
|
|
*psets = Polyset_LoadSets( file1, numpolysets, g_data.maxSurfaceTris );
|
|
|
|
|
|
|
|
//
|
|
|
|
// snap polysets
|
|
|
|
//
|
|
|
|
Polyset_SnapSets( *psets, *numpolysets );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( file1, ".3ds" ) || strstr( file1, ".3DS" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return MD3_TYPE_BASE3DS;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
Error( "Unknown model file type" );
|
|
|
|
|
|
|
|
return MD3_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_Base
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Base( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
char filename[1024];
|
|
|
|
|
|
|
|
GetToken( qfalse );
|
|
|
|
sprintf( filename, "%s/%s", g_cddir, token );
|
|
|
|
LoadBase( filename );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadBase( const char *filename ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int numpolysets;
|
|
|
|
polyset_t *psets;
|
2012-03-17 20:01:54 +00:00
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
ObjectAnimationFrame_t oaf;
|
|
|
|
|
|
|
|
// determine polyset splitting threshold
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.maxSurfaceTris = atoi( token );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_data.maxSurfaceTris = MAX_SURFACE_TRIS - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data.type = LoadModelFile( filename, &psets, &numpolysets );
|
|
|
|
|
|
|
|
Polyset_ComputeNormals( psets, numpolysets );
|
|
|
|
|
|
|
|
g_data.model.numSurfaces = numpolysets;
|
|
|
|
|
|
|
|
memset( &oaf, 0, sizeof( oaf ) );
|
|
|
|
|
|
|
|
for ( i = 0; i < numpolysets; i++ )
|
|
|
|
{
|
|
|
|
oaf.surfaces[i] = &psets[i];
|
|
|
|
oaf.numSurfaces = numpolysets;
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildBaseFrame( filename, &oaf );
|
|
|
|
|
|
|
|
free( psets[0].triangles );
|
|
|
|
free( psets );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_SpriteBase
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
$spritebase xorg yorg width height
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Generate a single square for the model
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_SpriteBase( void ){
|
|
|
|
float xl, yl, width, height;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
g_data.type = MD3_TYPE_SPRITE;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
xl = atof( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
yl = atof( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
width = atof( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
height = atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if (g_skipmodel || g_release || g_archive)
|
|
|
|
// return;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "---------------------\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
g_data.surfData[0].verts[0] = ( float * ) calloc( 1, sizeof( float ) * 6 * 4 );
|
|
|
|
|
|
|
|
g_data.surfData[0].header.numVerts = 4;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][0 + 0] = 0;
|
|
|
|
g_data.surfData[0].verts[0][0 + 1] = -xl;
|
|
|
|
g_data.surfData[0].verts[0][0 + 2] = yl + height;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][0 + 3] = -1;
|
|
|
|
g_data.surfData[0].verts[0][0 + 4] = 0;
|
|
|
|
g_data.surfData[0].verts[0][0 + 5] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.surfData[0].baseVertexes[0].st[0] = 0;
|
|
|
|
g_data.surfData[0].baseVertexes[0].st[1] = 0;
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][6 + 0] = 0;
|
|
|
|
g_data.surfData[0].verts[0][6 + 1] = -xl - width;
|
|
|
|
g_data.surfData[0].verts[0][6 + 2] = yl + height;
|
|
|
|
|
|
|
|
g_data.surfData[0].verts[0][6 + 3] = -1;
|
|
|
|
g_data.surfData[0].verts[0][6 + 4] = 0;
|
|
|
|
g_data.surfData[0].verts[0][6 + 5] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.surfData[0].baseVertexes[1].st[0] = 1;
|
|
|
|
g_data.surfData[0].baseVertexes[1].st[1] = 0;
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][12 + 0] = 0;
|
|
|
|
g_data.surfData[0].verts[0][12 + 1] = -xl - width;
|
|
|
|
g_data.surfData[0].verts[0][12 + 2] = yl;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][12 + 3] = -1;
|
|
|
|
g_data.surfData[0].verts[0][12 + 4] = 0;
|
|
|
|
g_data.surfData[0].verts[0][12 + 5] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.surfData[0].baseVertexes[2].st[0] = 1;
|
|
|
|
g_data.surfData[0].baseVertexes[2].st[1] = 1;
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][18 + 0] = 0;
|
|
|
|
g_data.surfData[0].verts[0][18 + 1] = -xl;
|
|
|
|
g_data.surfData[0].verts[0][18 + 2] = yl;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.surfData[0].verts[0][18 + 3] = -1;
|
|
|
|
g_data.surfData[0].verts[0][18 + 4] = 0;
|
|
|
|
g_data.surfData[0].verts[0][18 + 5] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
g_data.surfData[0].baseVertexes[3].st[0] = 0;
|
|
|
|
g_data.surfData[0].baseVertexes[3].st[1] = 1;
|
|
|
|
|
|
|
|
g_data.surfData[0].lodTriangles[0][0] = 0;
|
|
|
|
g_data.surfData[0].lodTriangles[0][1] = 1;
|
|
|
|
g_data.surfData[0].lodTriangles[0][2] = 2;
|
|
|
|
|
|
|
|
g_data.surfData[0].lodTriangles[1][0] = 2;
|
|
|
|
g_data.surfData[0].lodTriangles[1][1] = 3;
|
|
|
|
g_data.surfData[0].lodTriangles[1][2] = 0;
|
|
|
|
|
|
|
|
g_data.model.numSurfaces = 1;
|
|
|
|
|
|
|
|
g_data.surfData[0].header.numTriangles = 2;
|
|
|
|
g_data.surfData[0].header.numVerts = 4;
|
|
|
|
|
|
|
|
g_data.model.numFrames = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===========================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FRAME GRABBING
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
===========================================================================
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
GrabFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GrabFrame( const char *frame ){
|
|
|
|
int i, j, k;
|
|
|
|
char file1[1024];
|
|
|
|
md3Frame_t *fr;
|
|
|
|
md3Tag_t tagParent;
|
|
|
|
float *frameXyz;
|
|
|
|
float *frameNormals;
|
|
|
|
const char *framefile;
|
|
|
|
polyset_t *psets;
|
|
|
|
qboolean parentTagExists = qfalse;
|
|
|
|
int numpolysets;
|
|
|
|
int numtags = 0;
|
|
|
|
int tagcount;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// the frame 'run1' will be looked for as either
|
|
|
|
// run.1 or run1.tri, so the new alias sequence save
|
|
|
|
// feature an be used
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( frame[1] != ':' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// framefile = FindFrameFile (frame);
|
|
|
|
framefile = frame;
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s",g_cddir, framefile );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy( file1, frame );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "grabbing %s\n", file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.model.numFrames >= MD3_MAX_FRAMES ) {
|
|
|
|
Error( "model.numFrames >= MD3_MAX_FRAMES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
fr = &g_data.frames[g_data.model.numFrames];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( fr->name, frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
psets = Polyset_LoadSets( file1, &numpolysets, g_data.maxSurfaceTris );
|
|
|
|
|
|
|
|
//
|
|
|
|
// snap polysets
|
|
|
|
//
|
|
|
|
Polyset_SnapSets( psets, numpolysets );
|
|
|
|
|
|
|
|
//
|
|
|
|
// compute vertex normals
|
|
|
|
//
|
|
|
|
Polyset_ComputeNormals( psets, numpolysets );
|
|
|
|
|
|
|
|
//
|
|
|
|
// flip everything to compensate for the alias coordinate system
|
|
|
|
// and perform global scale and adjust
|
|
|
|
//
|
|
|
|
for ( i = 0; i < g_data.model.numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
triangle_t *ptri = psets[i].triangles;
|
|
|
|
int t;
|
|
|
|
|
|
|
|
for ( t = 0; t < psets[i].numtriangles; t++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
for ( j = 0; j < 3; j++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
// scale and adjust
|
|
|
|
for ( k = 0 ; k < 3 ; k++ ) {
|
|
|
|
ptri[t].verts[j][k] = ptri[t].verts[j][k] * g_data.scale_up +
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.adjust[k];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
if ( ptri[t].verts[j][k] > 1023 ||
|
2012-03-17 20:01:54 +00:00
|
|
|
ptri[t].verts[j][k] < -1023 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Model extents too large" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// find and count tags, locate parent tag
|
|
|
|
//
|
|
|
|
for ( i = 0; i < numpolysets; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( psets[i].name, "tag_" ) == psets[i].name ) {
|
|
|
|
if ( strstr( psets[i].name, "tag_parent" ) == psets[i].name ) {
|
|
|
|
if ( strstr( psets[i].name, "tag_parent" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
float tri[3][3];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( parentTagExists ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Multiple parent tags not allowed" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
memcpy( tri[0], psets[i].triangles[0].verts[0], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[1], psets[i].triangles[0].verts[1], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[2], psets[i].triangles[0].verts[2], sizeof( float ) * 3 );
|
|
|
|
|
|
|
|
MD3_ComputeTagFromTri( &tagParent, tri );
|
|
|
|
strcpy( tagParent.name, psets[i].name );
|
|
|
|
g_data.tags[g_data.model.numFrames][numtags] = tagParent;
|
|
|
|
parentTagExists = qtrue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
numtags++;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( psets[i].name, g_data.surfData[i].header.name ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Mismatched surfaces from base('%s') to frame('%s') in model '%s'\n", g_data.surfData[i].header.name, psets[i].name, g_modelname );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numtags != g_data.model.numTags ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "mismatched number of tags in frame(%d) vs. base(%d)", numtags, g_data.model.numTags );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numpolysets != g_data.model.numSurfaces ) {
|
|
|
|
Error( "mismatched number of surfaces in frame(%d) vs. base(%d)", numpolysets - numtags, g_data.model.numSurfaces );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// prepare to accumulate bounds and normals
|
|
|
|
//
|
|
|
|
ClearBounds( fr->bounds[0], fr->bounds[1] );
|
|
|
|
|
|
|
|
//
|
|
|
|
// store the frame's vertices in the same order as the base. This assumes the
|
|
|
|
// triangles and vertices in this frame are in exactly the same order as in the
|
|
|
|
// base
|
|
|
|
//
|
|
|
|
for ( i = 0, tagcount = 0; i < numpolysets; i++ )
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
triangle_t *pTris = psets[i].triangles;
|
|
|
|
|
|
|
|
strcpy( g_data.surfData[i].header.name, psets[i].name );
|
|
|
|
|
|
|
|
//
|
|
|
|
// parent tag adjust
|
|
|
|
//
|
|
|
|
if ( parentTagExists ) {
|
|
|
|
for ( t = 0; t < psets[i].numtriangles; t++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < 3 ; j++ )
|
|
|
|
{
|
|
|
|
vec3_t tmp;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorSubtract( pTris[t].verts[j], tagParent.origin, tmp );
|
|
|
|
|
|
|
|
pTris[t].verts[j][0] = DotProduct( tmp, tagParent.axis[0] );
|
|
|
|
pTris[t].verts[j][1] = DotProduct( tmp, tagParent.axis[1] );
|
|
|
|
pTris[t].verts[j][2] = DotProduct( tmp, tagParent.axis[2] );
|
|
|
|
|
|
|
|
VectorCopy( pTris[t].normals[j], tmp );
|
|
|
|
pTris[t].normals[j][0] = DotProduct( tmp, tagParent.axis[0] );
|
|
|
|
pTris[t].normals[j][1] = DotProduct( tmp, tagParent.axis[1] );
|
|
|
|
pTris[t].normals[j][2] = DotProduct( tmp, tagParent.axis[2] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// compute tag data
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( psets[i].name, "tag_" ) == psets[i].name ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
md3Tag_t *pTag = &g_data.tags[g_data.model.numFrames][tagcount];
|
|
|
|
float tri[3][3];
|
|
|
|
|
|
|
|
strcpy( pTag->name, psets[i].name );
|
|
|
|
|
|
|
|
memcpy( tri[0], pTris[0].verts[0], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[1], pTris[0].verts[1], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[2], pTris[0].verts[2], sizeof( float ) * 3 );
|
|
|
|
|
|
|
|
MD3_ComputeTagFromTri( pTag, tri );
|
|
|
|
tagcount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.surfData[i].verts[g_data.model.numFrames] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
free( g_data.surfData[i].verts[g_data.model.numFrames] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
frameXyz = g_data.surfData[i].verts[g_data.model.numFrames] = calloc( 1, sizeof( float ) * 6 * g_data.surfData[i].header.numVerts );
|
|
|
|
frameNormals = frameXyz + 3;
|
|
|
|
|
|
|
|
for ( t = 0; t < psets[i].numtriangles; t++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < 3 ; j++ )
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = g_data.surfData[i].baseTriangles[t].v[j].index;
|
2012-03-17 20:01:54 +00:00
|
|
|
frameXyz[index * 6 + 0] = pTris[t].verts[j][0];
|
|
|
|
frameXyz[index * 6 + 1] = pTris[t].verts[j][1];
|
|
|
|
frameXyz[index * 6 + 2] = pTris[t].verts[j][2];
|
|
|
|
frameNormals[index * 6 + 0] = pTris[t].normals[j][0];
|
|
|
|
frameNormals[index * 6 + 1] = pTris[t].normals[j][1];
|
|
|
|
frameNormals[index * 6 + 2] = pTris[t].normals[j][2];
|
|
|
|
AddPointToBounds( &frameXyz[index * 6], fr->bounds[0], fr->bounds[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data.model.numFrames++;
|
|
|
|
|
|
|
|
// only free the first triangle array, all of the psets in this array share the
|
|
|
|
// same triangle pool!!!
|
|
|
|
// free( psets[0].triangles );
|
|
|
|
// free( psets );
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Frame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Frame( void ){
|
|
|
|
while ( TokenAvailable() )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
if ( g_skipmodel ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( g_release || g_archive ) {
|
|
|
|
g_data.model.numFrames = 1; // don't skip the writeout
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrabFrame( token );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Skin
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void SkinFrom3DS( const char *filename ){
|
2007-11-04 03:34:51 +00:00
|
|
|
polyset_t *psets;
|
|
|
|
char name[1024];
|
|
|
|
int numPolysets;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_3DS_LoadPolysets( filename, &psets, &numPolysets, g_verbose );
|
|
|
|
|
|
|
|
for ( i = 0; i < numPolysets; i++ )
|
|
|
|
{
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( filename, gamedir + 1 ) )
|
|
|
|
{
|
|
|
|
strcpy( name, strstr( filename, gamedir + 1 ) + strlen( gamedir ) - 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy( name, filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strrchr( name, '/' ) )
|
|
|
|
*( strrchr( name, '/' ) + 1 ) = 0;
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( name, psets[i].materialname );
|
|
|
|
strcpy( g_data.surfData[i].shaders[g_data.surfData[i].header.numShaders].name, name );
|
|
|
|
|
|
|
|
g_data.surfData[i].header.numShaders++;
|
|
|
|
}
|
|
|
|
|
|
|
|
free( psets[0].triangles );
|
|
|
|
free( psets );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_Skin( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
char skinfile[1024];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.type == MD3_TYPE_BASE3DS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
|
|
|
|
sprintf( skinfile, "%s/%s", g_cddir, token );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( token, ".3ds" ) || strstr( token, ".3DS" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
SkinFrom3DS( skinfile );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Error( "Unknown file format for $skin '%s'\n", skinfile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Error( "invalid model type while processing $skin" );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data.model.numSkins++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_SpriteShader
|
|
|
|
=================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This routine is also called for $oldskin
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*/
|
|
|
|
void Cmd_SpriteShader(){
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
strcpy( g_data.surfData[0].shaders[g_data.surfData[0].header.numShaders].name, token );
|
|
|
|
g_data.surfData[0].header.numShaders++;
|
|
|
|
g_data.model.numSkins++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_Origin
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Origin( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
// rotate points into frame of reference so model points down the
|
|
|
|
// positive x axis
|
|
|
|
// FIXME: use alias native coordinate system
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.adjust[1] = -atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.adjust[0] = atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.adjust[2] = -atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_ScaleUp
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_ScaleUp( void ){
|
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.scale_up = atof( token );
|
|
|
|
if ( g_skipmodel || g_release || g_archive ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "Scale up: %f\n", g_data.scale_up );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_Skinsize
|
|
|
|
|
|
|
|
Set a skin size other than the default
|
|
|
|
QUAKE3: not needed
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Skinsize( void ){
|
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.fixedwidth = atoi( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.fixedheight = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_Modelname
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Begin creating a model of the given name
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Modelname( void ){
|
|
|
|
FinishModel( TYPE_UNKNOWN );
|
|
|
|
ClearModel();
|
|
|
|
|
|
|
|
GetToken( qfalse );
|
|
|
|
strcpy( g_modelname, token );
|
|
|
|
StripExtension( g_modelname );
|
|
|
|
strcat( g_modelname, ".md3" );
|
|
|
|
strcpy( g_data.model.name, g_modelname );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
fCmd_Cd
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Cd( void ){
|
|
|
|
if ( g_cddir[0] ) {
|
|
|
|
Error( "$cd command without a $modelname" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( qfalse );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( g_cddir, "%s%s", gamedir, token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if -only was specified and this cd doesn't match,
|
|
|
|
// skip the model (you only need to match leading chars,
|
|
|
|
// so you could regrab all monsters with -only models/monsters)
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_only[0] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( strncmp( token, g_only, strlen( g_only ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
g_skipmodel = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "skipping %s\n", token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Convert3DStoMD3( const char *file ){
|
2007-11-04 03:34:51 +00:00
|
|
|
LoadBase( file );
|
|
|
|
GrabFrame( file );
|
|
|
|
SkinFrom3DS( file );
|
|
|
|
|
|
|
|
strcpy( g_data.model.name, g_modelname );
|
|
|
|
|
|
|
|
FinishModel( TYPE_UNKNOWN );
|
|
|
|
ClearModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Cmd_3DSConvert
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_3DSConvert(){
|
2007-11-04 03:34:51 +00:00
|
|
|
char file[1024];
|
|
|
|
|
|
|
|
FinishModel( TYPE_UNKNOWN );
|
|
|
|
ClearModel();
|
|
|
|
|
|
|
|
GetToken( qfalse );
|
|
|
|
|
|
|
|
sprintf( file, "%s%s", gamedir, token );
|
|
|
|
strcpy( g_modelname, token );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( g_modelname, '.' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*strrchr( g_modelname, '.' ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( g_modelname, ".md3" );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( FileTime( file ) == -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "%s doesn't exist", file );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.scale_up = atof( token );
|
|
|
|
}
|
|
|
|
|
|
|
|
Convert3DStoMD3( file );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ConvertASE( const char *filename, int type, qboolean grabAnims );
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Cmd_ASEConvert
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_ASEConvert( qboolean grabAnims ){
|
2007-11-04 03:34:51 +00:00
|
|
|
char filename[1024];
|
|
|
|
int type = TYPE_ITEM;
|
|
|
|
|
|
|
|
FinishModel( TYPE_UNKNOWN );
|
|
|
|
ClearModel();
|
|
|
|
|
|
|
|
GetToken( qfalse );
|
|
|
|
sprintf( filename, "%s%s", gamedir, token );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( g_modelname, token );
|
|
|
|
StripExtension( g_modelname );
|
|
|
|
strcat( g_modelname, ".md3" );
|
|
|
|
strcpy( g_data.model.name, g_modelname );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strstr( filename, ".ase" ) && !strstr( filename, ".ASE" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( filename, ".ASE" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
g_data.maxSurfaceTris = MAX_SURFACE_TRIS - 1;
|
|
|
|
|
|
|
|
while ( TokenAvailable() )
|
|
|
|
{
|
|
|
|
GetToken( qfalse );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "-origin" ) ) {
|
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing parameter for -origin" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.aseAdjust[1] = -atof( token );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing parameter for -origin" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.aseAdjust[0] = atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing parameter for -origin" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.aseAdjust[2] = -atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( token, "-lod" ) ) {
|
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "No parameter for -lod" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.currentLod = atoi( token );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.currentLod > MD3_MAX_LODS - 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "-lod parameter too large! (%d)\n", g_data.currentLod );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "No second parameter for -lod" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.lodBias = atof( token );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( token, "-maxtris" ) ) {
|
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "No parameter for -maxtris" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.maxSurfaceTris = atoi( token );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( token, "-playerparms" ) ) {
|
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing skip start parameter for -playerparms" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.lowerSkipFrameStart = atoi( token );
|
|
|
|
|
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing skip end parameter for -playerparms" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.lowerSkipFrameEnd = atoi( token );
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing upper parameter for -playerparms" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.maxUpperFrames = atoi( token );
|
|
|
|
|
|
|
|
g_data.lowerSkipFrameEnd = g_data.maxUpperFrames - 1;
|
|
|
|
|
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "missing head parameter for -playerparms" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
g_data.maxHeadFrames = atoi( token );
|
|
|
|
#endif
|
|
|
|
g_data.maxHeadFrames = 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type != TYPE_ITEM ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "invalid argument" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
type = TYPE_PLAYER;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( token, "-weapon" ) ) {
|
|
|
|
if ( type != TYPE_ITEM ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "invalid argument" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
type = TYPE_WEAPON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data.type = MD3_TYPE_ASE;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type == TYPE_WEAPON && grabAnims ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "can't grab anims with weapon models" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type == TYPE_PLAYER && !grabAnims ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "player models must be converted with $aseanimconvert" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type == TYPE_WEAPON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
ConvertASE( filename, type, qfalse );
|
|
|
|
ConvertASE( filename, TYPE_HAND, qtrue );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConvertASE( filename, type, grabAnims );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static int GetSurfaceAnimations( SurfaceAnimation_t sanims[MAX_ANIM_SURFACES],
|
|
|
|
const char *part,
|
|
|
|
int skipFrameStart,
|
|
|
|
int skipFrameEnd,
|
|
|
|
int maxFrames ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int numSurfaces;
|
|
|
|
int numValidSurfaces;
|
|
|
|
int i;
|
|
|
|
int numFrames = -1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( numSurfaces = ASE_GetNumSurfaces() ) > MAX_ANIM_SURFACES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Too many surfaces in ASE" );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( numValidSurfaces = 0, i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
polyset_t *splitSets;
|
|
|
|
int numNewFrames;
|
|
|
|
const char *surfaceName = ASE_GetSurfaceName( i );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !surfaceName ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
// Error( "Missing animation frames in model" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( surfaceName, "tag_" ) ||
|
|
|
|
!strcmp( part, "any" ) ||
|
|
|
|
( strstr( surfaceName, part ) == surfaceName ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// skip this if it's an inappropriate tag
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( part, "any" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// ignore non-"tag_head" tags if this is the head
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( part, "h_" ) && strstr( surfaceName, "tag_" ) && strcmp( surfaceName, "tag_head" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// ignore "tag_head" if this is the legs
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( part, "l_" ) && !strcmp( surfaceName, "tag_head" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// ignore "tag_weapon" if this is the legs
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( part, "l_" ) && !strcmp( surfaceName, "tag_weapon" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( sanims[numValidSurfaces].frames = ASE_GetSurfaceAnimation( i, &sanims[numValidSurfaces].numFrames, skipFrameStart, skipFrameEnd, maxFrames ) ) != 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
splitSets = Polyset_SplitSets( sanims[numValidSurfaces].frames, sanims[numValidSurfaces].numFrames, &numNewFrames, g_data.maxSurfaceTris );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( numFrames == -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numFrames = sanims[numValidSurfaces].numFrames;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( numFrames != sanims[numValidSurfaces].numFrames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Different number of animation frames on surfaces" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( sanims[numValidSurfaces].frames != splitSets ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
// free old data if we split the surfaces
|
|
|
|
for ( j = 0; j < sanims[numValidSurfaces].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( sanims[numValidSurfaces].frames[j].triangles );
|
|
|
|
free( sanims[numValidSurfaces].frames );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
sanims[numValidSurfaces].frames = splitSets;
|
|
|
|
sanims[numValidSurfaces].numFrames = numNewFrames;
|
|
|
|
}
|
|
|
|
Polyset_SnapSets( sanims[numValidSurfaces].frames, sanims[numValidSurfaces].numFrames );
|
|
|
|
Polyset_ComputeNormals( sanims[numValidSurfaces].frames, sanims[numValidSurfaces].numFrames );
|
|
|
|
|
|
|
|
numValidSurfaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numValidSurfaces;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static int SurfaceOrderToFrameOrder( SurfaceAnimation_t sanims[], ObjectAnimationFrame_t oanims[], int numSurfaces ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i, s;
|
|
|
|
int numFrames = -1;
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
** we have the data here arranged in surface order, now we need to convert it to
|
2007-11-04 03:34:51 +00:00
|
|
|
** frame order
|
|
|
|
*/
|
|
|
|
for ( i = 0, s = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
int j;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( sanims[i].frames ) {
|
|
|
|
if ( numFrames == -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numFrames = sanims[i].numFrames;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( numFrames != sanims[i].numFrames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "numFrames != sanims[i].numFrames (%d != %d)\n", numFrames, sanims[i].numFrames );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
for ( j = 0; j < sanims[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
oanims[j].surfaces[s] = &sanims[i].frames[j];
|
|
|
|
oanims[j].numSurfaces = numSurfaces;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numFrames;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void WriteMD3( const char *_filename, ObjectAnimationFrame_t oanims[], int numFrames ){
|
2007-11-04 03:34:51 +00:00
|
|
|
char filename[1024];
|
|
|
|
|
|
|
|
strcpy( filename, _filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strchr( filename, '.' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*strchr( filename, '.' ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( filename, ".md3" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void BuildAnimationFromOAFs( const char *filename, ObjectAnimationFrame_t oanims[], int numFrames, int type ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int f, i, j, tagcount;
|
|
|
|
float *frameXyz;
|
|
|
|
float *frameNormals;
|
|
|
|
|
|
|
|
g_data.model.numSurfaces = oanims[0].numSurfaces;
|
|
|
|
g_data.model.numFrames = numFrames;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.model.numFrames < 0 ) {
|
|
|
|
Error( "model.numFrames < 0" );
|
|
|
|
}
|
|
|
|
if ( g_data.model.numFrames >= MD3_MAX_FRAMES ) {
|
|
|
|
Error( "model.numFrames >= MD3_MAX_FRAMES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// build base frame
|
|
|
|
BuildBaseFrame( filename, &oanims[0] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// build animation frames
|
|
|
|
for ( f = 0; f < numFrames; f++ )
|
|
|
|
{
|
|
|
|
ObjectAnimationFrame_t *pOAF = &oanims[f];
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean parentTagExists = qfalse;
|
|
|
|
md3Tag_t tagParent;
|
|
|
|
int numtags = 0;
|
|
|
|
md3Frame_t *fr;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
fr = &g_data.frames[f];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( fr->name, "(from ASE)" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// scale and adjust frame
|
|
|
|
for ( i = 0; i < pOAF->numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
triangle_t *pTris = pOAF->surfaces[i]->triangles;
|
|
|
|
int t;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( t = 0; t < pOAF->surfaces[i]->numtriangles; t++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < 3; j++ )
|
|
|
|
{
|
|
|
|
int k;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// scale and adjust
|
|
|
|
for ( k = 0 ; k < 3 ; k++ ) {
|
|
|
|
pTris[t].verts[j][k] = pTris[t].verts[j][k] * g_data.scale_up +
|
2012-03-17 20:01:54 +00:00
|
|
|
g_data.aseAdjust[k];
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
if ( pTris[t].verts[j][k] > 1023 ||
|
2012-03-17 20:01:54 +00:00
|
|
|
pTris[t].verts[j][k] < -1023 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Model extents too large" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// find and count tags, locate parent tag
|
|
|
|
//
|
|
|
|
for ( i = 0; i < pOAF->numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( pOAF->surfaces[i]->name, "tag_" ) == pOAF->surfaces[i]->name ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// ignore parent tags when grabbing a weapon model and this is the flash portion
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( pOAF->surfaces[i]->name, "tag_parent" ) && strstr( filename, "_flash.md3" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ( !strstr( filename, "_hand.md3" ) && (
|
2012-03-17 20:01:54 +00:00
|
|
|
( !strcmp( pOAF->surfaces[i]->name, "tag_parent" ) && !strstr( filename, "_flash.md3" ) ) ||
|
|
|
|
( !strcmp( pOAF->surfaces[i]->name, "tag_torso" ) && ( strstr( filename, "upper_" ) || strstr( filename, "upper.md3" ) ) ) ||
|
|
|
|
( !strcmp( pOAF->surfaces[i]->name, "tag_head" ) && ( strstr( filename, "head.md3" ) || strstr( filename, "head_" ) ) ) ||
|
|
|
|
( !strcmp( pOAF->surfaces[i]->name, "tag_flash" ) && strstr( filename, "_flash.md3" ) ) ||
|
|
|
|
( !strcmp( pOAF->surfaces[i]->name, "tag_weapon" ) && type == TYPE_WEAPON ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
float tri[3][3];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( parentTagExists ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Multiple parent tags not allowed" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
memcpy( tri[0], pOAF->surfaces[i]->triangles[0].verts[0], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[1], pOAF->surfaces[i]->triangles[0].verts[1], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[2], pOAF->surfaces[i]->triangles[0].verts[2], sizeof( float ) * 3 );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
MD3_ComputeTagFromTri( &tagParent, tri );
|
|
|
|
strcpy( tagParent.name, "tag_parent" );
|
|
|
|
g_data.tags[f][numtags] = tagParent;
|
|
|
|
parentTagExists = qtrue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float tri[3][3];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
memcpy( tri[0], pOAF->surfaces[i]->triangles[0].verts[0], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[1], pOAF->surfaces[i]->triangles[0].verts[1], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[2], pOAF->surfaces[i]->triangles[0].verts[2], sizeof( float ) * 3 );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
MD3_ComputeTagFromTri( &g_data.tags[f][numtags], tri );
|
|
|
|
strcpy( g_data.tags[f][numtags].name, pOAF->surfaces[i]->name );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( g_data.tags[f][numtags].name, "tag_flash" ) ) {
|
|
|
|
*( strstr( g_data.tags[f][numtags].name, "tag_flash" ) + strlen( "tag_flash" ) ) = 0;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
numtags++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( strcmp( pOAF->surfaces[i]->name, g_data.surfData[i].header.name ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Mismatched surfaces from base('%s') to frame('%s') in model '%s'\n", g_data.surfData[i].header.name, pOAF->surfaces[i]->name, filename );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( numtags != g_data.model.numTags ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "mismatched number of tags in frame(%d) vs. base(%d)", numtags, g_data.model.numTags );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// prepare to accumulate bounds and normals
|
|
|
|
//
|
|
|
|
ClearBounds( fr->bounds[0], fr->bounds[1] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// store the frame's vertices in the same order as the base. This assumes the
|
|
|
|
// triangles and vertices in this frame are in exactly the same order as in the
|
|
|
|
// base
|
|
|
|
//
|
|
|
|
for ( i = 0, tagcount = 0; i < pOAF->numSurfaces; i++ )
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
triangle_t *pTris = pOAF->surfaces[i]->triangles;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// parent tag adjust
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( parentTagExists ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( t = 0; t < pOAF->surfaces[i]->numtriangles; t++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < 3 ; j++ )
|
|
|
|
{
|
|
|
|
vec3_t tmp;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorSubtract( pTris[t].verts[j], tagParent.origin, tmp );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
pTris[t].verts[j][0] = DotProduct( tmp, tagParent.axis[0] );
|
|
|
|
pTris[t].verts[j][1] = DotProduct( tmp, tagParent.axis[1] );
|
|
|
|
pTris[t].verts[j][2] = DotProduct( tmp, tagParent.axis[2] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( pTris[t].normals[j], tmp );
|
|
|
|
pTris[t].normals[j][0] = DotProduct( tmp, tagParent.axis[0] );
|
|
|
|
pTris[t].normals[j][1] = DotProduct( tmp, tagParent.axis[1] );
|
|
|
|
pTris[t].normals[j][2] = DotProduct( tmp, tagParent.axis[2] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// compute tag data
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( pOAF->surfaces[i]->name, "tag_" ) == pOAF->surfaces[i]->name ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
md3Tag_t *pTag = &g_data.tags[f][tagcount];
|
|
|
|
float tri[3][3];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( pTag->name, pOAF->surfaces[i]->name );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
memcpy( tri[0], pTris[0].verts[0], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[1], pTris[0].verts[1], sizeof( float ) * 3 );
|
|
|
|
memcpy( tri[2], pTris[0].verts[2], sizeof( float ) * 3 );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
MD3_ComputeTagFromTri( pTag, tri );
|
|
|
|
tagcount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.surfData[i].verts[f] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
free( g_data.surfData[i].verts[f] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
frameXyz = g_data.surfData[i].verts[f] = calloc( 1, sizeof( float ) * 6 * g_data.surfData[i].header.numVerts );
|
|
|
|
frameNormals = frameXyz + 3;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( t = 0; t < pOAF->surfaces[i]->numtriangles; t++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < 3 ; j++ )
|
|
|
|
{
|
|
|
|
int index;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
index = g_data.surfData[i].baseTriangles[t].v[j].index;
|
2012-03-17 20:01:54 +00:00
|
|
|
frameXyz[index * 6 + 0] = pTris[t].verts[j][0];
|
|
|
|
frameXyz[index * 6 + 1] = pTris[t].verts[j][1];
|
|
|
|
frameXyz[index * 6 + 2] = pTris[t].verts[j][2];
|
|
|
|
frameNormals[index * 6 + 0] = pTris[t].normals[j][0];
|
|
|
|
frameNormals[index * 6 + 1] = pTris[t].normals[j][1];
|
|
|
|
frameNormals[index * 6 + 2] = pTris[t].normals[j][2];
|
|
|
|
AddPointToBounds( &frameXyz[index * 6], fr->bounds[0], fr->bounds[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( filename, gamedir + 1 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( g_modelname, strstr( filename, gamedir + 1 ) + strlen( gamedir ) - 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy( g_modelname, filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishModel( type );
|
|
|
|
ClearModel();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ConvertASE( const char *filename, int type, qboolean grabAnims ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i, j;
|
|
|
|
int numSurfaces;
|
|
|
|
int numFrames = -1;
|
|
|
|
SurfaceAnimation_t surfaceAnimations[MAX_ANIM_SURFACES];
|
|
|
|
ObjectAnimationFrame_t objectAnimationFrames[MAX_ANIM_FRAMES];
|
|
|
|
char outfilename[1024];
|
|
|
|
|
|
|
|
/*
|
|
|
|
** load ASE into memory
|
|
|
|
*/
|
|
|
|
ASE_Load( filename, g_verbose, grabAnims );
|
|
|
|
|
|
|
|
/*
|
|
|
|
** process parts
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type == TYPE_ITEM ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "any", -1, -1, -1 );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numSurfaces <= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "numSurfaces <= 0" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numFrames <= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "numFrames <= 0" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '.' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*( strrchr( outfilename, '.' ) + 1 ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "md3" );
|
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, type );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( type == TYPE_PLAYER ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
qboolean tagTorso = qfalse;
|
|
|
|
qboolean tagHead = qfalse;
|
|
|
|
qboolean tagWeapon = qfalse;
|
|
|
|
|
|
|
|
//
|
|
|
|
// verify that all necessary tags exist
|
|
|
|
//
|
|
|
|
numSurfaces = ASE_GetNumSurfaces();
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( ASE_GetSurfaceName( i ), "tag_head" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
tagHead = qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( ASE_GetSurfaceName( i ), "tag_torso" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
tagTorso = qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( ASE_GetSurfaceName( i ), "tag_weapon" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
tagWeapon = qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !tagWeapon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Missing tag_weapon!" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !tagTorso ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Missing tag_torso!" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !tagWeapon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Missing tag_weapon!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// get all upper body surfaces
|
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "u_", -1, -1, g_data.maxUpperFrames );
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '/' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*( strrchr( outfilename, '/' ) + 1 ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.currentLod == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "upper.md3" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char temp[128];
|
|
|
|
|
|
|
|
sprintf( temp, "upper_%d.md3", g_data.currentLod );
|
|
|
|
strcat( outfilename, temp );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, type );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get lower body surfaces
|
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "l_", g_data.lowerSkipFrameStart, g_data.lowerSkipFrameEnd, -1 );
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '/' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*( strrchr( outfilename, '/' ) + 1 ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.currentLod == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "lower.md3" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char temp[128];
|
|
|
|
|
|
|
|
sprintf( temp, "lower_%d.md3", g_data.currentLod );
|
|
|
|
strcat( outfilename, temp );
|
|
|
|
}
|
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, type );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get head surfaces
|
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "h_", -1, -1, g_data.maxHeadFrames );
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '/' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*( strrchr( outfilename, '/' ) + 1 ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_data.currentLod == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "head.md3" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char temp[128];
|
|
|
|
|
|
|
|
sprintf( temp, "head_%d.md3", g_data.currentLod );
|
|
|
|
strcat( outfilename, temp );
|
|
|
|
}
|
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, type );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( type == TYPE_WEAPON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// get the weapon surfaces
|
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "w_", -1, -1, -1 );
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '.' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*( strrchr( outfilename, '.' ) + 1 ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "md3" );
|
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, type );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the flash surfaces
|
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "f_", -1, -1, -1 );
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '.' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*strrchr( outfilename, '.' ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "_flash.md3" );
|
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, TYPE_ITEM );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( type == TYPE_HAND ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// get the hand tags
|
|
|
|
numSurfaces = GetSurfaceAnimations( surfaceAnimations, "tag_", -1, -1, -1 );
|
|
|
|
numFrames = SurfaceOrderToFrameOrder( surfaceAnimations, objectAnimationFrames, numSurfaces );
|
|
|
|
|
|
|
|
strcpy( outfilename, filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strrchr( outfilename, '.' ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*strrchr( outfilename, '.' ) = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
strcat( outfilename, "_hand.md3" );
|
|
|
|
BuildAnimationFromOAFs( outfilename, objectAnimationFrames, numFrames, TYPE_HAND );
|
|
|
|
|
|
|
|
// free memory
|
|
|
|
for ( i = 0; i < numSurfaces; i++ )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceAnimations[i].frames ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
for ( j = 0; j < surfaceAnimations[i].numFrames; j++ )
|
|
|
|
{
|
|
|
|
free( surfaceAnimations[i].frames[j].triangles );
|
|
|
|
}
|
|
|
|
free( surfaceAnimations[i].frames );
|
|
|
|
surfaceAnimations[i].frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Error( "Unknown type passed to ConvertASE()" );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data.currentLod = 0;
|
|
|
|
g_data.lodBias = 0;
|
|
|
|
g_data.maxHeadFrames = 0;
|
|
|
|
g_data.maxUpperFrames = 0;
|
|
|
|
g_data.lowerSkipFrameStart = 0;
|
|
|
|
g_data.lowerSkipFrameEnd = 0;
|
|
|
|
VectorCopy( vec3_origin, g_data.aseAdjust );
|
|
|
|
|
|
|
|
// unload ASE from memory
|
|
|
|
ASE_Free();
|
|
|
|
}
|