diff --git a/Makefile b/Makefile index 5cbcab99..49950f99 100644 --- a/Makefile +++ b/Makefile @@ -1423,12 +1423,12 @@ Q3OBJ = \ $(B)/client/tr_image_tga.o \ $(B)/client/tr_image_pcx.o \ $(B)/client/tr_init.o \ - $(B)/client/tr_model_iqm.o \ $(B)/client/tr_light.o \ $(B)/client/tr_main.o \ $(B)/client/tr_marks.o \ $(B)/client/tr_mesh.o \ $(B)/client/tr_model.o \ + $(B)/client/tr_model_iqm.o \ $(B)/client/tr_noise.o \ $(B)/client/tr_scene.o \ $(B)/client/tr_shade.o \ diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index fe97ea8d..93c4bae7 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -668,6 +668,7 @@ typedef struct { // inter-quake-model surface typedef struct srfIQModel_s { surfaceType_t surfaceType; + char name[MAX_QPATH]; shader_t *shader; iqmData_t *data; int first_vertex, num_vertexes; diff --git a/code/renderer/tr_model.c b/code/renderer/tr_model.c index bb90f29c..c25c4bd2 100644 --- a/code/renderer/tr_model.c +++ b/code/renderer/tr_model.c @@ -466,12 +466,14 @@ static qboolean R_LoadMD3 (model_t *mod, int lod, void *buffer, const char *mod_ LL(surf->ofsEnd); if ( surf->numVerts > SHADER_MAX_VERTEXES ) { - ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i verts on a surface (%i)", + ri.Printf(PRINT_WARNING, "R_LoadMD3: %s has more than %i verts on a surface (%i).\n", mod_name, SHADER_MAX_VERTEXES, surf->numVerts ); + return qfalse; } if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) { - ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i triangles on a surface (%i)", + ri.Printf(PRINT_WARNING, "R_LoadMD3: %s has more than %i triangles on a surface (%i).\n", mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles ); + return qfalse; } // change to surface identifier @@ -742,13 +744,13 @@ static qboolean R_LoadMDR( model_t *mod, void *buffer, int filesize, const char // now do the checks that may fail. if ( surf->numVerts > SHADER_MAX_VERTEXES ) { - ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i verts on a surface (%i)", + ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i verts on a surface (%i).\n", mod_name, SHADER_MAX_VERTEXES, surf->numVerts ); return qfalse; } if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) { - ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i triangles on a surface (%i)", + ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i triangles on a surface (%i).\n", mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles ); return qfalse; } @@ -957,12 +959,14 @@ static qboolean R_LoadMD4( model_t *mod, void *buffer, const char *mod_name ) { LL(surf->ofsEnd); if ( surf->numVerts > SHADER_MAX_VERTEXES ) { - ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i verts on a surface (%i)", + ri.Printf(PRINT_WARNING, "R_LoadMD4: %s has more than %i verts on a surface (%i).\n", mod_name, SHADER_MAX_VERTEXES, surf->numVerts ); + return qfalse; } if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) { - ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i triangles on a surface (%i)", + ri.Printf(PRINT_WARNING, "R_LoadMD4: %s has more than %i triangles on a surface (%i).\n", mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles ); + return qfalse; } // change to surface identifier diff --git a/code/renderer/tr_model_iqm.c b/code/renderer/tr_model_iqm.c index 51d5516e..ea2a903d 100644 --- a/code/renderer/tr_model_iqm.c +++ b/code/renderer/tr_model_iqm.c @@ -193,6 +193,13 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na LL( header->num_extensions ); LL( header->ofs_extensions ); + // check ioq3 joint limit + if ( header->num_joints > IQM_MAX_JOINTS ) { + ri.Printf(PRINT_WARNING, "R_LoadIQM: %s has more than %d joints (%d).\n", + mod_name, IQM_MAX_JOINTS, header->num_joints); + return qfalse; + } + // check and swap vertex arrays if( IQM_CheckRange( header, header->ofs_vertexarrays, header->num_vertexarrays, @@ -305,7 +312,21 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na LL( mesh->num_vertexes ); LL( mesh->first_triangle ); LL( mesh->num_triangles ); - + + // check ioq3 limits + if ( mesh->num_vertexes > SHADER_MAX_VERTEXES ) + { + ri.Printf(PRINT_WARNING, "R_LoadIQM: %s has more than %i verts on a surface (%i).\n", + mod_name, SHADER_MAX_VERTEXES, mesh->num_vertexes ); + return qfalse; + } + if ( mesh->num_triangles*3 > SHADER_MAX_INDEXES ) + { + ri.Printf(PRINT_WARNING, "R_LoadIQM: %s has more than %i triangles on a surface (%i).\n", + mod_name, SHADER_MAX_INDEXES / 3, mesh->num_triangles ); + return qfalse; + } + if( mesh->first_vertex >= header->num_vertexes || mesh->first_vertex + mesh->num_vertexes > header->num_vertexes || mesh->first_triangle >= header->num_triangles || @@ -319,8 +340,7 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na } // check and swap joints - if( header->num_joints > IQM_MAX_JOINTS || - IQM_CheckRange( header, header->ofs_joints, + if( IQM_CheckRange( header, header->ofs_joints, header->num_joints, sizeof(iqmJoint_t) ) ) { return qfalse; } @@ -542,6 +562,7 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na str = (char *)header + header->ofs_text; for( i = 0; i < header->num_meshes; i++, mesh++, surface++ ) { surface->surfaceType = SF_IQM; + Q_strncpyz(surface->name, str + mesh->name, sizeof (surface->name)); surface->shader = R_FindShader( str + mesh->material, LIGHTMAP_NONE, qtrue ); if( surface->shader->defaultShader ) surface->shader = tr.defaultShader; @@ -550,7 +571,7 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na surface->num_vertexes = mesh->num_vertexes; surface->first_triangle = mesh->first_triangle; surface->num_triangles = mesh->num_triangles; - } + } // copy vertexarrays and indexes vertexarray = (iqmVertexArray_t *)((byte *)header + header->ofs_vertexarrays); @@ -734,11 +755,12 @@ Add all surfaces of this model void R_AddIQMSurfaces( trRefEntity_t *ent ) { iqmData_t *data; srfIQModel_t *surface; - int i; + int i, j; qboolean personalModel; int cull; int fogNum; shader_t *shader; + skin_t *skin; data = tr.currentModel->modelData; surface = data->surfaces; @@ -790,8 +812,21 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) { fogNum = R_ComputeIQMFogNum( data, ent ); for ( i = 0 ; i < data->num_surfaces ; i++ ) { - if( ent->e.customShader ) { + if(ent->e.customShader) shader = R_GetShaderByHandle( ent->e.customShader ); + else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) + { + skin = R_GetSkinByHandle(ent->e.customSkin); + shader = tr.defaultShader; + + for(j = 0; j < skin->numSurfaces; j++) + { + if (!strcmp(skin->surfaces[j]->name, surface->name)) + { + shader = skin->surfaces[j]->shader; + break; + } + } } else { shader = surface->shader; } @@ -816,8 +851,7 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) { } if( !personalModel ) { - R_AddDrawSurf( &surface->surfaceType, - shader, fogNum, 0 ); + R_AddDrawSurf( (void *)surface, shader, fogNum, 0 ); } surface++;