Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

misc_model.c File Reference

#include "qbsp.h"
#include "aselib.h"

Include dependency graph for misc_model.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  loadedModel_t

Defines

#define LL(x)   x=LittleLong(x)
#define MAX_LOADED_MODELS   1024

Functions

void AddTriangleModels (tree_t *tree)
void InsertASEModel (const char *modelName, vec3_t origin, float angle, tree_t *tree)
void InsertMD3Model (const char *modelName, vec3_t origin, float angle, tree_t *tree)
md3Header_tLoadModel (const char *modelName)
md3Header_tR_LoadMD3 (const char *mod_name)

Variables

int c_triangleIndexes
int c_triangleModels
int c_triangleSurfaces
int c_triangleVertexes
loadedModel_t loadedModels [MAX_LOADED_MODELS]
int numLoadedModels


Define Documentation

#define LL  )     x=LittleLong(x)
 

Definition at line 54 of file misc_model.c.

#define MAX_LOADED_MODELS   1024
 

Definition at line 45 of file misc_model.c.


Function Documentation

void AddTriangleModels tree_t tree  ) 
 

Definition at line 428 of file misc_model.c.

References _printf(), c_triangleIndexes, c_triangleModels, c_triangleSurfaces, c_triangleVertexes, entities, entity_num, FloatForKey(), GetVectorForKey(), InsertASEModel(), InsertMD3Model(), Q_stricmp(), qprintf(), strstr(), tree(), ValueForKey(), and vec3_t.

Referenced by ProcessWorldModel().

00428                                        {
00429     int         entity_num;
00430     entity_t    *entity;
00431 
00432     qprintf("----- AddTriangleModels -----\n");
00433 
00434     for ( entity_num=1 ; entity_num< num_entities ; entity_num++ ) {
00435         entity = &entities[entity_num];
00436     
00437         // convert misc_models into raw geometry
00438         if ( !Q_stricmp( "misc_model", ValueForKey( entity, "classname" ) ) ) {
00439             const char  *model;
00440             vec3_t  origin;
00441             float   angle;
00442 
00443             // get the angle for rotation  FIXME: support full matrix positioning
00444             angle = FloatForKey( entity, "angle" );
00445 
00446             GetVectorForKey( entity, "origin", origin );
00447 
00448             model = ValueForKey( entity, "model" );
00449             if ( !model[0] ) {
00450                 _printf("WARNING: misc_model at %i %i %i without a model key\n", (int)origin[0],
00451                     (int)origin[1], (int)origin[2] );
00452                 continue;
00453             }
00454             if ( strstr( model, ".md3" ) || strstr( model, ".MD3" ) ) {
00455                 InsertMD3Model( model, origin, angle, tree );
00456                 continue;
00457             }
00458             if ( strstr( model, ".ase" ) || strstr( model, ".ASE" ) ) {
00459                 InsertASEModel( model, origin, angle, tree );
00460                 continue;
00461             }
00462             _printf( "Unknown misc_model type: %s\n", model );
00463             continue;
00464         }
00465     }
00466 
00467     qprintf( "%5i triangle models\n", c_triangleModels );
00468     qprintf( "%5i triangle surfaces\n", c_triangleSurfaces );
00469     qprintf( "%5i triangle vertexes\n", c_triangleVertexes );
00470     qprintf( "%5i triangle indexes\n", c_triangleIndexes );
00471 }

Here is the call graph for this function:

void InsertASEModel const char *  modelName,
vec3_t  origin,
float  angle,
tree_t tree
 

Definition at line 325 of file misc_model.c.

References AllocDrawSurf(), ASE_GetNumSurfaces(), ASE_GetSurfaceAnimation(), ASE_GetSurfaceName(), ASE_Load(), c_triangleIndexes, c_triangleModels, c_triangleSurfaces, c_triangleVertexes, drawVert_t::color, cos(), drawsurf_s::fogNum, gamedir, i, drawsurf_s::indexes, j, drawVert_t::lightmap, drawsurf_s::lightmapNum, malloc(), mapDrawSurface_t, polyset_t::materialname, drawsurf_s::miscModel, name, drawVert_t::normal, triangle_t::normals, drawsurf_s::numIndexes, polyset_t::numtriangles, drawsurf_s::numVerts, qfalse, drawsurf_s::shaderInfo, ShaderInfoForShader(), sin(), sprintf(), drawVert_t::st, triangle_t::texcoords, polyset_t::triangles, triangle_t::verts, drawsurf_s::verts, and drawVert_t::xyz.

Referenced by AddTriangleModels().

00325                                                                                        {
00326     int                 i, j;
00327     drawVert_t          *outv;
00328     float               angleCos, angleSin;
00329     mapDrawSurface_t    *out;
00330     int                 numSurfaces;
00331     const char          *name;
00332     polyset_t           *pset;
00333     int                 numFrames;
00334     char                filename[1024];
00335 
00336     sprintf( filename, "%s%s", gamedir, modelName );
00337 
00338     angle = angle / 180 * Q_PI;
00339     angleCos = cos( angle );
00340     angleSin = sin( angle );
00341 
00342     // load the model
00343     ASE_Load( filename, qfalse, qfalse );
00344 
00345     // each ase surface will become a new bsp surface
00346     numSurfaces = ASE_GetNumSurfaces();
00347 
00348     c_triangleModels++;
00349     c_triangleSurfaces += numSurfaces;
00350 
00351     // expand, translate, and rotate the vertexes
00352     // swap all the surfaces
00353     for ( i = 0 ; i < numSurfaces ; i++) {
00354         name = ASE_GetSurfaceName( i );
00355 
00356         pset = ASE_GetSurfaceAnimation( i, &numFrames, -1, -1, -1 );
00357         if ( !name || !pset ) {
00358             continue;
00359         }
00360 
00361         // allocate a surface
00362         out = AllocDrawSurf();
00363         out->miscModel = qtrue;
00364 
00365         out->shaderInfo = ShaderInfoForShader( pset->materialname );
00366 
00367         out->numVerts = 3 * pset->numtriangles;
00368         out->verts = malloc( out->numVerts * sizeof( out->verts[0] ) );
00369 
00370         out->numIndexes = 3 * pset->numtriangles;
00371         out->indexes = malloc( out->numIndexes * sizeof( out->indexes[0] ) );
00372 
00373         out->lightmapNum = -1;
00374         out->fogNum = -1;
00375 
00376         // emit the indexes
00377         c_triangleIndexes += out->numIndexes;
00378         for ( j = 0 ; j < out->numIndexes ; j++ ) {
00379             out->indexes[j] = j;
00380         }
00381 
00382         // emit the vertexes
00383         c_triangleVertexes += out->numVerts;
00384         for ( j = 0 ; j < out->numVerts ; j++ ) {
00385             int     index;
00386             triangle_t  *tri;
00387 
00388             index = j % 3;
00389             tri = &pset->triangles[ j / 3 ];
00390 
00391             outv = &out->verts[ j ];
00392 
00393             outv->st[0] = tri->texcoords[index][0];
00394             outv->st[1] = tri->texcoords[index][1];
00395 
00396             outv->lightmap[0] = 0;
00397             outv->lightmap[1] = 0;
00398 
00399             // the colors will be set by the lighting pass
00400             outv->color[0] = 255;
00401             outv->color[1] = 255;
00402             outv->color[2] = 255;
00403             outv->color[3] = 255;
00404 
00405             outv->xyz[0] = origin[0] + tri->verts[index][0];
00406             outv->xyz[1] = origin[1] + tri->verts[index][1];
00407             outv->xyz[2] = origin[2] + tri->verts[index][2];
00408 
00409             // rotate the normal
00410             outv->normal[0] = tri->normals[index][0];
00411             outv->normal[1] = tri->normals[index][1];
00412             outv->normal[2] = tri->normals[index][2];
00413         }
00414     }
00415 
00416 }

Here is the call graph for this function:

void InsertMD3Model const char *  modelName,
vec3_t  origin,
float  angle,
tree_t tree
 

Definition at line 210 of file misc_model.c.

References AllocDrawSurf(), byte, c_triangleIndexes, c_triangleModels, c_triangleSurfaces, c_triangleVertexes, drawVert_t::color, cos(), drawsurf_s::fogNum, i, md3Triangle_t::indexes, drawsurf_s::indexes, j, drawVert_t::lightmap, drawsurf_s::lightmapNum, LoadModel(), malloc(), mapDrawSurface_t, MD3_XYZ_SCALE, drawsurf_s::miscModel, md3Shader_t::name, drawVert_t::normal, md3XyzNormal_t::normal, drawsurf_s::numIndexes, md3Header_t::numSurfaces, md3Surface_t::numTriangles, md3Surface_t::numVerts, drawsurf_s::numVerts, md3Surface_t::ofsEnd, md3Surface_t::ofsShaders, md3Surface_t::ofsSt, md3Header_t::ofsSurfaces, md3Surface_t::ofsTriangles, md3Surface_t::ofsXyzNormals, Q_PI, drawsurf_s::shaderInfo, ShaderInfoForShader(), sin(), drawVert_t::st, vec3_t, drawsurf_s::verts, md3XyzNormal_t::xyz, and drawVert_t::xyz.

Referenced by AddTriangleModels().

00210                                                                                        {
00211     int                 i, j;
00212     md3Header_t         *md3;
00213     md3Surface_t        *surf;
00214     md3Shader_t         *shader;
00215     md3Triangle_t       *tri;
00216     md3St_t             *st;
00217     md3XyzNormal_t      *xyz;
00218     drawVert_t          *outv;
00219     float               lat, lng;
00220     float               angleCos, angleSin;
00221     mapDrawSurface_t    *out;
00222     vec3_t              temp;
00223 
00224     angle = angle / 180 * Q_PI;
00225     angleCos = cos( angle );
00226     angleSin = sin( angle );
00227 
00228     // load the model
00229     md3 = LoadModel( modelName );
00230     if ( !md3 ) {
00231         return;
00232     }
00233 
00234     // each md3 surface will become a new bsp surface
00235 
00236     c_triangleModels++;
00237     c_triangleSurfaces += md3->numSurfaces;
00238 
00239     // expand, translate, and rotate the vertexes
00240     // swap all the surfaces
00241     surf = (md3Surface_t *) ( (byte *)md3 + md3->ofsSurfaces );
00242     for ( i = 0 ; i < md3->numSurfaces ; i++) {
00243         // allocate a surface
00244         out = AllocDrawSurf();
00245         out->miscModel = qtrue;
00246 
00247         shader = (md3Shader_t *) ( (byte *)surf + surf->ofsShaders );
00248 
00249         out->shaderInfo = ShaderInfoForShader( shader->name );
00250 
00251         out->numVerts = surf->numVerts;
00252         out->verts = malloc( out->numVerts * sizeof( out->verts[0] ) );
00253 
00254         out->numIndexes = surf->numTriangles * 3;
00255         out->indexes = malloc( out->numIndexes * sizeof( out->indexes[0] ) );
00256 
00257         out->lightmapNum = -1;
00258         out->fogNum = -1;
00259 
00260         // emit the indexes
00261         c_triangleIndexes += surf->numTriangles * 3;
00262         tri = (md3Triangle_t *) ( (byte *)surf + surf->ofsTriangles );
00263         for ( j = 0 ; j < surf->numTriangles ; j++, tri++ ) {
00264             out->indexes[j*3+0] = tri->indexes[0];
00265             out->indexes[j*3+1] = tri->indexes[1];
00266             out->indexes[j*3+2] = tri->indexes[2];
00267         }
00268 
00269         // emit the vertexes
00270         st = (md3St_t *) ( (byte *)surf + surf->ofsSt );
00271         xyz = (md3XyzNormal_t *) ( (byte *)surf + surf->ofsXyzNormals );
00272 
00273         c_triangleVertexes += surf->numVerts;
00274         for ( j = 0 ; j < surf->numVerts ; j++, st++, xyz++ ) {
00275             outv = &out->verts[ j ];
00276 
00277             outv->st[0] = st->st[0];
00278             outv->st[1] = st->st[1];
00279 
00280             outv->lightmap[0] = 0;
00281             outv->lightmap[1] = 0;
00282 
00283             // the colors will be set by the lighting pass
00284             outv->color[0] = 255;
00285             outv->color[1] = 255;
00286             outv->color[2] = 255;
00287             outv->color[3] = 255;
00288 
00289             outv->xyz[0] = origin[0] + MD3_XYZ_SCALE * ( xyz->xyz[0] * angleCos - xyz->xyz[1] * angleSin );
00290             outv->xyz[1] = origin[1] + MD3_XYZ_SCALE * ( xyz->xyz[0] * angleSin +  xyz->xyz[1] * angleCos );
00291             outv->xyz[2] = origin[2] + MD3_XYZ_SCALE * ( xyz->xyz[2] );
00292 
00293             // decode the lat/lng normal to a 3 float normal
00294             lat = ( xyz->normal >> 8 ) & 0xff;
00295             lng = ( xyz->normal & 0xff );
00296             lat *= Q_PI/128;
00297             lng *= Q_PI/128;
00298 
00299             temp[0] = cos(lat) * sin(lng);
00300             temp[1] = sin(lat) * sin(lng);
00301             temp[2] = cos(lng);
00302 
00303             // rotate the normal
00304             outv->normal[0] = temp[0] * angleCos - temp[1] * angleSin;
00305             outv->normal[1] = temp[0] * angleSin +  temp[1] * angleCos;
00306             outv->normal[2] = temp[2];
00307         }
00308 
00309         // find the next surface
00310         surf = (md3Surface_t *)( (byte *)surf + surf->ofsEnd );
00311     }
00312 
00313 }

Here is the call graph for this function:

md3Header_t* LoadModel const char *  modelName  ) 
 

Definition at line 179 of file misc_model.c.

References Error(), loadedModel_t::header, i, loadedModel_t::modelName, numLoadedModels, R_LoadMD3(), strcmp(), and strcpy().

00179                                                 {
00180     int             i;
00181     loadedModel_t   *lm;
00182 
00183     // see if we already have it loaded
00184     for ( i = 0, lm = loadedModels ; i < numLoadedModels ; i++, lm++ ) {
00185         if ( !strcmp( modelName, lm->modelName ) ) {
00186             return lm->header;
00187         }
00188     }
00189 
00190     // load it
00191     if ( numLoadedModels == MAX_LOADED_MODELS ) {
00192         Error( "MAX_LOADED_MODELS" );
00193     }
00194     numLoadedModels++;
00195 
00196     strcpy( lm->modelName, modelName );
00197 
00198     lm->header = R_LoadMD3( modelName );
00199 
00200     return lm->header;
00201 }

Here is the call graph for this function:

md3Header_t* R_LoadMD3 const char *  mod_name  ) 
 

Definition at line 55 of file misc_model.c.

References _printf(), md3Frame_s::bounds, byte, Error(), md3Surface_t::flags, gamedir, i, md3Surface_t::ident, md3Triangle_t::indexes, j, LittleFloat(), LittleLong(), LittleShort(), LL, md3Frame_s::localOrigin, MD3_VERSION, md3Frame_t, md3XyzNormal_t::normal, md3Surface_t::numFrames, md3Surface_t::numShaders, md3Surface_t::numTriangles, md3Surface_t::numVerts, md3Surface_t::ofsEnd, md3Surface_t::ofsShaders, md3Surface_t::ofsSt, md3Surface_t::ofsTriangles, md3Surface_t::ofsXyzNormals, PakLoadAnyFile(), md3Frame_s::radius, SHADER_MAX_INDEXES, SHADER_MAX_VERTEXES, sprintf(), md3St_t::st, TryLoadFile(), and md3XyzNormal_t::xyz.

Referenced by LoadModel(), and RE_RegisterModel().

00055                                                {
00056     int                 i, j;
00057     md3Header_t         *md3;
00058     md3Frame_t          *frame;
00059     md3Surface_t        *surf;
00060     md3Triangle_t       *tri;
00061     md3St_t             *st;
00062     md3XyzNormal_t      *xyz;
00063     int                 version;
00064     char                filename[1024];
00065     int                 len;
00066 
00067     sprintf( filename, "%s%s", gamedir, mod_name );
00068     len = TryLoadFile( filename, (void **)&md3 );
00069 #ifdef _WIN32
00070   if ( len <= 0 ) {
00071     len = PakLoadAnyFile(filename, (void **)&md3);
00072   }
00073 #endif
00074     if ( len <= 0 ) {
00075       return NULL;
00076     }
00077 
00078   version = LittleLong (md3->version);
00079     if (version != MD3_VERSION) {
00080         _printf( "R_LoadMD3: %s has wrong version (%i should be %i)\n",
00081                  mod_name, version, MD3_VERSION);
00082         return NULL;
00083     }
00084 
00085     LL(md3->ident);
00086     LL(md3->version);
00087     LL(md3->numFrames);
00088     LL(md3->numTags);
00089     LL(md3->numSurfaces);
00090     LL(md3->numSkins);
00091     LL(md3->ofsFrames);
00092     LL(md3->ofsTags);
00093     LL(md3->ofsSurfaces);
00094     LL(md3->ofsEnd);
00095 
00096     if ( md3->numFrames < 1 ) {
00097         _printf( "R_LoadMD3: %s has no frames\n", mod_name );
00098         return NULL;
00099     }
00100 
00101     // we don't need to swap tags in the renderer, they aren't used
00102     
00103     // swap all the frames
00104     frame = (md3Frame_t *) ( (byte *)md3 + md3->ofsFrames );
00105     for ( i = 0 ; i < md3->numFrames ; i++, frame++) {
00106         frame->radius = LittleFloat( frame->radius );
00107         for ( j = 0 ; j < 3 ; j++ ) {
00108             frame->bounds[0][j] = LittleFloat( frame->bounds[0][j] );
00109             frame->bounds[1][j] = LittleFloat( frame->bounds[1][j] );
00110             frame->localOrigin[j] = LittleFloat( frame->localOrigin[j] );
00111         }
00112     }
00113 
00114     // swap all the surfaces
00115     surf = (md3Surface_t *) ( (byte *)md3 + md3->ofsSurfaces );
00116     for ( i = 0 ; i < md3->numSurfaces ; i++) {
00117 
00118         LL(surf->ident);
00119         LL(surf->flags);
00120         LL(surf->numFrames);
00121         LL(surf->numShaders);
00122         LL(surf->numTriangles);
00123         LL(surf->ofsTriangles);
00124         LL(surf->numVerts);
00125         LL(surf->ofsShaders);
00126         LL(surf->ofsSt);
00127         LL(surf->ofsXyzNormals);
00128         LL(surf->ofsEnd);
00129         
00130         if ( surf->numVerts > SHADER_MAX_VERTEXES ) {
00131             Error ("R_LoadMD3: %s has more than %i verts on a surface (%i)",
00132                 mod_name, SHADER_MAX_VERTEXES, surf->numVerts );
00133         }
00134         if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) {
00135             Error ("R_LoadMD3: %s has more than %i triangles on a surface (%i)",
00136                 mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles );
00137         }
00138 
00139         // swap all the triangles
00140         tri = (md3Triangle_t *) ( (byte *)surf + surf->ofsTriangles );
00141         for ( j = 0 ; j < surf->numTriangles ; j++, tri++ ) {
00142             LL(tri->indexes[0]);
00143             LL(tri->indexes[1]);
00144             LL(tri->indexes[2]);
00145         }
00146 
00147         // swap all the ST
00148         st = (md3St_t *) ( (byte *)surf + surf->ofsSt );
00149         for ( j = 0 ; j < surf->numVerts ; j++, st++ ) {
00150             st->st[0] = LittleFloat( st->st[0] );
00151             st->st[1] = LittleFloat( st->st[1] );
00152         }
00153 
00154         // swap all the XyzNormals
00155         xyz = (md3XyzNormal_t *) ( (byte *)surf + surf->ofsXyzNormals );
00156         for ( j = 0 ; j < surf->numVerts * surf->numFrames ; j++, xyz++ ) 
00157         {
00158             xyz->xyz[0] = LittleShort( xyz->xyz[0] );
00159             xyz->xyz[1] = LittleShort( xyz->xyz[1] );
00160             xyz->xyz[2] = LittleShort( xyz->xyz[2] );
00161 
00162             xyz->normal = LittleShort( xyz->normal );
00163         }
00164 
00165 
00166         // find the next surface
00167         surf = (md3Surface_t *)( (byte *)surf + surf->ofsEnd );
00168     }
00169 
00170     return md3;
00171 }

Here is the call graph for this function:


Variable Documentation

int c_triangleIndexes
 

Definition at line 42 of file misc_model.c.

Referenced by AddTriangleModels(), InsertASEModel(), and InsertMD3Model().

int c_triangleModels
 

Definition at line 39 of file misc_model.c.

Referenced by AddTriangleModels(), InsertASEModel(), and InsertMD3Model().

int c_triangleSurfaces
 

Definition at line 40 of file misc_model.c.

Referenced by AddTriangleModels(), InsertASEModel(), and InsertMD3Model().

int c_triangleVertexes
 

Definition at line 41 of file misc_model.c.

Referenced by AddTriangleModels(), InsertASEModel(), and InsertMD3Model().

loadedModel_t loadedModels[MAX_LOADED_MODELS]
 

Definition at line 46 of file misc_model.c.

int numLoadedModels
 

Definition at line 47 of file misc_model.c.

Referenced by LoadModel().


Generated on Thu Aug 25 16:59:08 2005 for Quake III Arena by  doxygen 1.3.9.1