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
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include "qdata.h"
|
|
|
|
#include "inout.h"
|
|
|
|
|
|
|
|
//=================================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
typedef struct
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int numnormals;
|
|
|
|
vec3_t normalsum;
|
2007-11-04 03:34:51 +00:00
|
|
|
} vertexnormals_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t v;
|
|
|
|
int lightnormalindex;
|
2007-11-04 03:34:51 +00:00
|
|
|
} trivert_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t mins, maxs;
|
|
|
|
char name[16];
|
|
|
|
trivert_t v[MAX_VERTS];
|
2007-11-04 03:34:51 +00:00
|
|
|
} frame_t;
|
|
|
|
|
|
|
|
//================================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
frame_t g_frames[MAX_FRAMES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dmdl_t model;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float scale_up; // set by $scale
|
|
|
|
vec3_t adjust; // set by $origin
|
|
|
|
int g_fixedwidth, g_fixedheight; // set by $skinsize
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// base frame info
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t base_xyz[MAX_VERTS];
|
|
|
|
dstvert_t base_st[MAX_VERTS];
|
|
|
|
dtriangle_t triangles[MAX_TRIANGLES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int triangle_st[MAX_TRIANGLES][3][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// the command list holds counts, s/t values, and xyz indexes
|
|
|
|
// that are valid for every frame
|
2012-03-17 20:01:54 +00:00
|
|
|
int commands[16384];
|
|
|
|
int numcommands;
|
|
|
|
int numglverts;
|
|
|
|
int used[MAX_TRIANGLES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char g_skins[MAX_MD2SKINS][64];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char cdarchive[1024];
|
|
|
|
char cdpartial[1024];
|
|
|
|
char cddir[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char modelname[64]; // empty unless $modelname issued (players)
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define NUMVERTEXNORMALS 162
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float avertexnormals[NUMVERTEXNORMALS][3] = {
|
2007-11-04 03:34:51 +00:00
|
|
|
#include "anorms.h"
|
|
|
|
};
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FILE *headerouthandle = NULL;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//==============================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
ClearModel
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void ClearModel( void ){
|
|
|
|
memset( &model, 0, sizeof( model ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
modelname[0] = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
scale_up = 1.0;
|
|
|
|
VectorCopy( vec3_origin, adjust );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_fixedwidth = g_fixedheight = 0;
|
|
|
|
g_skipmodel = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void H_printf( char *fmt, ... ){
|
2007-11-04 03:34:51 +00:00
|
|
|
va_list argptr;
|
2012-03-17 20:01:54 +00:00
|
|
|
char name[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !headerouthandle ) {
|
|
|
|
sprintf( name, "%s/tris.h", cddir );
|
|
|
|
headerouthandle = SafeOpenWrite( name );
|
|
|
|
fprintf( headerouthandle, "// %s\n\n", cddir );
|
|
|
|
fprintf( headerouthandle, "// This file generated by qdata - Do NOT Modify\n\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr, fmt );
|
|
|
|
vfprintf( headerouthandle, fmt, argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
WriteModelFile
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void WriteModelFile( FILE *modelouthandle ){
|
|
|
|
int i;
|
|
|
|
dmdl_t modeltemp;
|
|
|
|
int j, k;
|
|
|
|
frame_t *in;
|
|
|
|
daliasframe_t *out;
|
|
|
|
byte buffer[MAX_VERTS * 4 + 128];
|
|
|
|
float v;
|
|
|
|
int c_on, c_off;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
model.ident = IDALIASHEADER;
|
|
|
|
model.version = ALIAS_VERSION;
|
2012-03-17 20:01:54 +00:00
|
|
|
model.framesize = (int)&( (daliasframe_t *)0 )->verts[model.num_xyz];
|
2007-11-04 03:34:51 +00:00
|
|
|
model.num_glcmds = numcommands;
|
2012-03-17 20:01:54 +00:00
|
|
|
model.ofs_skins = sizeof( dmdl_t );
|
2007-11-04 03:34:51 +00:00
|
|
|
model.ofs_st = model.ofs_skins + model.num_skins * MAX_SKINNAME;
|
2012-03-17 20:01:54 +00:00
|
|
|
model.ofs_tris = model.ofs_st + model.num_st * sizeof( dstvert_t );
|
|
|
|
model.ofs_frames = model.ofs_tris + model.num_tris * sizeof( dtriangle_t );
|
|
|
|
model.ofs_glcmds = model.ofs_frames + model.num_frames * model.framesize;
|
|
|
|
model.ofs_end = model.ofs_glcmds + model.num_glcmds * 4;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the model header
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < sizeof( dmdl_t ) / 4 ; i++ )
|
|
|
|
( (int *)&modeltemp )[i] = LittleLong( ( (int *)&model )[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, &modeltemp, sizeof( modeltemp ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the skin names
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, g_skins, model.num_skins * MAX_SKINNAME );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the texture coordinates
|
|
|
|
//
|
|
|
|
c_on = c_off = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_st ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
base_st[i].s = LittleShort( base_st[i].s );
|
|
|
|
base_st[i].t = LittleShort( base_st[i].t );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, base_st, model.num_st * sizeof( base_st[0] ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the triangles
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_tris ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int j;
|
|
|
|
dtriangle_t tri;
|
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
|
|
|
tri.index_xyz[j] = LittleShort( triangles[i].index_xyz[j] );
|
|
|
|
tri.index_st[j] = LittleShort( triangles[i].index_st[j] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, &tri, sizeof( tri ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out the frames
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_frames ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
in = &g_frames[i];
|
|
|
|
out = (daliasframe_t *)buffer;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( out->name, in->name );
|
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
out->scale[j] = ( in->maxs[j] - in->mins[j] ) / 255;
|
2007-11-04 03:34:51 +00:00
|
|
|
out->translate[j] = in->mins[j];
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < model.num_xyz ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
// all of these are byte values, so no need to deal with endianness
|
2007-11-04 03:34:51 +00:00
|
|
|
out->verts[j].lightnormalindex = in->v[j].lightnormalindex;
|
|
|
|
|
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
|
|
|
// scale to byte values & min/max check
|
|
|
|
v = Q_rint( ( in->v[j].v[k] - out->translate[k] ) / out->scale[k] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// clamp, so rounding doesn't wrap from 255.6 to 0
|
|
|
|
if ( v > 255.0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
v = 255.0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( v < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
v = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
out->verts[j].v[k] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
out->scale[j] = LittleFloat( out->scale[j] );
|
|
|
|
out->translate[j] = LittleFloat( out->translate[j] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, out, model.framesize );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out glcmds
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( modelouthandle, commands, numcommands * 4 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
FinishModel
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void FinishModel( void ){
|
|
|
|
FILE *modelouthandle;
|
|
|
|
int i;
|
|
|
|
char name[1024];
|
|
|
|
|
|
|
|
if ( !model.num_frames ) {
|
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
|
|
|
//
|
|
|
|
// copy to release directory tree if doing a release build
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
if ( modelname[0] ) {
|
|
|
|
sprintf( name, "%s", modelname );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sprintf( name, "%s/tris.md2", cdpartial );
|
|
|
|
}
|
|
|
|
ReleaseFile( name );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_skins ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
ReleaseFile( g_skins[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
model.num_frames = 0;
|
|
|
|
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
|
|
|
if ( modelname[0] ) {
|
|
|
|
sprintf( name, "%s%s", gamedir, modelname );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sprintf( name, "%s/tris.md2", cddir );
|
|
|
|
}
|
|
|
|
printf( "saving to %s\n", name );
|
|
|
|
CreatePath( name );
|
|
|
|
modelouthandle = SafeOpenWrite( name );
|
|
|
|
|
|
|
|
WriteModelFile( modelouthandle );
|
|
|
|
|
|
|
|
printf( "%3dx%3d skin\n", model.skinwidth, model.skinheight );
|
|
|
|
printf( "%4d vertexes\n", model.num_xyz );
|
|
|
|
printf( "%4d triangles\n", model.num_tris );
|
|
|
|
printf( "%4d frame\n", model.num_frames );
|
|
|
|
printf( "%4d glverts\n", numglverts );
|
|
|
|
printf( "%4d glcmd\n", model.num_glcmds );
|
|
|
|
printf( "%4d skins\n", model.num_skins );
|
|
|
|
printf( "file size: %d\n", (int)ftell( modelouthandle ) );
|
|
|
|
printf( "---------------------\n" );
|
|
|
|
|
|
|
|
fclose( modelouthandle );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// finish writing header file
|
2012-03-17 20:01:54 +00:00
|
|
|
H_printf( "\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// scale_up is usefull to allow step distances to be adjusted
|
2012-03-17 20:01:54 +00:00
|
|
|
H_printf( "#define MODEL_SCALE\t\t%f\n", scale_up );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( headerouthandle );
|
2007-11-04 03:34:51 +00:00
|
|
|
headerouthandle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ALIAS MODEL DISPLAY LIST GENERATION
|
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
|
|
|
int strip_xyz[128];
|
|
|
|
int strip_st[128];
|
|
|
|
int strip_tris[128];
|
|
|
|
int stripcount;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
StripLength
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int StripLength( int starttri, int startv ){
|
|
|
|
int m1, m2;
|
|
|
|
int st1, st2;
|
|
|
|
int j;
|
|
|
|
dtriangle_t *last, *check;
|
|
|
|
int k;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
used[starttri] = 2;
|
|
|
|
|
|
|
|
last = &triangles[starttri];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strip_xyz[0] = last->index_xyz[( startv ) % 3];
|
|
|
|
strip_xyz[1] = last->index_xyz[( startv + 1 ) % 3];
|
|
|
|
strip_xyz[2] = last->index_xyz[( startv + 2 ) % 3];
|
|
|
|
strip_st[0] = last->index_st[( startv ) % 3];
|
|
|
|
strip_st[1] = last->index_st[( startv + 1 ) % 3];
|
|
|
|
strip_st[2] = last->index_st[( startv + 2 ) % 3];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
strip_tris[0] = starttri;
|
|
|
|
stripcount = 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
m1 = last->index_xyz[( startv + 2 ) % 3];
|
|
|
|
st1 = last->index_st[( startv + 2 ) % 3];
|
|
|
|
m2 = last->index_xyz[( startv + 1 ) % 3];
|
|
|
|
st2 = last->index_st[( startv + 1 ) % 3];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// look for a matching triangle
|
|
|
|
nexttri:
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = starttri + 1, check = &triangles[starttri + 1]
|
|
|
|
; j < model.num_tris ; j++, check++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
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
|
|
|
if ( check->index_xyz[k] != m1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( check->index_st[k] != st1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( check->index_xyz[ ( k + 1 ) % 3 ] != m2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( check->index_st[ ( k + 1 ) % 3 ] != st2 ) {
|
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
|
|
|
|
|
|
|
// this is the next part of the fan
|
|
|
|
|
|
|
|
// if we can't use this triangle, this tristrip is done
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( used[j] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
goto done;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// the new edge
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( stripcount & 1 ) {
|
|
|
|
m2 = check->index_xyz[ ( k + 2 ) % 3 ];
|
|
|
|
st2 = check->index_st[ ( k + 2 ) % 3 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
m1 = check->index_xyz[ ( k + 2 ) % 3 ];
|
|
|
|
st1 = check->index_st[ ( k + 2 ) % 3 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strip_xyz[stripcount + 2] = check->index_xyz[ ( k + 2 ) % 3 ];
|
|
|
|
strip_st[stripcount + 2] = check->index_st[ ( k + 2 ) % 3 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
strip_tris[stripcount] = j;
|
|
|
|
stripcount++;
|
|
|
|
|
|
|
|
used[j] = 2;
|
|
|
|
goto nexttri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
|
|
|
|
// clear the temp used flags
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = starttri + 1 ; j < model.num_tris ; j++ )
|
|
|
|
if ( used[j] == 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
used[j] = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return stripcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===========
|
|
|
|
FanLength
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
int FanLength( int starttri, int startv ){
|
|
|
|
int m1, m2;
|
|
|
|
int st1, st2;
|
|
|
|
int j;
|
|
|
|
dtriangle_t *last, *check;
|
|
|
|
int k;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
used[starttri] = 2;
|
|
|
|
|
|
|
|
last = &triangles[starttri];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strip_xyz[0] = last->index_xyz[( startv ) % 3];
|
|
|
|
strip_xyz[1] = last->index_xyz[( startv + 1 ) % 3];
|
|
|
|
strip_xyz[2] = last->index_xyz[( startv + 2 ) % 3];
|
|
|
|
strip_st[0] = last->index_st[( startv ) % 3];
|
|
|
|
strip_st[1] = last->index_st[( startv + 1 ) % 3];
|
|
|
|
strip_st[2] = last->index_st[( startv + 2 ) % 3];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
strip_tris[0] = starttri;
|
|
|
|
stripcount = 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
m1 = last->index_xyz[( startv + 0 ) % 3];
|
|
|
|
st1 = last->index_st[( startv + 0 ) % 3];
|
|
|
|
m2 = last->index_xyz[( startv + 2 ) % 3];
|
|
|
|
st2 = last->index_st[( startv + 2 ) % 3];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
// look for a matching triangle
|
|
|
|
nexttri:
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = starttri + 1, check = &triangles[starttri + 1]
|
|
|
|
; j < model.num_tris ; j++, check++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
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
|
|
|
if ( check->index_xyz[k] != m1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( check->index_st[k] != st1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( check->index_xyz[ ( k + 1 ) % 3 ] != m2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( check->index_st[ ( k + 1 ) % 3 ] != st2 ) {
|
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
|
|
|
|
|
|
|
// this is the next part of the fan
|
|
|
|
|
|
|
|
// if we can't use this triangle, this tristrip is done
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( used[j] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
goto done;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// the new edge
|
2012-03-17 20:01:54 +00:00
|
|
|
m2 = check->index_xyz[ ( k + 2 ) % 3 ];
|
|
|
|
st2 = check->index_st[ ( k + 2 ) % 3 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strip_xyz[stripcount + 2] = m2;
|
|
|
|
strip_st[stripcount + 2] = st2;
|
2007-11-04 03:34:51 +00:00
|
|
|
strip_tris[stripcount] = j;
|
|
|
|
stripcount++;
|
|
|
|
|
|
|
|
used[j] = 2;
|
|
|
|
goto nexttri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
|
|
|
|
// clear the temp used flags
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = starttri + 1 ; j < model.num_tris ; j++ )
|
|
|
|
if ( used[j] == 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
used[j] = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return stripcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
BuildGlCmds
|
|
|
|
|
|
|
|
Generate a list of trifans or strips
|
|
|
|
for the model, which holds for all frames
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void BuildGlCmds( void ){
|
|
|
|
int i, j, k;
|
|
|
|
int startv;
|
|
|
|
float s, t;
|
|
|
|
int len, bestlen, besttype;
|
|
|
|
int best_xyz[1024];
|
|
|
|
int best_st[1024];
|
|
|
|
int best_tris[1024];
|
|
|
|
int type;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// build tristrips
|
|
|
|
//
|
|
|
|
numcommands = 0;
|
|
|
|
numglverts = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( used, 0, sizeof( used ) );
|
|
|
|
for ( i = 0 ; i < model.num_tris ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// pick an unused triangle and start the trifan
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( used[i] ) {
|
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
|
|
|
|
|
|
|
bestlen = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( type = 0 ; type < 2 ; type++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
// type = 1;
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( startv = 0 ; startv < 3 ; startv++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( type == 1 ) {
|
|
|
|
len = StripLength( i, startv );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
len = FanLength( i, startv );
|
|
|
|
}
|
|
|
|
if ( len > bestlen ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
besttype = type;
|
|
|
|
bestlen = len;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < bestlen + 2 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
best_st[j] = strip_st[j];
|
|
|
|
best_xyz[j] = strip_xyz[j];
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < bestlen ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
best_tris[j] = strip_tris[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark the tris on the best strip/fan as used
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < bestlen ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
used[best_tris[j]] = 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( besttype == 1 ) {
|
|
|
|
commands[numcommands++] = ( bestlen + 2 );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
commands[numcommands++] = -( bestlen + 2 );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
numglverts += bestlen + 2;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < bestlen + 2 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// emit a vertex into the reorder buffer
|
|
|
|
k = best_st[j];
|
|
|
|
|
|
|
|
// emit s/t coords into the commands stream
|
|
|
|
s = base_st[k].s;
|
|
|
|
t = base_st[k].t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = ( s + 0.5 ) / model.skinwidth;
|
|
|
|
t = ( t + 0.5 ) / model.skinheight;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
*(float *)&commands[numcommands++] = s;
|
|
|
|
*(float *)&commands[numcommands++] = t;
|
|
|
|
*(int *)&commands[numcommands++] = best_xyz[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
commands[numcommands++] = 0; // end of list marker
|
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
|
|
|
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
|
|
|
============
|
|
|
|
BuildST
|
|
|
|
|
|
|
|
Builds the triangle_st array for the base frame and
|
|
|
|
model.skinwidth / model.skinheight
|
|
|
|
|
|
|
|
FIXME: allow this to be loaded from a file for
|
|
|
|
arbitrary mappings
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void BuildST( triangle_t *ptri, int numtri ){
|
|
|
|
int i, j;
|
|
|
|
int width, height, iwidth, iheight, swidth;
|
|
|
|
float basex, basey;
|
|
|
|
float s_scale, t_scale;
|
|
|
|
float scale;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
float *pbasevert;
|
|
|
|
vec3_t vtemp1, vtemp2, normal;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// find bounds of all the verts on the base frame
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
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++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
mins[i] = floor( mins[i] );
|
|
|
|
maxs[i] = ceil( maxs[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
width = maxs[0] - mins[0];
|
|
|
|
height = maxs[2] - mins[2];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_fixedwidth ) { // old style
|
2007-11-04 03:34:51 +00:00
|
|
|
scale = 8;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( width * scale >= 150 ) {
|
|
|
|
scale = 150.0 / width;
|
|
|
|
}
|
|
|
|
if ( height * scale >= 190 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
scale = 190.0 / height;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
s_scale = t_scale = scale;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
iwidth = ceil( width * s_scale );
|
|
|
|
iheight = ceil( height * t_scale );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
iwidth += 4;
|
|
|
|
iheight += 4;
|
|
|
|
}
|
|
|
|
else
|
2012-03-17 20:01:54 +00:00
|
|
|
{ // new style
|
2007-11-04 03:34:51 +00:00
|
|
|
iwidth = g_fixedwidth / 2;
|
|
|
|
iheight = g_fixedheight;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s_scale = (float)( iwidth - 4 ) / width;
|
|
|
|
t_scale = (float)( iheight - 4 ) / height;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// determine which side of each triangle to map the texture to
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < numtri ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( ptri[i].verts[0], ptri[i].verts[1], vtemp1 );
|
|
|
|
VectorSubtract( ptri[i].verts[2], ptri[i].verts[1], vtemp2 );
|
|
|
|
CrossProduct( vtemp1, vtemp2, normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( normal[1] > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
basex = iwidth + 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
basex = 2;
|
|
|
|
}
|
|
|
|
basey = 2;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
pbasevert = ptri[i].verts[j];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
triangle_st[i][j][0] = Q_rint( ( pbasevert[0] - mins[0] ) * s_scale + basex );
|
|
|
|
triangle_st[i][j][1] = Q_rint( ( maxs[2] - pbasevert[2] ) * t_scale + basey );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make the width a multiple of 4; some hardware requires this, and it ensures
|
|
|
|
// dword alignment for each scan
|
2012-03-17 20:01:54 +00:00
|
|
|
swidth = iwidth * 2;
|
|
|
|
model.skinwidth = ( swidth + 3 ) & ~3;
|
2007-11-04 03:34:51 +00:00
|
|
|
model.skinheight = iheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_Base
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Base( void ){
|
|
|
|
triangle_t *ptri;
|
|
|
|
int i, j, k;
|
|
|
|
int time1;
|
|
|
|
char file1[1024];
|
|
|
|
|
|
|
|
GetToken( false );
|
|
|
|
|
|
|
|
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( "---------------------\n" );
|
|
|
|
sprintf( file1, "%s/%s.%s", cdarchive, token, trifileext );
|
|
|
|
printf( "%s\n", file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ExpandPathAndArchive( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s.%s", cddir, token, trifileext );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
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
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( do3ds ) {
|
|
|
|
Load3DSTriangleList( file1, &ptri, &model.num_tris );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
LoadTriangleList( file1, &ptri, &model.num_tris );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get the ST values
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
BuildST( ptri, model.num_tris );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// run through all the base triangles, storing each unique vertex in the
|
|
|
|
// base vertex list and setting the indirect triangles to point to the base
|
|
|
|
// vertices
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_tris ; 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
|
|
|
{
|
|
|
|
// get the xyz index
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0 ; k < model.num_xyz ; k++ )
|
|
|
|
if ( VectorCompare( ptri[i].verts[j], base_xyz[k] ) ) {
|
|
|
|
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 == model.num_xyz ) { // new index
|
|
|
|
VectorCopy( ptri[i].verts[j], base_xyz[model.num_xyz] );
|
2007-11-04 03:34:51 +00:00
|
|
|
model.num_xyz++;
|
|
|
|
}
|
|
|
|
|
|
|
|
triangles[i].index_xyz[j] = k;
|
|
|
|
|
|
|
|
// get the st index
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0 ; k < model.num_st ; k++ )
|
|
|
|
if ( triangle_st[i][j][0] == base_st[k].s
|
|
|
|
&& triangle_st[i][j][1] == base_st[k].t ) {
|
|
|
|
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 == model.num_st ) { // new index
|
2007-11-04 03:34:51 +00:00
|
|
|
base_st[model.num_st].s = triangle_st[i][j][0];
|
|
|
|
base_st[model.num_st].t = triangle_st[i][j][1];
|
|
|
|
model.num_st++;
|
|
|
|
}
|
|
|
|
|
|
|
|
triangles[i].index_st[j] = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build triangle strips / fans
|
2012-03-17 20:01:54 +00:00
|
|
|
BuildGlCmds();
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===============================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char *FindFrameFile( char *frame ){
|
|
|
|
int time1;
|
|
|
|
char file1[1024];
|
|
|
|
static char retname[1024];
|
|
|
|
char base[32];
|
|
|
|
char suffix[32];
|
|
|
|
char *s;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( frame, "." ) ) {
|
|
|
|
return frame; // allready in dot format
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// split 'run1' into 'run' and '1'
|
2012-03-17 20:01:54 +00:00
|
|
|
s = frame + strlen( frame ) - 1;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( s != frame && *s >= '0' && *s <= '9' )
|
2007-11-04 03:34:51 +00:00
|
|
|
s--;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( suffix, s + 1 );
|
|
|
|
strcpy( base, frame );
|
|
|
|
base[s - frame + 1] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// check for 'run1.tri'
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s%s.%s",cddir, base, suffix, trifileext );
|
|
|
|
time1 = FileTime( file1 );
|
|
|
|
if ( time1 != -1 ) {
|
|
|
|
sprintf( retname, "%s%s.%s", base, suffix, trifileext );
|
2007-11-04 03:34:51 +00:00
|
|
|
return retname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for 'run.1'
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s.%s",cddir, base, suffix );
|
|
|
|
time1 = FileTime( file1 );
|
|
|
|
if ( time1 != -1 ) {
|
|
|
|
sprintf( retname, "%s.%s", base, suffix );
|
2007-11-04 03:34:51 +00:00
|
|
|
return retname;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "frame %s could not be found",frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
GrabFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GrabFrame( char *frame ){
|
|
|
|
triangle_t *ptri;
|
|
|
|
int i, j;
|
|
|
|
trivert_t *ptrivert;
|
|
|
|
int num_tris;
|
|
|
|
char file1[1024];
|
|
|
|
frame_t *fr;
|
|
|
|
vertexnormals_t vnorms[MAX_VERTS];
|
|
|
|
int index_xyz;
|
|
|
|
char *framefile;
|
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
|
|
|
framefile = FindFrameFile( frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s", cdarchive, framefile );
|
|
|
|
ExpandPathAndArchive( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s",cddir, framefile );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
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 ( model.num_frames >= MAX_FRAMES ) {
|
|
|
|
Error( "model.num_frames >= MAX_FRAMES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
fr = &g_frames[model.num_frames];
|
|
|
|
model.num_frames++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( fr->name, frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// load the frame
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( do3ds ) {
|
|
|
|
Load3DSTriangleList( file1, &ptri, &num_tris );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
LoadTriangleList( file1, &ptri, &num_tris );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( num_tris != model.num_tris ) {
|
|
|
|
Error( "%s: number of triangles doesn't match base frame\n", file1 );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// allocate storage for the frame's vertices
|
|
|
|
//
|
|
|
|
ptrivert = fr->v;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_xyz ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
vnorms[i].numnormals = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorClear( vnorms[i].normalsum );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
ClearBounds( fr->mins, fr->maxs );
|
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
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < num_tris ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t vtemp1, vtemp2, normal;
|
|
|
|
float ftemp;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( ptri[i].verts[0], ptri[i].verts[1], vtemp1 );
|
|
|
|
VectorSubtract( ptri[i].verts[2], ptri[i].verts[1], vtemp2 );
|
|
|
|
CrossProduct( vtemp1, vtemp2, normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorNormalize( normal, normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// rotate the normal so the model faces down the positive x axis
|
2007-11-04 03:34:51 +00:00
|
|
|
ftemp = normal[0];
|
|
|
|
normal[0] = -normal[1];
|
|
|
|
normal[1] = ftemp;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
index_xyz = triangles[i].index_xyz[j];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// rotate the vertices so the model faces down the positive x axis
|
|
|
|
// also adjust the vertices to the desired origin
|
|
|
|
ptrivert[index_xyz].v[0] = ( ( -ptri[i].verts[j][1] ) * scale_up ) +
|
|
|
|
adjust[0];
|
|
|
|
ptrivert[index_xyz].v[1] = ( ptri[i].verts[j][0] * scale_up ) +
|
|
|
|
adjust[1];
|
|
|
|
ptrivert[index_xyz].v[2] = ( ptri[i].verts[j][2] * scale_up ) +
|
|
|
|
adjust[2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPointToBounds( ptrivert[index_xyz].v, fr->mins, fr->maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorAdd( vnorms[index_xyz].normalsum, normal, vnorms[index_xyz].normalsum );
|
2007-11-04 03:34:51 +00:00
|
|
|
vnorms[index_xyz].numnormals++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// calculate the vertex normals, match them to the template list, and store the
|
|
|
|
// index of the best match
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < model.num_xyz ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int j;
|
|
|
|
vec3_t v;
|
|
|
|
float maxdot;
|
|
|
|
int maxdotindex;
|
|
|
|
int c;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
c = vnorms[i].numnormals;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !c ) {
|
|
|
|
Error( "Vertex with no triangles attached" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorScale( vnorms[i].normalsum, 1.0 / c, v );
|
|
|
|
VectorNormalize( v, v );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
maxdot = -999999.0;
|
|
|
|
maxdotindex = -1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < NUMVERTEXNORMALS ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
float dot;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dot = DotProduct( v, avertexnormals[j] );
|
|
|
|
if ( dot > maxdot ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
maxdot = dot;
|
|
|
|
maxdotindex = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ptrivert[i].lightnormalindex = maxdotindex;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
free( ptri );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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( false );
|
|
|
|
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 ) {
|
|
|
|
model.num_frames = 1; // don't skip the writeout
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
H_printf( "#define FRAME_%-16s\t%i\n", token, model.num_frames );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GrabFrame( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Skin
|
|
|
|
|
|
|
|
Skins aren't actually stored in the file, only a reference
|
|
|
|
is saved out to the header file.
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Skin( void ){
|
|
|
|
byte *palette;
|
|
|
|
byte *pixels;
|
|
|
|
int width, height;
|
|
|
|
byte *cropped;
|
|
|
|
int y;
|
|
|
|
char name[1024], savename[1024];
|
|
|
|
|
|
|
|
GetToken( false );
|
|
|
|
|
|
|
|
if ( model.num_skins == MAX_MD2SKINS ) {
|
|
|
|
Error( "model.num_skins == MAX_MD2SKINS" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_skipmodel ) {
|
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
|
|
|
sprintf( name, "%s/%s.lbm", cdarchive, token );
|
|
|
|
strcpy( name, ExpandPathAndArchive( name ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
// sprintf (name, "%s/%s.lbm", cddir, token);
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( TokenAvailable() ) {
|
|
|
|
GetToken( false );
|
|
|
|
sprintf( g_skins[model.num_skins], "%s.pcx", token );
|
|
|
|
sprintf( savename, "%s%s.pcx", gamedir, g_skins[model.num_skins] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( savename, "%s/%s.pcx", cddir, token );
|
|
|
|
sprintf( g_skins[model.num_skins], "%s/%s.pcx", cdpartial, token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model.num_skins++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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
|
|
|
|
|
|
|
// load the image
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "loading %s\n", name );
|
|
|
|
Load256Image( name, &pixels, &palette, &width, &height );
|
|
|
|
RemapZero( pixels, palette, width, height );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// crop it to the proper size
|
2012-03-17 20:01:54 +00:00
|
|
|
cropped = malloc( model.skinwidth * model.skinheight );
|
|
|
|
for ( y = 0 ; y < model.skinheight ; y++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( cropped + y * model.skinwidth,
|
|
|
|
pixels + y * width, model.skinwidth );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// save off the new image
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "saving %s\n", savename );
|
|
|
|
CreatePath( savename );
|
|
|
|
WritePCXfile( savename, cropped, model.skinwidth,
|
|
|
|
model.skinheight, palette );
|
|
|
|
|
|
|
|
free( pixels );
|
|
|
|
free( palette );
|
|
|
|
free( cropped );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
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
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
|
|
|
adjust[1] = -atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
|
|
|
adjust[0] = atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
|
|
|
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( false );
|
|
|
|
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", 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
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Skinsize( void ){
|
|
|
|
GetToken( false );
|
|
|
|
g_fixedwidth = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
g_fixedheight = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
Cmd_Modelname
|
|
|
|
|
|
|
|
Gives a different name/location for the file, instead of the cddir
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Cmd_Modelname( void ){
|
|
|
|
GetToken( false );
|
|
|
|
strcpy( modelname, token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Cd
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Cd( void ){
|
|
|
|
FinishModel();
|
|
|
|
ClearModel();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// this is a silly mess...
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( cdpartial, "models/%s", token );
|
|
|
|
sprintf( cdarchive, "%smodels/%s", gamedir + strlen( qdir ), token );
|
|
|
|
sprintf( cddir, "%s%s", gamedir, cdpartial );
|
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 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 = true;
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "skipping %s\n", cdpartial );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|